Commit 0411d8fe authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

Make use of NewConfirmationDialog

This replaces ConfirmationDialog by NewConfirmationDialog and
ConfirmationDialogCheck by NewConfirmationCheckDialog in most places.
parent 407f65fd
......@@ -56,8 +56,8 @@ from gajim import gui_menu_builder
from gajim import message_control
from gajim import dialogs
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.add_contact import AddNewContactWindow
from gajim.gtk.util import get_icon_name
from gajim.gtk.util import get_cursor
......@@ -1155,15 +1155,15 @@ class ChatControl(ChatControlBase):
time_ = app.last_message_time[self.account][self.get_full_jid()]
if time.time() - time_ < 2:
# 2 seconds
NewConfirmationDialog(
_('Close'),
_('You just received a new message from %s') % self.contact.jid,
_('If you close this tab and you have history disabled, '
_('You just received a new message '
'from %s') % self.contact.jid,
_('If you close this tab while having chat history disabled, '
'this message will be lost.'),
[DialogButton.make('Cancel',
callback=lambda: on_no(self)),
DialogButton.make('OK',
DialogButton.make('Remove',
text=_('Close'),
callback=lambda: on_yes(self))],
transient_for=self.parent_win.window).show()
......
......@@ -52,8 +52,9 @@ from gajim.message_control import MessageControl
from gajim.conversation_textview import ConversationTextview
from gajim.message_textview import MessageTextView
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import NewConfirmationCheckDialog
from gajim.gtk import util
from gajim.gtk.util import convert_rgb_to_hex
from gajim.gtk.util import at_the_end
......@@ -606,23 +607,27 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
image = clipboard.wait_for_image()
if image is not None:
if not app.config.get('confirm_paste_image'):
self._paste_event_confirmed(image)
self._paste_event_confirmed(True, image)
return
NewConfirmationDialog(
_('Warning'),
NewConfirmationCheckDialog(
_('Paste Image'),
_('You are trying to paste an image'),
_('Are you sure you want to paste your '
'clipboard image in the chat?'),
'clipboard\'s image into the chat window?'),
_('_Do not ask me again'),
[DialogButton.make('Cancel'),
DialogButton.make('OK',
callback=lambda: self._paste_event_confirmed(image))],
).show()
text=_('_Paste'),
callback=self._paste_event_confirmed,
args=[image])]).show()
def _paste_event_confirmed(self, image):
def _paste_event_confirmed(self, is_checked, image):
if is_checked:
app.config.set('confirm_paste_image', False)
tmp_dir = TemporaryDirectory()
dir_ = tmp_dir.name
# get file transfer preference
# Get file transfer preference
ft_pref = app.config.get_per('accounts', self.account,
'filetransfer_preference')
path = os.path.join(dir_, '0.png')
......
......@@ -47,8 +47,9 @@ from gajim.common import app
from gajim.common import helpers
from gajim.common.exceptions import GajimGeneralException
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import ConfirmationDialog
from gajim.gtk.dialogs import InputDialog
from gajim.gtk.dialogs import AspellDictError
from gajim.gtk.util import get_icon_name
......@@ -675,7 +676,7 @@ class ChangeStatusMessageDialog(TimeoutDialog):
if not msg_name: # msg_name was ''
msg_name = msg_text_1l
def on_ok2():
def _on_ok2():
self.preset_messages_dict[msg_name] = [
msg_text, self.pep_dict.get('activity'),
self.pep_dict.get('subactivity'),
......@@ -694,12 +695,19 @@ class ChangeStatusMessageDialog(TimeoutDialog):
app.config.set_per('statusmsg', msg_name, 'mood_text',
self.pep_dict.get('mood_text'))
if msg_name in self.preset_messages_dict:
ConfirmationDialog(_('Overwrite Status Message?'),
_('This name is already used. Do you want to overwrite this '
'status message?'), on_response_ok=on_ok2, transient_for=self.dialog)
NewConfirmationDialog(
_('Overwrite'),
_('Overwrite Status Message?'),
_('Preset name is already in use. '
'Do you want to overwrite this preset?'),
[DialogButton.make('Cancel'),
DialogButton.make('Remove',
text=_('_Overwrite'),
callback=_on_ok2)],
transient_for=self.dialog).show()
return
app.config.add_per('statusmsg', msg_name)
on_ok2()
_on_ok2()
iter_ = self.message_liststore.append((msg_name,))
# select in combobox the one we just saved
self.message_combobox.set_active_iter(iter_)
......
......@@ -67,9 +67,10 @@ from gajim.chat_control_base import ChatControlBase
from gajim.command_system.implementation.hosts import GroupChatCommands
from gajim.common.connection_handlers_events import GcMessageOutgoingEvent
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationCheckDialog
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import InputTextDialog
from gajim.gtk.dialogs import ConfirmationDialogCheck
from gajim.gtk.dialogs import DestroyMucDialog
from gajim.gtk.dialogs import InputDialog
from gajim.gtk.dialogs import ChangeNickDialog
......@@ -2352,27 +2353,30 @@ class GroupchatControl(ChatControlBase):
and self.is_connected and self.room_jid \
not in excludes:
def on_ok(clicked):
if clicked:
# user does not want to be asked again
def on_ok(is_checked):
if is_checked:
# User does not want to be asked again
app.config.set('confirm_close_muc', False)
on_yes(self)
def on_cancel(clicked):
if clicked:
# user does not want to be asked again
def on_cancel(is_checked):
if is_checked:
# User does not want to be asked again
app.config.set('confirm_close_muc', False)
on_no(self)
pritext = _('Are you sure you want to leave group chat "%s"?')\
% self.name
sectext = _('If you close this window, you will be disconnected '
'from this group chat.')
ConfirmationDialogCheck(pritext, sectext,
_('_Do not ask me again'), on_response_ok=on_ok,
on_response_cancel=on_cancel,
transient_for=self.parent_win.window)
NewConfirmationCheckDialog(
_('Leave Group Chat'),
_('Are you sure you want to leave this group chat?'),
_('If you close this window, you will be disconnected '
'from \'%s\'.') % self.name,
_('_Do not ask me again'),
[DialogButton.make('Cancel',
callback=on_cancel),
DialogButton.make('OK',
text=_('_Leave'),
callback=on_ok)],
transient_for=self.parent_win.window).show()
return
on_yes(self)
......
......@@ -32,19 +32,18 @@ from gajim.common.zeroconf.connection_zeroconf import ConnectionZeroconf
from gajim import gui_menu_builder
from gajim.gtk.settings import SettingsDialog
from gajim.gtk.settings import SettingsBox
from gajim.gtk.dialogs import ConfirmationDialog
from gajim.gtk.dialogs import DialogButton
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.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.util import get_builder
from gajim.gtk.const import Setting
from gajim.gtk.const import SettingKind
from gajim.gtk.const import SettingType
from gajim.gtk.settings import SettingsDialog
from gajim.gtk.settings import SettingsBox
from gajim.gtk.util import get_builder
log = logging.getLogger('gajim.gtk.accounts')
......@@ -180,7 +179,7 @@ class AccountsWindow(Gtk.ApplicationWindow):
# Detect if we have opened windows for this account
def remove(account):
def remove():
if (account in app.interface.instances and
'remove_account' in app.interface.instances[account]):
dialog = app.interface.instances[account]['remove_account']
......@@ -191,14 +190,17 @@ class AccountsWindow(Gtk.ApplicationWindow):
app.interface.instances[account]['remove_account'] = \
RemoveAccountWindow(account)
if win_opened:
ConfirmationDialog(
_('You have opened chat in account %s') % account,
_('All chat and groupchat windows will be closed. '
NewConfirmationDialog(
_('Remove Account'),
_('You still have open chats in your account %s') % account,
_('All chat and group chat windows will be closed.\n'
'Do you want to continue?'),
on_response_ok=(remove, account),
transient_for=self)
[DialogButton.make('Cancel'),
DialogButton.make('Remove',
callback=remove)],
transient_for=self).show()
else:
remove(account)
remove()
def remove_account(self, account):
del self._need_relogin[account]
......@@ -649,7 +651,7 @@ class AccountRow(Gtk.ListBoxRow):
[DialogButton.make('Cancel',
callback=lambda: switch.set_active(True)),
DialogButton.make('Remove',
text=_('Disable Account'),
text=_('_Disable Account'),
callback=_disable)],
transient_for=self.get_toplevel()).show()
return Gdk.EVENT_STOP
......@@ -1047,11 +1049,15 @@ class RemoveAccountWindow:
if self.account in app.connections and \
app.connections[self.account].connected:
ConfirmationDialog(
_('Account "%s" is connected to the server') % self.account,
NewConfirmationDialog(
_('Remove Account'),
_('Account \'%s\' is still connected to the '
'server') % self.account,
_('If you remove it, the connection will be lost.'),
on_response_ok=remove,
transient_for=self._ui.remove_account_window)
[DialogButton.make('Cancel'),
DialogButton.make('Remove',
callback=remove)],
transient_for=self._ui.remove_account_window).show()
else:
remove()
......
......@@ -320,7 +320,8 @@ class Themes(Gtk.ApplicationWindow):
_('Delete Theme'),
_('Do you want to permanently delete this theme?'),
[DialogButton.make('Cancel'),
DialogButton.make('Delete', callback=_remove_theme)],
DialogButton.make('Delete',
callback=_remove_theme)],
transient_for=self).show()
@staticmethod
......
......@@ -147,11 +147,14 @@ def scale_pixbuf_from_data(data, size):
pixbuf = get_pixbuf_from_data(data)
return scale_pixbuf(pixbuf, size)
def on_avatar_save_as_menuitem_activate(widget, avatar, default_name=''):
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import ConfirmationDialog
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import FTOverwriteConfirmationDialog
from gajim.gtk.filechoosers import AvatarSaveDialog
def on_continue(response, file_path):
if response < 0:
return
......@@ -169,7 +172,7 @@ def on_avatar_save_as_menuitem_activate(widget, avatar, default_name=''):
image_format = 'png'
file_path += '.png'
else:
image_format = extension[1:] # remove leading dot
image_format = extension[1:] # remove leading dot
# Save image
try:
......@@ -179,13 +182,23 @@ def on_avatar_save_as_menuitem_activate(widget, avatar, default_name=''):
if os.path.exists(file_path):
os.remove(file_path)
new_file_path = '.'.join(file_path.split('.')[:-1]) + '.png'
def on_ok(file_path, pixbuf):
def _on_ok(file_path, pixbuf):
pixbuf.savev(file_path, 'png', [], [])
ConfirmationDialog(_('Extension not supported'),
_('Image cannot be saved in %(type)s format. Save as '
'%(new_filename)s?') % {'type': image_format,
'new_filename': new_file_path},
on_response_ok=(on_ok, new_file_path, pixbuf))
NewConfirmationDialog(
_('Error While Saving'),
_('Extension not supported'),
_('Image cannot be saved in %(type)s format.\n'
'Save as %(new_filename)s?') % {
'type': image_format,
'new_filename': new_file_path},
[DialogButton.make('Cancel'),
DialogButton.make('OK',
text=_('_Save'),
callback=_on_ok,
args=[new_file_path,
pixbuf])]).show()
def on_ok(file_path):
if os.path.exists(file_path):
......
......@@ -568,11 +568,12 @@ class HistoryManager:
_('Delete'),
ngettext('Delete Conversation', 'Delete Conversations', paths_len),
ngettext('Do you want to permanently delete this '
'conversation with <b>%s</b>',
'Do you want to permanently delete these Conversations',
'conversation with <b>%s</b>?',
'Do you want to permanently delete these conversations?',
paths_len, liststore[list_of_paths[0]][0]),
[DialogButton.make('Cancel'),
DialogButton.make('Delete', callback=on_ok)],
DialogButton.make('Delete',
callback=on_ok)],
transient_for=self._ui.history_manager_window).show()
def _delete_logs(self, liststore, list_of_paths):
......@@ -609,7 +610,8 @@ class HistoryManager:
'Do you want to permanently delete these messages',
paths_len),
[DialogButton.make('Cancel'),
DialogButton.make('Delete', callback=on_ok)],
DialogButton.make('Delete',
callback=on_ok)],
transient_for=self._ui.history_manager_window).show()
def on_search_db_button_clicked(self, widget):
......
This diff is collapsed.
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