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

View File

@ -1016,20 +1016,56 @@ class ConfirmationDialog(HigDialog):
'''HIG compliant confirmation dialog.'''
def __init__(self, pritext, sectext='', on_response_ok = None,
on_response_cancel = None):
self.user_response_ok = on_response_ok
self.user_response_cancel = on_response_cancel
HigDialog.__init__(self, None,
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()
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):
'''HIG compliant non modal confirmation dialog.'''
def __init__(self, pritext, sectext='', on_response_ok = None,
on_response_cancel = None):
self.user_response_ok = on_response_ok
self.user_response_cancel = on_response_cancel
HigDialog.__init__(self, None,
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)
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):
def __init__(self, pritext, sectext=''):
'''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
dialog, dialog2 = None, None
def on_response_ok(widget, account, contact, file_props):
dialog.destroy()
def on_response_ok(account, contact, file_props):
def on_ok(widget, account, contact, file_props):
file_path = dialog2.get_filename()
@ -348,8 +347,7 @@ _('Connection with peer cannot be established.'))
dialog2.connect('delete-event', lambda widget, event:
on_cancel(widget, account, contact, file_props))
def on_response_cancel(widget, account, file_props):
dialog.destroy()
def on_response_cancel(account, file_props):
gajim.connections[account].send_file_rejection(file_props)
dialog = dialogs.NonModalConfirmationDialog(prim_text, sec_text,

View File

@ -850,9 +850,7 @@ class GroupchatControl(ChatControlBase):
def on_send_file(self, widget, gc_contact):
'''sends a file to a contact in the room'''
def _on_send_files(widget, gc_c):
if widget:
widget.destroy()
def _on_send_files(gc_c):
gajim.interface.instances['file_transfers'].show_file_send_request(
self.account, gc_c)
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))
dialog.popup()
else:
_on_send_files(None, gc_contact)
_on_send_files(gc_contact)
def draw_contact(self, nick, selected=False, focus=False):
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,
default_name = ''):
def on_ok(widget):
def on_ok2(widget, file_path, pixbuf):
def on_ok2(file_path, pixbuf):
pixbuf.save(file_path, 'jpeg')
dialog2.destroy()
dialog.destroy()
file_path = dialog.get_filename()
@ -806,7 +805,7 @@ default_name = ''):
if os.path.exists(file_path):
os.remove(file_path)
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},
on_response_ok = (on_ok2, new_file_path, pixbuf))
else:

View File

@ -481,9 +481,8 @@ class HistoryManager:
if paths_len == 0: # nothing is selected
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
self.dialog.destroy()
list_of_rowrefs = []
for path in list_of_paths: # make them treerowrefs (it's needed)
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 contacts?',
paths_len)
self.dialog = dialogs.ConfirmationDialog(pri_text,
dialogs.ConfirmationDialog(pri_text,
_('This is an irreversible operation.'), on_response_ok = (on_ok,
liststore, list_of_paths))
@ -523,8 +522,7 @@ class HistoryManager:
if paths_len == 0: # nothing is selected
return
def on_ok(widget, liststore, list_of_paths):
self.dialog.destroy()
def on_ok(liststore, list_of_paths):
# delete rows from db that match log_line_id
list_of_rowrefs = []
for path in list_of_paths: # make them treerowrefs (it's needed)
@ -550,7 +548,7 @@ class HistoryManager:
pri_text = i18n.ngettext(
'Do you really want to delete the selected message?',
'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,
liststore, list_of_paths))

View File

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