the configuration file is now parsed (but not saved atm)
This commit is contained in:
parent
e0e6bafbcd
commit
798fbfebf3
5 changed files with 94 additions and 24 deletions
|
@ -237,7 +237,7 @@ class Config:
|
|||
|
||||
def set(self, optname, value):
|
||||
if not self.__options.has_key(optname):
|
||||
print 'error: option %s doesn\'t exist' % (optname)
|
||||
# print 'error: option %s doesn\'t exist' % (optname)
|
||||
return -1
|
||||
opt = self.__options[optname]
|
||||
|
||||
|
@ -253,7 +253,7 @@ class Config:
|
|||
|
||||
def add_per(self, typename, name):
|
||||
if not self.__options_per_key.has_key(typename):
|
||||
print 'error: option %s doesn\'t exist' % (typename)
|
||||
# print 'error: option %s doesn\'t exist' % (typename)
|
||||
return -1
|
||||
|
||||
opt = self.__options_per_key[typename]
|
||||
|
@ -262,7 +262,7 @@ class Config:
|
|||
|
||||
def del_per(self, typename, name):
|
||||
if not self.__options_per_key.has_key(typename):
|
||||
print 'error: option %s doesn\'t exist' % (typename)
|
||||
# print 'error: option %s doesn\'t exist' % (typename)
|
||||
return -1
|
||||
|
||||
opt = self.__options_per_key[typename]
|
||||
|
@ -270,7 +270,7 @@ class Config:
|
|||
|
||||
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)
|
||||
# print 'error: option %s doesn\'t exist' % (optname)
|
||||
return -1
|
||||
dict = self.__options_per_key[optname][1]
|
||||
if not dict.has_key(key):
|
||||
|
|
|
@ -55,12 +55,12 @@ class Logger:
|
|||
files.append(ji)
|
||||
if common.gajim.config.get('lognotsep'):
|
||||
files.append('notify.log')
|
||||
elif kind == 'incoming': # we save time:recv:message:
|
||||
elif kind == 'incoming': # we save time:recv:message
|
||||
files.append(ji)
|
||||
jid = 'recv'
|
||||
show = msg
|
||||
msg = ''
|
||||
elif kind == 'outgoing': # we save time:sent:message:
|
||||
elif kind == 'outgoing': # we save time:sent:message
|
||||
files.append(ji)
|
||||
jid = 'sent'
|
||||
show = msg
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
## GNU General Public License for more details.
|
||||
##
|
||||
|
||||
import logging, os, string
|
||||
|
||||
log = logging.getLogger('common.options')
|
||||
import os
|
||||
from common import connection
|
||||
from common import gajim
|
||||
|
||||
class OptionsParser:
|
||||
def __init__(self, fname):
|
||||
|
@ -47,21 +47,86 @@ class OptionsParser:
|
|||
option = line[0:index]
|
||||
option = option.strip()
|
||||
value = line[index+2:-1]
|
||||
if string.find(option, 'password') == -1:
|
||||
try:
|
||||
i = string.atoi(value)
|
||||
except ValueError:
|
||||
self.tab[section][option] = value
|
||||
if option.find('password') == -1:
|
||||
if value == 'False':
|
||||
self.tab[section][option] = False
|
||||
elif value == 'True':
|
||||
self.tab[section][option] = True
|
||||
else:
|
||||
self.tab[section][option] = i
|
||||
try:
|
||||
i = int(value)
|
||||
except ValueError:
|
||||
self.tab[section][option] = value
|
||||
else:
|
||||
self.tab[section][option] = i
|
||||
else:
|
||||
self.tab[section][option] = value
|
||||
fd.close()
|
||||
# END parseCfgFile
|
||||
|
||||
def __str__(self):
|
||||
return "OptionsParser"
|
||||
# END __str__
|
||||
def _fill_config_key(self, section, option, key):
|
||||
if not self.tab.has_key(section):
|
||||
return
|
||||
if not self.tab[section].has_key(option):
|
||||
return
|
||||
gajim.config.set(key, self.tab[section][option])
|
||||
|
||||
def fill_config(self):
|
||||
self._fill_config_key('Profile', 'log', 'log')
|
||||
self._fill_config_key('Core', 'delauth', 'delauth')
|
||||
self._fill_config_key('Core', 'delroster', 'delroster')
|
||||
self._fill_config_key('Logger', 'lognotsep', 'lognotsep')
|
||||
self._fill_config_key('Logger', 'lognotusr', 'lognotusr')
|
||||
|
||||
if self.tab.has_key('GtkGui'):
|
||||
for k in self.tab['GtkGui']:
|
||||
self._fill_config_key('GtkGui', k, k)
|
||||
# status messages
|
||||
for msg in gajim.config.get_per('statusmsg'):
|
||||
gajim.config.del_per('statusmsg', msg)
|
||||
i = 0
|
||||
while self.tab['GtkGui'].has_key('msg%s_name' % i):
|
||||
gajim.config.add_per('statusmsg', self.tab['GtkGui']['msg%s_name' \
|
||||
% i])
|
||||
gajim.config.set_per('statusmsg', self.tab['GtkGui']['msg%s_name' \
|
||||
% i], 'message', self.tab['GtkGui']['msg%s' % i])
|
||||
i += 1
|
||||
# emoticons
|
||||
if self.tab['GtkGui'].has_key('emoticons'):
|
||||
for emot in gajim.config.get_per('emoticons'):
|
||||
gajim.config.del_per('emoticons', emot)
|
||||
emots = self.tab['GtkGui']['emoticons'].split('\t')
|
||||
for i in range(0, len(emots)/2):
|
||||
gajim.config.add_per('emoticons', emots[2*i])
|
||||
gajim.config.set_per('emoticons', emots[2*i], 'path', \
|
||||
emots[2*i+1])
|
||||
# sound events
|
||||
for event in gajim.config.get_per('soundevents'):
|
||||
gajim.config.del_per('soundevents', event)
|
||||
for key in self.tab['GtkGui']:
|
||||
if key.find('sound_'):
|
||||
continue
|
||||
if not self.tab['GtkGui'].has_key(key + '_file'):
|
||||
continue
|
||||
event = key[6:]
|
||||
gajim.config.add_per('soundevents', event)
|
||||
gajim.config.set_per('soundevents', event, 'enabled', \
|
||||
self.tab['GtkGui'][key])
|
||||
gajim.config.set_per('soundevents', event, 'path', \
|
||||
self.tab['GtkGui'][key + '_file'])
|
||||
|
||||
# accounts
|
||||
if self.tab.has_key('Profile'):
|
||||
if self.tab['Profile'].has_key('accounts'):
|
||||
accounts = self.tab['Profile']['accounts'].split()
|
||||
for account in accounts:
|
||||
if not self.tab.has_key(account):
|
||||
continue
|
||||
gajim.connections[account] = connection.connection(account)
|
||||
gajim.config.add_per('accounts', account)
|
||||
for key in self.tab[account]:
|
||||
gajim.config.set_per('accounts', account, key, \
|
||||
self.tab[account][key])
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr.startswith('__') and attr in self.__dict__.keys():
|
||||
|
@ -93,7 +158,4 @@ class OptionsParser:
|
|||
return 1
|
||||
# END writeCfgFile
|
||||
|
||||
def stop(self):
|
||||
return self.writeCfgFile()
|
||||
# END stop
|
||||
# END OptionsParser
|
||||
|
|
|
@ -562,10 +562,10 @@ class About_dialog:
|
|||
|
||||
dlg = gtk.AboutDialog()
|
||||
dlg.set_name('Gajim')
|
||||
dlg.set_version(gajim.version.version)
|
||||
dlg.set_version(gajim.version)
|
||||
s = u'Copyright \xa9 2003-2005 Gajim Team'
|
||||
dlg.set_copyright(s)
|
||||
text = open('COPYING').read()
|
||||
text = open('../COPYING').read()
|
||||
dlg.set_license(text)
|
||||
|
||||
dlg.set_comments(_('A GTK jabber client'))
|
||||
|
@ -573,7 +573,7 @@ class About_dialog:
|
|||
|
||||
authors = ['Yann Le Boulanger <asterix@lagaule.org>', 'Vincent Hanquez <tab@snarc.org>', 'Nikos Kouremenos <kourem@gmail.com>', 'Alex Podaras <bigpod@gmail.com>']
|
||||
dlg.set_authors(authors)
|
||||
dlg.set_logo(gtk.gdk.pixbuf_new_from_file('plugins/gtkgui/pixmaps/logo.png'))
|
||||
dlg.set_logo(gtk.gdk.pixbuf_new_from_file('../data/pixmaps/logo.png'))
|
||||
dlg.set_translator_credits(_('translator_credits'))
|
||||
|
||||
rep = dlg.run() # this run doesn't crash threads.. interesting..
|
||||
|
|
|
@ -25,6 +25,7 @@ import pango
|
|||
import gobject
|
||||
import os
|
||||
import sre
|
||||
from common import optparser
|
||||
from common import gajim
|
||||
import common.sleepy
|
||||
|
||||
|
@ -687,6 +688,10 @@ class interface:
|
|||
gajim.connections[account].connection.process(0.01)
|
||||
return True
|
||||
|
||||
def save_config(self):
|
||||
pass
|
||||
#common.optparser.write()
|
||||
|
||||
def __init__(self):
|
||||
if gtk.pygtk_version >= (2, 6, 0):
|
||||
gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')
|
||||
|
@ -757,5 +762,8 @@ if __name__ == '__main__':
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
parser = optparser.OptionsParser('~/.gajim/config')
|
||||
parser.parseCfgFile()
|
||||
parser.fill_config()
|
||||
interface()
|
||||
gtk.main()
|
||||
|
|
Loading…
Add table
Reference in a new issue