ability to send contacts via DnD to another contact. Fixes #378
This commit is contained in:
		
							parent
							
								
									99c74ab6a2
								
							
						
					
					
						commit
						0de2e8522d
					
				
					 3 changed files with 49 additions and 8 deletions
				
			
		| 
						 | 
					@ -1364,6 +1364,25 @@ class Connection(ConnectionHandlers):
 | 
				
			||||||
		if callback:
 | 
							if callback:
 | 
				
			||||||
			callback(msg_id, *callback_args)
 | 
								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):
 | 
						def send_stanza(self, stanza):
 | 
				
			||||||
		''' send a stanza untouched '''
 | 
							''' send a stanza untouched '''
 | 
				
			||||||
		if not self.connection:
 | 
							if not self.connection:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1783,11 +1783,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 | 
				
			||||||
		action = items_list[0].getAttr('action')
 | 
							action = items_list[0].getAttr('action')
 | 
				
			||||||
		if action == None:
 | 
							if action == None:
 | 
				
			||||||
			action = 'add'
 | 
								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')
 | 
								jid = item.getAttr('jid')
 | 
				
			||||||
			name = item.getAttr('name')
 | 
								name = item.getAttr('name')
 | 
				
			||||||
			groups=[]
 | 
								groups=[]
 | 
				
			||||||
			for group in item.getChildren():
 | 
								for group in item.getTags('group'):
 | 
				
			||||||
				groups.append(group.getData())
 | 
									groups.append(group.getData())
 | 
				
			||||||
			exchange_items_list[jid] = []
 | 
								exchange_items_list[jid] = []
 | 
				
			||||||
			exchange_items_list[jid].append(name)
 | 
								exchange_items_list[jid].append(name)
 | 
				
			||||||
| 
						 | 
					@ -1809,9 +1810,9 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		# check if the message is a roster item exchange (XEP-0144)
 | 
							# check if the message is a roster item exchange (XEP-0144)
 | 
				
			||||||
		#if msg.getTag('x') and msg.getTag('x').namespace == common.xmpp.NS_ROSTERX:
 | 
							if msg.getTag('x', namespace=common.xmpp.NS_ROSTERX):
 | 
				
			||||||
			#self._rosterItemExchangeCB(con, msg)
 | 
								self._rosterItemExchangeCB(con, msg)
 | 
				
			||||||
			#return
 | 
								return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# check if the message is a XEP-0070 confirmation request
 | 
							# check if the message is a XEP-0070 confirmation request
 | 
				
			||||||
		if msg.getTag('confirm', namespace=common.xmpp.NS_HTTP_AUTH):
 | 
							if msg.getTag('confirm', namespace=common.xmpp.NS_HTTP_AUTH):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3767,6 +3767,10 @@ class RosterWindow:
 | 
				
			||||||
	def drag_end(self, treeview, context):
 | 
						def drag_end(self, treeview, context):
 | 
				
			||||||
		self.dragging = False
 | 
							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,
 | 
						def on_drop_in_contact(self, widget, account_source, c_source, account_dest,
 | 
				
			||||||
	c_dest, was_big_brother, context, etime):
 | 
						c_dest, was_big_brother, context, etime):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4089,9 +4093,26 @@ class RosterWindow:
 | 
				
			||||||
			if not c_dest:
 | 
								if not c_dest:
 | 
				
			||||||
				# c_dest is None if jid_dest doesn't belong to account
 | 
									# c_dest is None if jid_dest doesn't belong to account
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			self.on_drop_in_contact(treeview, account_source, c_source,
 | 
								menu = gtk.Menu()
 | 
				
			||||||
				account_dest, c_dest, is_big_brother, context, etime)
 | 
								item = gtk.MenuItem(_('Send %s to %s') % (c_source.get_shown_name(),
 | 
				
			||||||
			return
 | 
									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....
 | 
					### Everything about images and icons....
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue