added send_file remote command
This commit is contained in:
		
							parent
							
								
									a51c320245
								
							
						
					
					
						commit
						e4a28f6572
					
				
					 4 changed files with 51 additions and 1 deletions
				
			
		| 
						 | 
					@ -136,6 +136,15 @@ sent using this account'), False),
 | 
				
			||||||
					[
 | 
										[
 | 
				
			||||||
						('jid', _('JID of the contact'), True)
 | 
											('jid', _('JID of the contact'), True)
 | 
				
			||||||
					]
 | 
										]
 | 
				
			||||||
 | 
									],
 | 
				
			||||||
 | 
								'send_file': [
 | 
				
			||||||
 | 
										_('Send file to a contact'),
 | 
				
			||||||
 | 
										[
 | 
				
			||||||
 | 
											(_('file'), _('File path'), True),
 | 
				
			||||||
 | 
											('jid', _('JID of the contact'), True),
 | 
				
			||||||
 | 
											(_('account'), _('if specified, file will be sent \
 | 
				
			||||||
 | 
					using this account'), False)
 | 
				
			||||||
 | 
										]
 | 
				
			||||||
				]
 | 
									]
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		if self.argv_len  < 2 or \
 | 
							if self.argv_len  < 2 or \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -253,6 +253,11 @@ _('Connection with peer cannot be established.'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def send_file(self, account, contact, file_path):
 | 
						def send_file(self, account, contact, file_path):
 | 
				
			||||||
		''' start the real transfer(upload) of the file '''
 | 
							''' start the real transfer(upload) of the file '''
 | 
				
			||||||
 | 
							if type(contact) == str:
 | 
				
			||||||
 | 
								if contact.find('/') == -1:
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								(jid, resource) = contact.split("/", 1)
 | 
				
			||||||
 | 
								contact = gajim.Contact(jid = jid, resource = resource)
 | 
				
			||||||
		(file_dir, file_name) = os.path.split(file_path)
 | 
							(file_dir, file_name) = os.path.split(file_path)
 | 
				
			||||||
		file_props = self.get_send_file_props(account, contact, 
 | 
							file_props = self.get_send_file_props(account, contact, 
 | 
				
			||||||
				file_path, file_name)
 | 
									file_path, file_name)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -339,6 +339,7 @@ class Interface:
 | 
				
			||||||
						self.roster.popup_notification_windows.append(instance)
 | 
											self.roster.popup_notification_windows.append(instance)
 | 
				
			||||||
				if self.remote and self.remote.is_enabled():
 | 
									if self.remote and self.remote.is_enabled():
 | 
				
			||||||
					self.remote.raise_signal('ContactAbsence', (account, array))
 | 
										self.remote.raise_signal('ContactAbsence', (account, array))
 | 
				
			||||||
 | 
									# stop non active file transfers
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
		elif self.windows[account]['gc'].has_key(ji):
 | 
							elif self.windows[account]['gc'].has_key(ji):
 | 
				
			||||||
			#it is a groupchat presence
 | 
								#it is a groupchat presence
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,7 +100,8 @@ class SignalObject(DbusPrototype):
 | 
				
			||||||
				self.change_status,
 | 
									self.change_status,
 | 
				
			||||||
				self.open_chat,
 | 
									self.open_chat,
 | 
				
			||||||
				self.send_message,
 | 
									self.send_message,
 | 
				
			||||||
				self.contact_info
 | 
									self.contact_info,
 | 
				
			||||||
 | 
									self.send_file
 | 
				
			||||||
			])
 | 
								])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def raise_signal(self, signal, arg):
 | 
						def raise_signal(self, signal, arg):
 | 
				
			||||||
| 
						 | 
					@ -121,6 +122,39 @@ class SignalObject(DbusPrototype):
 | 
				
			||||||
	def VcardInfo(self, *vcard):
 | 
						def VcardInfo(self, *vcard):
 | 
				
			||||||
		pass
 | 
							pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						def send_file(self, *args):
 | 
				
			||||||
 | 
							''' send_file(file_path, jid, account=None) 
 | 
				
			||||||
 | 
							send file, located at 'file_path' to 'jid', using account 
 | 
				
			||||||
 | 
							(optional) 'account' '''
 | 
				
			||||||
 | 
							file_path, jid, account = self._get_real_arguments(args, 3)
 | 
				
			||||||
 | 
							accounts = gajim.contacts.keys()
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							# if there is only one account in roster, take it as default
 | 
				
			||||||
 | 
							if not account and len(accounts) == 1:
 | 
				
			||||||
 | 
								account = accounts[0]
 | 
				
			||||||
 | 
							if account:
 | 
				
			||||||
 | 
								if gajim.connections[account].connected > 1: # account is  online
 | 
				
			||||||
 | 
									connected_account = gajim.connections[account]
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								for account in accounts:
 | 
				
			||||||
 | 
									if gajim.contacts[account].has_key(jid) and \
 | 
				
			||||||
 | 
										gajim.connections[account].connected > 1: # account is  online
 | 
				
			||||||
 | 
										connected_account = gajim.connections[account]
 | 
				
			||||||
 | 
										break
 | 
				
			||||||
 | 
							if gajim.contacts.has_key(account) and \
 | 
				
			||||||
 | 
								gajim.contacts[account].has_key(jid):
 | 
				
			||||||
 | 
								contact = gajim.get_highest_prio_contact_from_contacts(
 | 
				
			||||||
 | 
									gajim.contacts[account][jid])
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								contact = jid
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if connected_account:
 | 
				
			||||||
 | 
								if os.path.isfile(file_path): # is it file?
 | 
				
			||||||
 | 
									self.plugin.windows['file_transfers'].send_file(account, 
 | 
				
			||||||
 | 
										contact, file_path)
 | 
				
			||||||
 | 
									return True
 | 
				
			||||||
 | 
							return False
 | 
				
			||||||
 | 
							
 | 
				
			||||||
	def send_message(self, *args):
 | 
						def send_message(self, *args):
 | 
				
			||||||
		''' send_message(jid, message, keyID=None, account=None)
 | 
							''' send_message(jid, message, keyID=None, account=None)
 | 
				
			||||||
		send 'message' to 'jid', using account (optional) 'account'.
 | 
							send 'message' to 'jid', using account (optional) 'account'.
 | 
				
			||||||
| 
						 | 
					@ -394,6 +428,7 @@ class SignalObject(DbusPrototype):
 | 
				
			||||||
		open_chat = method(INTERFACE)(open_chat)
 | 
							open_chat = method(INTERFACE)(open_chat)
 | 
				
			||||||
		contact_info = method(INTERFACE)(contact_info)
 | 
							contact_info = method(INTERFACE)(contact_info)
 | 
				
			||||||
		send_message = method(INTERFACE)(send_message)
 | 
							send_message = method(INTERFACE)(send_message)
 | 
				
			||||||
 | 
							send_file = method(INTERFACE)(send_file)
 | 
				
			||||||
		VcardInfo = signal(INTERFACE)(VcardInfo)
 | 
							VcardInfo = signal(INTERFACE)(VcardInfo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SessionBusNotPresent(Exception):
 | 
					class SessionBusNotPresent(Exception):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue