update check media db dialog, add accelerators to some advanced menu items

This commit is contained in:
Damien Elmes 2010-12-11 01:48:28 +09:00
parent f17eb0a836
commit 451b77cd46
3 changed files with 50 additions and 36 deletions

View file

@ -3026,32 +3026,43 @@ Proceed?""")):
mb.setWindowTitle(_("Anki")) mb.setWindowTitle(_("Anki"))
mb.setIcon(QMessageBox.Warning) mb.setIcon(QMessageBox.Warning)
mb.setText(_("""\ mb.setText(_("""\
This operation:<br> This operation looks through the content of your cards for media, and \
- deletes files not referenced by cards<br> registers it so that it can be used with the online and mobile clients.
- either tags cards, or deletes references to missing files<br>
- renames files to a string of numbers and letters<br> If you choose Scan+Delete, any media in your media folder that is not \
- updates checksums for files which have been changed<br> used by cards will be deleted. Please note that media is only \
<br> counted as used if it appears on the question or answer of a card. If \
<b>This operation is not undoable.</b><br> media is in a field that is not on your cards, the media will \
Consider backing up your media directory first.""")) be deleted, and there is no way to undo this. Please make a backup if in \
bTag = QPushButton(_("Tag Cards")) doubt."""))
mb.addButton(bTag, QMessageBox.RejectRole) bScan = QPushButton(_("Scan"))
bDelete = QPushButton(_("Delete Refs")) mb.addButton(bScan, QMessageBox.RejectRole)
bDelete = QPushButton(_("Scan+Delete"))
mb.addButton(bDelete, QMessageBox.RejectRole) mb.addButton(bDelete, QMessageBox.RejectRole)
bCancel = QPushButton(_("Cancel")) bCancel = QPushButton(_("Cancel"))
mb.addButton(bCancel, QMessageBox.RejectRole) mb.addButton(bCancel, QMessageBox.RejectRole)
mb.exec_() mb.exec_()
if mb.clickedButton() == bTag: if mb.clickedButton() == bScan:
(missing, unused) = rebuildMediaDir(self.deck, False) delete = False
elif mb.clickedButton() == bDelete: elif mb.clickedButton() == bDelete:
(missing, unused) = rebuildMediaDir(self.deck, True) delete = True
else: else:
return return
ui.utils.showInfo( (have, nohave, unused) = rebuildMediaDir(self.deck, delete=delete)
ngettext("%d missing reference.", "%d missing references.", # generate report
missing) % missing + "\n" + report = ngettext("%d media in use.", "%d media in use.", have) % have
ngettext("%d unused file removed.", "%d unused files removed.", if nohave:
unused) % unused) 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): def onDownloadMissingMedia(self):
res = downloadMissing(self.deck) res = downloadMissing(self.deck)

View file

@ -40,23 +40,26 @@ def showInfo(text, parent=None, help="", func=None):
else: else:
break break
def showText(text, parent=None): def showText(txt, parent=None, type="text"):
if not parent: if not parent:
parent = ankiqt.mw parent = ankiqt.mw
d = QDialog(parent) diag = QDialog(parent)
d.setWindowTitle("Anki") diag.setWindowTitle("Anki")
v = QVBoxLayout() layout = QVBoxLayout(diag)
l = QLabel(text) diag.setLayout(layout)
l.setWordWrap(True) text = QTextEdit()
l.setTextInteractionFlags(Qt.TextSelectableByMouse) text.setReadOnly(True)
v.addWidget(l) if type == "text":
buts = QDialogButtonBox.Ok text.setPlainText(txt)
b = QDialogButtonBox(buts) else:
v.addWidget(b) text.setHtml(txt)
d.setLayout(v) layout.addWidget(text)
d.connect(b.button(QDialogButtonBox.Ok), box = QDialogButtonBox(QDialogButtonBox.Close)
SIGNAL("clicked()"), d.accept) layout.addWidget(box)
d.exec_() diag.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()"))
diag.setMinimumHeight(400)
diag.setMinimumWidth(500)
diag.exec_()
def askUser(text, parent=None, help=""): def askUser(text, parent=None, help=""):
"Show a yes/no question. Return true if yes." "Show a yes/no question. Return true if yes."

View file

@ -3518,7 +3518,7 @@
<normaloff>:/icons/text-speak.png</normaloff>:/icons/text-speak.png</iconset> <normaloff>:/icons/text-speak.png</normaloff>:/icons/text-speak.png</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Check Media Database...</string> <string>Check &amp;Media Database...</string>
</property> </property>
<property name="statusTip"> <property name="statusTip">
<string>Check the files in the media directory</string> <string>Check the files in the media directory</string>
@ -3689,7 +3689,7 @@
<normaloff>:/icons/sqlitebrowser.png</normaloff>:/icons/sqlitebrowser.png</iconset> <normaloff>:/icons/sqlitebrowser.png</normaloff>:/icons/sqlitebrowser.png</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Check Database...</string> <string>&amp;Check Database...</string>
</property> </property>
</action> </action>
<action name="actionOpenRecent"> <action name="actionOpenRecent">