config file is now saved to disk when we change an option or quit Gajim
This commit is contained in:
parent
5a354c283c
commit
8cc28a8faa
3 changed files with 63 additions and 17 deletions
|
@ -246,7 +246,9 @@ class Config:
|
||||||
opt[OPT_VAL] = value
|
opt[OPT_VAL] = value
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get(self, optname):
|
def get(self, optname = None):
|
||||||
|
if not optname:
|
||||||
|
return self.__options.keys()
|
||||||
if not self.__options.has_key(optname):
|
if not self.__options.has_key(optname):
|
||||||
return None
|
return None
|
||||||
return self.__options[optname][OPT_VAL]
|
return self.__options[optname][OPT_VAL]
|
||||||
|
|
|
@ -75,6 +75,7 @@ class OptionsParser:
|
||||||
self._fill_config_key('Profile', 'log', 'log')
|
self._fill_config_key('Profile', 'log', 'log')
|
||||||
self._fill_config_key('Core', 'delauth', 'delauth')
|
self._fill_config_key('Core', 'delauth', 'delauth')
|
||||||
self._fill_config_key('Core', 'delroster', 'delroster')
|
self._fill_config_key('Core', 'delroster', 'delroster')
|
||||||
|
self._fill_config_key('Core', 'alwaysauth', 'alwaysauth')
|
||||||
self._fill_config_key('Logger', 'lognotsep', 'lognotsep')
|
self._fill_config_key('Logger', 'lognotsep', 'lognotsep')
|
||||||
self._fill_config_key('Logger', 'lognotusr', 'lognotusr')
|
self._fill_config_key('Logger', 'lognotusr', 'lognotusr')
|
||||||
|
|
||||||
|
@ -131,23 +132,66 @@ class OptionsParser:
|
||||||
gajim.connections[account].password = gajim.config.get_per( \
|
gajim.connections[account].password = gajim.config.get_per( \
|
||||||
'accounts', account, 'password')
|
'accounts', account, 'password')
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def read_config(self):
|
||||||
if attr.startswith('__') and attr in self.__dict__.keys():
|
self.tab = {}
|
||||||
return self.__dict__[attr]
|
self.tab['Profile'] = {}
|
||||||
elif self.tab.has_key(attr):
|
self.tab['Profile']['log'] = gajim.config.get('log')
|
||||||
return self.tab[attr]
|
|
||||||
else:
|
self.tab['Core'] = {}
|
||||||
# for key in self.__dict__.keys():
|
self.tab['Core']['delauth'] = gajim.config.get('delauth')
|
||||||
# if key == attr:
|
self.tab['Core']['delroster'] = gajim.config.get('delroster')
|
||||||
# return self.__dict__[attr]
|
self.tab['Core']['alwaysauth'] = gajim.config.get('alwaysauth')
|
||||||
return None
|
|
||||||
# END __getattr__
|
self.tab['Logger'] = {}
|
||||||
|
self.tab['Logger']['lognotsep'] = gajim.config.get('lognotsep')
|
||||||
|
self.tab['Logger']['lognotusr'] = gajim.config.get('lognotusr')
|
||||||
|
|
||||||
|
self.tab['GtkGui'] = {}
|
||||||
|
for key in gajim.config.get(None):
|
||||||
|
if key in self.tab['Profile']:
|
||||||
|
continue
|
||||||
|
if key in self.tab['Core']:
|
||||||
|
continue
|
||||||
|
if key in self.tab['Logger']:
|
||||||
|
continue
|
||||||
|
self.tab['GtkGui'][key] = gajim.config.get(key)
|
||||||
|
|
||||||
|
# status messages
|
||||||
|
i = 0
|
||||||
|
for msg in gajim.config.get_per('statusmsg'):
|
||||||
|
self.tab['GtkGui']['msg%s_name' % i] = msg
|
||||||
|
self.tab['GtkGui']['msg%s' % i] = gajim.config.get_per('statusmsg', \
|
||||||
|
msg, 'message')
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# sounds
|
||||||
|
for event in gajim.config.get_per('soundevents'):
|
||||||
|
self.tab['GtkGui']['sound_' + event] = gajim.config.get_per( \
|
||||||
|
'soundevents', event, 'enabled')
|
||||||
|
self.tab['GtkGui']['sound_' + event + '_file'] = gajim.config.get_per(\
|
||||||
|
'soundevents', event, 'path')
|
||||||
|
|
||||||
|
# emoticons
|
||||||
|
emots = []
|
||||||
|
for emot in gajim.config.get_per('emoticons'):
|
||||||
|
emots.append(emot)
|
||||||
|
emots.append(gajim.config.get_per('emoticons', emot, 'path'))
|
||||||
|
self.tab['GtkGui']['emoticons'] = '\t'.join(emots)
|
||||||
|
|
||||||
|
# accounts
|
||||||
|
accounts = gajim.config.get_per('accounts')
|
||||||
|
self.tab['Profile']['accounts'] = ' '.join(accounts)
|
||||||
|
for account in accounts:
|
||||||
|
self.tab[account] = {}
|
||||||
|
for key in gajim.config.get_per('accounts', account):
|
||||||
|
self.tab[account][key] = gajim.config.get_per('accounts', account, \
|
||||||
|
key)
|
||||||
|
|
||||||
def writeCfgFile(self):
|
def writeCfgFile(self):
|
||||||
try:
|
try:
|
||||||
fd = open(self.__fname, 'w')
|
fd = open(self.__fname, 'w')
|
||||||
except:
|
except:
|
||||||
log.debug("Can't write config %s" % self.__fname)
|
log.debug('Can\'t write config %s' % self.__fname)
|
||||||
return 0
|
return 0
|
||||||
index = 0
|
index = 0
|
||||||
for s in self.tab.keys():
|
for s in self.tab.keys():
|
||||||
|
|
|
@ -25,7 +25,6 @@ import pango
|
||||||
import gobject
|
import gobject
|
||||||
import os
|
import os
|
||||||
import sre
|
import sre
|
||||||
from common import optparser
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
import common.sleepy
|
import common.sleepy
|
||||||
|
|
||||||
|
@ -36,6 +35,8 @@ APP = i18n.APP
|
||||||
gtk.glade.bindtextdomain(APP, i18n.DIR)
|
gtk.glade.bindtextdomain(APP, i18n.DIR)
|
||||||
gtk.glade.textdomain(APP)
|
gtk.glade.textdomain(APP)
|
||||||
|
|
||||||
|
from common import optparser
|
||||||
|
parser = optparser.OptionsParser('~/.gajim/config')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import winsound # windows-only built-in module for playing wav
|
import winsound # windows-only built-in module for playing wav
|
||||||
|
@ -689,8 +690,8 @@ class interface:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save_config(self):
|
def save_config(self):
|
||||||
pass
|
parser.read_config()
|
||||||
#common.optparser.write()
|
parser.writeCfgFile()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if gtk.pygtk_version >= (2, 6, 0):
|
if gtk.pygtk_version >= (2, 6, 0):
|
||||||
|
@ -762,7 +763,6 @@ if __name__ == '__main__':
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
parser = optparser.OptionsParser('~/.gajim/config')
|
|
||||||
parser.parseCfgFile()
|
parser.parseCfgFile()
|
||||||
parser.fill_config()
|
parser.fill_config()
|
||||||
interface()
|
interface()
|
||||||
|
|
Loading…
Add table
Reference in a new issue