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:
Lucas Scharenbroch 2024-02-12 00:29:16 -06:00 committed by GitHub
parent 12681ae2e7
commit c6a63cf959
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 24 deletions

View file

@ -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

View file

@ -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.

View file

@ -189,6 +189,7 @@ def show(mw: aqt.AnkiQt) -> QDialog:
"Gustavo Sales",
"Akash Reddy",
"Marko Sisovic",
"Lucas Scharenbroch",
)
)

View file

@ -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">
@ -783,7 +776,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="syncDeauth">
<widget class="QPushButton" name="syncLogout">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -791,7 +784,23 @@
</sizepolicy>
</property>
<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 name="autoDefault">
<bool>false</bool>
@ -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>

View file

@ -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
@ -13,9 +15,11 @@ from aqt import AnkiQt
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,
@ -73,6 +77,9 @@ class Preferences(QDialog):
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
@ -84,6 +91,9 @@ class Preferences(QDialog):
self.done(0)
aqt.dialogs.markClosed("Preferences")
if callback:
callback()
self.update_collection(after_collection_update)
def reject(self) -> None:
@ -181,24 +191,33 @@ class Preferences(QDialog):
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)
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.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:
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():
@ -206,7 +225,11 @@ class Preferences(QDialog):
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()

View file

@ -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: