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.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
2005-04-18 16:05:30 +02:00
|
|
|
import sre
|
2005-04-14 09:28:59 +02:00
|
|
|
import copy
|
2005-05-21 18:01:52 +02:00
|
|
|
from common import i18n
|
|
|
|
_ = i18n._
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
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-05-28 20:20:27 +02:00
|
|
|
'verbose': [ opt_bool, False ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'delauth': [ opt_bool, True ],
|
|
|
|
'delroster': [ opt_bool, True ],
|
|
|
|
'alwaysauth': [ opt_bool, False ],
|
|
|
|
'autopopup': [ opt_bool, False ],
|
2005-05-21 15:53:09 +02:00
|
|
|
'notify_on_signin': [ opt_bool, True ],
|
|
|
|
'notify_on_signout': [ opt_bool, False ],
|
2005-04-17 01:15:03 +02:00
|
|
|
'notify_on_new_message': [ opt_bool, False ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'autopopupaway': [ opt_bool, False ],
|
|
|
|
'ignore_unknown_contacts': [ opt_bool, False ],
|
|
|
|
'showoffline': [ opt_bool, False ],
|
|
|
|
'autoaway': [ opt_bool, True ],
|
2005-05-23 18:58:14 +02:00
|
|
|
'autoawaytime': [ opt_int, 5 ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'autoxa': [ opt_bool, True ],
|
2005-05-23 18:58:14 +02:00
|
|
|
'autoxatime': [ opt_int, 15 ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'ask_online_status': [ opt_bool, False ],
|
|
|
|
'ask_offline_status': [ opt_bool, False ],
|
2005-06-30 21:23:41 +02:00
|
|
|
'last_status_msg_online': [ opt_str, '' ],
|
|
|
|
'last_status_msg_chat': [ opt_str, '' ],
|
|
|
|
'last_status_msg_away': [ opt_str, '' ],
|
|
|
|
'last_status_msg_xa': [ opt_str, '' ],
|
|
|
|
'last_status_msg_dnd': [ opt_str, '' ],
|
|
|
|
'last_status_msg_invisible': [ opt_str, '' ],
|
|
|
|
'last_status_msg_offline': [ 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' ],
|
2005-05-25 19:13:50 +02:00
|
|
|
'use_transports_iconsets': [ opt_bool, True ],
|
2005-06-11 16:37:59 +02:00
|
|
|
'inmsgcolor': [ opt_color, '#a34526' ],
|
|
|
|
'outmsgcolor': [ opt_color, '#164e6f' ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'statusmsgcolor': [ opt_color, '#1eaa1e' ],
|
2005-06-16 21:14:07 +02:00
|
|
|
'markedmsgcolor': [ opt_color, '#ff8080' ],
|
2005-05-18 18:30:59 +02:00
|
|
|
'collapsed_rows': [ opt_str, '' ],
|
2005-04-29 15:04:06 +02:00
|
|
|
'roster_theme': [ opt_str, 'green' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'saveposition': [ opt_bool, True ],
|
|
|
|
'mergeaccounts': [ opt_bool, False ],
|
2005-05-29 20:41:13 +02:00
|
|
|
'sort_by_show': [ opt_bool, True ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'usetabbedchat': [ opt_bool, True ],
|
2005-05-26 02:07:49 +02:00
|
|
|
'use_speller': [ opt_bool, False ],
|
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' ],
|
2005-06-13 14:20:34 +02:00
|
|
|
'gc-x-position': [opt_int, 0],
|
|
|
|
'gc-y-position': [opt_int, 0],
|
|
|
|
'gc-width': [opt_int, 675],
|
|
|
|
'gc-height': [opt_int, 400],
|
|
|
|
'gc-hpaned-position': [opt_int, 535],
|
2005-06-17 00:18:46 +02:00
|
|
|
'gc_refer_to_nick_char': [opt_str, ','],
|
2005-06-13 14:20:34 +02:00
|
|
|
'chat-x-position': [opt_int, 0],
|
|
|
|
'chat-y-position': [opt_int, 0],
|
|
|
|
'chat-width': [opt_int, 415],
|
|
|
|
'chat-height': [opt_int, 430],
|
2005-04-14 09:28:59 +02:00
|
|
|
'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-24 14:18:49 +02:00
|
|
|
'send_os_info': [ opt_bool, True ],
|
2005-05-21 16:37:36 +02:00
|
|
|
'check_for_new_version': [ opt_bool, False ],
|
2005-04-16 16:50:26 +02:00
|
|
|
'usegpg': [ opt_bool, False ],
|
2005-04-27 17:06:25 +02:00
|
|
|
'log_notif_in_user_file': [ opt_bool, True ],
|
|
|
|
'log_notif_in_sep_file': [ opt_bool, True ],
|
2005-05-13 20:00:13 +02:00
|
|
|
'change_roster_title': [ opt_bool, True ],
|
2005-05-30 23:00:04 +02:00
|
|
|
'restore_lines': [opt_int, 4],
|
2005-06-02 18:28:01 +02:00
|
|
|
'restore_timeout': [opt_int, 60],
|
2005-06-05 22:38:53 +02:00
|
|
|
'send_on_ctrl_enter': [opt_bool, False], # send on ctrl+enter
|
2005-06-06 01:20:06 +02:00
|
|
|
'show_roster_on_startup': [opt_bool, True],
|
2005-06-07 18:25:55 +02:00
|
|
|
'key_up_lines': [opt_int, 25], # how many lines to store for key up
|
2005-06-25 03:23:21 +02:00
|
|
|
'version': [ None, '0.8' ],
|
2005-06-30 15:31:31 +02:00
|
|
|
'always_compact_view': [opt_bool, False], # initial compact view state
|
2005-06-25 03:23:21 +02:00
|
|
|
'search_engine': [opt_str, 'http://www.google.com/search?&q='],
|
2005-07-17 22:26:43 +02:00
|
|
|
'dictionary_url': [opt_str, 'http://dictionary.reference.com/search?q='],
|
|
|
|
'always_english_wikipedia': [opt_bool, False],
|
2005-07-17 23:41:54 +02:00
|
|
|
'use_dbus': [opt_bool, False], # allow control via dbus service
|
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-06-18 23:55:31 +02:00
|
|
|
'autoconnect': [ opt_bool, True ],
|
2005-06-08 17:48:53 +02:00
|
|
|
'proxy': [ opt_str, '' ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'keyid': [ opt_str, '' ],
|
|
|
|
'keyname': [ opt_str, '' ],
|
2005-05-30 13:01:08 +02:00
|
|
|
'usessl': [ opt_bool, False ],
|
2005-06-14 12:26:01 +02:00
|
|
|
'use_custom_host': [ opt_bool, False ],
|
|
|
|
'custom_port': [ opt_int, 5222 ],
|
|
|
|
'custom_host': [ 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-06-15 12:00:08 +02:00
|
|
|
'sync_with_global_status': [ opt_bool, False ],
|
2005-04-14 09:28:59 +02:00
|
|
|
'no_log_for': [ opt_str, '' ],
|
2005-05-29 23:34:01 +02:00
|
|
|
'attached_gpg_keys': [ opt_str, '' ],
|
2005-06-26 01:25:17 +02:00
|
|
|
'keep_alives_enabled': [ opt_bool, True],
|
|
|
|
# send keepalive every 60 seconds of inactivity
|
|
|
|
'keep_alive_every_foo_secs': [ opt_int, 60 ],
|
|
|
|
# disconnect if 2 minutes have passed and server didn't reply
|
|
|
|
'keep_alive_disconnect_secs': [ opt_int, 120 ],
|
|
|
|
# try for 2 minutes before giving up (aka. timeout after those seconds)
|
|
|
|
'try_connecting_for_foo_secs': [ opt_int, 120 ],
|
2005-06-29 10:28:12 +02:00
|
|
|
'max_stanza_per_sec': [ opt_int, 5],
|
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-06-08 17:48:53 +02:00
|
|
|
'proxies': ({
|
|
|
|
'type': [ opt_str, 'http' ],
|
|
|
|
'host': [ opt_str, '' ],
|
|
|
|
'port': [ opt_int, 3128 ],
|
|
|
|
'user': [ opt_str, '' ],
|
2005-06-09 00:05:45 +02:00
|
|
|
'pass': [ opt_str, '' ],
|
2005-06-08 17:48:53 +02:00
|
|
|
}, {}),
|
2005-06-14 00:11:09 +02:00
|
|
|
'themes': ({
|
|
|
|
'accounttextcolor': [ opt_color, '' ],
|
|
|
|
'accountbgcolor': [ opt_color, '' ],
|
|
|
|
'accountfont': [ opt_str, '' ],
|
|
|
|
'grouptextcolor': [ opt_color, '' ],
|
|
|
|
'groupbgcolor': [ opt_color, '' ],
|
|
|
|
'groupfont': [ opt_str, '' ],
|
|
|
|
'contacttextcolor': [ opt_color, '' ],
|
|
|
|
'contactbgcolor': [ opt_color, '' ],
|
|
|
|
'contactfont': [ opt_str, '' ],
|
|
|
|
'bannertextcolor': [ opt_color, '' ],
|
|
|
|
'bannerbgcolor': [ opt_color, '' ],
|
|
|
|
}, {}),
|
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-07-06 14:19:04 +02:00
|
|
|
_('Sleeping'): 'ZZZZzzzzzZZZZZ',
|
2005-06-06 12:51:24 +02:00
|
|
|
_('Back soon'): _('Back in some minutes.'),
|
|
|
|
_('Eating'): _("I'm eating, so leave me a message."),
|
|
|
|
_('Movie'): _("I'm watching a movie."),
|
|
|
|
_('Working'): _("I'm working."),
|
|
|
|
_('Phone'): _("I'm on the phone."),
|
|
|
|
_('Out'): _("I'm out enjoying life"),
|
2005-04-16 16:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
soundevents_default = {
|
2005-05-07 22:23:55 +02:00
|
|
|
'first_message_received': [ True, '../data/sounds/message1.wav' ],
|
|
|
|
'next_message_received': [ True, '../data/sounds/message2.wav' ],
|
|
|
|
'contact_connected': [ True, '../data/sounds/connected.wav' ],
|
|
|
|
'contact_disconnected': [ True, '../data/sounds/disconnected.wav' ],
|
|
|
|
'message_sent': [ True, '../data/sounds/sent.wav' ],
|
2005-04-16 16:50:26 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 00:11:09 +02:00
|
|
|
themes_default = {
|
|
|
|
'green': [ '#ffffff', '#94aa8c', 'Sans Bold 10', '#0000ff', '#eff3e7',
|
|
|
|
'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff',
|
|
|
|
'#94aa8c' ],
|
|
|
|
'cyan': [ '#ff0000', '#9fdfff', 'Sans Bold 10', '#0000ff', '#ffffff',
|
|
|
|
'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff',
|
|
|
|
'#9fdfff' ],
|
|
|
|
'marine': [ '#ffffff', '#918caa', 'Sans Bold 10', '#0000ff', '#e9e7f3',
|
|
|
|
'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff',
|
|
|
|
'#918caa' ],
|
|
|
|
'human': [ '#ffffff', '#996442', 'Sans Bold 10', '#ab5920', '#e3ca94',
|
|
|
|
'Sans Italic 10', '#000000', '#ffffff', 'Sans 10', '#ffffff',
|
|
|
|
'#996442' ],
|
|
|
|
}
|
|
|
|
|
2005-04-27 01:53:11 +02:00
|
|
|
def foreach(self, cb, data = None):
|
2005-04-14 09:28:59 +02:00
|
|
|
for opt in self.__options:
|
2005-04-27 00:17:47 +02:00
|
|
|
cb(data, opt, None, self.__options[opt])
|
2005-04-14 09:28:59 +02:00
|
|
|
for opt in self.__options_per_key:
|
2005-04-27 00:17:47 +02:00
|
|
|
cb(data, opt, None, None)
|
2005-04-14 09:28:59 +02:00
|
|
|
dict = self.__options_per_key[opt][1]
|
|
|
|
for opt2 in dict.keys():
|
2005-04-27 00:17:47 +02:00
|
|
|
cb(data, opt2, [opt], None)
|
2005-04-14 09:28:59 +02:00
|
|
|
for opt3 in dict[opt2]:
|
2005-04-27 00:17:47 +02:00
|
|
|
cb(data, opt3, [opt, opt2], dict[opt2][opt3])
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
def is_valid_int(self, val):
|
|
|
|
try:
|
|
|
|
ival = int(val)
|
|
|
|
except:
|
2005-04-27 01:41:20 +02:00
|
|
|
return None
|
|
|
|
return ival
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
def is_valid_bool(self, val):
|
2005-04-27 01:41:20 +02:00
|
|
|
if val == 'True':
|
|
|
|
return True
|
|
|
|
elif val == 'False':
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
ival = self.is_valid_int(val)
|
|
|
|
if ival:
|
|
|
|
return True
|
2005-05-26 23:09:01 +02:00
|
|
|
elif ival == None:
|
|
|
|
return None
|
2005-04-27 01:41:20 +02:00
|
|
|
return False
|
2005-06-09 17:31:29 +02:00
|
|
|
return None
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
def is_valid_string(self, val):
|
2005-04-27 01:41:20 +02:00
|
|
|
return val
|
2005-06-09 17:31:29 +02:00
|
|
|
|
2005-04-14 09:28:59 +02:00
|
|
|
def is_valid(self, type, val):
|
2005-05-01 00:24:45 +02:00
|
|
|
if not type:
|
|
|
|
return None
|
2005-04-14 09:28:59 +02:00
|
|
|
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:
|
2005-04-27 01:41:20 +02:00
|
|
|
if sre.match(type[1], val):
|
|
|
|
return val
|
|
|
|
else:
|
|
|
|
return None
|
2005-04-14 09:28:59 +02:00
|
|
|
|
|
|
|
def set(self, optname, value):
|
|
|
|
if not self.__options.has_key(optname):
|
2005-06-09 17:31:29 +02:00
|
|
|
# print 'error: option %s does not exist' % optname
|
2005-04-14 09:28:59 +02:00
|
|
|
return -1
|
|
|
|
opt = self.__options[optname]
|
2005-04-27 01:41:20 +02:00
|
|
|
value = self.is_valid(opt[OPT_TYPE], value)
|
|
|
|
if value == None:
|
2005-04-14 09:28:59 +02:00
|
|
|
return -1
|
2005-06-09 17:31:29 +02:00
|
|
|
|
2005-04-14 09:28:59 +02:00
|
|
|
opt[OPT_VAL] = value
|
|
|
|
return 0
|
2005-06-09 17:31:29 +02:00
|
|
|
|
2005-04-17 00:12:41 +02:00
|
|
|
def get(self, optname = None):
|
|
|
|
if not optname:
|
|
|
|
return self.__options.keys()
|
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
|
|
|
|
2005-04-19 01:55:13 +02:00
|
|
|
def add_per(self, typename, name): # per_group_of_option
|
2005-04-14 09:28:59 +02:00
|
|
|
if not self.__options_per_key.has_key(typename):
|
2005-04-16 19:03:21 +02:00
|
|
|
# print 'error: option %s doesn\'t exist' % (typename)
|
2005-04-14 09:28:59 +02:00
|
|
|
return -1
|
|
|
|
|
|
|
|
opt = self.__options_per_key[typename]
|
2005-04-27 01:41:20 +02:00
|
|
|
if opt[1].has_key(name):
|
|
|
|
return -2
|
2005-04-14 09:28:59 +02:00
|
|
|
opt[1][name] = copy.deepcopy(opt[0])
|
2005-04-27 01:41:20 +02:00
|
|
|
return 0
|
2005-04-14 09:28:59 +02:00
|
|
|
|
2005-04-19 01:55:13 +02:00
|
|
|
def del_per(self, typename, name): # per_group_of_option
|
2005-04-14 09:28:59 +02:00
|
|
|
if not self.__options_per_key.has_key(typename):
|
2005-04-16 19:03:21 +02:00
|
|
|
# print 'error: option %s doesn\'t exist' % (typename)
|
2005-04-14 09:28:59 +02:00
|
|
|
return -1
|
|
|
|
|
|
|
|
opt = self.__options_per_key[typename]
|
|
|
|
del opt[1][name]
|
|
|
|
|
2005-04-19 01:55:13 +02:00
|
|
|
def set_per(self, optname, key, subname, value): # per_group_of_option
|
2005-04-14 09:28:59 +02:00
|
|
|
if not self.__options_per_key.has_key(optname):
|
2005-04-16 19:03:21 +02:00
|
|
|
# print 'error: option %s doesn\'t exist' % (optname)
|
2005-04-14 09:28:59 +02:00
|
|
|
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]
|
2005-04-27 01:41:20 +02:00
|
|
|
value = self.is_valid(subobj[OPT_TYPE], value)
|
|
|
|
if value == None:
|
2005-04-14 09:28:59 +02:00
|
|
|
return -1
|
|
|
|
subobj[OPT_VAL] = value
|
|
|
|
return 0
|
2005-06-09 17:31:29 +02:00
|
|
|
|
2005-04-19 01:55:13 +02:00
|
|
|
def get_per(self, optname, key = None, subname = None): # per_group_of_option
|
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])
|
2005-04-14 09:28:59 +02:00
|
|
|
return
|