Philipp Hörist pushed to branch master at gajim / gajim
Commits: c723247a by Daniel Brötzmann at 2019-07-08T21:30:22Z Replace YesNoDialogs with NewConfirmationDialogs
- - - - - 66e191a1 by Daniel Brötzmann at 2019-07-08T21:30:35Z Remove YesNoDialog
- - - - -
7 changed files:
- gajim/gtk/accounts.py - gajim/gtk/dialogs.py - gajim/gtk/filetransfer.py - gajim/gui_interface.py - gajim/history_manager.py - gajim/message_window.py - gajim/plugins/gui.py
Changes:
===================================== gajim/gtk/accounts.py ===================================== @@ -34,7 +34,6 @@ from gajim.gtk.dialogs import NewConfirmationDialog from gajim.gtk.dialogs import ConfirmationDialogDoubleRadio from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dialogs import PassphraseDialog -from gajim.gtk.dialogs import YesNoDialog from gajim.gtk.const import Setting from gajim.gtk.const import SettingKind from gajim.gtk.const import SettingType @@ -134,12 +133,16 @@ class AccountsWindow(Gtk.ApplicationWindow): account, 'offline', _('Be right back.')) GLib.timeout_add(500, login, account, show_before, status_before)
- YesNoDialog( - _('Relogin now?'), - _('If you want all the changes to apply instantly, ' - 'you must relogin.'), - transient_for=self, - on_response_yes=lambda *args: relog(account)) + NewConfirmationDialog( + _('Re-Login'), + _('Re-Login now?'), + _('To apply all changes instantly, you have to re-login.'), + [DialogButton.make('Cancel', + text=_('_Later')), + DialogButton.make('OK', + text=_('_Re-Login'), + callback=lambda *args: relog(account))], + transient_for=self).show()
@staticmethod def _get_relogin_settings(account):
===================================== gajim/gtk/dialogs.py ===================================== @@ -243,93 +243,6 @@ class ErrorDialog(HigDialog): self.popup()
-class YesNoDialog(HigDialog): - """ - HIG compliant YesNo dialog - """ - - def __init__(self, pritext, sectext='', checktext='', text_label=None, - on_response_yes=None, on_response_no=None, type_=Gtk.MessageType.QUESTION, - transient_for=None): - self.user_response_yes = on_response_yes - self.user_response_no = on_response_no - if transient_for is None: - transient_for = app.app.get_active_window() - HigDialog.__init__(self, transient_for, type_, Gtk.ButtonsType.YES_NO, pritext, - sectext, on_response_yes=self.on_response_yes, - on_response_no=self.on_response_no) - - vbox = self.get_content_area() - if checktext: - self.checkbutton = Gtk.CheckButton.new_with_mnemonic(checktext) - vbox.pack_start(self.checkbutton, False, True, 0) - else: - self.checkbutton = None - if text_label: - label = Gtk.Label(label=text_label) - vbox.pack_start(label, False, True, 0) - buff = Gtk.TextBuffer() - self.textview = Gtk.TextView.new_with_buffer(buff) - frame = Gtk.Frame() - frame.set_shadow_type(Gtk.ShadowType.IN) - frame.add(self.textview) - vbox.pack_start(frame, False, True, 0) - else: - self.textview = None - self.set_modal(False) - self.popup() - - def on_response_yes(self, widget): - if self.user_response_yes: - if self.textview: - buff = self.textview.get_buffer() - start, end = buff.get_bounds() - txt = self.textview.get_buffer().get_text(start, end, True) - - if isinstance(self.user_response_yes, tuple): - if self.textview: - self.user_response_yes[0](self.is_checked(), txt, - *self.user_response_yes[1:]) - else: - self.user_response_yes[0](self.is_checked(), - *self.user_response_yes[1:]) - else: - if self.textview: - self.user_response_yes(self.is_checked(), txt) - else: - self.user_response_yes(self.is_checked()) - self.call_cancel_on_destroy = False - self.destroy() - - def on_response_no(self, widget): - if self.user_response_no: - if self.textview: - buff = self.textview.get_buffer() - start, end = buff.get_bounds() - txt = self.textview.get_buffer().get_text(start, end, True) - - if isinstance(self.user_response_no, tuple): - if self.textview: - self.user_response_no[0](txt, *self.user_response_no[1:]) - else: - self.user_response_no[0](*self.user_response_no[1:]) - else: - if self.textview: - self.user_response_no(txt) - else: - self.user_response_no() - self.call_cancel_on_destroy = False - self.destroy() - - def is_checked(self): - """ - Get active state of the checkbutton - """ - if not self.checkbutton: - return False - return self.checkbutton.get_active() - - class ConfirmationDialogDoubleCheck(ConfirmationDialog): """ HIG compliant confirmation dialog with 2 checkbuttons
===================================== gajim/gtk/filetransfer.py ===================================== @@ -44,7 +44,6 @@ from gajim.gtk.dialogs import DialogButton from gajim.gtk.dialogs import NewConfirmationDialog from gajim.gtk.dialogs import HigDialog from gajim.gtk.dialogs import InformationDialog -from gajim.gtk.dialogs import YesNoDialog from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.filechoosers import FileSaveDialog from gajim.gtk.filechoosers import FileChooserDialog @@ -329,14 +328,20 @@ class FileTransfersWindow: file_name = os.path.basename(file_props.file_name) else: file_name = file_props.name - YesNoDialog( - _('File transfer error'), - _('The file %(file)s has been received, but it seems to have ' + NewConfirmationDialog( + _('File Transfer Error'), + _('File Transfer Error'), + _('The file %s has been received, but it seems to have ' 'been damaged along the way.\n' - 'Do you want to download it again?') % - {'file': file_name}, - on_response_yes=(on_yes, jid, file_props, account), - type_=Gtk.MessageType.ERROR) + 'Do you want to download it again?') % file_name, + [DialogButton.make('Cancel', + text=_('_No')), + DialogButton.make('OK', + text=_('_Download Again'), + callback=on_yes, + args=[jid, + file_props, + account])]).show()
def show_file_send_request(self, account, contact): send_callback = partial(self.send_file, account, contact)
===================================== gajim/gui_interface.py ===================================== @@ -98,8 +98,9 @@ from gajim.gtk.notification import Notification from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dialogs import WarningDialog from gajim.gtk.dialogs import InformationDialog +from gajim.gtk.dialogs import NewConfirmationDialog +from gajim.gtk.dialogs import DialogButton from gajim.gtk.dialogs import InputDialog -from gajim.gtk.dialogs import YesNoDialog from gajim.gtk.dialogs import PassphraseDialog from gajim.gtk.dialogs import PlainConnectionDialog from gajim.gtk.dialogs import SSLErrorDialog @@ -161,24 +162,35 @@ class Interface:
@staticmethod def handle_event_http_auth(obj): - #('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg)) - def response(account, answer): + # ('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg)) + def _response(account, answer): obj.conn.get_module('HTTPAuth').build_http_auth_answer( obj.stanza, answer)
- def on_yes(is_checked, obj): - response(obj, 'yes') - account = obj.conn.name + pri_msg = _('HTTP (%(method)s) Authorization ' + 'for %(url)s (ID: %(id)s)') % { + 'method': obj.method, + 'url': obj.url, + 'id': obj.iq_id} sec_msg = _('Do you accept this request?') if app.get_number_of_connected_accounts() > 1: - sec_msg = _('Do you accept this request on account %s?') % account + sec_msg = _('Do you accept this request (account: %s)?') % account if obj.msg: sec_msg = obj.msg + '\n' + sec_msg - YesNoDialog(_('HTTP (%(method)s) Authorization for ' - '%(url)s (ID: %(id)s)') % {'method': obj.method, 'url': obj.url, - 'id': obj.iq_id}, sec_msg, on_response_yes=(on_yes, obj), - on_response_no=(response, obj, 'no')) + + NewConfirmationDialog( + _('Authorization'), + pri_msg, + sec_msg, + [DialogButton.make('Cancel', + text=_('_No'), + callback=_response, + args=[obj, 'yes']), + DialogButton.make('OK', + text=_('_Accept'), + callback=_response, + args=[obj, 'no'])]).show()
def handle_event_iq_error(self, event): ctrl = self.msg_win_mgr.get_control(event.properties.jid.getBare(), @@ -424,16 +436,22 @@ class Interface: % obj.jid)
def show_unsubscribed_dialog(self, account, contact): - def on_yes(is_checked, list_): + def _remove(list_): self.roster.on_req_usub(None, list_) list_ = [(contact, account)] - YesNoDialog( - _('Contact "%s" removed subscription from you') % contact.jid, - _('You will always see them as offline.\nDo you want to ' - 'remove them from your contact list?'), - on_response_yes=(on_yes, list_)) - # FIXME: Per RFC 3921, we can "deny" ack as well, but the GUI does - # not show deny + + NewConfirmationDialog( + _('Subscription Removed'), + _('Contact '%s' removed subscription from you') % contact.jid, + _('You will always see this contact as offline.\n' + 'Do you want to remove them from your contact list?'), + [DialogButton.make('Cancel', + text=_('_No')), + DialogButton.make('Remove', + callback=_remove(list_))]).show() + + # FIXME: Per RFC 3921, we can "deny" ack as well, but the GUI does + # not show deny
def handle_event_unsubscribed_presence(self, obj): #('UNSUBSCRIBED', account, jid)
===================================== gajim/history_manager.py ===================================== @@ -82,7 +82,6 @@ if is_standalone():
# pylint: disable=C0413 from gajim.common import helpers -from gajim.gtk.dialogs import YesNoDialog from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dialogs import NewConfirmationDialog from gajim.gtk.dialogs import DialogButton @@ -234,27 +233,27 @@ class HistoryManager: Gtk.main_quit() return
- def on_yes(clicked): + def _on_yes(): self.cur.execute('VACUUM') self.con.commit() if is_standalone(): Gtk.main_quit()
- def on_no(): + def _on_no(): if is_standalone(): Gtk.main_quit()
- dialog = YesNoDialog( + NewConfirmationDialog( + _('Database Cleanup'), _('Do you want to clean up the database? ' '(STRONGLY NOT RECOMMENDED IF GAJIM IS RUNNING)'), - _('Normally allocated database size will not be freed, ' - 'it will just become reusable. If you really want to reduce ' - 'database filesize, click YES, else click NO.' - '\n\nIn case you click YES, please wait…'), - on_response_yes=on_yes, on_response_no=on_no) - dialog.set_title(_('Database Cleanup')) - button_box = dialog.get_children()[0].get_children()[1] - button_box.get_children()[0].grab_focus() + _('Normally, the allocated database size will not be freed, it ' + 'will just become reusable. This operation may take a while.'), + [DialogButton.make('Cancel', + callback=_on_no), + DialogButton.make('Remove', + text=_('_Cleanup'), + callback=_on_yes)]).show()
def _fill_jids_listview(self): # get those jids that have at least one entry in logs @@ -581,7 +580,7 @@ class HistoryManager: if paths_len == 0: # nothing is selected return
- def on_ok(liststore, list_of_paths): + def on_ok(): # delete rows from db that match log_line_id list_of_rowrefs = [] for path in list_of_paths: # make them treerowrefs (it's needed)
===================================== gajim/message_window.py ===================================== @@ -40,7 +40,8 @@ from gajim import message_control from gajim.chat_control_base import ChatControlBase from gajim.chat_control import ChatControl
-from gajim.gtk.dialogs import YesNoDialog +from gajim.gtk.dialogs import DialogButton +from gajim.gtk.dialogs import NewConfirmationCheckDialog from gajim.gtk.util import get_icon_name from gajim.gtk.util import resize_window from gajim.gtk.util import move_window @@ -231,7 +232,7 @@ class MessageWindow: number_of_closed_control += 1
if number_of_closed_control > 1: - def on_yes1(checked): + def _on_yes1(checked): if checked: app.config.set('confirm_close_multiple_tabs', False) self.dont_warn_on_delete = True @@ -246,11 +247,16 @@ class MessageWindow: ctrl.minimize() # destroy window return False - YesNoDialog( + + NewConfirmationCheckDialog( + _('Close Tabs'), _('You are going to close several tabs'), _('Do you really want to close them all?'), - checktext=_('_Do not ask me again'), on_response_yes=on_yes1, - transient_for=self.window) + _('_Do not ask me again'), + [DialogButton.make('Cancel'), + DialogButton.make('OK', + callback=_on_yes1)], + transient_for=self.window).show() return True
def on_yes(ctrl):
===================================== gajim/plugins/gui.py ===================================== @@ -39,7 +39,8 @@ from gajim.plugins.helpers import GajimPluginActivateException from gajim.plugins.plugins_i18n import _
from gajim.gtk.dialogs import WarningDialog -from gajim.gtk.dialogs import YesNoDialog +from gajim.gtk.dialogs import DialogButton +from gajim.gtk.dialogs import NewConfirmationDialog from gajim.gtk.filechoosers import ArchiveChooserDialog from gajim.gtk.util import get_builder from gajim.gtk.util import load_icon @@ -260,9 +261,9 @@ class PluginsWindow: dialog.popup()
def _on_plugin_exists(zip_filename): - def on_yes(is_checked): + def _on_yes(): plugin = app.plugin_manager.install_from_zip(zip_filename, - True) + True) if not plugin: show_warn_dialog() return @@ -273,13 +274,24 @@ class PluginsWindow: model.remove(row.iter) break
- iter_ = model.append([plugin, plugin.name, False, - plugin.activatable, self.get_plugin_icon(plugin)]) + iter_ = model.append([ + plugin, + plugin.name, + False, + plugin.activatable, + self.get_plugin_icon(plugin)]) sel = self.installed_plugins_treeview.get_selection() sel.select_iter(iter_)
- YesNoDialog(_('Plugin already exists'), sectext=_('Overwrite?'), - on_response_yes=on_yes, transient_for=self.window) + NewConfirmationDialog( + _('Overwrite Plugin?'), + _('Plugin already exists'), + _('Do you want to overwrite the currently installed version?'), + [DialogButton.make('Cancel'), + DialogButton.make('Remove', + text=_('_Overwrite'), + callback=_on_yes)], + transient_for=self.window).show()
def _try_install(zip_filename): try:
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/c34545bdf2833684c1e5f10c5a7a387075...