mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00

Because Qt translations need to be initialized before any widgets are created, and because the Qt language needs to match the gettext language in order for translated shortcuts to work, per-profile language settings aren't possible. So instead of storing the language in the profile, we use pm.meta['defaultLang'] for all profiles and initialize language handling in __init__.py The language selection in the preferences has been removed, because in a school setting a student fiddling with the language could potentially cause other students to be unable to navigate the UI. Instead, Anki will accept -l/--lang passed on the command line to override the original language chosen at first program startup.
148 lines
5.1 KiB
Python
148 lines
5.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import datetime, time, os
|
|
from aqt.qt import *
|
|
from aqt.utils import openFolder, showWarning, getText, openHelp
|
|
import aqt
|
|
|
|
class Preferences(QDialog):
|
|
|
|
def __init__(self, mw):
|
|
QDialog.__init__(self, mw, Qt.Window)
|
|
self.mw = mw
|
|
self.prof = self.mw.pm.profile
|
|
self.form = aqt.forms.preferences.Ui_Preferences()
|
|
self.form.setupUi(self)
|
|
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
|
|
lambda: openHelp("profileprefs"))
|
|
self.setupCollection()
|
|
self.setupNetwork()
|
|
self.setupBackup()
|
|
self.setupOptions()
|
|
self.show()
|
|
|
|
def accept(self):
|
|
self.updateCollection()
|
|
self.updateNetwork()
|
|
self.updateBackup()
|
|
self.updateOptions()
|
|
self.mw.pm.save()
|
|
self.mw.reset()
|
|
self.done(0)
|
|
|
|
def reject(self):
|
|
self.accept()
|
|
|
|
# Collection options
|
|
######################################################################
|
|
|
|
def setupCollection(self):
|
|
import anki.consts as c
|
|
f = self.form
|
|
qc = self.mw.col.conf
|
|
self.startDate = datetime.datetime.fromtimestamp(self.mw.col.crt)
|
|
f.dayOffset.setValue(self.startDate.hour)
|
|
f.lrnCutoff.setValue(qc['collapseTime']/60.0)
|
|
f.timeLimit.setValue(qc['timeLim']/60.0)
|
|
f.showEstimates.setChecked(qc['estTimes'])
|
|
f.showProgress.setChecked(qc['dueCounts'])
|
|
f.newSpread.addItems(c.newCardSchedulingLabels().values())
|
|
f.newSpread.setCurrentIndex(qc['newSpread'])
|
|
|
|
def updateCollection(self):
|
|
f = self.form
|
|
d = self.mw.col
|
|
qc = d.conf
|
|
qc['dueCounts'] = f.showProgress.isChecked()
|
|
qc['estTimes'] = f.showEstimates.isChecked()
|
|
qc['newSpread'] = f.newSpread.currentIndex()
|
|
qc['timeLim'] = f.timeLimit.value()*60
|
|
qc['collapseTime'] = f.lrnCutoff.value()*60
|
|
hrs = f.dayOffset.value()
|
|
old = self.startDate
|
|
date = datetime.datetime(
|
|
old.year, old.month, old.day, hrs)
|
|
d.crt = int(time.mktime(date.timetuple()))
|
|
d.setMod()
|
|
|
|
# Network
|
|
######################################################################
|
|
|
|
def setupNetwork(self):
|
|
self.form.syncOnProgramOpen.setChecked(
|
|
self.prof['autoSync'])
|
|
self.form.syncMedia.setChecked(
|
|
self.prof['syncMedia'])
|
|
if not self.prof['syncKey']:
|
|
self._hideAuth()
|
|
else:
|
|
self.connect(self.form.syncDeauth, SIGNAL("clicked()"),
|
|
self.onSyncDeauth)
|
|
self.form.proxyHost.setText(self.prof['proxyHost'])
|
|
self.form.proxyPort.setValue(self.prof['proxyPort'])
|
|
self.form.proxyUser.setText(self.prof['proxyUser'])
|
|
self.form.proxyPass.setText(self.prof['proxyPass'])
|
|
|
|
def _hideAuth(self):
|
|
self.form.syncDeauth.setShown(False)
|
|
self.form.syncLabel.setText(_("""\
|
|
<b>Synchronization</b><br>
|
|
Not currently enabled; click the sync button in the main window to enable."""))
|
|
|
|
def onSyncDeauth(self):
|
|
self.prof['syncKey'] = None
|
|
self._hideAuth()
|
|
|
|
def updateNetwork(self):
|
|
self.prof['autoSync'] = self.form.syncOnProgramOpen.isChecked()
|
|
self.prof['syncMedia'] = self.form.syncMedia.isChecked()
|
|
self.prof['proxyHost'] = unicode(self.form.proxyHost.text())
|
|
self.prof['proxyPort'] = int(self.form.proxyPort.value())
|
|
self.prof['proxyUser'] = unicode(self.form.proxyUser.text())
|
|
self.prof['proxyPass'] = unicode(self.form.proxyPass.text())
|
|
|
|
# Backup
|
|
######################################################################
|
|
|
|
def setupBackup(self):
|
|
self.form.numBackups.setValue(self.prof['numBackups'])
|
|
self.connect(self.form.openBackupFolder,
|
|
SIGNAL("linkActivated(QString)"),
|
|
self.onOpenBackup)
|
|
|
|
def onOpenBackup(self):
|
|
openFolder(self.mw.pm.backupFolder())
|
|
|
|
def updateBackup(self):
|
|
self.prof['numBackups'] = self.form.numBackups.value()
|
|
|
|
# Basic & Advanced Options
|
|
######################################################################
|
|
|
|
def setupOptions(self):
|
|
self.form.deleteMedia.setChecked(self.prof['deleteMedia'])
|
|
self.form.stripHTML.setChecked(self.prof['stripHTML'])
|
|
self.connect(
|
|
self.form.profilePass, SIGNAL("clicked()"),
|
|
self.onProfilePass)
|
|
|
|
def updateOptions(self):
|
|
self.prof['stripHTML'] = self.form.stripHTML.isChecked()
|
|
self.prof['deleteMedia'] = self.form.deleteMedia.isChecked()
|
|
|
|
def onProfilePass(self):
|
|
pw, ret = getText(_("""\
|
|
Lock account with password, or leave blank:"""))
|
|
if not ret:
|
|
return
|
|
if not pw:
|
|
self.prof['key'] = None
|
|
return
|
|
pw2, ret = getText(_("Confirm password:"))
|
|
if not ret:
|
|
return
|
|
if pw != pw2:
|
|
showWarning(_("Passwords didn't match"))
|
|
self.prof['key'] = self.mw.pm._pwhash(pw)
|