Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log-in button to preferences screen #2994

Merged
3 changes: 2 additions & 1 deletion ftl/core/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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-some-settings-will-take-effect-after = Some settings will take effect after you restart Anki.
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-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-user-interface-size = User interface size
preferences-when-adding-default-to-current-deck = When adding, default to current deck
Expand Down
1 change: 1 addition & 0 deletions ftl/core/sync.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ sync-syncing = Syncing...
sync-checking = Checking...
sync-connecting = Connecting...
sync-added-updated-count = Added/modified: { $up }↑ { $down }↓
sync-log-in-button = Log In
sync-log-out-button = Log Out
sync-collection-complete = Collection sync complete.
1 change: 1 addition & 0 deletions qt/aqt/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def on_dialog_destroyed() -> None:
"Gustavo Sales",
"Akash Reddy",
"Marko Sisovic",
"Lucas Scharenbroch",
)
)

Expand Down
30 changes: 20 additions & 10 deletions qt/aqt/forms/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="syncLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -783,15 +776,31 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="syncDeauth">
<widget class="QPushButton" name="syncLogout">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<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 notr="true">LOGOUT</string>
<string>sync_log_in_button</string>
</property>
<property name="autoDefault">
<bool>false</bool>
Expand Down Expand Up @@ -1098,7 +1107,8 @@
<tabstop>fullSync</tabstop>
<tabstop>network_timeout</tabstop>
<tabstop>media_log</tabstop>
<tabstop>syncDeauth</tabstop>
<tabstop>syncLogout</tabstop>
<tabstop>syncLogin</tabstop>
<tabstop>custom_sync_url</tabstop>
<tabstop>minutes_between_backups</tabstop>
<tabstop>daily_backups</tabstop>
Expand Down
47 changes: 35 additions & 12 deletions qt/aqt/preferences.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

from __future__ import annotations

import functools
import re

Expand All @@ -13,9 +15,11 @@
from aqt.operations.collection import set_preferences
from aqt.profiles import VideoDriver
from aqt.qt import *
from aqt.sync import sync_login
from aqt.theme import Theme
from aqt.utils import (
HelpPage,
askUser,
disable_help_button,
is_win,
openHelp,
Expand Down Expand Up @@ -73,6 +77,9 @@ def setup_configurable_answer_keys(self):
line_edit.setPlaceholderText(tr.preferences_shortcut_placeholder())

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
if not self.mw.col:
return
Expand All @@ -84,6 +91,9 @@ def after_collection_update() -> None:
self.done(0)
aqt.dialogs.markClosed("Preferences")

if callback:
callback()

self.update_collection(after_collection_update)

def reject(self) -> None:
Expand Down Expand Up @@ -181,32 +191,45 @@ def setup_network(self) -> None:
self.form.syncOnProgramOpen.setChecked(self.mw.pm.auto_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.custom_sync_url.setText(self.mw.pm.custom_sync_url())
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._hide_sync_auth_settings()
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", ""))
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.network_timeout.setValue(self.mw.pm.network_timeout())
self.form.syncLogin.setVisible(False)
self.form.syncLogout.setVisible(True)

def on_media_log(self) -> None:
self.mw.media_syncer.show_sync_log()

def _hide_sync_auth_settings(self) -> None:
self.form.syncDeauth.setVisible(False)
self.form.syncUser.setText("")
self.form.syncLabel.setText(
tr.preferences_synchronizationnot_currently_enabled_click_the_sync()
)
def sync_login(self) -> None:
def on_success():
if self.prof.get("syncKey"):
self.update_login_status()
self.confirm_sync_after_login()

sync_login(self.mw, on_success)

def sync_logout(self) -> None:
if self.mw.media_syncer.is_syncing():
showWarning("Can't log out while sync in progress.")
return
self.prof["syncKey"] = None
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:
self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked()
Expand Down
1 change: 1 addition & 0 deletions qt/aqt/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def get_id_and_pass_from_user(
vbox.addWidget(bb)
diag.setLayout(vbox)
diag.show()
user.setFocus()

accepted = diag.exec()
if not accepted:
Expand Down