Cleanup OAuth re-auth dialog

This commit is contained in:
Kovid Goyal 2026-02-15 11:21:34 +05:30
parent 396bc2a772
commit f65d7f8e4a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 42 deletions

View File

@ -2,61 +2,41 @@
# License: GPLv3 Copyright: 2026, Kovid Goyal <kovid at kovidgoyal.net>
from qt.core import QDialog, QDialogButtonBox, QGridLayout, QIcon, QLabel, QPushButton, QSizePolicy, Qt
from qt.core import QIcon
from calibre.utils.resources import get_image_path as I
from calibre.gui2.dialogs.message_box import MessageBox
class OAuthReauthMessage(QDialog):
class OAuthReauthMessage(MessageBox):
def __init__(self, parent=None, title=None, provider=None):
QDialog.__init__(self, parent)
self.gui = parent
self.setWindowTitle(_('Email Authorization Required'))
self.setWindowIcon(QIcon(I('mail.png')))
l = QGridLayout(self)
self.setLayout(l)
la = QLabel()
la.setPixmap(QIcon(I('dialog_warning.png')).pixmap(64, 64))
la.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
l.addWidget(la, 0, 0, Qt.AlignmentFlag.AlignTop)
pname = {'gmail': 'Google', 'outlook': 'Microsoft'}.get(provider, provider or 'your email provider')
pname = {'gmail': 'Google', 'outlook': 'Microsoft'}.get(provider, provider or _('email provider'))
msg = _(
'<h3>Email Authorization Expired</h3>'
'<h3>Email authorization expired</h3>'
'<p>Your {0} authorization has expired or been revoked. '
'This can happen if you changed your password, revoked access, '
'or the authorization expired due to inactivity.</p>'
'<p>Click <b>Re-authorize</b> to set up email again.</p>'
'<p>Click <b>Re-authorize</b> to set up authorization for email again.</p>'
).format(pname)
if title:
msg = _('<p>Failed to email: {0}</p>').format(title) + msg
self.msg = QLabel(msg)
self.msg.setWordWrap(True)
l.addWidget(self.msg, 0, 1)
super().__init__(
MessageBox.QUESTION, _('Email authorization required'), msg,
parent=parent, show_copy_button=False, q_icon=QIcon.ic('dialog_warning.png'),
yes_text=_('Re-&authorize'), yes_icon=QIcon.ic('config.png'), no_text=_('&Close'),
)
self.accepted.connect(show_email_preferences)
bb = QDialogButtonBox()
self.reauth_btn = QPushButton(_('&Re-authorize'))
self.reauth_btn.setIcon(QIcon(I('config.png')))
self.reauth_btn.clicked.connect(self.do_reauth)
bb.addButton(self.reauth_btn, QDialogButtonBox.ButtonRole.AcceptRole)
bb.addButton(QDialogButtonBox.StandardButton.Close)
bb.rejected.connect(self.reject)
l.addWidget(bb, 1, 0, 1, 2)
self.resize(450, 250)
def do_reauth(self):
self.accept()
if self.gui is not None:
try:
self.gui.iactions['Preferences'].do_config(
initial_plugin=('Sharing', 'Email'), close_after_initial=True)
except Exception:
pass
def show_email_preferences():
from calibre.gui2.ui import get_gui
if gui := get_gui():
try:
gui.iactions['Preferences'].do_config(
initial_plugin=('Sharing', 'Email'), close_after_initial=True)
except Exception:
pass
if __name__ == '__main__':

View File

@ -1085,7 +1085,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
d.setModal(False)
d.show()
self._modeless_dialogs.append(d)
return
return # ))))
if 'calibre.utils.oauth2.OAuth2ReauthenticationRequired' in job.details:
if not minz:
@ -1097,7 +1097,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
provider = 'gmail'
elif 'Microsoft' in job.details:
provider = 'outlook'
d = OAuthReauthMessage(self, title=title, provider=provider)
d = OAuthReauthMessage(parent=self, title=title, provider=provider)
d.setModal(False)
d.show()
self._modeless_dialogs.append(d)