register xmpp:// gajim-remote handler in GNOME; various cleanup

This commit is contained in:
Nikos Kouremenos 2005-09-07 21:12:30 +00:00
parent 3f71cbb6c5
commit 914749b740
5 changed files with 74 additions and 37 deletions

View File

@ -147,6 +147,7 @@ class Config:
'avatar_width': [opt_int, 52],
'avatar_height': [opt_int, 52],
'quit_on_roster_x_button': [opt_bool, False, _('If True, quits Gajim when X button of Window Manager is clicked. This option make sense only if trayicon is used.')],
'set_xmpp://_handler_everytime': [opt_bool, False, _('If True, Gajim registers for xmpp:// on each startup.')],
}
__options_per_key = {

View File

@ -112,7 +112,7 @@ have "sync with global status" option set'), False)
]
],
'open_chat': [
_('Show the chat dialog so that you can send message to a \
_('Show the chat dialog so that you can send messages to a \
contact'),
[
('jid', _('JID of the contact that you want to chat \
@ -189,7 +189,7 @@ using this account'), False)
if self.command == 'send_message':
self.argv_len -= 2
if res == False:
if res is False:
if self.argv_len < 4:
send_error(_('\'%s\' is not in your roster.\n\
Please specify account for sending the message.') % sys.argv[2])

View File

@ -59,7 +59,7 @@ from common import optparser
profile = ''
try:
opts, args = getopt.getopt(sys.argv[2:], 'hvp:', ['help', 'verbose',
opts, args = getopt.getopt(sys.argv[1:], 'hvp:', ['help', 'verbose',
'profile=', 'sm-config-prefix=', 'sm-client-id='])
except getopt.error, msg:
print msg
@ -1211,41 +1211,38 @@ if __name__ == '__main__':
cli = gnome.ui.master_client()
cli.connect('die', die_cb)
if os.path.isdir('.svn'): # we are svn user
cwd = os.getcwd()
svn_src = False
svn_trunk = False
script = '#!/bin/sh\n'
if cwd.endswith('trunk'): # we run with ./launch.sh
script += 'cd %s/src' % cwd
svn_trunk = True
elif cwd.endswith('src'): # we run with ./gajim.py in src/
script += 'cd %s' % cwd
svn_src = True
if svn_src or svn_trunk:
if svn_trunk:
path_to_gajim_script = cwd + '/scripts/gajim_sm_script'
elif svn_src:
path_to_gajim_script = cwd + '/../scripts/gajim_sm_script'
if os.path.exists(path_to_gajim_script):
os.remove(path_to_gajim_script)
f = open(path_to_gajim_script, 'w')
script += '\nexec python -OOt gajim.py $0 $@\n'
f.write(script)
f.close()
os.chmod(path_to_gajim_script, 0700)
else: # normal user (not svn user)
# always make it like '/usr/local/bin/gajim'
path_to_gajim_script = helpers.is_in_path('gajim', True)
path_to_gajim_script = gtkgui_helpers.get_abspath_for_script('gajim')
if path_to_gajim_script:
argv = [path_to_gajim_script]
cli.set_restart_command(len(argv), argv)
try:
import gconf
# in try because daemon may not be there
client = gconf.client_get_default()
except:
pass
else:
we_set = False
print client.get_string('/desktop/gnome/url-handlers/xmpp/command')
if client.get_string('/desktop/gnome/url-handlers/xmpp/command') is None:
we_set = True
elif gajim.config.get('set_xmpp://_handler_everytime'):
we_set = True
print we_set
if we_set:
path_to_gajim_script, type = gtkgui_helpers.get_abspath_for_script(
'gajim-remote', True)
print path_to_gajim_script
if path_to_gajim_script:
if type == 'svn':
command = path_to_gajim_script + 'open_chat %s'
print command
else: # 'installed'
command = 'gajim-remote open_chat %s'
client.set_string('/desktop/gnome/url-handlers/xmpp/command', command)
Interface()
gtk.main()

View File

@ -190,3 +190,37 @@ def set_unset_urgency_hint(window, unread_messages_no):
window.props.urgency_hint = True
else:
window.props.urgency_hint = False
def get_abspath_for_script(scriptname, want_type = False):
'''checks if we are svn or normal user and returns abspath to asked script
if want_type is True we return 'svn' or 'install' '''
if os.path.isdir('.svn'): # we are svn user
type = 'svn'
cwd = os.getcwd() # it's always ending with src
if scriptname == 'gajim-remote':
path_to_script = cwd + '/gajim-remote.py'
elif scriptname == 'gajim':
script = '#!/bin/sh\n' # the script we may create
script += 'cd %s' % cwd
path_to_script = cwd + '/../scripts/gajim_sm_script'
if os.path.exists(path_to_script):
os.remove(path_to_script)
f = open(path_to_script, 'w')
script += '\nexec python -OOt gajim.py $0 $@\n'
f.write(script)
f.close()
os.chmod(path_to_script, 0700)
else: # normal user (not svn user)
type = 'install'
# always make it like '/usr/local/bin/gajim'
path_to_script = helpers.is_in_path(scriptname, True)
if want_type:
return path_to_script, type
else:
return path_to_script

View File

@ -1,9 +1,10 @@
## roster_window.py
## remote_control.py
##
## Gajim Team:
## - Yann Le Boulanger <asterix@lagaule.org>
## - Vincent Hanquez <tab@snarc.org>
## - Nikos Kouremenos <kourem@gmail.com>
## - Dimitur Kirov <dkirov@gmail.com>
##
## Copyright (C) 2003-2005 Gajim Team
##
@ -188,13 +189,17 @@ class SignalObject(DbusPrototype):
def open_chat(self, *args):
''' start_chat(jid, account=None) -> shows the tabbed window for new
message to 'jid', using account(optional) 'account ' '''
message to 'jid', using account(optional) 'account' '''
if self.disabled:
return
jid, account = self._get_real_arguments(args, 2)
if not jid:
# FIXME: raise exception for missing argument (dbus0.35+ - released last week)
# FIXME: raise exception for missing argument (dbus0.35+)
return None
if jid.startswith('xmpp://'):
jid = jid[7:] # len('xmpp://') = 7
#FIXME: does not work :(((
if account:
accounts = [account]
else: