make ChangeStatusMessageDialog asychronous. see #4147

This commit is contained in:
Yann Leboulanger 2008-08-04 13:34:29 +00:00
parent 80f6d7909c
commit 1a3a795908
3 changed files with 181 additions and 159 deletions

View file

@ -518,8 +518,9 @@ class ChangeMoodDialog:
self.window.destroy()
class ChangeStatusMessageDialog:
def __init__(self, show = None):
def __init__(self, on_response, show = None):
self.show = show
self.on_response = on_response
self.xml = gtkgui_helpers.get_glade('change_status_message_dialog.glade')
self.window = self.xml.get_widget('change_status_message_dialog')
self.window.set_transient_for(gajim.interface.roster.window)
@ -563,6 +564,10 @@ class ChangeStatusMessageDialog:
for msg_name in sorted_keys_list:
self.message_liststore.append((msg_name,))
self.xml.signal_autoconnect(self)
if self.countdown_time > 0:
self.countdown()
gobject.timeout_add(1000, self.countdown)
self.window.connect('response', self.on_dialog_response)
self.window.show_all()
def countdown(self):
@ -580,14 +585,8 @@ class ChangeStatusMessageDialog:
self.window.set_title(self.title_text)
return False
def run(self):
'''Wait for OK or Cancel button to be pressed and return status messsage
(None if users pressed Cancel or x button of WM'''
if self.countdown_time > 0:
self.countdown()
gobject.timeout_add(1000, self.countdown)
rep = self.window.run()
if rep == gtk.RESPONSE_OK:
def on_dialog_response(self, dialog, response):
if response == gtk.RESPONSE_OK:
beg, end = self.message_buffer.get_bounds()
message = self.message_buffer.get_text(beg, end).decode('utf-8')\
.strip()
@ -598,7 +597,7 @@ class ChangeStatusMessageDialog:
else:
message = None # user pressed Cancel button or X wm button
self.window.destroy()
return message
self.on_response(message)
def on_message_combobox_changed(self, widget):
self.countdown_enabled = False

View file

@ -2081,26 +2081,29 @@ class RosterWindow:
if sys.platform == 'darwin':
self.make_menu(force = True)
def get_status_message(self, show):
def get_status_message(self, show, on_response):
if show in gajim.config.get_per('defaultstatusmsg'):
if gajim.config.get_per('defaultstatusmsg', show, 'enabled'):
return gajim.config.get_per('defaultstatusmsg', show, 'message')
on_response(gajim.config.get_per('defaultstatusmsg', show,
'message'))
return
if (show == 'online' and not gajim.config.get('ask_online_status')) or \
(show in ('offline', 'invisible')
and not gajim.config.get('ask_offline_status')):
return ''
dlg = dialogs.ChangeStatusMessageDialog(show)
on_response('')
return
dlg = dialogs.ChangeStatusMessageDialog(on_response, show)
dlg.window.present() # show it on current workspace
message = dlg.run()
return message
def change_status(self, widget, account, status):
def change(account, status):
message = self.get_status_message(status)
def on_response(message):
if message is None:
# user pressed Cancel to change status message dialog
return
self.send_status(account, status, message)
self.get_status_message(status, on_response)
if status == 'invisible' and self.connected_rooms(account):
dialogs.ConfirmationDialog(
@ -2219,7 +2222,7 @@ class RosterWindow:
gajim.interface.hide_systray()
gtk.main_quit()
def on_quit_request(self, widget = None):
def on_quit_request(self, widget=None):
''' user want to quit. Check if he should be warned about messages
pending. Terminate all sessions and send offline to all connected
account. We do NOT really quit gajim here '''
@ -2229,16 +2232,16 @@ class RosterWindow:
if gajim.connections[acct].connected:
get_msg = True
break
if get_msg:
message = self.get_status_message('offline')
def on_continue(message):
if message is None:
# user pressed Cancel to change status message dialog
return
# check if we have unread messages
unread = gajim.events.get_nb_events()
if not gajim.config.get('notify_on_all_muc_messages'):
unread_not_to_notify = gajim.events.get_nb_events(['printed_gc_msg'])
unread_not_to_notify = gajim.events.get_nb_events(
['printed_gc_msg'])
unread -= unread_not_to_notify
# check if we have recent messages
@ -2269,6 +2272,11 @@ class RosterWindow:
if not self.quit_on_next_offline:
self.quit_gtkgui_interface()
if get_msg:
self.get_status_message('offline', on_continue)
else:
self.on_continue('')
################################################################################
### Menu and GUI callbacks
### FIXME: order callbacks in itself...
@ -2514,9 +2522,12 @@ class RosterWindow:
def on_block(self, widget, titer, group_list):
''' When clicked on the 'block' button in context menu. '''
def on_continue(msg):
if msg is None:
# user pressed Cancel to change status message dialog
return
model = self.modelfilter
accounts = []
msg = self.get_status_message('offline')
if group_list is None:
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
@ -2541,7 +2552,8 @@ class RosterWindow:
'child': [u'message', u'iq', u'presence-out']}
gajim.connections[account].blocked_list.append(new_rule)
# needed for draw_contact:
gajim.connections[account].blocked_contacts.append(contact.jid)
gajim.connections[account].blocked_contacts.append(
contact.jid)
self.draw_contact(contact.jid, account)
else:
group = model[titer][C_JID].decode('utf-8')
@ -2556,7 +2568,8 @@ class RosterWindow:
self.send_status(account, 'offline', msg, to=contact.jid)
self.draw_contact(contact.jid, account)
new_rule = {'order': u'1', 'type': u'group', 'action': u'deny',
'value' : group, 'child': [u'message', u'iq', u'presence-out']}
'value' : group, 'child': [u'message', u'iq',
u'presence-out']}
gajim.connections[account].blocked_list.append(new_rule)
for account in accounts:
gajim.connections[account].set_privacy_list(
@ -2566,6 +2579,8 @@ class RosterWindow:
gajim.connections[account].set_default_list('block')
gajim.connections[account].get_privacy_list('block')
self.get_status_message('offline', on_continue)
def on_unblock(self, widget, titer, group_list):
''' When clicked on the 'unblock' button in context menu. '''
model = self.modelfilter
@ -2954,10 +2969,10 @@ class RosterWindow:
def on_change_status_message_activate(self, widget, account):
show = gajim.SHOW_LIST[gajim.connections[account].connected]
dlg = dialogs.ChangeStatusMessageDialog(show)
message = dlg.run()
def on_response(message):
if message is not None: # None is if user pressed Cancel
self.send_status(account, show, message)
dialogs.ChangeStatusMessageDialog(on_response, show)
def on_add_to_roster(self, widget, contact, account):
dialogs.AddNewContactWindow(account, contact.jid, contact.name)
@ -3062,16 +3077,17 @@ class RosterWindow:
show = helpers.get_global_show()
if show == 'offline':
return True
dlg = dialogs.ChangeStatusMessageDialog(show)
message = dlg.run()
if not message:
def on_response(message):
if message is None:
return True
for acct in gajim.connections:
if not gajim.config.get_per('accounts', acct,
'sync_with_global_status'):
continue
current_show = gajim.SHOW_LIST[gajim.connections[acct].connected]
current_show = gajim.SHOW_LIST[gajim.connections[acct].\
connected]
self.send_status(acct, current_show, message)
dialogs.ChangeStatusMessageDialog(on_response, show)
return True
elif event.button == 1: # Left click
@ -3164,9 +3180,9 @@ class RosterWindow:
def on_send_custom_status(self, widget, contact_list, show, group=None):
'''send custom status'''
dlg = dialogs.ChangeStatusMessageDialog(show)
message = dlg.run()
if message is not None: # None if user pressed Cancel
def on_response(message):
if message is None: # None if user pressed Cancel
return
for (contact, account) in contact_list:
our_jid = gajim.get_jid_from_account(account)
accounts = []
@ -3182,6 +3198,7 @@ class RosterWindow:
if not gajim.interface.status_sent_to_users.has_key(account):
gajim.interface.status_sent_to_users[account] = {}
gajim.interface.status_sent_to_users[account][contact.jid] = show
dialogs.ChangeStatusMessageDialog(on_response, show)
def on_status_combobox_changed(self, widget):
'''When we change our status via the combobox'''
@ -3205,8 +3222,7 @@ class RosterWindow:
# 'Change status message' selected:
# do not change show, just show change status dialog
status = model[self.previous_status_combobox_active][2].decode('utf-8')
dlg = dialogs.ChangeStatusMessageDialog(status)
message = dlg.run()
def on_response(message):
if message is not None: # None if user pressed Cancel
for account in accounts:
if not gajim.config.get_per('accounts', account,
@ -3219,6 +3235,7 @@ class RosterWindow:
self.status_combobox.set_active(
self.previous_status_combobox_active)
self.combobox_callback_active = True
dialogs.ChangeStatusMessageDialog(on_response, status)
return
# we are about to change show, so save this new show so in case
# after user chooses "Change status message" menuitem
@ -3245,29 +3262,34 @@ class RosterWindow:
if dialog.get_response() != gtk.RESPONSE_OK:
self.update_status_combobox()
return
message = self.get_status_message(status)
if message is None: # user pressed Cancel to change status message dialog
def on_continue(message):
if message is None:
# user pressed Cancel to change status message dialog
self.update_status_combobox()
return
global_sync_accounts = []
for acct in accounts:
if gajim.config.get_per('accounts', acct, 'sync_with_global_status'):
if gajim.config.get_per('accounts', acct,
'sync_with_global_status'):
global_sync_accounts.append(acct)
global_sync_connected_accounts = gajim.get_number_of_connected_accounts(
global_sync_accounts)
global_sync_connected_accounts = \
gajim.get_number_of_connected_accounts(global_sync_accounts)
for account in accounts:
if not gajim.config.get_per('accounts', account,
'sync_with_global_status'):
continue
# we are connected (so we wanna change show and status)
# or no account is connected and we want to connect with new show and
# status
# or no account is connected and we want to connect with new show
# and status
if not global_sync_connected_accounts > 0 or \
gajim.connections[account].connected > 0:
self.send_status(account, status, message)
self.update_status_combobox()
self.get_status_message(status, on_continue)
def on_preferences_menuitem_activate(self, widget):
if gajim.interface.instances.has_key('preferences'):
gajim.interface.instances['preferences'].window.present()

View file

@ -358,10 +358,9 @@ class Systray:
model = gajim.interface.roster.status_combobox.get_model()
active = gajim.interface.roster.status_combobox.get_active()
status = model[active][2].decode('utf-8')
dlg = dialogs.ChangeStatusMessageDialog(status)
dlg.window.present()
message = dlg.run()
if message is not None: # None if user press Cancel
def on_response(message):
if message is None: # None if user press Cancel
return
accounts = gajim.connections.keys()
for acct in accounts:
if not gajim.config.get_per('accounts', acct,
@ -369,6 +368,8 @@ class Systray:
continue
show = gajim.SHOW_LIST[gajim.connections[acct].connected]
gajim.interface.roster.send_status(acct, show, message)
dlg = dialogs.ChangeStatusMessageDialog(on_response, status)
dlg.window.present()
def show_tooltip(self, widget):
position = widget.window.get_origin()