From 0bde1f52ef2892f45b6ccd7dac093cd03f1215f1 Mon Sep 17 00:00:00 2001 From: Dimitur Kirov Date: Wed, 20 Jul 2005 15:45:56 +0000 Subject: [PATCH] 'send_message' and 'open_chat' with jid not in the roster (if multiple accounts) sends error --- scripts/gajim-remote.py | 22 +++++++++++++++++----- src/remote_control.py | 37 +++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/scripts/gajim-remote.py b/scripts/gajim-remote.py index 412cd95cb..f0e2dfb78 100755 --- a/scripts/gajim-remote.py +++ b/scripts/gajim-remote.py @@ -112,11 +112,11 @@ list of this account'), False) ] ], 'send_message':[ - _('Send new message to a contact in the roster'), + _('Send new message to a contact in the roster. Both pgp key and account are optional. If you want to set only \'account\', whitout \'pgp key\', just set \'pgp key\' to \'\'.'), [ ('jid', _('jid of the contact that will receive the message'), True), (_('message'), _('message contents'), True), - (_('keyID'), _('if specified the message will be encrypted using \ + (_('pgp key'), _('if specified the message will be encrypted using \ this pulic key'), False), (_('account'), _('if specified the message will be sent using this account'), False), ] @@ -222,6 +222,8 @@ def call_remote_method(method): res = method(sys.argv[2], sys.argv[3]) elif argv_len == 5: res = method(sys.argv[2], sys.argv[3], sys.argv[4]) + elif argv_len == 6: + res = method(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) return res except: send_error(_('Service not available')) @@ -271,9 +273,19 @@ if command == 'contact_info': res = call_remote_method(method) - -if res: - print res +if res is not None: + if command in ['open_chat', 'send_message']: + if command == 'send_message': + argv_len -= 2 + + if res == False: + if argv_len < 4: + send_error(_('\'%s\' is not in your roster.\n\ +Please specify account for sending the message.') % sys.argv[2]) + else: + send_error(_('You have no active account')) + elif res is True: + print res if command == 'contact_info': gobject.timeout_add(5000, gtk_quit) # wait 5 sec maximum diff --git a/src/remote_control.py b/src/remote_control.py index 97f5a70c3..6e7b28ab7 100644 --- a/src/remote_control.py +++ b/src/remote_control.py @@ -130,11 +130,16 @@ class SignalObject(DbusPrototype): if not keyID: keyID = '' connected_account = None - if account and \ - gajim.connections[account].connected > 1: # account is online - connected_account = gajim.connections[account] + 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 gajim.contacts.keys(): + 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] @@ -157,22 +162,30 @@ class SignalObject(DbusPrototype): accounts = [account] else: accounts = gajim.connections.keys() + if len(accounts) == 1: + account = accounts[0] connected_account = None - for account in accounts: - if self.plugin.windows[account]['chats'].has_key(jid) and \ - gajim.connections[account].connected > 1: # account is online - connected_account = account - break - elif gajim.connections[account].connected > 1: # account is online - connected_account = account - if gajim.contacts[account].has_key(jid): + for acct in accounts: + if gajim.connections[acct].connected > 1: # account is online + if self.plugin.windows[acct]['chats'].has_key(jid): + connected_account = acct break + # jid is in roster + elif gajim.contacts[acct].has_key(jid): + connected_account = acct + break + # we send the message to jid not in roster, because account is specified, + # or there is only one account + elif account: + connected_account = acct if connected_account: self.plugin.roster.new_chat_from_jid(connected_account, jid) # preserve the 'steal focus preservation' win = self.plugin.windows[connected_account]['chats'][jid].window if win.get_property('visible'): win.window.focus() + return True + return False def change_status(self, *args, **keywords): ''' change_status(status, message, account). account is optional -