fix strings to be more readable; add get_status (did not test yet); raise allover

This commit is contained in:
Nikos Kouremenos 2005-11-30 15:26:08 +00:00
parent 7d357dfe5a
commit b854555e58
2 changed files with 81 additions and 52 deletions

View file

@ -59,6 +59,14 @@ class DbusNotSupported(Exception):
def __str__(self): def __str__(self):
return _('D-Bus is not present on this machine or python module is missing') return _('D-Bus is not present on this machine or python module is missing')
class SessionBusNotPresent(Exception):
'''This exception indicates that there is no session daemon'''
def __init__(self):
Exception.__init__(self)
def __str__(self):
return _('Session bus is not available')
try: try:
import dbus import dbus
except: except:
@ -88,7 +96,7 @@ class GajimRemote:
# #
self.commands = { self.commands = {
'help':[ 'help':[
_('show a help on specific command'), _('shows a help on specific command'),
[ [
#User gets help for the command, specified by this parameter #User gets help for the command, specified by this parameter
(_('command'), (_('command'),
@ -100,110 +108,112 @@ class GajimRemote:
[] []
], ],
'show_next_unread': [ 'show_next_unread': [
_('Popup a window with the next unread message'), _('Popups a window with the next unread message'),
[] []
], ],
'list_contacts': [ 'list_contacts': [
_('Print a list of all contacts in the roster. \ _('Prints a list of all contacts in the roster. Each contact appear on a separate line'),
Each contact appear on a separate line'),
[ [
(_('account'), _('show only contacts of the \ (_('account'), _('show only contacts of the given account'), False)
given account'), False)
] ]
], ],
'list_accounts': [ 'list_accounts': [
_('Print a list of registered accounts'), _('Prints a list of registered accounts'),
[] []
], ],
'change_status': [ 'change_status': [
_('Change the status of account or accounts'), _('Changes the status of account or accounts'),
[ [
(_('status'), _('one of: offline, online, chat, away, \ (_('status'), _('one of: offline, online, chat, away, xa, dnd, invisible '), True),
xa, dnd, invisible '), True),
(_('message'), _('status message'), False), (_('message'), _('status message'), False),
(_('account'), _('change status of account "account". \ (_('account'), _('change status of account "account". '
If not specified, try to change status of all accounts that \ 'If not specified, try to change status of all accounts that have '
have "sync with global status" option set'), False) '"sync with global status" option set'), False)
] ]
], ],
'open_chat': [ 'open_chat': [
_('Show the chat dialog so that you can send messages to a \ _('Shows the chat dialog so that you can send messages to a contact'),
contact'),
[ [
('jid', _('JID of the contact that you want to chat \ ('jid', _('JID of the contact that you want to chat with'),
with'),
True), True),
(_('account'), _('if specified, contact is taken from \ (_('account'), _('if specified, contact is taken from the '
the contact list of this account'), False) 'contact list of this account'), False)
] ]
], ],
'send_message':[ 'send_message':[
_('Send new message to a contact in the roster. Both OpenPGP \ _('Sends new message to a contact in the roster. Both OpenPGP key '
key and account are optional. If you want to set only \'account\', without \ 'and account are optional. If you want to set only \'account\', '
\'OpenPGP key\', just set \'OpenPGP key\' to \'\'.'), 'without \'OpenPGP key\', just set \'OpenPGP key\' to \'\'.'),
[ [
('jid', _('JID of the contact that will receive the \ ('jid', _('JID of the contact that will receive the message'), True),
message'), True),
(_('message'), _('message contents'), True), (_('message'), _('message contents'), True),
(_('pgp key'), _('if specified, the message will be \ (_('pgp key'), _('if specified, the message will be encrypted '
encrypted using this public key'), False), 'using this public key'), False),
(_('account'), _('if specified, the message will be \ (_('account'), _('if specified, the message will be sent '
sent using this account'), False), 'using this account'), False),
] ]
], ],
'contact_info': [ 'contact_info': [
_('Get detailed info on a contact'), _('Gets detailed info on a contact'),
[ [
('jid', _('JID of the contact'), True) ('jid', _('JID of the contact'), True)
] ]
], ],
'send_file': [ 'send_file': [
_('Send file to a contact'), _('Sends file to a contact'),
[ [
(_('file'), _('File path'), True), (_('file'), _('File path'), True),
('jid', _('JID of the contact'), True), ('jid', _('JID of the contact'), True),
(_('account'), _('if specified, file will be sent \ (_('account'), _('if specified, file will be sent using this '
using this account'), False) 'account'), False)
] ]
], ],
'prefs_list': [ 'prefs_list': [
_('List all preferences and their values'), _('Lists all preferences and their values'),
[ ] [ ]
], ],
'prefs_put': [ 'prefs_put': [
_('Set value of \'key\' to \'value\'.'), _('Sets value of \'key\' to \'value\'.'),
[ [
(_('key=value'), _('\'key\' is the name of the preference, \ (_('key=value'), _('\'key\' is the name of the preference, '
\'value\' is the value to set it to'), True) '\'value\' is the value to set it to'), True)
] ]
], ],
'prefs_del': [ 'prefs_del': [
_('Delete a preference item'), _('Deletes a preference item'),
[ [
(_('key'), _('name of the preference to be deleted'), True) (_('key'), _('name of the preference to be deleted'), True)
] ]
], ],
'prefs_store': [ 'prefs_store': [
_('Write the current state of Gajim preferences to the \ _('Writes the current state of Gajim preferences to the .config '
.config file'), 'file'),
[ ] [ ]
], ],
'remove_contact': [ 'remove_contact': [
_('Remove contact from roster'), _('Removes contact from roster'),
[ [
('jid', _('JID of the contact'), True), ('jid', _('JID of the contact'), True),
(_('account'), _('if specified, contact is taken from \ (_('account'), _('if specified, contact is taken from the '
the contact list of this account'), False) 'contact list of this account'), False)
] ]
], ],
'add_contact': [ 'add_contact': [
_('Add contact to roster'), _('Adds contact to roster'),
[ [
(_('account'), _('Add new contact to this account.'), True) (_('account'), _('Adds new contact to this account.'), True)
] ]
] ],
'get_status': [
_('Returns current status'),
[
(_('account'), _('if specified, returns status for this account; '
'Else returns global status'), False)
]
],
} }
if self.argv_len < 2 or \ if self.argv_len < 2 or \
@ -227,7 +237,7 @@ the contact list of this account'), False)
id = self.sbus.add_signal_receiver(self.show_vcard_info, id = self.sbus.add_signal_receiver(self.show_vcard_info,
'VcardInfo', INTERFACE, SERVICE, OBJ_PATH) 'VcardInfo', INTERFACE, SERVICE, OBJ_PATH)
except Exception, e: except Exception, e:
send_error(_('Service not available') + ': ' + str(e)) raise ServiceNotAvailable
res = self.call_remote_method() res = self.call_remote_method()
self.print_result(res) self.print_result(res)
@ -245,8 +255,8 @@ the contact list of this account'), False)
if res is False: if res is False:
if self.argv_len < 4: if self.argv_len < 4:
send_error(_('\'%s\' is not in your roster.\n\ send_error(_('\'%s\' is not in your roster.\n'
Please specify account for sending the message.') % sys.argv[2]) 'Please specify account for sending the message.') % sys.argv[2])
else: else:
send_error(_('You have no active account')) send_error(_('You have no active account'))
elif self.command == 'list_accounts': elif self.command == 'list_accounts':
@ -273,7 +283,7 @@ Please specify account for sending the message.') % sys.argv[2])
try: try:
self.sbus = dbus.SessionBus() self.sbus = dbus.SessionBus()
except: except:
send_error(_('Session bus is not available.') + ': ' + str(e)) raise SessionBusNotPresent
if _version[1] >= 30: if _version[1] >= 30:
obj = self.sbus.get_object(SERVICE, OBJ_PATH) obj = self.sbus.get_object(SERVICE, OBJ_PATH)
@ -555,7 +565,7 @@ Type "%s help %s" for more info') % (args[argv_len][0], BASENAME, self.command))
res = self.method(sys.argv[2], sys.argv[3], sys.argv[4], res = self.method(sys.argv[2], sys.argv[3], sys.argv[4],
sys.argv[5]) sys.argv[5])
return res return res
except Exception, e: except Exception:
raise ServiceNotAvailable raise ServiceNotAvailable
return None return None

View file

@ -48,6 +48,9 @@ INTERFACE = 'org.gajim.dbus.RemoteInterface'
OBJ_PATH = '/org/gajim/dbus/RemoteObject' OBJ_PATH = '/org/gajim/dbus/RemoteObject'
SERVICE = 'org.gajim.dbus' SERVICE = 'org.gajim.dbus'
STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
'invisible']
class Remote: class Remote:
def __init__(self): def __init__(self):
self.signal_object = None self.signal_object = None
@ -106,7 +109,8 @@ class SignalObject(DbusPrototype):
self.prefs_del, self.prefs_del,
self.prefs_put, self.prefs_put,
self.add_contact, self.add_contact,
self.remove_contact self.remove_contact,
self.get_status,
]) ])
def raise_signal(self, signal, arg): def raise_signal(self, signal, arg):
@ -127,14 +131,29 @@ class SignalObject(DbusPrototype):
def VcardInfo(self, *vcard): def VcardInfo(self, *vcard):
pass pass
def get_status(self, *args):
'''get_status(account = None)
returns status (show to be exact) which is the global one
unless account is given'''
account = self._get_real_arguments(args, 1)
accounts = gajim.contacts.keys()
if not account and len(accounts) == 1:
# if there is only one account in roster, take it as default
# if user did not ask for account
account = accounts[0] # FIXME: get global status, not the status from first (ask Yann)
if account: # return show for this account (either first or the specified)
index = gajim.connections[account].connected
return STATUS_LIST[index]
def send_file(self, *args): def send_file(self, *args):
''' send_file(file_path, jid, account=None) '''send_file(file_path, jid, account=None)
send file, located at 'file_path' to 'jid', using account send file, located at 'file_path' to 'jid', using account
(optional) 'account' ''' (optional) 'account' '''
file_path, jid, account = self._get_real_arguments(args, 3) file_path, jid, account = self._get_real_arguments(args, 3)
accounts = gajim.contacts.keys() accounts = gajim.contacts.keys()
# if there is only one account in roster, take it as default # if there is only one account in roster, take it as default
# if user did not ask for account
if not account and len(accounts) == 1: if not account and len(accounts) == 1:
account = accounts[0] account = accounts[0]
if account: if account: