diff --git a/omemo/gtk/key.py b/omemo/gtk/key.py index 2d5e58a..9941344 100644 --- a/omemo/gtk/key.py +++ b/omemo/gtk/key.py @@ -26,11 +26,12 @@ from gi.repository import Gtk from gi.repository import GdkPixbuf from gajim.common import app +from gajim.common.const import ButtonAction from gajim.plugins.plugins_i18n import _ from gajim.plugins.helpers import get_builder +from gajim.gtk.dialogs import NewConfirmationDialog +from gajim.gtk.dialogs import DialogButton -from omemo.gtk.util import DialogButton, ButtonAction -from omemo.gtk.util import NewConfirmationDialog from omemo.backend.util import Trust from omemo.backend.util import IdentityKeyExtended from omemo.backend.util import get_fingerprint @@ -278,17 +279,15 @@ class KeyRow(Gtk.ListBoxRow): self.get_parent().remove(self) self.destroy() - buttons = { - Gtk.ResponseType.CANCEL: DialogButton(_('Cancel')), - Gtk.ResponseType.OK: DialogButton(_('Delete'), - _remove, - ButtonAction.DESTRUCTIVE), - } - NewConfirmationDialog( + _('Delete'), _('Delete Fingerprint'), _('Doing so will permanently delete this Fingerprint'), - buttons, + [DialogButton.make('Cancel'), + DialogButton.make('OK', + text=_('Delete'), + callback=_remove, + action=ButtonAction.DESTRUCTIVE)], transient_for=self.get_toplevel()) def set_trust(self): diff --git a/omemo/gtk/util.py b/omemo/gtk/util.py deleted file mode 100644 index 44ff2cf..0000000 --- a/omemo/gtk/util.py +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2019 Philipp Hörist -# -# This file is part of OMEMO Gajim Plugin. -# -# OMEMO Gajim Plugin is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published -# by the Free Software Foundation; version 3 only. -# -# OMEMO Gajim Plugin is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with OMEMO Gajim Plugin. If not, see . - - -from collections import namedtuple -from enum import IntEnum -from enum import Enum - -from gi.repository import Gtk - -DialogButton = namedtuple('DialogButton', 'text callback action') -DialogButton.__new__.__defaults__ = (None, None) # type: ignore - - -class ButtonAction(Enum): - DESTRUCTIVE = 'destructive-action' - SUGGESTED = 'suggested-action' - - -class NewConfirmationDialog(Gtk.MessageDialog): - def __init__(self, text, sec_text, buttons, transient_for=None): - Gtk.MessageDialog.__init__(self, - transient_for=transient_for, - message_type=Gtk.MessageType.QUESTION, - text=text) - - self._buttons = buttons - - for response, button in buttons.items(): - self.add_button(button.text, response) - if button.action is not None: - widget = self.get_widget_for_response(response) - widget.get_style_context().add_class(button.action.value) - - self.format_secondary_markup(sec_text) - - self.connect('response', self._on_response) - - self.run() - - def _on_response(self, dialog, response): - if response == Gtk.ResponseType.DELETE_EVENT: - # Look if DELETE_EVENT is mapped to another response - response = self._buttons.get(response, None) - if response is None: - # If DELETE_EVENT was not mapped we assume CANCEL - response = Gtk.ResponseType.CANCEL - - button = self._buttons.get(response, None) - if button is None: - self.destroy() - return - - if button.callback is not None: - button.callback() - self.destroy()