syncOpen/close into single setting, add option to disable syncName check

This commit is contained in:
Damien Elmes 2010-12-04 13:21:24 +09:00
parent e2b42e0d8d
commit 798b35d474
4 changed files with 36 additions and 68 deletions

View file

@ -97,10 +97,9 @@ class Config(dict):
'studyOptionsScreen': 0, 'studyOptionsScreen': 0,
'suppressEstimates': False, 'suppressEstimates': False,
'suppressUpdate': False, 'suppressUpdate': False,
'syncDisableWhenMoved': True,
'syncInMsgBox': False, 'syncInMsgBox': False,
'syncOnClose': False,
'syncOnLoad': False, 'syncOnLoad': False,
'syncOnProgramClose': True,
'syncOnProgramOpen': True, 'syncOnProgramOpen': True,
'syncPassword': "", 'syncPassword': "",
'syncUsername': "", 'syncUsername': "",

View file

@ -56,6 +56,7 @@ class AnkiQt(QMainWindow):
self.setupSystemHacks() self.setupSystemHacks()
self.setupSound() self.setupSound()
self.setupTray() self.setupTray()
self.setupSync()
self.connectMenuActions() self.connectMenuActions()
ui.splash.update() ui.splash.update()
self.setupViews() self.setupViews()
@ -872,7 +873,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
if self.deck.modifiedSinceSave(): if self.deck.modifiedSinceSave():
if (self.deck.path is None or if (self.deck.path is None or
(not self.config['saveOnClose'] and (not self.config['saveOnClose'] and
not self.config['syncOnClose'])): not self.config['syncOnLoad'])):
# backed in memory or autosave/sync off, must confirm # backed in memory or autosave/sync off, must confirm
while 1: while 1:
res = ui.unsaved.ask(parent) res = ui.unsaved.ask(parent)
@ -885,7 +886,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
else: else:
break break
# auto sync (saving automatically) # auto sync (saving automatically)
if self.config['syncOnClose'] and self.deck.syncName: if self.config['syncOnLoad'] and self.deck.syncName:
# force save, the user may not have set passwd/etc # force save, the user may not have set passwd/etc
self.deck.save() self.deck.save()
if self.syncDeck(False, reload=False): if self.syncDeck(False, reload=False):
@ -896,7 +897,7 @@ Debug info:\n%s""") % traceback.format_exc(), help="DeckErrors")
self.hideWelcome = False self.hideWelcome = False
return True return True
# auto save # auto save
if self.config['saveOnClose'] or self.config['syncOnClose']: if self.config['saveOnClose'] or self.config['syncOnLoad']:
if self.deck: if self.deck:
self.save() self.save()
# close if the deck wasn't already closed by a failed sync # close if the deck wasn't already closed by a failed sync
@ -1423,7 +1424,7 @@ later by using File>Close.
if not self.saveAndClose(hideWelcome=True): if not self.saveAndClose(hideWelcome=True):
event.ignore() event.ignore()
else: else:
if self.config['syncOnProgramClose']: if self.config['syncOnProgramOpen']:
self.hideWelcome = True self.hideWelcome = True
self.syncDeck(interactive=False) self.syncDeck(interactive=False)
self.prepareForExit() self.prepareForExit()
@ -2146,6 +2147,10 @@ it to your friends.
# Syncing # Syncing
########################################################################## ##########################################################################
def setupSync(self):
if not self.config['syncDisableWhenMoved']:
anki.deck.Deck.checkSyncHash = lambda self: True
def syncDeck(self, interactive=True, onlyMerge=False, reload=True): def syncDeck(self, interactive=True, onlyMerge=False, reload=True):
"Synchronise a deck with the server." "Synchronise a deck with the server."
if not self.inMainWindow() and interactive and interactive!=-1: return if not self.inMainWindow() and interactive and interactive!=-1: return

View file

@ -101,9 +101,8 @@ class Preferences(QDialog):
def setupNetwork(self): def setupNetwork(self):
self.dialog.syncOnOpen.setChecked(self.config['syncOnLoad']) self.dialog.syncOnOpen.setChecked(self.config['syncOnLoad'])
self.dialog.syncOnClose.setChecked(self.config['syncOnClose'])
self.dialog.syncOnProgramOpen.setChecked(self.config['syncOnProgramOpen']) self.dialog.syncOnProgramOpen.setChecked(self.config['syncOnProgramOpen'])
self.dialog.syncOnProgramClose.setChecked(self.config['syncOnProgramClose']) self.dialog.disableWhenMoved.setChecked(self.config['syncDisableWhenMoved'])
self.dialog.syncUser.setText(self.config['syncUsername']) self.dialog.syncUser.setText(self.config['syncUsername'])
self.dialog.syncPass.setText(self.config['syncPassword']) self.dialog.syncPass.setText(self.config['syncPassword'])
self.dialog.proxyHost.setText(self.config['proxyHost']) self.dialog.proxyHost.setText(self.config['proxyHost'])
@ -115,9 +114,8 @@ class Preferences(QDialog):
def updateNetwork(self): def updateNetwork(self):
self.config['syncOnLoad'] = self.dialog.syncOnOpen.isChecked() self.config['syncOnLoad'] = self.dialog.syncOnOpen.isChecked()
self.config['syncOnClose'] = self.dialog.syncOnClose.isChecked()
self.config['syncOnProgramOpen'] = self.dialog.syncOnProgramOpen.isChecked() self.config['syncOnProgramOpen'] = self.dialog.syncOnProgramOpen.isChecked()
self.config['syncOnProgramClose'] = self.dialog.syncOnProgramClose.isChecked() self.config['syncDisableWhenMoved'] = self.dialog.disableWhenMoved.isChecked()
self.config['syncUsername'] = unicode(self.dialog.syncUser.text()) self.config['syncUsername'] = unicode(self.dialog.syncUser.text())
self.config['syncPassword'] = unicode(self.dialog.syncPass.text()) self.config['syncPassword'] = unicode(self.dialog.syncPass.text())
self.config['proxyHost'] = unicode(self.dialog.proxyHost.text()) self.config['proxyHost'] = unicode(self.dialog.proxyHost.text())

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>365</width> <width>365</width>
<height>467</height> <height>419</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -33,7 +33,7 @@
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>&lt;h1&gt;Language&lt;/h1&gt;</string> <string>&lt;b&gt;Language&lt;/b&gt;</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>false</bool> <bool>false</bool>
@ -62,7 +62,7 @@
<enum>Qt::TabFocus</enum> <enum>Qt::TabFocus</enum>
</property> </property>
<property name="text"> <property name="text">
<string>&lt;h1&gt;Reviewing&lt;/h1&gt;</string> <string>&lt;b&gt;Reviewing&lt;/b&gt;</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>false</bool> <bool>false</bool>
@ -166,7 +166,7 @@
<item> <item>
<widget class="QLabel" name="label_16"> <widget class="QLabel" name="label_16">
<property name="text"> <property name="text">
<string>&lt;h1&gt;Synchronisation&lt;/h1&gt;&lt;a href=&quot;http://anki.ichi2.net/&quot;&gt;Create a free account&lt;/a&gt;.</string> <string>&lt;b&gt;Synchronisation&lt;/b&gt;&lt;a href=&quot;http://anki.ichi2.net/&quot;&gt;&lt;br&gt;Create a free account&lt;/a&gt;.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -201,16 +201,6 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="syncUser"/> <widget class="QLineEdit" name="syncUser"/>
</item> </item>
<item row="3" column="0">
<widget class="QCheckBox" name="syncOnClose">
<property name="text">
<string>Sync on deck close</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="syncPass"> <widget class="QLineEdit" name="syncPass">
<property name="echoMode"> <property name="echoMode">
@ -218,27 +208,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="syncOnOpen"> <widget class="QCheckBox" name="syncOnOpen">
<property name="text"> <property name="text">
<string>Sync on deck open</string> <string>Sync on deck open/close</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="syncOnProgramOpen"> <widget class="QCheckBox" name="syncOnProgramOpen">
<property name="text"> <property name="text">
<string>Sync on program open</string> <string>Sync on program open/close</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="syncOnProgramClose"> <widget class="QCheckBox" name="disableWhenMoved">
<property name="text"> <property name="text">
<string>Sync on program close</string> <string>Disable sync when deck moved</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -251,7 +241,7 @@
<item> <item>
<widget class="QLabel" name="label_13"> <widget class="QLabel" name="label_13">
<property name="text"> <property name="text">
<string>&lt;h1&gt;Proxy&lt;/h1&gt;</string> <string>&lt;b&gt;Proxy&lt;/b&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -349,7 +339,7 @@
<item> <item>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
<string>&lt;h1&gt;Autosaving&lt;/h1&gt;</string> <string>&lt;b&gt;Autosaving&lt;/b&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -427,7 +417,7 @@
<item> <item>
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="text"> <property name="text">
<string>&lt;h1&gt;Backups&lt;/h1&gt;Decks are backed up when they are opened, and only if they have been modified since the last backup.</string> <string>&lt;b&gt;Backups&lt;/b&gt;&lt;br&gt;Decks are backed up when they are opened or synchronised, and only if they have been modified since the last backup.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -520,86 +510,63 @@
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item> <item>
<layout class="QGridLayout"> <layout class="QGridLayout">
<item row="2" column="0"> <item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>&lt;h1&gt;Advanced settings&lt;/h1&gt;</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="showTimer"> <widget class="QCheckBox" name="showTimer">
<property name="text"> <property name="text">
<string>Show timer</string> <string>Show timer</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="2" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="alternativeTheme"> <widget class="QCheckBox" name="alternativeTheme">
<property name="text"> <property name="text">
<string>Alternative theme</string> <string>Alternative theme</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item row="6" column="0">
<widget class="QCheckBox" name="showStudyOptions"> <widget class="QCheckBox" name="showStudyOptions">
<property name="text"> <property name="text">
<string>Show study options on deck load</string> <string>Show study options on deck load</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="5" column="0">
<widget class="QCheckBox" name="showTray"> <widget class="QCheckBox" name="showTray">
<property name="text"> <property name="text">
<string>Show tray icon</string> <string>Show tray icon</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="0"> <item row="10" column="0">
<widget class="QCheckBox" name="addZeroSpace"> <widget class="QCheckBox" name="addZeroSpace">
<property name="text"> <property name="text">
<string>Add hidden char to text (fixes Thai on OSX)</string> <string>Add hidden char to text (fixes Thai on OSX)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0"> <item row="7" column="0">
<widget class="QCheckBox" name="openLastDeck"> <widget class="QCheckBox" name="openLastDeck">
<property name="text"> <property name="text">
<string>Always open last deck on startup</string> <string>Always open last deck on startup</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0"> <item row="8" column="0">
<widget class="QCheckBox" name="deckBrowserOrder"> <widget class="QCheckBox" name="deckBrowserOrder">
<property name="text"> <property name="text">
<string>Show decks with cards due first in browser</string> <string>Show decks with cards due first in browser</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="0"> <item row="9" column="0">
<widget class="QCheckBox" name="deleteMedia"> <widget class="QCheckBox" name="deleteMedia">
<property name="text"> <property name="text">
<string>Delete original media on add</string> <string>Delete original media on add</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="3" column="0">
<widget class="QCheckBox" name="colourTimes"> <widget class="QCheckBox" name="colourTimes">
<property name="text"> <property name="text">
<string>Colour next times</string> <string>Colour next times</string>
@ -702,9 +669,8 @@
<tabstop>syncUser</tabstop> <tabstop>syncUser</tabstop>
<tabstop>syncPass</tabstop> <tabstop>syncPass</tabstop>
<tabstop>syncOnOpen</tabstop> <tabstop>syncOnOpen</tabstop>
<tabstop>syncOnClose</tabstop>
<tabstop>syncOnProgramOpen</tabstop> <tabstop>syncOnProgramOpen</tabstop>
<tabstop>syncOnProgramClose</tabstop> <tabstop>disableWhenMoved</tabstop>
<tabstop>proxyHost</tabstop> <tabstop>proxyHost</tabstop>
<tabstop>proxyPort</tabstop> <tabstop>proxyPort</tabstop>
<tabstop>proxyUser</tabstop> <tabstop>proxyUser</tabstop>