From 48258e96d555f293346604ade7ca6ccb7769a613 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 25 Feb 2004 00:33:06 +0000 Subject: [PATCH] new config file management --- core/core.py | 59 ++++++++++++++++++++++++++++++++----- plugins/gtkgui/gtkgui.glade | 2 +- plugins/gtkgui/gtkgui.py | 28 +++++++++++++----- plugins/logger/logger.py | 3 +- 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/core/core.py b/core/core.py index 7303ff559..b49a735a9 100644 --- a/core/core.py +++ b/core/core.py @@ -17,7 +17,7 @@ ## GNU General Public License for more details. ## -import sys +import sys, os sys.path.append("..") import time @@ -37,16 +37,44 @@ class GajimCore: """Core""" def __init__(self): self.connected = 0 + self.init_cfg_file() self.cfgParser = common.optparser.OptionsParser(CONFPATH) self.hub = common.hub.GajimHub() self.parse() # END __init__ + def init_cfg_file(self): + fname = os.path.expanduser(CONFPATH) + reps = string.split(fname, '/') + del reps[0] + path = '' + while len(reps) > 1: + path = path + '/' + reps[0] + del reps[0] + try: + os.stat(os.path.expanduser(path)) + except OSError: + try: + os.mkdir(os.path.expanduser(path)) + except: + print "Can't create %s" % path + sys.exit + try: + os.stat(fname) + except: + print "creating %s" % fname + fic = open(fname, "w") + fic.write("[Profile]\naccounts = \n\n[Core]\ndelauth = 1\nalwaysauth = 0\nmodules = logger gtkgui\ndelroster = 1\n") + fic.close() + # END init_cfg_file + def parse(self): self.cfgParser.parseCfgFile() self.accounts = {} - accts = self.cfgParser.tab['Profile']['accounts'] - for a in string.split(accts, ' '): + accts = string.split(self.cfgParser.tab['Profile']['accounts'], ' ') + if accts == ['']: + accts = [] + for a in accts: self.accounts[a] = self.cfgParser.tab[a] def vCardCB(self, con, vc): @@ -95,7 +123,10 @@ class GajimCore: self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', \ prs.getFrom().getResource())) else: - self.hub.sendPlugin('SUBSCRIBE', who) + txt = prs.getStatus() + if not txt: + txt = "I would like to add you to my roster." + self.hub.sendPlugin('SUBSCRIBE', (who, 'txt')) elif type == 'subscribed': jid = prs.getFrom() self.hub.sendPlugin('SUBSCRIBED', {'jid':jid.getBasic(), \ @@ -193,19 +224,26 @@ class GajimCore: self.con.disconnect() self.hub.sendPlugin('QUIT', ()) return - #('ASK_CONFIG', (who_ask, section)) + #('ASK_CONFIG', (who_ask, section, default_config)) elif ev[0] == 'ASK_CONFIG': if ev[1][1] == 'accounts': self.hub.sendPlugin('CONFIG', (ev[1][0], self.accounts)) else: - self.hub.sendPlugin('CONFIG', (ev[1][0], \ - self.cfgParser.__getattr__(ev[1][1]))) + if self.cfgParser.tab.has_key(ev[1][1]): + self.hub.sendPlugin('CONFIG', (ev[1][0], \ + self.cfgParser.__getattr__(ev[1][1]))) + else: + self.cfgParser.tab[ev[1][1]] = ev[1][2] + self.cfgParser.writeCfgFile() + self.hub.sendPlugin('CONFIG', (ev[1][0], ev[1][2])) #('CONFIG', (section, config)) elif ev[0] == 'CONFIG': if ev[1][0] == 'accounts': #Remove all old accounts accts = string.split(self.cfgParser.tab\ ['Profile']['accounts'], ' ') + if accts == ['']: + accts = [] for a in accts: del self.cfgParser.tab[a] #Write all new accounts @@ -241,7 +279,12 @@ class GajimCore: #('SUB', (jid, txt)) elif ev[0] == 'SUB': log.debug('subscription request for %s' % ev[1][0]) - self.con.send(common.jabber.Presence(ev[1][0], 'subscribe')) + pres = common.jabber.Presence(ev[1][0], 'subscribe') + if ev[1][1]: + pres.setStatus(ev[1][1]) + else: + pres.setStatus("I would like to add you to my roster.") + self.con.send(pres) #('REQ', jid) elif ev[0] == 'AUTH': self.con.send(common.jabber.Presence(ev[1], 'subscribed')) diff --git a/plugins/gtkgui/gtkgui.glade b/plugins/gtkgui/gtkgui.glade index 02c61b9d3..f8dd9a047 100644 --- a/plugins/gtkgui/gtkgui.glade +++ b/plugins/gtkgui/gtkgui.glade @@ -2673,7 +2673,7 @@ on the server. 0 - 0 + 5 True True diff --git a/plugins/gtkgui/gtkgui.py b/plugins/gtkgui/gtkgui.py index b7c955058..b1dba29b4 100644 --- a/plugins/gtkgui/gtkgui.py +++ b/plugins/gtkgui/gtkgui.py @@ -588,7 +588,7 @@ class accountPreference_Window: del self.accs.r.plugin.accounts[self.acc] #if it's a new account else: - if name in self.accs.r.accounts: + if name in self.accs.r.plugin.accounts: warning_Window('An account already has this name') return 0 #if we neeed to register a new account @@ -664,7 +664,7 @@ class accounts_Window: (mod, iter) = sel.get_selected() model = self.treeview.get_model() account = model.get_value(iter, 0) - del self.r.plugin.accountsi[account] + del self.r.plugin.accounts[account] self.r.queueOUT.put(('CONFIG', ('accounts', self.r.plugin.accounts))) self.init_accounts() @@ -755,12 +755,14 @@ class authorize_Window: self.r.queueOUT.put(('DENY', self.jid)) self.delete_event(self) - def __init__(self, roster, jid): + def __init__(self, roster, jid, txt): xml = gtk.glade.XML(GTKGUI_GLADE, 'Sub_req') self.window = xml.get_widget('Sub_req') self.r = roster self.jid = jid xml.get_widget('label').set_text('Subscription request from ' + self.jid) + #TOTOTO + xml.get_widget("textview_sub").get_buffer().set_text(txt) xml.signal_connect('on_button_auth_clicked', self.auth) xml.signal_connect('on_button_deny_clicked', self.deny) xml.signal_connect('on_button_close_clicked', self.delete_event) @@ -1199,8 +1201,11 @@ class roster_Window: txt = w.run() else: txt = widget.name - self.queueOUT.put(('STATUS',(widget.name, txt, \ - self.plugin.accounts.keys()[0]))) + if len(self.plugin.accounts) > 0: + self.queueOUT.put(('STATUS',(widget.name, txt, \ + self.plugin.accounts.keys()[0]))) + else: + warning_Window("You must setup an account before connecting to jabber network.") def on_prefs(self, widget): """When preferences is selected : @@ -1518,7 +1523,7 @@ class plugin: self.r.tab_messages[jid].print_conversation(ev[1][1]) elif ev[0] == 'SUBSCRIBE': - authorize_Window(self.r, ev[1]) + authorize_Window(self.r, ev[1][0], ev[1][1]) elif ev[0] == 'SUBSCRIBED': jid = ev[1]['jid'] if self.r.l_contact.has_key(jid): @@ -1586,7 +1591,16 @@ class plugin: gtk.threads_init() gtk.threads_enter() self.queueIN = quIN - quOUT.put(('ASK_CONFIG', ('GtkGui', 'GtkGui'))) + quOUT.put(('ASK_CONFIG', ('GtkGui', 'GtkGui', {'autopopup':1,\ + 'showoffline':0,\ + 'autoaway':0,\ + 'autoawaytime':10,\ + 'autoxa':0,\ + 'autoxatime':20,\ + 'iconstyle':'sun',\ + 'inmsgcolor':'#ff000',\ + 'outmsgcolor': '#0000ff',\ + 'statusmsgcolor':'#1eaa1e'}))) self.config = self.wait('CONFIG') quOUT.put(('ASK_CONFIG', ('GtkGui', 'accounts'))) self.accounts = self.wait('CONFIG') diff --git a/plugins/logger/logger.py b/plugins/logger/logger.py index 76cab9011..b4b3ef906 100644 --- a/plugins/logger/logger.py +++ b/plugins/logger/logger.py @@ -83,7 +83,8 @@ class plugin: def __init__(self, quIN, quOUT): self.queueIN = quIN self.queueOUT = quOUT - quOUT.put(('ASK_CONFIG', ('Logger', 'Logger'))) + quOUT.put(('ASK_CONFIG', ('Logger', 'Logger', {\ + 'lognotsep':1, 'lognotusr':1}))) self.config = self.wait('CONFIG') #create ~/.gajim/logs/ if it doesn't exist try: