From e4a28f6572a95cb88ac37c05a70fc1aaf9213d1f Mon Sep 17 00:00:00 2001 From: Dimitur Kirov Date: Tue, 23 Aug 2005 23:41:23 +0000 Subject: [PATCH] added send_file remote command --- scripts/gajim-remote.py | 9 +++++++++ src/filetransfers_window.py | 5 +++++ src/gajim.py | 1 + src/remote_control.py | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/scripts/gajim-remote.py b/scripts/gajim-remote.py index 64c3b8ca0..d6c5513d1 100755 --- a/scripts/gajim-remote.py +++ b/scripts/gajim-remote.py @@ -136,6 +136,15 @@ sent using this account'), False), [ ('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 \ diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index 8b4e843a2..db6a561e5 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -253,6 +253,11 @@ _('Connection with peer cannot be established.')) def send_file(self, account, contact, file_path): ''' 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_props = self.get_send_file_props(account, contact, file_path, file_name) diff --git a/src/gajim.py b/src/gajim.py index 6bdb56455..2b5d6ab5d 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -339,6 +339,7 @@ class Interface: self.roster.popup_notification_windows.append(instance) if self.remote and self.remote.is_enabled(): self.remote.raise_signal('ContactAbsence', (account, array)) + # stop non active file transfers elif self.windows[account]['gc'].has_key(ji): #it is a groupchat presence diff --git a/src/remote_control.py b/src/remote_control.py index 9ef83933e..b441cdb6f 100644 --- a/src/remote_control.py +++ b/src/remote_control.py @@ -100,7 +100,8 @@ class SignalObject(DbusPrototype): self.change_status, self.open_chat, self.send_message, - self.contact_info + self.contact_info, + self.send_file ]) def raise_signal(self, signal, arg): @@ -121,6 +122,39 @@ class SignalObject(DbusPrototype): def VcardInfo(self, *vcard): 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): ''' send_message(jid, message, keyID=None, account=None) send 'message' to 'jid', using account (optional) 'account'. @@ -394,6 +428,7 @@ class SignalObject(DbusPrototype): open_chat = method(INTERFACE)(open_chat) contact_info = method(INTERFACE)(contact_info) send_message = method(INTERFACE)(send_message) + send_file = method(INTERFACE)(send_file) VcardInfo = signal(INTERFACE)(VcardInfo) class SessionBusNotPresent(Exception):