From b83f9ae5d6a7fceb723716a159ca27b88035ee23 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 5 Aug 2009 23:58:25 +0200 Subject: [PATCH] [Dicson] add support for key 'body' in the Message Action, and add jid via roster command. Fixes #5195 --- src/gajim-remote.py | 36 +++++++++++++++++++++++++++++++----- src/gajim.py | 5 ++++- src/remote_control.py | 6 +++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/gajim-remote.py b/src/gajim-remote.py index b686897fb..c0a7ccf59 100644 --- a/src/gajim-remote.py +++ b/src/gajim-remote.py @@ -120,7 +120,10 @@ class GajimRemote: ('jid', _('JID of the contact that you want to chat with'), True), (_('account'), _('if specified, contact is taken from the ' - 'contact list of this account'), False) + 'contact list of this account'), False), + (_('message'), + _('message content. The account must be specified or ""'), + False) ] ], 'send_chat_message':[ @@ -257,7 +260,8 @@ class GajimRemote: [ (_('uri'), _('URI to handle'), True), (_('account'), _('Account in which you want to handle it'), - False) + False), + (_('message'), _('Message content'), False) ] ], 'join_room': [ @@ -282,7 +286,7 @@ class GajimRemote: } self.sbus = None - if self.argv_len < 2 or sys.argv[1] not in self.commands.keys(): + if self.argv_len < 2 or sys.argv[1] not in self.commands.keys(): # no args or bad args send_error(self.compose_help()) self.command = sys.argv[1] @@ -405,7 +409,7 @@ class GajimRemote: if len(command_props[1]) > 0: str_ += '\n\n' + _('Arguments:') + '\n' for argument in command_props[1]: - str_ += ' ' + argument[0] + ' - ' + argument[1] + '\n' + str_ += ' ' + argument[0] + ' - ' + argument[1] + '\n' return str_ send_error(_('%s not found') % command) @@ -506,6 +510,25 @@ class GajimRemote: if not '?' in uri: self.command = sys.argv[1] = 'open_chat' return + if 'body=' in uri: + # Open chat window and paste the text in the input message dialog + self.command = sys.argv[1] = 'open_chat' + message = uri.split('body=') + message = message[1].split(';')[0] + try: + message = urllib.unquote(message) + except UnicodeDecodeError: + pass + sys.argv[2] = uri.split('?')[0] + if len(sys.argv) == 4: + # jid in the sys.argv + sys.argv.append(message) + else: + sys.argv.append('') + sys.argv.append(message) + sys.argv[3] = '' + sys.argv[4] = message + return (jid, action) = uri.split('?', 1) try: jid = urllib.unquote(jid) @@ -519,7 +542,10 @@ class GajimRemote: sys.argv.append(sys.argv[3]) sys.argv[3] = '' return - + if action.startswith('roster'): + # Add contact to roster + self.command = sys.argv[1] = 'add_contact' + return sys.exit(0) def call_remote_method(self): diff --git a/src/gajim.py b/src/gajim.py index e44209c5a..085c7cbc4 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -2887,7 +2887,7 @@ class Interface: return chat_control - def new_chat_from_jid(self, account, fjid): + def new_chat_from_jid(self, account, fjid, message=None): jid, resource = gajim.get_room_and_nick_from_fjid(fjid) contact = gajim.contacts.get_contact(account, jid, resource) added_to_roster = False @@ -2904,6 +2904,9 @@ class Interface: if len(gajim.events.get_events(account, fjid)): ctrl.read_queue() + if message: + buffer = ctrl.msg_textview.get_buffer() + buffer.set_text(message) mw = ctrl.parent_win mw.set_active_tab(ctrl) # For JEP-0172 diff --git a/src/remote_control.py b/src/remote_control.py index 5135ca2e1..f9c6d5947 100644 --- a/src/remote_control.py +++ b/src/remote_control.py @@ -329,8 +329,8 @@ class SignalObject(dbus.service.Object): return DBUS_BOOLEAN(True) return DBUS_BOOLEAN(False) - @dbus.service.method(INTERFACE, in_signature='ss', out_signature='b') - def open_chat(self, jid, account): + @dbus.service.method(INTERFACE, in_signature='sss', out_signature='b') + def open_chat(self, jid, account, message): '''Shows the tabbed window for new message to 'jid', using account (optional) 'account' ''' if not jid: @@ -372,7 +372,7 @@ class SignalObject(dbus.service.Object): connected_account = first_connected_acct if connected_account: - gajim.interface.new_chat_from_jid(connected_account, jid) + gajim.interface.new_chat_from_jid(connected_account, jid, message) # preserve the 'steal focus preservation' win = gajim.interface.msg_win_mgr.get_window(jid, connected_account).window