ability to send contacts via DnD to another contact. Fixes #378
This commit is contained in:
parent
99c74ab6a2
commit
0de2e8522d
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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....
|
||||
|
|
Loading…
Reference in New Issue