add option to disable media syncing

https://forums.ankiweb.net/t/error-when-adding-audio-file/495/2
This commit is contained in:
Damien Elmes 2020-07-01 11:35:24 +10:00
parent 05fb67d409
commit bedd9dadb1
4 changed files with 21 additions and 2 deletions

View file

@ -1231,8 +1231,10 @@ Difference to correct time: %s."""
def on_autosync_timer(self): def on_autosync_timer(self):
elap = self.media_syncer.seconds_since_last_sync() elap = self.media_syncer.seconds_since_last_sync()
# autosync if 15 minutes have elapsed since last sync minutes = self.pm.auto_sync_media_minutes()
if elap > 15 * 60: if not minutes:
return
if elap > minutes * 60:
self.maybe_auto_sync_media() self.maybe_auto_sync_media()
# Permanent libanki hooks # Permanent libanki hooks

View file

@ -169,6 +169,7 @@ class Preferences(QDialog):
qconnect(self.form.media_log.clicked, self.on_media_log) qconnect(self.form.media_log.clicked, self.on_media_log)
self.form.syncOnProgramOpen.setChecked(self.prof["autoSync"]) self.form.syncOnProgramOpen.setChecked(self.prof["autoSync"])
self.form.syncMedia.setChecked(self.prof["syncMedia"]) self.form.syncMedia.setChecked(self.prof["syncMedia"])
self.form.autoSyncMedia.setChecked(self.mw.pm.auto_sync_media_minutes() != 0)
if not self.prof["syncKey"]: if not self.prof["syncKey"]:
self._hideAuth() self._hideAuth()
else: else:
@ -200,6 +201,7 @@ Not currently enabled; click the sync button in the main window to enable."""
def updateNetwork(self): def updateNetwork(self):
self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked() self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked()
self.prof["syncMedia"] = self.form.syncMedia.isChecked() self.prof["syncMedia"] = self.form.syncMedia.isChecked()
self.mw.pm.set_auto_sync_media_minutes(self.form.autoSyncMedia.isChecked() and 15 or 0)
if self.form.fullSync.isChecked(): if self.form.fullSync.isChecked():
self.mw.col.modSchema(check=False) self.mw.col.modSchema(check=False)
self.mw.col.setMod() self.mw.col.setMod()

View file

@ -635,6 +635,12 @@ create table if not exists profiles
self.profile["syncUser"] = None self.profile["syncUser"] = None
self.profile["hostNum"] = 0 self.profile["hostNum"] = 0
def auto_sync_media_minutes(self) -> int:
return self.profile.get("autoSyncMediaMinutes", 15)
def set_auto_sync_media_minutes(self, val: int):
self.profile["autoSyncMediaMinutes"] = val
###################################################################### ######################################################################
def apply_profile_options(self) -> None: def apply_profile_options(self) -> None:

View file

@ -363,6 +363,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="autoSyncMedia">
<property name="text">
<string>Periodically sync media</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="fullSync"> <widget class="QCheckBox" name="fullSync">
<property name="text"> <property name="text">
@ -581,6 +588,7 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>lang</tabstop>
<tabstop>hwAccel</tabstop> <tabstop>hwAccel</tabstop>
<tabstop>showPlayButtons</tabstop> <tabstop>showPlayButtons</tabstop>
<tabstop>interrupt_audio</tabstop> <tabstop>interrupt_audio</tabstop>
@ -600,6 +608,7 @@
<tabstop>timeLimit</tabstop> <tabstop>timeLimit</tabstop>
<tabstop>syncMedia</tabstop> <tabstop>syncMedia</tabstop>
<tabstop>syncOnProgramOpen</tabstop> <tabstop>syncOnProgramOpen</tabstop>
<tabstop>autoSyncMedia</tabstop>
<tabstop>fullSync</tabstop> <tabstop>fullSync</tabstop>
<tabstop>syncDeauth</tabstop> <tabstop>syncDeauth</tabstop>
<tabstop>media_log</tabstop> <tabstop>media_log</tabstop>