mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
Add log-in button to preferences screen (#2994)
* Add log-in button to preferences screen
* Fix to python to conform to linter
* Add translations for log in/out
* Clean up whitespace/naming
* Move translations from python to qt forms
* Remove sync-not-enabled text on prefs screen
* Add my name to about.py
* Add "sync now?" dialog upon successful login
* Close preferences dialog before syncing
* Yet another Qt 6.6.1 focus fix (dae)
Like 9364dad49a
This commit is contained in:
parent
12681ae2e7
commit
c6a63cf959
6 changed files with 61 additions and 24 deletions
|
@ -24,8 +24,9 @@ preferences-show-play-buttons-on-cards-with = Show play buttons on cards with au
|
||||||
preferences-show-remaining-card-count = Show remaining card count
|
preferences-show-remaining-card-count = Show remaining card count
|
||||||
preferences-some-settings-will-take-effect-after = Some settings will take effect after you restart Anki.
|
preferences-some-settings-will-take-effect-after = Some settings will take effect after you restart Anki.
|
||||||
preferences-tab-synchronisation = Synchronization
|
preferences-tab-synchronisation = Synchronization
|
||||||
preferences-synchronizationnot-currently-enabled-click-the-sync = <b>Synchronization</b><br> Not currently enabled; click the sync button in the main window to enable.
|
|
||||||
preferences-synchronize-audio-and-images-too = Synchronize audio and images too
|
preferences-synchronize-audio-and-images-too = Synchronize audio and images too
|
||||||
|
preferences-not-logged-in = Not currently logged in to AnkiWeb.
|
||||||
|
preferences-login-successful-sync-now = Log-in successful. Save preferences and sync now?
|
||||||
preferences-timebox-time-limit = Timebox time limit
|
preferences-timebox-time-limit = Timebox time limit
|
||||||
preferences-user-interface-size = User interface size
|
preferences-user-interface-size = User interface size
|
||||||
preferences-when-adding-default-to-current-deck = When adding, default to current deck
|
preferences-when-adding-default-to-current-deck = When adding, default to current deck
|
||||||
|
|
|
@ -63,5 +63,6 @@ sync-syncing = Syncing...
|
||||||
sync-checking = Checking...
|
sync-checking = Checking...
|
||||||
sync-connecting = Connecting...
|
sync-connecting = Connecting...
|
||||||
sync-added-updated-count = Added/modified: { $up }↑ { $down }↓
|
sync-added-updated-count = Added/modified: { $up }↑ { $down }↓
|
||||||
|
sync-log-in-button = Log In
|
||||||
sync-log-out-button = Log Out
|
sync-log-out-button = Log Out
|
||||||
sync-collection-complete = Collection sync complete.
|
sync-collection-complete = Collection sync complete.
|
||||||
|
|
|
@ -189,6 +189,7 @@ def show(mw: aqt.AnkiQt) -> QDialog:
|
||||||
"Gustavo Sales",
|
"Gustavo Sales",
|
||||||
"Akash Reddy",
|
"Akash Reddy",
|
||||||
"Marko Sisovic",
|
"Marko Sisovic",
|
||||||
|
"Lucas Scharenbroch",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -725,13 +725,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="syncLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -783,7 +776,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="syncDeauth">
|
<widget class="QPushButton" name="syncLogout">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -791,7 +784,23 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">LOGOUT</string>
|
<string>sync_log_out_button</string>
|
||||||
|
</property>
|
||||||
|
<property name="autoDefault">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="syncLogin">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>sync_log_in_button</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoDefault">
|
<property name="autoDefault">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -1098,7 +1107,8 @@
|
||||||
<tabstop>fullSync</tabstop>
|
<tabstop>fullSync</tabstop>
|
||||||
<tabstop>network_timeout</tabstop>
|
<tabstop>network_timeout</tabstop>
|
||||||
<tabstop>media_log</tabstop>
|
<tabstop>media_log</tabstop>
|
||||||
<tabstop>syncDeauth</tabstop>
|
<tabstop>syncLogout</tabstop>
|
||||||
|
<tabstop>syncLogin</tabstop>
|
||||||
<tabstop>custom_sync_url</tabstop>
|
<tabstop>custom_sync_url</tabstop>
|
||||||
<tabstop>minutes_between_backups</tabstop>
|
<tabstop>minutes_between_backups</tabstop>
|
||||||
<tabstop>daily_backups</tabstop>
|
<tabstop>daily_backups</tabstop>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Copyright: Ankitects Pty Ltd and contributors
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -13,9 +15,11 @@ from aqt import AnkiQt
|
||||||
from aqt.operations.collection import set_preferences
|
from aqt.operations.collection import set_preferences
|
||||||
from aqt.profiles import VideoDriver
|
from aqt.profiles import VideoDriver
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
from aqt.sync import sync_login
|
||||||
from aqt.theme import Theme
|
from aqt.theme import Theme
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
HelpPage,
|
HelpPage,
|
||||||
|
askUser,
|
||||||
disable_help_button,
|
disable_help_button,
|
||||||
is_win,
|
is_win,
|
||||||
openHelp,
|
openHelp,
|
||||||
|
@ -73,6 +77,9 @@ class Preferences(QDialog):
|
||||||
line_edit.setPlaceholderText(tr.preferences_shortcut_placeholder())
|
line_edit.setPlaceholderText(tr.preferences_shortcut_placeholder())
|
||||||
|
|
||||||
def accept(self) -> None:
|
def accept(self) -> None:
|
||||||
|
self.accept_with_callback()
|
||||||
|
|
||||||
|
def accept_with_callback(self, callback: Callable[[], None] | None = None) -> None:
|
||||||
# avoid exception if main window is already closed
|
# avoid exception if main window is already closed
|
||||||
if not self.mw.col:
|
if not self.mw.col:
|
||||||
return
|
return
|
||||||
|
@ -84,6 +91,9 @@ class Preferences(QDialog):
|
||||||
self.done(0)
|
self.done(0)
|
||||||
aqt.dialogs.markClosed("Preferences")
|
aqt.dialogs.markClosed("Preferences")
|
||||||
|
|
||||||
|
if callback:
|
||||||
|
callback()
|
||||||
|
|
||||||
self.update_collection(after_collection_update)
|
self.update_collection(after_collection_update)
|
||||||
|
|
||||||
def reject(self) -> None:
|
def reject(self) -> None:
|
||||||
|
@ -181,24 +191,33 @@ class Preferences(QDialog):
|
||||||
self.form.syncOnProgramOpen.setChecked(self.mw.pm.auto_syncing_enabled())
|
self.form.syncOnProgramOpen.setChecked(self.mw.pm.auto_syncing_enabled())
|
||||||
self.form.syncMedia.setChecked(self.mw.pm.media_syncing_enabled())
|
self.form.syncMedia.setChecked(self.mw.pm.media_syncing_enabled())
|
||||||
self.form.autoSyncMedia.setChecked(self.mw.pm.auto_sync_media_minutes() != 0)
|
self.form.autoSyncMedia.setChecked(self.mw.pm.auto_sync_media_minutes() != 0)
|
||||||
if not self.prof.get("syncKey"):
|
|
||||||
self._hide_sync_auth_settings()
|
|
||||||
else:
|
|
||||||
self.form.syncUser.setText(self.prof.get("syncUser", ""))
|
|
||||||
qconnect(self.form.syncDeauth.clicked, self.sync_logout)
|
|
||||||
self.form.syncDeauth.setText(tr.sync_log_out_button())
|
|
||||||
self.form.custom_sync_url.setText(self.mw.pm.custom_sync_url())
|
self.form.custom_sync_url.setText(self.mw.pm.custom_sync_url())
|
||||||
self.form.network_timeout.setValue(self.mw.pm.network_timeout())
|
self.form.network_timeout.setValue(self.mw.pm.network_timeout())
|
||||||
|
|
||||||
|
self.update_login_status()
|
||||||
|
qconnect(self.form.syncLogout.clicked, self.sync_logout)
|
||||||
|
qconnect(self.form.syncLogin.clicked, self.sync_login)
|
||||||
|
|
||||||
|
def update_login_status(self) -> None:
|
||||||
|
if not self.prof.get("syncKey"):
|
||||||
|
self.form.syncUser.setText(tr.preferences_not_logged_in())
|
||||||
|
self.form.syncLogin.setVisible(True)
|
||||||
|
self.form.syncLogout.setVisible(False)
|
||||||
|
else:
|
||||||
|
self.form.syncUser.setText(self.prof.get("syncUser", ""))
|
||||||
|
self.form.syncLogin.setVisible(False)
|
||||||
|
self.form.syncLogout.setVisible(True)
|
||||||
|
|
||||||
def on_media_log(self) -> None:
|
def on_media_log(self) -> None:
|
||||||
self.mw.media_syncer.show_sync_log()
|
self.mw.media_syncer.show_sync_log()
|
||||||
|
|
||||||
def _hide_sync_auth_settings(self) -> None:
|
def sync_login(self) -> None:
|
||||||
self.form.syncDeauth.setVisible(False)
|
def on_success():
|
||||||
self.form.syncUser.setText("")
|
if self.prof.get("syncKey"):
|
||||||
self.form.syncLabel.setText(
|
self.update_login_status()
|
||||||
tr.preferences_synchronizationnot_currently_enabled_click_the_sync()
|
self.confirm_sync_after_login()
|
||||||
)
|
|
||||||
|
sync_login(self.mw, on_success)
|
||||||
|
|
||||||
def sync_logout(self) -> None:
|
def sync_logout(self) -> None:
|
||||||
if self.mw.media_syncer.is_syncing():
|
if self.mw.media_syncer.is_syncing():
|
||||||
|
@ -206,7 +225,11 @@ class Preferences(QDialog):
|
||||||
return
|
return
|
||||||
self.prof["syncKey"] = None
|
self.prof["syncKey"] = None
|
||||||
self.mw.col.media.force_resync()
|
self.mw.col.media.force_resync()
|
||||||
self._hide_sync_auth_settings()
|
self.update_login_status()
|
||||||
|
|
||||||
|
def confirm_sync_after_login(self) -> None:
|
||||||
|
if askUser(tr.preferences_login_successful_sync_now()):
|
||||||
|
self.accept_with_callback(self.mw.on_sync_button_clicked)
|
||||||
|
|
||||||
def update_network(self) -> None:
|
def update_network(self) -> None:
|
||||||
self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked()
|
self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked()
|
||||||
|
|
|
@ -357,6 +357,7 @@ def get_id_and_pass_from_user(
|
||||||
vbox.addWidget(bb)
|
vbox.addWidget(bb)
|
||||||
diag.setLayout(vbox)
|
diag.setLayout(vbox)
|
||||||
diag.show()
|
diag.show()
|
||||||
|
user.setFocus()
|
||||||
|
|
||||||
accepted = diag.exec()
|
accepted = diag.exec()
|
||||||
if not accepted:
|
if not accepted:
|
||||||
|
|
Loading…
Reference in a new issue