diff --git a/anki/media.py b/anki/media.py index 7493964b1..b0b6d1c83 100644 --- a/anki/media.py +++ b/anki/media.py @@ -439,6 +439,10 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0); return self.db.scalar( "select count() from media where csum is not null") + def dirtyCount(self): + return self.db.scalar( + "select count() from media where dirty=1") + def forceResync(self): self.db.execute("delete from media") self.db.execute("update meta set lastUsn=0,dirMod=0") diff --git a/anki/sync.py b/anki/sync.py index 06939f1d1..ded617279 100644 --- a/anki/sync.py +++ b/anki/sync.py @@ -14,6 +14,7 @@ from anki.utils import ids2str, intTime, json, isWin, isMac, platDesc, checksum from anki.consts import * from hooks import runHook import anki +from lang import ngettext # syncing vars HTTP_TIMEOUT = 90 @@ -789,11 +790,16 @@ class MediaSyncer(object): # and we need to send our own updateConflict = False + toSend = self.col.media.dirtyCount() while True: zip, fnames = self.col.media.mediaChangesZip() if not fnames: break + runHook("syncMsg", ngettext( + "%d media change to upload", "%d media changes to upload", toSend) + % toSend) + processedCnt, serverLastUsn = self.server.uploadChanges(zip) self.col.media.markClean(fnames[0:processedCnt]) @@ -811,6 +817,8 @@ class MediaSyncer(object): self.col.media.db.commit() updateConflict = True + toSend -= processedCnt + if updateConflict: self.col.log("restart sync due to concurrent update") return self.sync() @@ -826,6 +834,11 @@ class MediaSyncer(object): def _downloadFiles(self, fnames): self.col.log("%d files to fetch"%len(fnames)) while fnames: + n = len(fnames) + runHook("syncMsg", ngettext( + "%d media file to download", "%d media files to download", n) + % n) + top = fnames[0:SYNC_ZIP_COUNT] self.col.log("fetch %s"%top) zipData = self.server.downloadFiles(files=top) diff --git a/aqt/sync.py b/aqt/sync.py index f56482266..e3bc5d517 100644 --- a/aqt/sync.py +++ b/aqt/sync.py @@ -116,6 +116,9 @@ Please visit AnkiWeb, upgrade your deck, then try again.""")) if m: self.label = m self._updateLabel() + elif evt == "syncMsg": + self.label = args[0] + self._updateLabel() elif evt == "error": self._didError = True showText(_("Syncing failed:\n%s")% @@ -296,6 +299,8 @@ class SyncThread(QThread): self.byteUpdate = time.time() def syncEvent(type): self.fireEvent("sync", type) + def syncMsg(msg): + self.fireEvent("syncMsg", msg) def canPost(): if (time.time() - self.byteUpdate) > 0.1: self.byteUpdate = time.time() @@ -309,6 +314,7 @@ class SyncThread(QThread): if canPost(): self.fireEvent("recv", self.recvTotal) addHook("sync", syncEvent) + addHook("syncMsg", syncMsg) addHook("httpSend", sendEvent) addHook("httpRecv", recvEvent) # run sync and catch any errors @@ -323,6 +329,7 @@ class SyncThread(QThread): # don't bump mod time unless we explicitly save self.col.close(save=False) remHook("sync", syncEvent) + remHook("syncMsg", syncMsg) remHook("httpSend", sendEvent) remHook("httpRecv", recvEvent)