Commit 10bbeda0 authored by Philipp Hörist's avatar Philipp Hörist

[omemo] Use Gajims confirmation dialog

parent 9d810ef5
...@@ -26,11 +26,12 @@ from gi.repository import Gtk ...@@ -26,11 +26,12 @@ from gi.repository import Gtk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
from gajim.common import app from gajim.common import app
from gajim.common.const import ButtonAction
from gajim.plugins.plugins_i18n import _ from gajim.plugins.plugins_i18n import _
from gajim.plugins.helpers import get_builder 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 Trust
from omemo.backend.util import IdentityKeyExtended from omemo.backend.util import IdentityKeyExtended
from omemo.backend.util import get_fingerprint from omemo.backend.util import get_fingerprint
...@@ -278,17 +279,15 @@ class KeyRow(Gtk.ListBoxRow): ...@@ -278,17 +279,15 @@ class KeyRow(Gtk.ListBoxRow):
self.get_parent().remove(self) self.get_parent().remove(self)
self.destroy() self.destroy()
buttons = {
Gtk.ResponseType.CANCEL: DialogButton(_('Cancel')),
Gtk.ResponseType.OK: DialogButton(_('Delete'),
_remove,
ButtonAction.DESTRUCTIVE),
}
NewConfirmationDialog( NewConfirmationDialog(
_('Delete'),
_('Delete Fingerprint'), _('Delete Fingerprint'),
_('Doing so will permanently delete this 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()) transient_for=self.get_toplevel())
def set_trust(self): def set_trust(self):
......
# Copyright (C) 2019 Philipp Hörist <philipp AT hoerist.com>
#
# 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 <http://www.gnu.org/licenses/>.
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment