diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 01782fc6d..066887d6a 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -616,9 +616,11 @@ class ConnectionVcard: show=sshow, status=self.status) p = self.add_sha(p) self.connection.send(p) - self.dispatch('VCARD_PUBLISHED', ()) + gajim.nec.push_incoming_event(VcardPublishedEvent(None, + conn=self)) elif iq_obj.getType() == 'error': - self.dispatch('VCARD_NOT_PUBLISHED', ()) + gajim.nec.push_incoming_event(VcardNotPublishedEvent(None, + conn=self)) elif self.awaiting_answers[id_][0] == VCARD_ARRIVED: # If vcard is empty, we send to the interface an empty vcard so that # it knows it arrived diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index a1efbc9b3..c08a09347 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -1275,4 +1275,12 @@ class NewAccountNotConnectedEvent(nec.NetworkIncomingEvent): class ConnectionTypeEvent(nec.NetworkIncomingEvent): name = 'connection-type' + base_network_events = [] + +class VcardPublishedEvent(nec.NetworkIncomingEvent): + name = 'vcard-published' + base_network_events = [] + +class VcardNotPublishedEvent(nec.NetworkIncomingEvent): + name = 'vcard-not-published' base_network_events = [] \ No newline at end of file diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 3b94b3018..8a04cd657 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -397,6 +397,8 @@ class GroupchatControl(ChatControlBase): self._nec_gc_presence_received) gajim.ged.register_event_handler('gc-message-received', ged.GUI1, self._nec_gc_message_received) + gajim.ged.register_event_handler('vcard-published', ged.GUI1, + self._nec_vcard_published) gajim.gc_connected[self.account][self.room_jid] = False # disable win, we are not connected yet ChatControlBase.got_disconnected(self) @@ -810,6 +812,13 @@ class GroupchatControl(ChatControlBase): # destroy menu menu.destroy() + def _nec_vcard_published(self, obj): + if obj.conn.name != self.account: + return + show = gajim.SHOW_LIST[obj.conn.connected] + status = obj.conn.status + obj.conn.send_gc_status(self.nick, self.room_jid, show, status) + def _nec_gc_message_received(self, obj): if obj.room_jid != self.room_jid or obj.conn.name != self.account: return @@ -1716,6 +1725,8 @@ class GroupchatControl(ChatControlBase): self._nec_gc_presence_received) gajim.ged.remove_event_handler('gc-message-received', ged.GUI1, self._nec_gc_message_received) + gajim.ged.remove_event_handler('vcard-published', ged.GUI1, + self._nec_vcard_published) if self.room_jid in gajim.gc_connected[self.account] and \ gajim.gc_connected[self.account][self.room_jid]: diff --git a/src/gui_interface.py b/src/gui_interface.py index 9e0b5f26c..d60e725ce 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -1233,23 +1233,6 @@ class Interface: self.instances[account]['xml_console'].print_stanza(stanza, 'outgoing') - def handle_event_vcard_published(self, account, array): - if 'profile' in self.instances[account]: - win = self.instances[account]['profile'] - win.vcard_published() - for gc_control in self.msg_win_mgr.get_controls( - message_control.TYPE_GC) + self.minimized_controls[account].values(): - if gc_control.account == account: - show = gajim.SHOW_LIST[gajim.connections[account].connected] - status = gajim.connections[account].status - gajim.connections[account].send_gc_status(gc_control.nick, - gc_control.room_jid, show, status) - - def handle_event_vcard_not_published(self, account, array): - if 'profile' in self.instances[account]: - win = self.instances[account]['profile'] - win.vcard_not_published() - def ask_offline_status(self, account): for contact in gajim.contacts.iter_contacts(account): gajim.connections[account].request_last_status_time(contact.jid, @@ -1810,8 +1793,6 @@ class Interface: 'FILE_SEND_ERROR': [self.handle_event_file_send_error], 'STANZA_ARRIVED': [self.handle_event_stanza_arrived], 'STANZA_SENT': [self.handle_event_stanza_sent], - 'VCARD_PUBLISHED': [self.handle_event_vcard_published], - 'VCARD_NOT_PUBLISHED': [self.handle_event_vcard_not_published], 'SIGNED_IN': [self.handle_event_signed_in], 'METACONTACTS': [self.handle_event_metacontacts], 'ATOM_ENTRY': [self.handle_atom_entry], diff --git a/src/profile_window.py b/src/profile_window.py index 6a400e2f7..0699607a8 100644 --- a/src/profile_window.py +++ b/src/profile_window.py @@ -34,6 +34,7 @@ import dialogs import vcard from common import gajim +from common import ged class ProfileWindow: @@ -55,15 +56,19 @@ class ProfileWindow: self.avatar_mime_type = None self.avatar_encoded = None self.message_id = self.statusbar.push(self.context_id, - _('Retrieving profile...')) + _('Retrieving profile...')) self.update_progressbar_timeout_id = gobject.timeout_add(100, - self.update_progressbar) + self.update_progressbar) self.remove_statusbar_timeout_id = None # Create Image for avatar button image = gtk.Image() self.xml.get_object('PHOTO_button').set_image(image) self.xml.connect_signals(self) + gajim.ged.register_event_handler('vcard-published', ged.GUI1, + self._nec_vcard_published) + gajim.ged.register_event_handler('vcard-not-published', ged.GUI1, + self._nec_vcard_not_published) self.window.show_all() def update_progressbar(self): @@ -79,6 +84,10 @@ class ProfileWindow: gobject.source_remove(self.update_progressbar_timeout_id) if self.remove_statusbar_timeout_id is not None: gobject.source_remove(self.remove_statusbar_timeout_id) + gajim.ged.remove_event_handler('vcard-published', ged.GUI1, + self._nec_vcard_published) + gajim.ged.remove_event_handler('vcard-not-published', ged.GUI1, + self._nec_vcard_not_published) del gajim.interface.instances[self.account]['profile'] if self.dialog: # Image chooser dialog self.dialog.destroy() @@ -356,26 +365,30 @@ class ProfileWindow: self.update_progressbar_timeout_id = gobject.timeout_add(100, self.update_progressbar) - def vcard_published(self): + def _nec_vcard_published(self, obj): + if obj.conn.name != self.account: + return if self.update_progressbar_timeout_id is not None: gobject.source_remove(self.update_progressbar_timeout_id) self.update_progressbar_timeout_id = None self.window.destroy() - def vcard_not_published(self): + def _nec_vcard_not_published(self, obj): + if obj.conn.name != self.account: + return if self.message_id: self.statusbar.remove_message(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, - _('Information NOT published')) + _('Information NOT published')) self.remove_statusbar_timeout_id = gobject.timeout_add_seconds(3, - self.remove_statusbar, self.message_id) + self.remove_statusbar, self.message_id) if self.update_progressbar_timeout_id is not None: gobject.source_remove(self.update_progressbar_timeout_id) self.progressbar.set_fraction(0) self.update_progressbar_timeout_id = None dialogs.InformationDialog(_('vCard publication failed'), - _('There was an error while publishing your personal information, ' - 'try again later.')) + _('There was an error while publishing your personal information, ' + 'try again later.')) def on_cancel_button_clicked(self, widget): self.window.destroy()