From 0de2e8522dbfe973ba1d0190999d8f5e2d2d35aa Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 7 Jul 2009 16:28:26 +0200 Subject: [PATCH] ability to send contacts via DnD to another contact. Fixes #378 --- src/common/connection.py | 19 +++++++++++++++++++ src/common/connection_handlers.py | 11 ++++++----- src/roster_window.py | 27 ++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 74a91c22f..9189ece2b 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1364,6 +1364,25 @@ class Connection(ConnectionHandlers): if callback: callback(msg_id, *callback_args) + def send_contacts(self, contacts, jid): + '''Send contacts with RosterX (Xep-0144)''' + if not self.connection: + return + if len(contacts) == 1: + msg = _('Sent contact: "%s" (%s)') % (contacts[0].get_full_jid(), + contacts[0].get_shown_name()) + else: + msg = _('Sent contacts:') + for contact in contacts: + msg += '\n "%s" (%s)' % (contact.get_full_jid(), + contact.get_shown_name()) + msg_iq = common.xmpp.Message(to=jid, body=msg) + x = msg_iq.addChild(name='x', namespace=common.xmpp.NS_ROSTERX) + for contact in contacts: + x.addChild(name='item', attrs={'action': 'add', 'jid': contact.jid, + 'name': contact.get_shown_name()}) + self.connection.send(msg_iq) + def send_stanza(self, stanza): ''' send a stanza untouched ''' if not self.connection: diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 48819d8d9..e61af324a 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1783,11 +1783,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, action = items_list[0].getAttr('action') if action == None: action = 'add' - for item in msg.getTag('x').getChildren(): + for item in msg.getTag('x', + namespace=common.xmpp.NS_ROSTERX).getChildren(): jid = item.getAttr('jid') name = item.getAttr('name') groups=[] - for group in item.getChildren(): + for group in item.getTags('group'): groups.append(group.getData()) exchange_items_list[jid] = [] exchange_items_list[jid].append(name) @@ -1809,9 +1810,9 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, return # check if the message is a roster item exchange (XEP-0144) - #if msg.getTag('x') and msg.getTag('x').namespace == common.xmpp.NS_ROSTERX: - #self._rosterItemExchangeCB(con, msg) - #return + if msg.getTag('x', namespace=common.xmpp.NS_ROSTERX): + self._rosterItemExchangeCB(con, msg) + return # check if the message is a XEP-0070 confirmation request if msg.getTag('confirm', namespace=common.xmpp.NS_HTTP_AUTH): diff --git a/src/roster_window.py b/src/roster_window.py index b97f36823..4111c9fca 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -3767,6 +3767,10 @@ class RosterWindow: def drag_end(self, treeview, context): self.dragging = False + def on_drop_rosterx(self, widget, account_source, c_source, account_dest, + c_dest, was_big_brother, context, etime): + gajim.connections[account_dest].send_contacts([c_source], c_dest.jid) + def on_drop_in_contact(self, widget, account_source, c_source, account_dest, c_dest, was_big_brother, context, etime): @@ -4089,9 +4093,26 @@ class RosterWindow: if not c_dest: # c_dest is None if jid_dest doesn't belong to account return - self.on_drop_in_contact(treeview, account_source, c_source, - account_dest, c_dest, is_big_brother, context, etime) - return + menu = gtk.Menu() + item = gtk.MenuItem(_('Send %s to %s') % (c_source.get_shown_name(), + c_dest.get_shown_name())) + item.connect('activate', self.on_drop_rosterx, account_source, + c_source, account_dest, c_dest, is_big_brother, context, etime) + menu.append(item) + + item = gtk.MenuItem(_('Make %s and %s metacontacts') % ( + c_source.get_shown_name(), c_dest.get_shown_name())) + item.connect('activate', self.on_drop_in_contact, account_source, + c_source, account_dest, c_dest, is_big_brother, context, etime) + + menu.append(item) + + menu.attach_to_widget(self.tree, None) + menu.connect('selection-done', gtkgui_helpers.destroy_widget) + menu.show_all() + menu.popup(None, None, None, 1, etime) +# self.on_drop_in_contact(treeview, account_source, c_source, +# account_dest, c_dest, is_big_brother, context, etime) ################################################################################ ### Everything about images and icons....