From 0060dc553ab864ede2376efb1c6c8f676f74d3b3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 16 Oct 2008 03:06:36 +0900 Subject: [PATCH] bulk media updater --- ankiqt/ui/main.py | 20 ++++++++++++++++++++ ankiqt/ui/sync.py | 19 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 6535680d1..39952fb91 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1093,6 +1093,9 @@ class AnkiQt(QMainWindow): self.connect(self.syncThread, SIGNAL("syncClockOff"), self.syncClockOff) self.connect(self.syncThread, SIGNAL("cleanNewDeck"), self.cleanNewDeck) self.connect(self.syncThread, SIGNAL("syncFinished"), self.syncFinished) + self.connect(self.syncThread, SIGNAL("openSyncProgress"), self.openSyncProgress) + self.connect(self.syncThread, SIGNAL("closeSyncProgress"), self.closeSyncProgress) + self.connect(self.syncThread, SIGNAL("updateSyncProgress"), self.updateSyncProgress) self.syncThread.start() self.setEnabled(False) while not self.syncThread.isFinished(): @@ -1149,6 +1152,23 @@ class AnkiQt(QMainWindow): ui.utils.showWarning(text, self) self.setStatus("") + def openSyncProgress(self): + self.syncProgressDialog = QProgressDialog(_("Syncing Media.."), + "", 0, 0, self) + self.syncProgressDialog.setCancelButton(None) + + def closeSyncProgress(self): + self.syncProgressDialog.cancel() + + def updateSyncProgress(self, args): + (type, x, y, fname) = args + self.syncProgressDialog.setMaximum(y) + self.syncProgressDialog.setValue(x) + if type == "up": + self.syncProgressDialog.setLabelText("Uploading %s.." % fname) + else: + self.syncProgressDialog.setLabelText("Downloading %s.." % fname) + # Menu, title bar & status ########################################################################## diff --git a/ankiqt/ui/sync.py b/ankiqt/ui/sync.py index 84de30afe..761a7f0c1 100644 --- a/ankiqt/ui/sync.py +++ b/ankiqt/ui/sync.py @@ -6,7 +6,8 @@ from PyQt4.QtCore import * import os, types, socket, time, traceback import ankiqt import anki -from anki.sync import SyncClient, HttpSyncServerProxy +from anki.sync import SyncClient, HttpSyncServerProxy, BulkMediaSyncerProxy +from anki.sync import BulkMediaSyncer from anki.errors import * from anki import DeckStorage import ankiqt.forms @@ -107,6 +108,10 @@ class Sync(QThread): # apply reply self.setStatus(_("Applying reply.."), 0) client.applyPayloadReply(res) + # bulk update? + if not client.bundleMedia: + # need to load bulk media fetcher now + self.doBulkDownload() # finished. save deck, preserving mod time self.setStatus(_("Sync complete.")) self.deck.lastLoaded = self.deck.modified @@ -151,6 +156,18 @@ class Sync(QThread): time.sleep(3) self.emit(SIGNAL("syncFinished")) + def doBulkDownload(self): + self.emit(SIGNAL("openSyncProgress")) + client = BulkMediaSyncer(self.deck) + client.server = BulkMediaSyncerProxy(self.user, self.pwd) + client.server.deckName = self.parent.syncName + client.progressCallback = self.bulkCallback + client.sync() + self.emit(SIGNAL("closeSyncProgress")) + + def bulkCallback(self, *args): + self.emit(SIGNAL("updateSyncProgress"), args) + # Choosing a deck to sync to ##########################################################################