From 451b77cd46623d0f082bc94ef2c7a3b1b979131d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 11 Dec 2010 01:48:28 +0900 Subject: [PATCH] update check media db dialog, add accelerators to some advanced menu items --- ankiqt/ui/main.py | 49 ++++++++++++++++++++++++++++------------------ ankiqt/ui/utils.py | 33 +++++++++++++++++-------------- designer/main.ui | 4 ++-- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index b7d2810e9..c8cd84762 100755 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -3026,32 +3026,43 @@ Proceed?""")): mb.setWindowTitle(_("Anki")) mb.setIcon(QMessageBox.Warning) mb.setText(_("""\ -This operation:
- - deletes files not referenced by cards
- - either tags cards, or deletes references to missing files
- - renames files to a string of numbers and letters
- - updates checksums for files which have been changed
-
-This operation is not undoable.
-Consider backing up your media directory first.""")) - bTag = QPushButton(_("Tag Cards")) - mb.addButton(bTag, QMessageBox.RejectRole) - bDelete = QPushButton(_("Delete Refs")) +This operation looks through the content of your cards for media, and \ +registers it so that it can be used with the online and mobile clients. + +If you choose Scan+Delete, any media in your media folder that is not \ +used by cards will be deleted. Please note that media is only \ +counted as used if it appears on the question or answer of a card. If \ +media is in a field that is not on your cards, the media will \ +be deleted, and there is no way to undo this. Please make a backup if in \ +doubt.""")) + bScan = QPushButton(_("Scan")) + mb.addButton(bScan, QMessageBox.RejectRole) + bDelete = QPushButton(_("Scan+Delete")) mb.addButton(bDelete, QMessageBox.RejectRole) bCancel = QPushButton(_("Cancel")) mb.addButton(bCancel, QMessageBox.RejectRole) mb.exec_() - if mb.clickedButton() == bTag: - (missing, unused) = rebuildMediaDir(self.deck, False) + if mb.clickedButton() == bScan: + delete = False elif mb.clickedButton() == bDelete: - (missing, unused) = rebuildMediaDir(self.deck, True) + delete = True else: return - ui.utils.showInfo( - ngettext("%d missing reference.", "%d missing references.", - missing) % missing + "\n" + - ngettext("%d unused file removed.", "%d unused files removed.", - unused) % unused) + (have, nohave, unused) = rebuildMediaDir(self.deck, delete=delete) + # generate report + report = ngettext("%d media in use.", "%d media in use.", have) % have + if nohave: + report += "\n\n" + _( + "Used on cards but missing from media folder:") + report += "\n" + "\n".join(nohave) + if unused: + if delete: + report += "\n\n" + _("Deleted unused:") + else: + report += "\n\n" + _( + "In media folder but not used by any cards:") + report += "\n" + "\n".join(unused) + ui.utils.showText(report, parent=self, type="text") def onDownloadMissingMedia(self): res = downloadMissing(self.deck) diff --git a/ankiqt/ui/utils.py b/ankiqt/ui/utils.py index 97742eb2b..8805e89b5 100644 --- a/ankiqt/ui/utils.py +++ b/ankiqt/ui/utils.py @@ -40,23 +40,26 @@ def showInfo(text, parent=None, help="", func=None): else: break -def showText(text, parent=None): +def showText(txt, parent=None, type="text"): if not parent: parent = ankiqt.mw - d = QDialog(parent) - d.setWindowTitle("Anki") - v = QVBoxLayout() - l = QLabel(text) - l.setWordWrap(True) - l.setTextInteractionFlags(Qt.TextSelectableByMouse) - v.addWidget(l) - buts = QDialogButtonBox.Ok - b = QDialogButtonBox(buts) - v.addWidget(b) - d.setLayout(v) - d.connect(b.button(QDialogButtonBox.Ok), - SIGNAL("clicked()"), d.accept) - d.exec_() + diag = QDialog(parent) + diag.setWindowTitle("Anki") + layout = QVBoxLayout(diag) + diag.setLayout(layout) + text = QTextEdit() + text.setReadOnly(True) + if type == "text": + text.setPlainText(txt) + else: + text.setHtml(txt) + layout.addWidget(text) + box = QDialogButtonBox(QDialogButtonBox.Close) + layout.addWidget(box) + diag.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) + diag.setMinimumHeight(400) + diag.setMinimumWidth(500) + diag.exec_() def askUser(text, parent=None, help=""): "Show a yes/no question. Return true if yes." diff --git a/designer/main.ui b/designer/main.ui index 6074019d4..35451e677 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -3518,7 +3518,7 @@ :/icons/text-speak.png:/icons/text-speak.png - Check Media Database... + Check &Media Database... Check the files in the media directory @@ -3689,7 +3689,7 @@ :/icons/sqlitebrowser.png:/icons/sqlitebrowser.png - Check Database... + &Check Database...