HistoryManager: Use NewConfirmationDialog

This commit is contained in:
Philipp Hörist 2019-03-26 21:47:18 +01:00
parent 21aa352a34
commit acd9f67d92
3 changed files with 31 additions and 33 deletions

View File

@ -19,6 +19,7 @@ from gi.repository import Gtk
from gajim.common import app from gajim.common import app
from gajim.common import helpers from gajim.common import helpers
from gajim.common.i18n import _ from gajim.common.i18n import _
from gajim.common.const import ButtonAction
from gajim.gtk.util import get_builder from gajim.gtk.util import get_builder
from gajim.gtk.util import load_icon from gajim.gtk.util import load_icon
@ -47,6 +48,11 @@ class DialogButton(namedtuple('DialogButton', ('response text callback args '
elif type_ == 'Cancel': elif type_ == 'Cancel':
default_kwargs['response'] = Gtk.ResponseType.CANCEL default_kwargs['response'] = Gtk.ResponseType.CANCEL
default_kwargs['text'] = _('Cancel') default_kwargs['text'] = _('Cancel')
elif type_ == 'Delete':
default_kwargs['response'] = Gtk.ResponseType.OK
default_kwargs['text'] = _('Delete')
default_kwargs['action'] = ButtonAction.DESTRUCTIVE
else: else:
raise ValueError('Unknown button type: %s ' % type_) raise ValueError('Unknown button type: %s ' % type_)

View File

@ -323,13 +323,9 @@ class Themes(Gtk.ApplicationWindow):
NewConfirmationDialog( NewConfirmationDialog(
_('Delete'), _('Delete'),
_('Delete Theme'), _('Delete Theme'),
_('Do you want to permanently ' _('Do you want to permanently delete this theme?'),
'delete this theme?'),
[DialogButton.make('Cancel'), [DialogButton.make('Cancel'),
DialogButton.make('OK', DialogButton.make('Delete', callback=_remove_theme)],
text=_('Delete'),
callback=_remove_theme,
action=ButtonAction.DESTRUCTIVE)],
transient_for=self) transient_for=self)
@staticmethod @staticmethod

View File

@ -47,6 +47,7 @@ from gajim.common import app
from gajim.common import i18n from gajim.common import i18n
from gajim.common import configpaths from gajim.common import configpaths
from gajim.common.i18n import _ from gajim.common.i18n import _
from gajim.common.i18n import ngettext
from gajim.common.const import StyleAttr from gajim.common.const import StyleAttr
from gajim.common.const import JIDConstant from gajim.common.const import JIDConstant
from gajim.common.const import KindConstant from gajim.common.const import KindConstant
@ -88,7 +89,8 @@ if is_standalone():
from gajim.common import helpers from gajim.common import helpers
from gajim.gtk.dialogs import YesNoDialog from gajim.gtk.dialogs import YesNoDialog
from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import ConfirmationDialog from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.filechoosers import FileSaveDialog from gajim.gtk.filechoosers import FileSaveDialog
from gajim.gtk.util import convert_rgb_to_hex from gajim.gtk.util import convert_rgb_to_hex
from gajim.gtk.util import get_builder from gajim.gtk.util import get_builder
@ -539,7 +541,7 @@ class HistoryManager:
if paths_len == 0: # nothing is selected if paths_len == 0: # nothing is selected
return return
def on_ok(liststore, list_of_paths): def on_ok():
# delete all rows from db that match jid_id # delete all rows from db that match jid_id
list_of_rowrefs = [] list_of_rowrefs = []
for path in list_of_paths: # make them treerowrefs (it's needed) for path in list_of_paths: # make them treerowrefs (it's needed)
@ -567,21 +569,16 @@ class HistoryManager:
self.AT_LEAST_ONE_DELETION_DONE = True self.AT_LEAST_ONE_DELETION_DONE = True
if paths_len == 1: NewConfirmationDialog(
jid_id = '<i>%s</i>' % liststore[list_of_paths[0]][0] _('Delete'),
pri_text = _('Do you wish to delete all correspondence with %(jid)s?') \ ngettext('Delete Conversation', 'Delete Conversations', paths_len),
% {'jid': jid_id} ngettext('Do you want to permanently delete this '
else: 'conversation with <b>%s</b>',
pri_text = _( 'Do you want to permanently delete these Conversations',
'Do you wish to delete all correspondence with the selected contacts?') paths_len, liststore[list_of_paths[0]][0]),
dialog = ConfirmationDialog('', [DialogButton.make('Cancel'),
_('This can not be undone.'), on_response_ok=(on_ok, DialogButton.make('Delete', callback=on_ok)],
liststore, list_of_paths)) transient_for=self._ui.history_manager_window)
dialog.set_title(_('Deletion Confirmation'))
dialog.set_markup(pri_text)
ok_button = dialog.get_children()[0].get_children()[1].get_children()[0]
ok_button.grab_focus()
dialog.set_transient_for(self._ui.history_manager_window)
def _delete_logs(self, liststore, list_of_paths): def _delete_logs(self, liststore, list_of_paths):
paths_len = len(list_of_paths) paths_len = len(list_of_paths)
@ -610,16 +607,15 @@ class HistoryManager:
self.AT_LEAST_ONE_DELETION_DONE = True self.AT_LEAST_ONE_DELETION_DONE = True
pri_text = i18n.ngettext( NewConfirmationDialog(
'Do you really want to delete the selected message?', _('Delete'),
'Do you really want to delete the selected messages?', paths_len) ngettext('Delete Message', 'Delete Messages', paths_len),
dialog = ConfirmationDialog(pri_text, ngettext('Do you want to permanently delete this message',
_('This can not be undone.'), on_response_ok=(on_ok, 'Do you want to permanently delete these messages',
liststore, list_of_paths)) paths_len),
dialog.set_title(_('Deletion Confirmation')) [DialogButton.make('Cancel'),
ok_button = dialog.get_children()[0].get_children()[1].get_children()[0] DialogButton.make('Delete', callback=on_ok)],
ok_button.grab_focus() transient_for=self._ui.history_manager_window)
dialog.set_transient_for(self._ui.history_manager_window)
def on_search_db_button_clicked(self, widget): def on_search_db_button_clicked(self, widget):
text = self._ui.search_entry.get_text() text = self._ui.search_entry.get_text()