2005-04-14 09:28:59 +02:00
|
|
|
## common/config.py
|
|
|
|
##
|
|
|
|
## Gajim Team:
|
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <nkour@jabber.org>
|
|
|
|
##
|
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
import copy
|
|
|
|
|
|
|
|
OPT_TYPE = 0
|
|
|
|
OPT_VAL = 1
|
|
|
|
|
|
|
|
opt_int = [ 'integer', 0 ]
|
|
|
|
opt_str = [ 'string', 0 ]
|
|
|
|
opt_bool = [ 'boolean', 0 ]
|
|
|
|
opt_color = [ 'color', '^#[0-9a-fA-F]{6}$' ]
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
|
|
__options = {
|
|
|
|
# name: [ type, value ]
|
2005-04-16 16:50:26 +02:00
|
|
|
'log': [ opt_bool, True ],
|
|
|
|
'delauth': [ opt_bool, True ],
|
|
|
|
'delroster': [ opt_bool, True ],
|
|
|
|
'alwaysauth': [ opt_bool, False ],
|
|
|
|
'autopopup': [ opt_bool, False ],
|
|
|
|
'autopopupaway': [ opt_bool, False ],
|
|
|
|
'ignore_unknown_contacts': [ opt_bool, False ],
|
|
|
|
'showoffline': [ opt_bool, False ],
|
|
|
|
'autoaway': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'autoawaytime': [ opt_int, 10 ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'autoxa': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'autoxatime': [ opt_int, 20 ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'ask_online_status': [ opt_bool, False ],
|
|
|
|
'ask_offline_status': [ opt_bool, False ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'last_msg': [ opt_str, '' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'trayicon': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'iconset': [ opt_str, 'sun' ],
|
|
|
|
'inmsgcolor': [ opt_color, '#ff0000' ],
|
|
|
|
'outmsgcolor': [ opt_color, '#0000ff' ],
|
|
|
|
'statusmsgcolor': [ opt_color, '#1eaa1e' ],
|
|
|
|
'hiddenlines': [ opt_str, '' ],
|
|
|
|
'accounttextcolor': [ opt_color, '#ffffff' ],
|
|
|
|
'accountbgcolor': [ opt_color, '#94aa8c' ],
|
|
|
|
'accountfont': [ opt_str, 'Sans Bold 10' ],
|
|
|
|
'grouptextcolor': [ opt_color, '#0000ff' ],
|
|
|
|
'groupbgcolor': [ opt_color, '#eff3e7' ],
|
|
|
|
'groupfont': [ opt_str, 'Sans Italic 10' ],
|
|
|
|
'usertextcolor': [ opt_color, '#000000' ],
|
|
|
|
'userbgcolor': [ opt_color, '#ffffff' ],
|
|
|
|
'userfont': [ opt_str, 'Sans 10' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'saveposition': [ opt_bool, True ],
|
|
|
|
'mergeaccounts': [ opt_bool, False ],
|
|
|
|
'usetabbedchat': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'print_time': [ opt_str, 'always' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'useemoticons': [ opt_bool, True ],
|
|
|
|
'sounds_on': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'soundplayer': [ opt_str, 'play' ],
|
|
|
|
'openwith': [ opt_str, 'gnome-open' ],
|
|
|
|
'custombrowser': [ opt_str, 'firefox' ],
|
|
|
|
'custommailapp': [ opt_str, 'mozilla-thunderbird -compose' ],
|
|
|
|
'x-position': [ opt_int, 0 ],
|
|
|
|
'y-position': [ opt_int, 0 ],
|
|
|
|
'width': [ opt_int, 150 ],
|
|
|
|
'height': [ opt_int, 400 ],
|
|
|
|
'latest_disco_addresses': [ opt_str, '' ],
|
|
|
|
'recently_groupchat': [ opt_str, '' ],
|
|
|
|
'before_time': [ opt_str, '[' ],
|
|
|
|
'after_time': [ opt_str, ']' ],
|
|
|
|
'before_nickname': [ opt_str, '<' ],
|
|
|
|
'after_nickname': [ opt_str, '>' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'do_not_send_os_info': [ opt_bool, False ],
|
|
|
|
'usegpg': [ opt_bool, False ],
|
|
|
|
'lognotusr': [ opt_bool, True ],
|
|
|
|
'lognotsep': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__options_per_key = {
|
|
|
|
'accounts': ({
|
2005-04-16 16:50:26 +02:00
|
|
|
'name': [ opt_str, '' ],
|
|
|
|
'hostname': [ opt_str, '' ],
|
|
|
|
'savepass': [ opt_bool, False ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'password': [ opt_str, '' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'resource': [ opt_str, 'gajim' ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'priority': [ opt_int, 5 ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'autoconnect': [ opt_bool, False ],
|
|
|
|
'use_proxy': [ opt_bool, False ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'proxyhost': [ opt_str, '' ],
|
|
|
|
'proxyport': [ opt_int, 3128 ],
|
|
|
|
'keyid': [ opt_str, '' ],
|
|
|
|
'keyname': [ opt_str, '' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'savegpgpass': [ opt_bool, False ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'gpgpassword': [ opt_str, '' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'sync_with_global_status': [ opt_bool, True ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'no_log_for': [ opt_str, '' ],
|
2005-04-15 13:37:56 +02:00
|
|
|
}, {}),
|
|
|
|
'statusmsg': ({
|
|
|
|
'message': [ opt_str, '' ],
|
|
|
|
}, {}),
|
2005-04-16 16:50:26 +02:00
|
|
|
'emoticons': ({
|
|
|
|
'path': [ opt_str, '' ],
|
|
|
|
}, {}),
|
|
|
|
'soundevents': ({
|
|
|
|
'enabled': [ opt_bool, True ],
|
|
|
|
'path': [ opt_str, '' ],
|
|
|
|
}, {}),
|
2005-04-14 09:28:59 +02:00
|
|
|
}
|
2005-04-16 16:50:26 +02:00
|
|
|
|
|
|
|
emoticons_default = {
|
2005-04-16 17:01:06 +02:00
|
|
|
':-)': '../data/emoticons/smile.png',
|
|
|
|
'(@)': '../data/emoticons/pussy.png',
|
|
|
|
'8)': '../data/emoticons/coolglasses.png',
|
|
|
|
':(': '../data/emoticons/unhappy.png',
|
|
|
|
':)': '../data/emoticons/smile.png',
|
|
|
|
':/': '../data/emoticons/frowning.png',
|
|
|
|
'(})': '../data/emoticons/hugleft.png',
|
|
|
|
':$': '../data/emoticons/blush.png',
|
|
|
|
'(Y)': '../data/emoticons/yes.png',
|
|
|
|
':-@': '../data/emoticons/angry.png',
|
|
|
|
':-D': '../data/emoticons/biggrin.png',
|
|
|
|
'(U)': '../data/emoticons/brheart.png',
|
|
|
|
'(F)': '../data/emoticons/flower.png',
|
|
|
|
':-[': '../data/emoticons/bat.png',
|
|
|
|
':>': '../data/emoticons/biggrin.png',
|
|
|
|
'(T)': '../data/emoticons/phone.png',
|
|
|
|
':-S': '../data/emoticons/frowning.png',
|
|
|
|
':-P': '../data/emoticons/tongue.png',
|
|
|
|
'(H)': '../data/emoticons/coolglasses.png',
|
|
|
|
'(D)': '../data/emoticons/drink.png',
|
|
|
|
':-O': '../data/emoticons/oh.png',
|
|
|
|
'(C)': '../data/emoticons/coffee.png',
|
|
|
|
'({)': '../data/emoticons/hugright.png',
|
|
|
|
'(*)': '../data/emoticons/star.png',
|
|
|
|
'B-)': '../data/emoticons/coolglasses.png',
|
|
|
|
'(Z)': '../data/emoticons/boy.png',
|
|
|
|
'(E)': '../data/emoticons/mail.png',
|
|
|
|
'(N)': '../data/emoticons/no.png',
|
|
|
|
'(P)': '../data/emoticons/photo.png',
|
|
|
|
'(K)': '../data/emoticons/kiss.png',
|
|
|
|
'(R)': '../data/emoticons/rainbow.png',
|
|
|
|
':-|': '../data/emoticons/stare.png',
|
|
|
|
';-)': '../data/emoticons/wink.png',
|
|
|
|
';-(': '../data/emoticons/cry.png',
|
|
|
|
'(6)': '../data/emoticons/devil.png',
|
|
|
|
'(L)': '../data/emoticons/heart.png',
|
|
|
|
'(W)': '../data/emoticons/brflower.png',
|
|
|
|
':|': '../data/emoticons/stare.png',
|
|
|
|
':O': '../data/emoticons/oh.png',
|
|
|
|
';)': '../data/emoticons/wink.png',
|
|
|
|
';(': '../data/emoticons/cry.png',
|
|
|
|
':S': '../data/emoticons/frowning.png',
|
|
|
|
';\'-(': '../data/emoticons/cry.png',
|
|
|
|
':-(': '../data/emoticons/unhappy.png',
|
|
|
|
'8-)': '../data/emoticons/coolglasses.png',
|
|
|
|
'(B)': '../data/emoticons/beer.png',
|
|
|
|
':D': '../data/emoticons/biggrin.png',
|
|
|
|
'(8)': '../data/emoticons/music.png',
|
|
|
|
':@': '../data/emoticons/angry.png',
|
|
|
|
'B)': '../data/emoticons/coolglasses.png',
|
|
|
|
':-$': '../data/emoticons/blush.png',
|
|
|
|
':\'(': '../data/emoticons/cry.png',
|
|
|
|
':->': '../data/emoticons/biggrin.png',
|
|
|
|
':[': '../data/emoticons/bat.png',
|
|
|
|
'(I)': '../data/emoticons/lamp.png',
|
|
|
|
':P': '../data/emoticons/tongue.png',
|
|
|
|
'(%)': '../data/emoticons/cuffs.png',
|
|
|
|
'(S)': '../data/emoticons/moon.png',
|
2005-04-16 16:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
statusmsg_default = {
|
2005-04-16 17:01:06 +02:00
|
|
|
'Nap': 'I\'m taking a nap.',
|
|
|
|
'Brb': 'Back in some minutes.',
|
|
|
|
'Eating': 'so leave me a message.',
|
|
|
|
'Movie' : 'I\'m watching a movie.' ,
|
|
|
|
'Working': 'I\'m working.',
|
2005-04-16 16:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
soundevents_default = {
|
|
|
|
'first_message_received': [ True, 'sounds/message1.wav' ],
|
|
|
|
'next_message_received': [ True, 'sounds/message2.wav' ],
|
|
|
|
'contact_connected': [ True, 'sounds/connected.wav' ],
|
|
|
|
'contact_disconnected': [ True, 'sounds/disconnected.wav' ],
|
|
|
|
'message_sent': [ True, 'sounds/sent.wav' ],
|
|
|
|
}
|
|
|
|
|
2005-04-14 09:28:59 +02:00
|
|
|
def foreach(self, func):
|
|
|
|
for opt in self.__options:
|
|
|
|
func(opt, None, self.__options[opt])
|
|
|
|
for opt in self.__options_per_key:
|
|
|
|
func(opt, None, None)
|
|
|
|
dict = self.__options_per_key[opt][1]
|
|
|
|
for opt2 in dict.keys():
|
|
|
|
func(opt2, [opt], None)
|
|
|
|
for opt3 in dict[opt2]:
|
|
|
|
func(opt3, [opt, opt2], dict[opt2][opt3])
|
|
|
|
|
|
|
|
def is_valid_int(self, val):
|
|
|
|
try:
|
|
|
|
ival = int(val)
|
|
|
|
except:
|
|
|
|
return 0
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def is_valid_bool(self, val):
|
|
|
|
if self.is_valid_int(val):
|
|
|
|
if int(val) == 0 or int(val) == 1:
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def is_valid_string(self, val):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def is_valid(self, type, val):
|
|
|
|
if type[0] == 'boolean':
|
|
|
|
return self.is_valid_bool(val)
|
|
|
|
elif type[0] == 'integer':
|
|
|
|
return self.is_valid_int(val)
|
|
|
|
elif type[0] == 'string':
|
|
|
|
return self.is_valid_string(val)
|
|
|
|
else:
|
|
|
|
return re.match(type[1], val)
|
|
|
|
|
|
|
|
def set(self, optname, value):
|
|
|
|
if not self.__options.has_key(optname):
|
|
|
|
print 'error: option %s doesn\'t exist' % (optname)
|
|
|
|
return -1
|
|
|
|
opt = self.__options[optname]
|
|
|
|
|
|
|
|
if not self.is_valid(opt[OPT_TYPE], value):
|
|
|
|
return -1
|
|
|
|
opt[OPT_VAL] = value
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get(self, optname):
|
2005-04-16 16:50:26 +02:00
|
|
|
if not self.__options.has_key(optname):
|
2005-04-14 09:28:59 +02:00
|
|
|
return None
|
2005-04-16 16:50:26 +02:00
|
|
|
return self.__options[optname][OPT_VAL]
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
def add_per(self, typename, name):
|
|
|
|
if not self.__options_per_key.has_key(typename):
|
|
|
|
print 'error: option %s doesn\'t exist' % (typename)
|
|
|
|
return -1
|
|
|
|
|
|
|
|
opt = self.__options_per_key[typename]
|
|
|
|
|
|
|
|
opt[1][name] = copy.deepcopy(opt[0])
|
|
|
|
|
|
|
|
def del_per(self, typename, name):
|
|
|
|
if not self.__options_per_key.has_key(typename):
|
|
|
|
print 'error: option %s doesn\'t exist' % (typename)
|
|
|
|
return -1
|
|
|
|
|
|
|
|
opt = self.__options_per_key[typename]
|
|
|
|
del opt[1][name]
|
|
|
|
|
|
|
|
def set_per(self, optname, key, subname, value):
|
|
|
|
if not self.__options_per_key.has_key(optname):
|
|
|
|
print 'error: option %s doesn\'t exist' % (optname)
|
|
|
|
return -1
|
|
|
|
dict = self.__options_per_key[optname][1]
|
|
|
|
if not dict.has_key(key):
|
|
|
|
return -1
|
|
|
|
obj = dict[key]
|
|
|
|
if not obj.has_key(subname):
|
|
|
|
return -1
|
|
|
|
subobj = obj[subname]
|
|
|
|
if not self.is_valid(subobj[OPT_TYPE], value):
|
|
|
|
return -1
|
|
|
|
subobj[OPT_VAL] = value
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get_per(self, optname, key = None, subname = None):
|
2005-04-14 09:42:26 +02:00
|
|
|
if not self.__options_per_key.has_key(optname):
|
2005-04-14 09:28:59 +02:00
|
|
|
return None
|
2005-04-14 09:42:26 +02:00
|
|
|
dict = self.__options_per_key[optname][1]
|
2005-04-14 09:28:59 +02:00
|
|
|
if not key:
|
|
|
|
return dict.keys()
|
|
|
|
if not dict.has_key(key):
|
|
|
|
return None
|
|
|
|
obj = dict[key]
|
|
|
|
if not subname:
|
|
|
|
return obj
|
|
|
|
if not obj.has_key(subname):
|
|
|
|
return None
|
2005-04-14 13:06:58 +02:00
|
|
|
return obj[subname][OPT_VAL]
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
def __init__(self):
|
2005-04-16 16:50:26 +02:00
|
|
|
#init default values
|
2005-04-16 17:01:06 +02:00
|
|
|
for event in self.soundevents_default:
|
|
|
|
default = self.soundevents_default[event]
|
|
|
|
self.add_per('soundevents', event)
|
|
|
|
self.set_per('soundevents', event, 'enable', default[0])
|
|
|
|
self.set_per('soundevents', event, 'path', default[1])
|
|
|
|
for emot in self.emoticons_default:
|
|
|
|
self.add_per('emoticons', emot)
|
|
|
|
self.set_per('emoticons', emot, 'path', self.emoticons_default[emot])
|
|
|
|
for msg in self.statusmsg_default:
|
|
|
|
self.add_per('statusmsg', msg)
|
|
|
|
self.set_per('statusmsg', msg, 'message', self.statusmsg_default[msg])
|
2005-04-14 09:28:59 +02:00
|
|
|
return
|