implement full sync uploading

This commit is contained in:
Damien Elmes 2009-05-31 01:24:42 +09:00
parent 7a4855233b
commit 619d2bcbaf
2 changed files with 57 additions and 19 deletions

View file

@ -1787,6 +1787,9 @@ it to your friends.
self.connect(self.syncThread, SIGNAL("closeSyncProgress"), self.closeSyncProgress)
self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress)
self.connect(self.syncThread, SIGNAL("bulkSyncFailed"), self.bulkSyncFailed)
self.connect(self.syncThread, SIGNAL("fullSyncStarted"), self.fullSyncStarted)
self.connect(self.syncThread, SIGNAL("fullSyncFinished"), self.fullSyncFinished)
self.connect(self.syncThread, SIGNAL("fullSyncProgress"), self.fullSyncProgress)
self.syncThread.start()
self.switchToWelcomeScreen()
self.setEnabled(False)
@ -1887,6 +1890,20 @@ Couldn't contact Anki Online. Please check your internet connection.""")
ui.utils.showWarning(_(
"Failed to upload media. Please run 'check media db'."), self)
def fullSyncStarted(self, ret):
self.startProgress(max=ret[2])
if ret[0] == "fromLocal":
s = _("Uploading to server...")
else:
s = _("Downloading from server...")
self.updateProgress(label=s)
def fullSyncFinished(self):
self.finishProgress()
def fullSyncProgress(self, val):
self.updateProgress(value=val)
# Menu, title bar & status
##########################################################################

View file

@ -7,10 +7,11 @@ import os, types, socket, time, traceback
import ankiqt
import anki
from anki.sync import SyncClient, HttpSyncServerProxy, BulkMediaSyncerProxy
from anki.sync import BulkMediaSyncer
from anki.sync import BulkMediaSyncer, SYNC_HOST, SYNC_PORT
from anki.errors import *
from anki import DeckStorage
import ankiqt.forms
from anki.hooks import addHook, removeHook
# Synchronising a deck with a public server
##########################################################################
@ -28,12 +29,27 @@ class Sync(QThread):
self.ok = True
self.onlyMerge = onlyMerge
self.sourcesToCheck = sourcesToCheck
addHook('fullSyncStarted', self.fullSyncStarted)
addHook('fullSyncFinished', self.fullSyncFinished)
addHook('fullSyncProgress', self.fullSyncProgress)
def setStatus(self, msg, timeout=5000):
self.emit(SIGNAL("setStatus"), msg, timeout)
def run(self):
self.syncDeck()
removeHook('fullSyncStarted', self.fullSyncStarted)
removeHook('fullSyncFinished', self.fullSyncFinished)
removeHook('fullSyncProgress', self.fullSyncProgress)
def fullSyncStarted(self, ret):
self.emit(SIGNAL("fullSyncStarted"), ret)
def fullSyncFinished(self):
self.emit(SIGNAL("fullSyncFinished"))
def fullSyncProgress(self, val):
self.emit(SIGNAL("fullSyncProgress"), val)
def error(self, error):
if getattr(error, 'data', None) is None:
@ -101,6 +117,11 @@ class Sync(QThread):
# summary
self.setStatus(_("Fetching summary from server..."), 0)
sums = client.summaries()
if client.needFullSync(sums):
self.setStatus(_("Preparing full sync..."), 0)
client.fullSync()
self.setStatus(_("Sync complete."), 0)
else:
# diff
self.setStatus(_("Determining differences..."), 0)
payload = client.genPayload(sums)