NonModalConfirmationDialog and ConfirmationDialognow automaticaly close window on ok or cancel. fixes #3486

This commit is contained in:
Yann Leboulanger 2007-10-07 17:22:47 +00:00
parent 5fe9126101
commit 10f8279e57
7 changed files with 69 additions and 47 deletions

View file

@ -1645,10 +1645,7 @@ class AccountsWindow:
win_opened = True win_opened = True
break break
# Detect if we have opened windows for this account # Detect if we have opened windows for this account
self.dialog = None def remove(account):
def remove(widget, account):
if self.dialog:
self.dialog.destroy()
if gajim.interface.instances[account].has_key('remove_account'): if gajim.interface.instances[account].has_key('remove_account'):
gajim.interface.instances[account]['remove_account'].window.\ gajim.interface.instances[account]['remove_account'].window.\
present() present()
@ -1656,13 +1653,13 @@ class AccountsWindow:
gajim.interface.instances[account]['remove_account'] = \ gajim.interface.instances[account]['remove_account'] = \
RemoveAccountWindow(account) RemoveAccountWindow(account)
if win_opened: if win_opened:
self.dialog = dialogs.ConfirmationDialog( dialog = dialogs.ConfirmationDialog(
_('You have opened chat in account %s') % account, _('You have opened chat in account %s') % account,
_('All chat and groupchat windows will be closed. Do you want to ' _('All chat and groupchat windows will be closed. Do you want to '
'continue?'), 'continue?'),
on_response_ok = (remove, account)) on_response_ok = (remove, account))
else: else:
remove(widget, account) remove(account)
def on_rename_button_clicked(self, widget): def on_rename_button_clicked(self, widget):
if gajim.connections[self.current_account].connected != 0: if gajim.connections[self.current_account].connected != 0:
@ -2524,9 +2521,7 @@ class RemoveAccountWindow:
self.window.show_all() self.window.show_all()
def on_remove_button_clicked(self, widget): def on_remove_button_clicked(self, widget):
def remove(widget): def remove():
if self.dialog:
self.dialog.destroy()
if gajim.connections[self.account].connected and \ if gajim.connections[self.account].connected and \
not self.remove_and_unregister_radiobutton.get_active(): not self.remove_and_unregister_radiobutton.get_active():
# change status to offline only if we will not remove this JID from # change status to offline only if we will not remove this JID from
@ -2549,14 +2544,13 @@ class RemoveAccountWindow:
else: else:
self._on_remove_success(True) self._on_remove_success(True)
self.dialog = None
if gajim.connections[self.account].connected: if gajim.connections[self.account].connected:
self.dialog = dialogs.ConfirmationDialog( dialog = dialogs.ConfirmationDialog(
_('Account "%s" is connected to the server') % self.account, _('Account "%s" is connected to the server') % self.account,
_('If you remove it, the connection will be lost.'), _('If you remove it, the connection will be lost.'),
on_response_ok = remove) on_response_ok = remove)
else: else:
remove(None) remove()
def _on_remove_success(self, res): def _on_remove_success(self, res):
# action of unregistration has failed, we don't remove the account # action of unregistration has failed, we don't remove the account

View file

@ -1016,20 +1016,56 @@ class ConfirmationDialog(HigDialog):
'''HIG compliant confirmation dialog.''' '''HIG compliant confirmation dialog.'''
def __init__(self, pritext, sectext='', on_response_ok = None, def __init__(self, pritext, sectext='', on_response_ok = None,
on_response_cancel = None): on_response_cancel = None):
self.user_response_ok = on_response_ok
self.user_response_cancel = on_response_cancel
HigDialog.__init__(self, None, HigDialog.__init__(self, None,
gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, pritext, sectext, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, pritext, sectext,
on_response_ok, on_response_cancel) self.on_response_ok, self.on_response_cancel)
self.popup() self.popup()
def on_response_ok(self, widget):
if self.user_response_ok:
if isinstance(self.user_response_ok, tuple):
self.user_response_ok[0](*self.user_response_ok[1:])
else:
self.user_response_ok()
self.destroy()
def on_response_cancel(self, widget):
if self.user_response_cancel:
if isinstance(self.user_response_cancel, tuple):
self.user_response_cancel[0](*self.user_response_ok[1:])
else:
self.user_response_cancel()
self.destroy()
class NonModalConfirmationDialog(HigDialog): class NonModalConfirmationDialog(HigDialog):
'''HIG compliant non modal confirmation dialog.''' '''HIG compliant non modal confirmation dialog.'''
def __init__(self, pritext, sectext='', on_response_ok = None, def __init__(self, pritext, sectext='', on_response_ok = None,
on_response_cancel = None): on_response_cancel = None):
self.user_response_ok = on_response_ok
self.user_response_cancel = on_response_cancel
HigDialog.__init__(self, None, HigDialog.__init__(self, None,
gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, pritext, sectext, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, pritext, sectext,
on_response_ok, on_response_cancel) self.on_response_ok, self.on_response_cancel)
self.set_modal(False) self.set_modal(False)
def on_response_ok(self, widget):
if self.user_response_ok:
if isinstance(self.user_response_ok, tuple):
self.user_response_ok[0](*self.user_response_ok[1:])
else:
self.user_response_ok()
self.destroy()
def on_response_cancel(self, widget):
if self.user_response_cancel:
if isinstance(self.user_response_cancel, tuple):
self.user_response_cancel[0](*self.user_response_ok[1:])
else:
self.user_response_cancel()
self.destroy()
class WarningDialog(HigDialog): class WarningDialog(HigDialog):
def __init__(self, pritext, sectext=''): def __init__(self, pritext, sectext=''):
'''HIG compliant warning dialog.''' '''HIG compliant warning dialog.'''

View file

@ -294,8 +294,7 @@ _('Connection with peer cannot be established.'))
prim_text = _('%s wants to send you a file:') % contact.jid prim_text = _('%s wants to send you a file:') % contact.jid
dialog, dialog2 = None, None dialog, dialog2 = None, None
def on_response_ok(widget, account, contact, file_props): def on_response_ok(account, contact, file_props):
dialog.destroy()
def on_ok(widget, account, contact, file_props): def on_ok(widget, account, contact, file_props):
file_path = dialog2.get_filename() file_path = dialog2.get_filename()
@ -348,8 +347,7 @@ _('Connection with peer cannot be established.'))
dialog2.connect('delete-event', lambda widget, event: dialog2.connect('delete-event', lambda widget, event:
on_cancel(widget, account, contact, file_props)) on_cancel(widget, account, contact, file_props))
def on_response_cancel(widget, account, file_props): def on_response_cancel(account, file_props):
dialog.destroy()
gajim.connections[account].send_file_rejection(file_props) gajim.connections[account].send_file_rejection(file_props)
dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text, dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text,

View file

@ -850,9 +850,7 @@ class GroupchatControl(ChatControlBase):
def on_send_file(self, widget, gc_contact): def on_send_file(self, widget, gc_contact):
'''sends a file to a contact in the room''' '''sends a file to a contact in the room'''
def _on_send_files(widget, gc_c): def _on_send_files(gc_c):
if widget:
widget.destroy()
gajim.interface.instances['file_transfers'].show_file_send_request( gajim.interface.instances['file_transfers'].show_file_send_request(
self.account, gc_c) self.account, gc_c)
self_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, self_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid,
@ -865,7 +863,7 @@ class GroupchatControl(ChatControlBase):
on_response_ok = (_on_send_files, gc_contact)) on_response_ok = (_on_send_files, gc_contact))
dialog.popup() dialog.popup()
else: else:
_on_send_files(None, gc_contact) _on_send_files(gc_contact)
def draw_contact(self, nick, selected=False, focus=False): def draw_contact(self, nick, selected=False, focus=False):
iter = self.get_contact_iter(nick) iter = self.get_contact_iter(nick)

View file

@ -750,9 +750,8 @@ def destroy_widget(widget):
def on_avatar_save_as_menuitem_activate(widget, jid, account, def on_avatar_save_as_menuitem_activate(widget, jid, account,
default_name = ''): default_name = ''):
def on_ok(widget): def on_ok(widget):
def on_ok2(widget, file_path, pixbuf): def on_ok2(file_path, pixbuf):
pixbuf.save(file_path, 'jpeg') pixbuf.save(file_path, 'jpeg')
dialog2.destroy()
dialog.destroy() dialog.destroy()
file_path = dialog.get_filename() file_path = dialog.get_filename()
@ -806,7 +805,7 @@ default_name = ''):
if os.path.exists(file_path): if os.path.exists(file_path):
os.remove(file_path) os.remove(file_path)
new_file_path = '.'.join(file_path.split('.')[:-1]) + '.jpeg' new_file_path = '.'.join(file_path.split('.')[:-1]) + '.jpeg'
dialog2 = dialogs.ConfirmationDialog(_('Extension not supported'), dialogs.ConfirmationDialog(_('Extension not supported'),
_('Image cannot be saved in %(type)s format. Save as %(new_filename)s?') % {'type': type_, 'new_filename': new_file_path}, _('Image cannot be saved in %(type)s format. Save as %(new_filename)s?') % {'type': type_, 'new_filename': new_file_path},
on_response_ok = (on_ok2, new_file_path, pixbuf)) on_response_ok = (on_ok2, new_file_path, pixbuf))
else: else:

View file

@ -481,9 +481,8 @@ class HistoryManager:
if paths_len == 0: # nothing is selected if paths_len == 0: # nothing is selected
return return
def on_ok(widget, liststore, list_of_paths): def on_ok(liststore, list_of_paths):
# delete all rows from db that match jid_id # delete all rows from db that match jid_id
self.dialog.destroy()
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)
list_of_rowrefs.append(gtk.TreeRowReference(liststore, path)) list_of_rowrefs.append(gtk.TreeRowReference(liststore, path))
@ -514,7 +513,7 @@ class HistoryManager:
'Do you really want to delete logs of the selected contact?', 'Do you really want to delete logs of the selected contact?',
'Do you really want to delete logs of the selected contacts?', 'Do you really want to delete logs of the selected contacts?',
paths_len) paths_len)
self.dialog = dialogs.ConfirmationDialog(pri_text, dialogs.ConfirmationDialog(pri_text,
_('This is an irreversible operation.'), on_response_ok = (on_ok, _('This is an irreversible operation.'), on_response_ok = (on_ok,
liststore, list_of_paths)) liststore, list_of_paths))
@ -523,8 +522,7 @@ class HistoryManager:
if paths_len == 0: # nothing is selected if paths_len == 0: # nothing is selected
return return
def on_ok(widget, liststore, list_of_paths): def on_ok(liststore, list_of_paths):
self.dialog.destroy()
# delete rows from db that match log_line_id # delete rows from db that match log_line_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)
@ -550,7 +548,7 @@ class HistoryManager:
pri_text = i18n.ngettext( pri_text = i18n.ngettext(
'Do you really want to delete the selected message?', 'Do you really want to delete the selected message?',
'Do you really want to delete the selected messages?', paths_len) 'Do you really want to delete the selected messages?', paths_len)
self.dialog = dialogs.ConfirmationDialog(pri_text, dialogs.ConfirmationDialog(pri_text,
_('This is an irreversible operation.'), on_response_ok = (on_ok, _('This is an irreversible operation.'), on_response_ok = (on_ok,
liststore, list_of_paths)) liststore, list_of_paths))

View file

@ -1524,8 +1524,7 @@ class RosterWindow:
gajim.contacts.remove_contact(account, contact) gajim.contacts.remove_contact(account, contact)
return return
def remove(widget, list_): def remove(list_):
self.dialog.destroy()
for (contact, account) in list_: for (contact, account) in list_:
full_jid = contact.get_full_jid() full_jid = contact.get_full_jid()
gajim.connections[account].unsubscribe_agent(full_jid) gajim.connections[account].unsubscribe_agent(full_jid)
@ -1557,7 +1556,7 @@ class RosterWindow:
jids = jids[:-1] + '.' jids = jids[:-1] + '.'
sectext = _('You will no longer be able to send and receive messages ' sectext = _('You will no longer be able to send and receive messages '
'to contacts from these transports:%s') % jids 'to contacts from these transports:%s') % jids
self.dialog = dialogs.ConfirmationDialog(pritext, sectext, dialogs.ConfirmationDialog(pritext, sectext,
on_response_ok = (remove, list_)) on_response_ok = (remove, list_))
def on_block(self, widget, iter, group_list): def on_block(self, widget, iter, group_list):
@ -3345,18 +3344,22 @@ class RosterWindow:
if _('Not in Roster') in contact.groups: if _('Not in Roster') in contact.groups:
gajim.events.remove_events(account, contact.jid) gajim.events.remove_events(account, contact.jid)
self.readd_if_needed(contact, account) self.readd_if_needed(contact, account)
def on_ok2(list_):
on_ok(False, list_)
if len(list_) == 1: if len(list_) == 1:
contact = list_[0][0] contact = list_[0][0]
account = list_[0][1] account = list_[0][1]
pritext = _('Contact "%s" will be removed from your roster') % \ pritext = _('Contact "%s" will be removed from your roster') % \
contact.get_shown_name() contact.get_shown_name()
if contact.sub == 'to': if contact.sub == 'to':
self.dialog = dialogs.ConfirmationDialog(pritext, dialogs.ConfirmationDialog(pritext,
_('By removing this contact you also remove authorization ' _('By removing this contact you also remove authorization '
'resulting in him or her always seeing you as offline.'), 'resulting in him or her always seeing you as offline.'),
on_response_ok = (on_ok, list_)) on_response_ok = (on_ok2, list_))
else: else:
self.dialog = dialogs.ConfirmationDialogCheck(pritext, dialogs.ConfirmationDialogCheck(pritext,
_('By removing this contact you also by default remove ' _('By removing this contact you also by default remove '
'authorization resulting in him or her always seeing you as ' 'authorization resulting in him or her always seeing you as '
'offline.'), 'offline.'),
@ -3371,7 +3374,7 @@ class RosterWindow:
sectext = _('By removing these contacts:%s\nyou also remove ' sectext = _('By removing these contacts:%s\nyou also remove '
'authorization resulting in them always seeing you as offline.') % \ 'authorization resulting in them always seeing you as offline.') % \
jids jids
self.dialog = dialogs.ConfirmationDialog(pritext, sectext, dialogs.ConfirmationDialog(pritext, sectext,
on_response_ok = (on_ok, list_)) on_response_ok = (on_ok, list_))
@ -3530,24 +3533,21 @@ class RosterWindow:
return False return False
def change_status(self, widget, account, status): def change_status(self, widget, account, status):
def change(widget, account, status): def change(account, status):
if self.dialog:
self.dialog.destroy()
message = self.get_status_message(status) message = self.get_status_message(status)
if message is None: if message is None:
# user pressed Cancel to change status message dialog # user pressed Cancel to change status message dialog
return return
self.send_status(account, status, message) self.send_status(account, status, message)
self.dialog = None
if status == 'invisible' and self.connected_rooms(account): if status == 'invisible' and self.connected_rooms(account):
self.dialog = dialogs.ConfirmationDialog( dialogs.ConfirmationDialog(
_('You are participating in one or more group chats'), _('You are participating in one or more group chats'),
_('Changing your status to invisible will result in disconnection ' _('Changing your status to invisible will result in disconnection '
'from those group chats. Are you sure you want to go invisible?'), 'from those group chats. Are you sure you want to go invisible?'),
on_response_ok = (change, account, status)) on_response_ok = (change, account, status))
else: else:
change(None, account, status) change(account, status)
def on_send_custom_status(self, widget, contact_list, show, group=None): def on_send_custom_status(self, widget, contact_list, show, group=None):
'''send custom status''' '''send custom status'''
@ -4936,8 +4936,7 @@ class RosterWindow:
uri = data.strip() uri = data.strip()
uri_splitted = uri.split() # we may have more than one file dropped uri_splitted = uri.split() # we may have more than one file dropped
nb_uri = len(uri_splitted) nb_uri = len(uri_splitted)
def _on_send_files(widget, account, jid, uris): def _on_send_files(account, jid, uris):
dialog.destroy()
c = gajim.contacts.get_contact_with_highest_priority(account, jid) c = gajim.contacts.get_contact_with_highest_priority(account, jid)
for uri in uris: for uri in uris:
path = helpers.get_file_path_from_dnd_dropped_uri(uri) path = helpers.get_file_path_from_dnd_dropped_uri(uri)
@ -4952,7 +4951,7 @@ class RosterWindow:
for uri in uri_splitted: for uri in uri_splitted:
path = helpers.get_file_path_from_dnd_dropped_uri(uri) path = helpers.get_file_path_from_dnd_dropped_uri(uri)
sec_text += '\n' + os.path.basename(path) sec_text += '\n' + os.path.basename(path)
dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text, dialogs.NonModalConfirmationDialog(prim_text, sec_text,
on_response_ok = (_on_send_files, account_dest, jid_dest, on_response_ok = (_on_send_files, account_dest, jid_dest,
uri_splitted)) uri_splitted))
dialog.popup() dialog.popup()