diff --git a/aqt/getshared.py b/aqt/getshared.py index d2c96437d..f4644b87d 100644 --- a/aqt/getshared.py +++ b/aqt/getshared.py @@ -222,7 +222,7 @@ Error was:
%s
""") tit = tit[0:40] if self.type == 0: # deck - dd = self.parent.documentDir + dd = self.parent.config['documentDir'] p = os.path.join(dd, tit + ".anki") if os.path.exists(p): tit += "%d" % time.time() diff --git a/aqt/main.py b/aqt/main.py index 48a178123..78c285f4f 100755 --- a/aqt/main.py +++ b/aqt/main.py @@ -24,6 +24,8 @@ from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \ config = aqt.config +## fixme: open plugin folder broken on win32? + class AnkiQt(QMainWindow): def __init__(self, app, config, args, splash): QMainWindow.__init__(self) @@ -419,7 +421,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors") if not name.endswith(".anki"): name += ".anki" break - path = os.path.join(self.documentDir, name) + path = os.path.join(self.config['documentDir'], name) if os.path.exists(path): if askUser(_("That deck already exists. Overwrite?"), defaultno=True): @@ -515,7 +517,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors") if self.deck.path: dir = os.path.dirname(self.deck.path) else: - dir = self.documentDir + dir = self.config['documentDir'] file = QFileDialog.getSaveFileName(self, title, dir, _("Deck files (*.anki)"), @@ -1191,23 +1193,25 @@ It can take a long time. Proceed?""")): def setupDocumentDir(self): if self.config['documentDir']: - self.documentDir = self.config['documentDir'] - elif sys.platform.startswith("win32"): + return + if sys.platform.startswith("win32"): s = QSettings(QSettings.UserScope, "Microsoft", "Windows") s.beginGroup("CurrentVersion/Explorer/Shell Folders") - self.documentDir = unicode(s.value("Personal").toString()) - if os.path.exists(self.documentDir): - self.documentDir = os.path.join(self.documentDir, "Anki") + d = unicode(s.value("Personal").toString()) + if os.path.exists(d): + d = os.path.join(d, "Anki") else: - self.documentDir = os.path.expanduser("~/.anki/decks") + d = os.path.expanduser("~/.anki/decks") elif sys.platform.startswith("darwin"): - self.documentDir = os.path.expanduser("~/Documents/Anki") + d = os.path.expanduser("~/Documents/Anki") else: - self.documentDir = os.path.expanduser("~/.anki/decks") + d = os.path.expanduser("~/.anki/decks") try: - os.mkdir(self.documentDir) + os.mkdir(d) except (OSError, IOError): + # already exists pass + self.config['documentDir'] = d # Proxy support ########################################################################## diff --git a/aqt/preferences.py b/aqt/preferences.py index 7e02b7dad..59f5829c8 100644 --- a/aqt/preferences.py +++ b/aqt/preferences.py @@ -6,7 +6,7 @@ import os from PyQt4.QtGui import * from PyQt4.QtCore import * from anki.lang import langs -from aqt.utils import openFolder +from aqt.utils import openFolder, showWarning import aqt class Preferences(QDialog): @@ -147,6 +147,9 @@ class Preferences(QDialog): self.form.deleteMedia.setChecked(self.config['deleteMedia']) self.form.stripHTML.setChecked(self.config['stripHTML']) self.form.autoplaySounds.setChecked(self.config['autoplaySounds']) + self.connect(self.form.documentFolder, + SIGNAL("clicked()"), + self.onChangeFolder) def updateOptions(self): self.config['suppressEstimates'] = not self.form.showEstimates.isChecked() @@ -165,3 +168,20 @@ class Preferences(QDialog): n += 1 # default to english return self.codeToIndex("en") + + def onChangeFolder(self): + d = QFileDialog(self) + d.setWindowModality(Qt.WindowModal) + d.setFileMode(QFileDialog.Directory) + d.setOption(QFileDialog.ShowDirsOnly, True) + d.setDirectory(self.config['documentDir']) + if d.exec_(): + dir = unicode(list(d.selectedFiles())[0]) + # make sure we can write into it + try: + f = os.path.join(dir, "test.txt") + open(f, "w").write("test") + os.unlink(f) + except (OSError, IOError): + return + self.config['documentDir'] = dir diff --git a/aqt/sync.py b/aqt/sync.py index e36acb687..29486494b 100755 --- a/aqt/sync.py +++ b/aqt/sync.py @@ -160,7 +160,7 @@ Are you sure?""" % deckName), elif self.loadAfterSync and self.deckPath: if self.loadAfterSync == 2: name = re.sub("[<>]", "", self.syncName) - p = os.path.join(self.documentDir, name + ".anki") + p = os.path.join(self.config['documentDir'], name + ".anki") shutil.copy2(self.deckPath, p) self.deckPath = p # since we've moved the deck, we have to set sync path @@ -196,7 +196,7 @@ Are you sure?""" % deckName), self.syncName = name if name: # name chosen - p = os.path.join(self.documentDir, name + ".anki") + p = os.path.join(self.config['documentDir'], name + ".anki") if os.path.exists(p): d = askUserDialog(_("""\ This deck already exists on your computer. Overwrite the local copy?"""), diff --git a/designer/preferences.ui b/designer/preferences.ui index f2eb6f7c1..4a3172261 100644 --- a/designer/preferences.ui +++ b/designer/preferences.ui @@ -453,6 +453,16 @@ + + + + Change document folder... + + + false + + + @@ -513,6 +523,7 @@ stripHTML openLastDeck deleteMedia + documentFolder buttonBox