From b3b34310721c514c140ec295ee719805f739e944 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 19 Jul 2006 10:49:23 +0000 Subject: [PATCH] add a self contact when another resource is connected to our account. Fixes #744 and usefull for ad-hoc commands --- data/glade/roster_contact_context_menu.glade | 30 ++++---- src/gajim.py | 18 +++-- src/roster_window.py | 76 ++++++++++++++++---- 3 files changed, 93 insertions(+), 31 deletions(-) diff --git a/data/glade/roster_contact_context_menu.glade b/data/glade/roster_contact_context_menu.glade index 60a98dfc3..0f54cfd2a 100644 --- a/data/glade/roster_contact_context_menu.glade +++ b/data/glade/roster_contact_context_menu.glade @@ -2,6 +2,7 @@ + @@ -11,7 +12,7 @@ True - + True gtk-jump-to 1 @@ -31,7 +32,7 @@ True - + True gtk-new 1 @@ -50,7 +51,7 @@ True - + True gtk-refresh 1 @@ -83,7 +84,7 @@ True - + True gtk-file 1 @@ -103,7 +104,7 @@ - + True gtk-dialog-authentication 1 @@ -123,7 +124,7 @@ True - + True gtk-info 1 @@ -137,7 +138,7 @@ - + True @@ -148,7 +149,7 @@ True - + True gtk-dialog-question 1 @@ -169,7 +170,7 @@ True - + True gtk-go-up 1 @@ -189,7 +190,7 @@ True - + True gtk-go-down 1 @@ -209,7 +210,7 @@ True - + True gtk-stop 1 @@ -232,7 +233,7 @@ True - + True gtk-add 1 @@ -251,7 +252,7 @@ True - + True gtk-remove 1 @@ -283,7 +284,7 @@ True - + True gtk-justify-fill 1 @@ -296,4 +297,5 @@ + diff --git a/src/gajim.py b/src/gajim.py index 7aacbfc56..558b10a32 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -377,7 +377,7 @@ class Interface: # Update contact jid_list = gajim.contacts.get_jid_list(account) - if ji in jid_list: + if ji in jid_list or jid == gajim.get_jid_from_account(account): lcontact = gajim.contacts.get_contacts_from_jid(account, ji) contact1 = None resources = [] @@ -394,7 +394,18 @@ class Interface: return else: contact1 = gajim.contacts.get_first_contact_from_jid(account, ji) - if contact1.show in statuss: + if not contact1: + # presence of another resource of out jid + contact1 = gajim.contacts.create_contact(jid = ji, + name = gajim.nicks[account], groups = [], + show = array[1], status = status_message, sub = 'both', + ask = 'none', priority = priority, keyID = keyID, + resource = resource) + old_show = 0 + gajim.contacts.add_contact(account, contact1) + lcontact.append(contact1) + self.roster.add_self_contact(account) + elif contact1.show in statuss: old_show = statuss.index(contact1.show) if (resources != [''] and (len(lcontact) != 1 or lcontact[0].show != 'offline')) and jid.find('@') > 0: @@ -440,9 +451,6 @@ class Interface: gajim.block_signed_in_notifications[account_ji] = True gobject.timeout_add(30000, self.unblock_signed_in_notifications, account_ji) - elif jid == gajim.get_jid_from_account(account): - # It's another of our resources. We don't need to see that! - return elif ji in jid_list: # It isn't an agent # reset chatstate if needed: diff --git a/src/roster_window.py b/src/roster_window.py index a741e0fcf..034b2b599 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -82,6 +82,12 @@ class RosterWindow: return group_iter def get_contact_iter(self, jid, account): + if jid == gajim.get_jid_from_account(account): + iter = self.get_self_contact_iter(account) + if iter: + return [iter] + else: + return [] model = self.tree.get_model() acct = self.get_account_iter(account) found = [] @@ -203,6 +209,9 @@ class RosterWindow: # If contact already in roster, do not add it if len(self.get_contact_iter(jid, account)): return + if jid == gajim.get_jid_from_account(account): + self.add_self_contact(account) + return if gajim.jid_is_transport(contact.jid): contact.groups = [_('Transports')] @@ -324,6 +333,29 @@ class RosterWindow: data['jid']) self.add_contact_to_roster(data['jid'], data['account']) + def get_self_contact_iter(self, account): + model = self.tree.get_model() + iterAcct = self.get_account_iter(account) + iter = model.iter_children(iterAcct) + if not iter: + return None + if model[iter][C_TYPE] == 'self_contact': + return iter + return None + + def add_self_contact(self, account): + jid = gajim.get_jid_from_account(account) + if self.get_self_contact_iter(account): + self.draw_contact(jid, account) + self.draw_avatar(jid, account) + return + model = self.tree.get_model() + iterAcct = self.get_account_iter(account) + model.append(iterAcct, (None, gajim.nicks[account], 'self_contact', jid, + account, False, None)) + self.draw_contact(jid, account) + self.draw_avatar(jid, account) + def add_transport_to_roster(self, account, transport): c = gajim.contacts.create_contact(jid = transport, name = transport, groups = [_('Transports')], show = 'offline', status = 'offline', @@ -1078,7 +1110,7 @@ class RosterWindow: except: self.tooltip.hide_tooltip() return - if model[iter][C_TYPE] == 'contact': + if model[iter][C_TYPE] in ('contact', 'self_contact'): # we're on a contact entry in the roster account = model[iter][C_ACCOUNT].decode('utf-8') jid = model[iter][C_JID].decode('utf-8') @@ -1238,7 +1270,10 @@ class RosterWindow: if contact is None: dialogs.SingleMessageWindow(account, action = 'send') else: - dialogs.SingleMessageWindow(account, contact.jid, 'send') + jid = contact.jid + if contact.jid == gajim.get_jid_from_account(account): + jid += '/' + contact.resource + dialogs.SingleMessageWindow(account, jid, 'send') def on_send_file_menuitem_activate(self, widget, account, contact): gajim.interface.instances['file_transfers'].show_file_send_request( @@ -1253,6 +1288,7 @@ class RosterWindow: jid = model[iter][C_JID].decode('utf-8') path = model.get_path(iter) account = model[iter][C_ACCOUNT].decode('utf-8') + our_jid = jid == gajim.get_jid_from_account(account) contact = gajim.contacts.get_contact_with_highest_priority(account, jid) if not contact: return @@ -1276,20 +1312,30 @@ class RosterWindow: add_special_notification_menuitem.hide() add_special_notification_menuitem.set_no_show_all(True) - - # add a special img for rename menuitem - path_to_kbd_input_img = os.path.join(gajim.DATA_DIR, 'pixmaps', - 'kbd_input.png') - img = gtk.Image() - img.set_from_file(path_to_kbd_input_img) - rename_menuitem.set_image(img) - # skip a separator + if not our_jid: + # add a special img for rename menuitem + path_to_kbd_input_img = os.path.join(gajim.DATA_DIR, 'pixmaps', + 'kbd_input.png') + img = gtk.Image() + img.set_from_file(path_to_kbd_input_img) + rename_menuitem.set_image(img) + + above_subscription_separator = xml.get_widget( + 'above_subscription_separator') subscription_menuitem = xml.get_widget('subscription_menuitem') send_auth_menuitem, ask_auth_menuitem, revoke_auth_menuitem =\ subscription_menuitem.get_submenu().get_children() add_to_roster_menuitem = xml.get_widget('add_to_roster_menuitem') - remove_from_roster_menuitem = xml.get_widget('remove_from_roster_menuitem') + remove_from_roster_menuitem = xml.get_widget( + 'remove_from_roster_menuitem') + + if our_jid: + for menuitem in (rename_menuitem, edit_groups_menuitem, + above_subscription_separator, subscription_menuitem, + remove_from_roster_menuitem): + menuitem.set_no_show_all(True) + menuitem.hide() # skip a separator information_menuitem = xml.get_widget('information_menuitem') history_menuitem = xml.get_widget('history_menuitem') @@ -1706,7 +1752,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid) self.make_group_menu(event, iter) elif type == 'agent': self.make_transport_menu(event, iter) - elif type == 'contact': + elif type in ('contact', 'self_contact'): self.make_contact_menu(event, iter) elif type == 'account': self.make_account_menu(event, iter) @@ -2559,6 +2605,8 @@ _('If "%s" accepts this request you will know his or her status.') % jid) if self.open_event(account, fjid, first_ev): return c = gajim.contacts.get_contact_with_highest_priority(account, jid) + if jid == gajim.get_jid_from_account(account): + resource = c.resource self.on_open_chat_window(widget, c, account, resource = resource) def on_roster_treeview_row_expanded(self, widget, iter, path): @@ -2972,6 +3020,10 @@ _('If "%s" accepts this request you will know his or her status.') % jid) name2 = name2.decode('utf-8') type1 = model[iter1][C_TYPE] type2 = model[iter2][C_TYPE] + if type1 == 'self_contact': + return -1 + if type2 == 'self_contact': + return 1 if type1 == 'group': if name1 == _('Transports'): return 1