[misc] handle uri like room_jid?join. see #2133

This commit is contained in:
Yann Leboulanger 2007-01-02 02:45:43 +00:00
parent 7945ceac83
commit cafef3c1c5
3 changed files with 58 additions and 4 deletions

View File

@ -228,6 +228,23 @@ class GajimRemote:
False)
]
],
'handle_uri': [
_('Handle a xmpp:/ uri'),
[
(_('uri'), _(''), True),
(_('account'), _(''), False)
]
],
'join_room': [
_('Join a MUC room'),
[
(_('room'), _(''), True),
(_('nick'), _(''), False),
(_('password'), _(''), False),
(_('account'), _(''), False)
]
],
}
if self.argv_len < 2 or \
sys.argv[1] not in self.commands.keys(): # no args or bad args
@ -239,7 +256,8 @@ class GajimRemote:
else:
print self.compose_help().encode(PREFERRED_ENCODING)
sys.exit(0)
if self.command == 'handle_uri':
self.handle_uri()
self.init_connection()
self.check_arguments()
@ -420,6 +438,22 @@ class GajimRemote:
'Type "%s help %s" for more info') %
(args[argv_len][0], BASENAME, self.command))
def handle_uri(self):
if not sys.argv[2:][0].startswith('xmpp:'):
send_error(_('Wrong uri'))
sys.argv[2] = sys.argv[2][5:]
uri = sys.argv[2:][0]
if not '?' in uri:
self.command = sys.argv[1] = 'open_chat'
return
(jid, action) = uri.split('?', 1)
sys.argv[2] = jid
if action == 'join':
self.command = sys.argv[1] = 'join_room'
return
sys.exit(0)
def call_remote_method(self):
''' calls self.method with arguments from sys.argv[2:] '''
args = sys.argv[2:]

View File

@ -665,9 +665,9 @@ def possibly_set_gajim_as_xmpp_handler():
path_to_gajim_script, typ = get_abspath_for_script('gajim-remote', True)
if path_to_gajim_script:
if typ == 'svn':
command = path_to_gajim_script + ' open_chat %s'
command = path_to_gajim_script + ' handle_uri %s'
else: # 'installed'
command = 'gajim-remote open_chat %s'
command = 'gajim-remote handle_uri %s'
# setting for GNOME/Gconf
client.set_bool('/desktop/gnome/url-handlers/xmpp/enabled', True)

View File

@ -21,7 +21,7 @@ import os
from common import gajim
from common import helpers
from time import time
from dialogs import AddNewContactWindow, NewChatDialog
from dialogs import AddNewContactWindow, NewChatDialog, JoinGroupchatWindow
from common import dbus_support
if dbus_support.supported:
@ -631,3 +631,23 @@ class SignalObject(dbus.service.Object):
else:
for acc in gajim.contacts.get_accounts():
gajim.connections[acc].send_stanza(xml)
@dbus.service.method(INTERFACE)
def join_room(self, *args):
room_jid, nick, passwd, account = self._get_real_arguments(args, 4)
if not account:
# get the first connected account
accounts = gajim.connections.keys()
for acct in accounts:
if gajim.account_is_connected(acct):
account = acct
break
if not account:
account = gajim.contacts.get_accounts()[0]
print account
if nick is None:
nick = ''
gajim.interface.instances[account]['join_gc'] = \
JoinGroupchatWindow(account, room_jid, nick)
else:
gajim.connections[account].join_gc(nick, room_jid, password)