mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
allow non-latin chars in profile names
This commit is contained in:
parent
35b366872b
commit
c3c9156fdb
3 changed files with 24 additions and 13 deletions
|
@ -39,7 +39,7 @@ _html = """
|
|||
.fname { font-size: 10px; vertical-align: middle; padding: 0;
|
||||
font-family: "%s"; }
|
||||
#dupes { font-size: 12px; }
|
||||
img { max-width: 100%%; max-height: 90%%; }
|
||||
img { max-width: 100%%; }
|
||||
body { margin: 5px; }
|
||||
</style><script>
|
||||
%s
|
||||
|
|
19
aqt/main.py
19
aqt/main.py
|
@ -138,14 +138,22 @@ class AnkiQt(QMainWindow):
|
|||
self.loadProfile()
|
||||
return True
|
||||
|
||||
def profileNameOk(self, str):
|
||||
from anki.utils import invalidFilename, invalidFilenameChars
|
||||
if invalidFilename(str):
|
||||
showWarning(
|
||||
_("A profile name cannot contain these characters: %s") %
|
||||
" ".join(invalidFilenameChars))
|
||||
return
|
||||
return True
|
||||
|
||||
def onAddProfile(self):
|
||||
name = getOnlyText(_("Name:"))
|
||||
if name:
|
||||
if name in self.pm.profiles():
|
||||
return showWarning(_("Name exists."))
|
||||
if not re.match("^[A-Za-z0-9 ]+$", name):
|
||||
return showWarning(
|
||||
_("Only numbers, letters and spaces can be used."))
|
||||
if not self.profileNameOk(name):
|
||||
return
|
||||
self.pm.create(name)
|
||||
self.refreshProfilesList()
|
||||
|
||||
|
@ -159,9 +167,8 @@ class AnkiQt(QMainWindow):
|
|||
return
|
||||
if name in self.pm.profiles():
|
||||
return showWarning(_("Name exists."))
|
||||
if not re.match("^[A-Za-z0-9 ]+$", name):
|
||||
return showWarning(
|
||||
_("Only numbers, letters and spaces can be used."))
|
||||
if not self.profileNameOk(name):
|
||||
return
|
||||
self.pm.rename(name)
|
||||
self.refreshProfilesList()
|
||||
|
||||
|
|
|
@ -119,12 +119,14 @@ computer."""))
|
|||
|
||||
def profiles(self):
|
||||
return sorted(
|
||||
x for x in self.db.list("select name from profiles")
|
||||
unicode(x, "utf8") for x in
|
||||
self.db.list("select name from profiles")
|
||||
if x != "_global")
|
||||
|
||||
def load(self, name, passwd=None):
|
||||
prof = cPickle.loads(
|
||||
self.db.scalar("select data from profiles where name = ?", name))
|
||||
self.db.scalar("select data from profiles where name = ?",
|
||||
name.encode("utf8")))
|
||||
if prof['key'] and prof['key'] != self._pwhash(passwd):
|
||||
self.name = None
|
||||
return False
|
||||
|
@ -135,26 +137,28 @@ computer."""))
|
|||
|
||||
def save(self):
|
||||
sql = "update profiles set data = ? where name = ?"
|
||||
self.db.execute(sql, cPickle.dumps(self.profile), self.name)
|
||||
self.db.execute(sql, cPickle.dumps(self.profile),
|
||||
self.name.encode("utf8"))
|
||||
self.db.execute(sql, cPickle.dumps(self.meta), "_global")
|
||||
self.db.commit()
|
||||
|
||||
def create(self, name):
|
||||
prof = profileConf.copy()
|
||||
self.db.execute("insert into profiles values (?, ?)",
|
||||
name, cPickle.dumps(prof))
|
||||
name.encode("utf8"), cPickle.dumps(prof))
|
||||
self.db.commit()
|
||||
|
||||
def remove(self, name):
|
||||
shutil.rmtree(self.profileFolder())
|
||||
self.db.execute("delete from profiles where name = ?", name)
|
||||
self.db.execute("delete from profiles where name = ?",
|
||||
name.encode("utf8"))
|
||||
self.db.commit()
|
||||
|
||||
def rename(self, name):
|
||||
oldFolder = self.profileFolder()
|
||||
# update name
|
||||
self.db.execute("update profiles set name = ? where name = ?",
|
||||
name, self.name)
|
||||
name.encode("utf8"), self.name.encode("utf-8"))
|
||||
# rename folder
|
||||
self.name = name
|
||||
newFolder = self.profileFolder()
|
||||
|
|
Loading…
Reference in a new issue