- new configuration File management

- bugfix : message from unknown personne
This commit is contained in:
Yann Leboulanger 2004-01-24 20:32:51 +00:00
parent b2ec388e4b
commit f913e4cd0e
9 changed files with 283 additions and 229 deletions

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##
@ -18,9 +17,7 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
import ConfigParser import ConfigParser, logging, os, string
import logging
import os
log = logging.getLogger('common.options') log = logging.getLogger('common.options')
@ -28,6 +25,7 @@ class OptionsParser(ConfigParser.ConfigParser):
def __init__(self, fname): def __init__(self, fname):
ConfigParser.ConfigParser.__init__(self) ConfigParser.ConfigParser.__init__(self)
self.__fname = os.path.expanduser(fname) self.__fname = os.path.expanduser(fname)
self.tab = {}
# END __init__ # END __init__
def parseCfgFile(self): def parseCfgFile(self):
@ -41,10 +39,19 @@ class OptionsParser(ConfigParser.ConfigParser):
self.__sections = self.sections() self.__sections = self.sections()
for section in self.__sections: for section in self.__sections:
self.tab[section] = {}
for option in self.options(section): for option in self.options(section):
value = self.get(section, option, 1) value = self.get(section, option, 1)
setattr(self, str(section) + '_' + \ #convert to int options than can be
str(option), value) try:
i = string.atoi(value)
except ValueError:
self.tab[section][option] = value
else:
self.tab[section][option] = i
# setattr(self, str(section) + '_' + \
# str(option), value)
# END parseCfgFile # END parseCfgFile
def __str__(self): def __str__(self):
@ -54,14 +61,24 @@ class OptionsParser(ConfigParser.ConfigParser):
def __getattr__(self, attr): def __getattr__(self, attr):
if attr.startswith('__') and attr in self.__dict__.keys(): if attr.startswith('__') and attr in self.__dict__.keys():
return self.__dict__[attr] return self.__dict__[attr]
elif self.tab.has_key(attr):
return self.tab[attr]
else: else:
for key in self.__dict__.keys(): # for key in self.__dict__.keys():
if key == attr: # if key == attr:
return self.__dict__[attr] # return self.__dict__[attr]
return None return None
# END __getattr__ # END __getattr__
def writeCfgFile(self): def writeCfgFile(self):
#Remove all sections
for s in self.sections():
self.remove_section(s)
#recreate sections
for s in self.tab.keys():
self.add_section(s)
for o in self.tab[s].keys():
self.set(s, o, self.tab[s][o])
try: try:
self.write(open(self.__fname, 'w')) self.write(open(self.__fname, 'w'))
except: except:

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##
@ -40,9 +39,16 @@ class GajimCore:
self.connected = 0 self.connected = 0
self.cfgParser = common.optparser.OptionsParser(CONFPATH) self.cfgParser = common.optparser.OptionsParser(CONFPATH)
self.hub = common.hub.GajimHub() self.hub = common.hub.GajimHub()
self.cfgParser.parseCfgFile() self.parse()
# END __init__ # END __init__
def parse(self):
self.cfgParser.parseCfgFile()
self.accounts = {}
accts = self.cfgParser.tab['Profile']['accounts']
for a in string.split(accts, ' '):
self.accounts[a] = self.cfgParser.tab[a]
def messageCB(self, con, msg): def messageCB(self, con, msg):
"""Called when we recieve a message""" """Called when we recieve a message"""
self.hub.sendPlugin('MSG', (msg.getFrom().getBasic(), \ self.hub.sendPlugin('MSG', (msg.getFrom().getBasic(), \
@ -60,17 +66,20 @@ class GajimCore:
show = prs.getShow() show = prs.getShow()
else: else:
show = 'online' show = 'online'
self.hub.sendPlugin('NOTIFY', \ self.hub.sendPlugin('NOTIFY', (prs.getFrom().getBasic(), \
(prs.getFrom().getBasic(), show, prs.getStatus(), prs.getFrom().getResource())) show, prs.getStatus(), prs.getFrom().getResource()))
elif type == 'unavailable': elif type == 'unavailable':
self.hub.sendPlugin('NOTIFY', \ self.hub.sendPlugin('NOTIFY', \
(prs.getFrom().getBasic(), 'offline', prs.getStatus(), prs.getFrom().getResource())) (prs.getFrom().getBasic(), 'offline', prs.getStatus(), \
prs.getFrom().getResource()))
elif type == 'subscribe': elif type == 'subscribe':
log.debug("subscribe request from %s" % who) log.debug("subscribe request from %s" % who)
if self.cfgParser.Core_alwaysauth == 1 or string.find(who, "@") <= 0: if self.cfgParser.Core['alwaysauth'] == 1 or \
string.find(who, "@") <= 0:
self.con.send(common.jabber.Presence(who, 'subscribed')) self.con.send(common.jabber.Presence(who, 'subscribed'))
if string.find(who, "@") <= 0: if string.find(who, "@") <= 0:
self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', prs.getFrom().getResource())) self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', \
prs.getFrom().getResource()))
else: else:
self.hub.sendPlugin('SUBSCRIBE', who) self.hub.sendPlugin('SUBSCRIBE', who)
elif type == 'subscribed': elif type == 'subscribed':
@ -79,7 +88,7 @@ class GajimCore:
'nom':jid.getNode(), 'ressource':jid.getResource()}) 'nom':jid.getNode(), 'ressource':jid.getResource()})
self.hub.queueIn.put(('UPDUSER', (jid.getBasic(), \ self.hub.queueIn.put(('UPDUSER', (jid.getBasic(), \
jid.getNode(), ['general']))) jid.getNode(), ['general'])))
# self.con.updateRosterItem(jid=jid.getBasic(), name=jid.getNode(), groups=['general']) #BE CAREFUL : no self.con.updateRosterItem() in a callback
log.debug("we are now subscribed to %s" % who) log.debug("we are now subscribed to %s" % who)
elif type == 'unsubscribe': elif type == 'unsubscribe':
log.debug("unsubscribe request from %s" % who) log.debug("unsubscribe request from %s" % who)
@ -87,17 +96,17 @@ class GajimCore:
log.debug("we are now unsubscribed to %s" % who) log.debug("we are now unsubscribed to %s" % who)
self.hub.sendPlugin('UNSUBSCRIBED', prs.getFrom().getBasic()) self.hub.sendPlugin('UNSUBSCRIBED', prs.getFrom().getBasic())
elif type == 'error': elif type == 'error':
# print "\n\n******** ERROR *******" print "\n\n******** ERROR *******"
# print "From : %s" % prs.getFrom() #print "From : %s" % prs.getFrom()
# print "To : %s" % prs.getTo() #print "To : %s" % prs.getTo()
# print "Status : %s" % prs.getStatus() #print "Status : %s" % prs.getStatus()
# print "Show : %s" % prs.getShow() #print "Show : %s" % prs.getShow()
# print "X : %s" % prs.getX() #print "X : %s" % prs.getX()
# print "XNode : %s" % prs.getXNode() #print "XNode : %s" % prs.getXNode()
# print "XPayload : %s" % prs.getXPayload() #print "XPayload : %s" % prs.getXPayload()
# print "_node : %s" % prs._node.getData() #print "_node : %s" % prs._node.getData()
# print "kids : %s" % prs._node.kids[0].getData() #print "kids : %s" % prs._node.kids[0].getData()
# print "\n\n" #print "\n\n"
errmsg = prs._node.kids[0].getData() errmsg = prs._node.kids[0].getData()
# END presenceCB # END presenceCB
@ -112,14 +121,15 @@ class GajimCore:
def connect(self, account): def connect(self, account):
"""Connect and authentificate to the Jabber server""" """Connect and authentificate to the Jabber server"""
self.cfgParser.parseCfgFile() hostname = self.cfgParser.tab[account]["hostname"]
hostname = self.cfgParser.__getattr__("%s" % account+"_hostname") name = self.cfgParser.tab[account]["name"]
name = self.cfgParser.__getattr__("%s" % account+"_name") password = self.cfgParser.tab[account]["password"]
password = self.cfgParser.__getattr__("%s" % account+"_password") ressource = self.cfgParser.tab[account]["ressource"]
ressource = self.cfgParser.__getattr__("%s" % account+"_ressource") self.con = common.jabber.Client(host = hostname, \
self.con = common.jabber.Client(host = \ debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
hostname, debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, connection=common.xmlstream.TCP, port=5222) connection=common.xmlstream.TCP, port=5222)
# hostname, debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, connection=common.xmlstream.TCP_SSL, port=5223) #debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
#connection=common.xmlstream.TCP_SSL, port=5223)
try: try:
self.con.connect() self.con.connect()
except IOError, e: except IOError, e:
@ -151,12 +161,14 @@ class GajimCore:
else: else:
log.debug("Couldn't authentificate to %s" % hostname) log.debug("Couldn't authentificate to %s" % hostname)
self.hub.sendPlugin('STATUS', 'offline') self.hub.sendPlugin('STATUS', 'offline')
self.hub.sendPlugin('WARNING', 'Authentification failed, check your login and password') self.hub.sendPlugin('WARNING', \
'Authentification failed, check your login and password')
return 0 return 0
# END connect # END connect
def mainLoop(self): def mainLoop(self):
"""Main Loop : Read the incomming queue to execute commands comming from plugins and process Jabber""" """Main Loop : Read the incomming queue to execute commands comming from
plugins and process Jabber"""
while 1: while 1:
if not self.hub.queueIn.empty(): if not self.hub.queueIn.empty():
ev = self.hub.queueIn.get() ev = self.hub.queueIn.get()
@ -166,6 +178,31 @@ class GajimCore:
self.con.disconnect() self.con.disconnect()
self.hub.sendPlugin('QUIT', ()) self.hub.sendPlugin('QUIT', ())
return return
#('ASK_CONFIG', section)
elif ev[0] == 'ASK_CONFIG':
if ev[1] == 'accounts':
self.hub.sendPlugin('CONFIG', self.accounts)
else:
self.hub.sendPlugin('CONFIG', \
self.cfgParser.__getattr__(ev[1]))
#('CONFIG', (section, config))
elif ev[0] == 'CONFIG':
if ev[1][0] == 'accounts':
#Remove all old accounts
accts = string.split(self.cfgParser.tab\
['Profile']['accounts'], ' ')
for a in accts:
del self.cfgParser.tab[a]
#Write all new accounts
accts = ev[1][1].keys()
self.cfgParser.tab['Profile']['accounts'] = \
string.join(accts)
for a in accts:
self.cfgParser.tab[a] = ev[1][1][a]
else:
self.cfgParser.tab[ev[1][0]] = ev[1][1]
self.cfgParser.writeCfgFile()
#TODO: tell the changes to other plugins
#('STATUS', (status, msg, account)) #('STATUS', (status, msg, account))
elif ev[0] == 'STATUS': elif ev[0] == 'STATUS':
if (ev[1][0] != 'offline') and (self.connected == 0): if (ev[1][0] != 'offline') and (self.connected == 0):
@ -198,17 +235,22 @@ class GajimCore:
self.con.send(common.jabber.Presence(ev[1], 'unsubscribed')) self.con.send(common.jabber.Presence(ev[1], 'unsubscribed'))
#('UNSUB', jid) #('UNSUB', jid)
elif ev[0] == 'UNSUB': elif ev[0] == 'UNSUB':
delauth = self.cfgParser.Core_delauth if self.cfgParser.Core.has_key('delauth'):
if not delauth: delauth = 1 delauth = self.cfgParser.Core['delauth']
delroster = self.cfgParser.Core_delroster else:
if not delroster: delroster = 1 delauth = 1
if self.cfgParser.Core.has_key('delroster'):
delroster = self.cfgParser.Core['delroster']
else:
delroster = 1
if delauth: if delauth:
self.con.send(common.jabber.Presence(ev[1], 'unsubscribe')) self.con.send(common.jabber.Presence(ev[1], 'unsubscribe'))
if delroster: if delroster:
self.con.removeRosterItem(ev[1]) self.con.removeRosterItem(ev[1])
#('UPDUSER', (jid, name, groups)) #('UPDUSER', (jid, name, groups))
elif ev[0] == 'UPDUSER': elif ev[0] == 'UPDUSER':
self.con.updateRosterItem(jid=ev[1][0], name=ev[1][1], groups=ev[1][2]) self.con.updateRosterItem(jid=ev[1][0], name=ev[1][1], \
groups=ev[1][2])
elif ev[0] == 'REQ_AGENTS': elif ev[0] == 'REQ_AGENTS':
agents = self.con.requestAgents() agents = self.con.requestAgents()
self.hub.sendPlugin('AGENTS', agents) self.hub.sendPlugin('AGENTS', agents)
@ -239,7 +281,7 @@ class GajimCore:
else: else:
self.hub.sendPlugin('ACC_OK', ev[1]) self.hub.sendPlugin('ACC_OK', ev[1])
else: else:
log.debug("Unknown Command") log.debug("Unknown Command %s" % ev[0])
elif self.connected == 1: elif self.connected == 1:
self.con.process(1) self.con.process(1)
time.sleep(0.1) time.sleep(0.1)
@ -247,8 +289,9 @@ class GajimCore:
# END GajimCore # END GajimCore
def loadPlugins(gc): def loadPlugins(gc):
"""Load defaults plugins : 'modules' option in section Core in ConfFile and register then to the hub""" """Load defaults plugins : plugins in 'modules' option of Core section
modStr = gc.cfgParser.Core_modules in ConfFile and register them to the hub"""
modStr = gc.cfgParser.Core['modules']
if modStr: if modStr:
mods = string.split (modStr, ' ') mods = string.split (modStr, ' ')
@ -266,6 +309,7 @@ def loadPlugins(gc):
gc.hub.register(mod, 'AGENT_INFO') gc.hub.register(mod, 'AGENT_INFO')
gc.hub.register(mod, 'QUIT') gc.hub.register(mod, 'QUIT')
gc.hub.register(mod, 'ACC_OK') gc.hub.register(mod, 'ACC_OK')
gc.hub.register(mod, 'CONFIG')
modObj.load() modObj.load()
# END loadPLugins # END loadPLugins
@ -273,6 +317,10 @@ def start():
"""Start the Core""" """Start the Core"""
gc = GajimCore() gc = GajimCore()
loadPlugins(gc) loadPlugins(gc)
################ pr des tests ###########
gc.hub.sendPlugin('NOTIFY', ('aste@lagaule.org', 'online', 'online', 'oleron'))
# gc.hub.sendPlugin('MSG', ('ate@lagaule.org', 'msg'))
#########################################
try: try:
gc.mainLoop() gc.mainLoop()
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -2,7 +2,6 @@
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface> <glade-interface>
<requires lib="gnome"/>
<widget class="GtkWindow" id="Gajim"> <widget class="GtkWindow" id="Gajim">
<property name="visible">True</property> <property name="visible">True</property>
@ -340,7 +339,6 @@
<property name="resizable">True</property> <property name="resizable">True</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Sun, 12 Oct 2003 18:17:05 GMT"/> <signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Sun, 12 Oct 2003 18:17:05 GMT"/>
<signal name="check_resize" handler="on_check_resize" last_modification_time="Tue, 20 Jan 2004 16:57:47 GMT"/>
<child> <child>
<widget class="GtkVBox" id="vbox2"> <widget class="GtkVBox" id="vbox2">

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##
@ -25,7 +24,7 @@ from gtk import TRUE, FALSE
import gtk.glade,gobject import gtk.glade,gobject
import os,string,time,Queue import os,string,time,Queue
import common.optparser,common.sleepy import common.optparser,common.sleepy
CONFPATH = "~/.gajim/config" #CONFPATH = "~/.gajim/config"
Wbrowser = 0 Wbrowser = 0
Waccounts = 0 Waccounts = 0
@ -48,13 +47,6 @@ class user:
self.status = args[4] self.status = args[4]
self.sub = args[5] self.sub = args[5]
self.resource = args[6] self.resource = args[6]
# elif ((len(args)) and (type (args[0]) == type (self)) and
# (self.__class__ == args[0].__class__)):
# self.name = args[0].name
# self.groups = args[0].groups
# self.show = args[0].show
# self.status = args[0].status
# self.sub = args[0].sub
else: raise TypeError, 'bad arguments' else: raise TypeError, 'bad arguments'
class info_user: class info_user:
@ -69,6 +61,7 @@ class info_user:
def on_close(self, widget): def on_close(self, widget):
"""Save user's informations and update the roster on the Jabber server""" """Save user's informations and update the roster on the Jabber server"""
#TODO: send things to server only if changes are done
#update user.name if it's not "" #update user.name if it's not ""
newName = self.entry_name.get_text() newName = self.entry_name.get_text()
if newName != '': if newName != '':
@ -202,64 +195,62 @@ class prefs:
colSt = '#'+(hex(self.colorIn.red)+'0')[2:4]\ colSt = '#'+(hex(self.colorIn.red)+'0')[2:4]\
+(hex(self.colorIn.green)+'0')[2:4]\ +(hex(self.colorIn.green)+'0')[2:4]\
+(hex(self.colorIn.blue)+'0')[2:4] +(hex(self.colorIn.blue)+'0')[2:4]
self.r.cfgParser.set('GtkGui', 'inmsgcolor', colSt) self.r.plugin.config['inmsgcolor'] = colSt
for j in self.r.tab_messages.keys(): for j in self.r.tab_messages.keys():
self.r.tab_messages[j].tagIn.set_property("foreground", colSt) self.r.tab_messages[j].tagIn.set_property("foreground", colSt)
#Color for outgoing messages #Color for outgoing messages
colSt = '#'+(hex(self.colorOut.red)+'0')[2:4]\ colSt = '#'+(hex(self.colorOut.red)+'0')[2:4]\
+(hex(self.colorOut.green)+'0')[2:4]\ +(hex(self.colorOut.green)+'0')[2:4]\
+(hex(self.colorOut.blue)+'0')[2:4] +(hex(self.colorOut.blue)+'0')[2:4]
self.r.cfgParser.set('GtkGui', 'outmsgcolor', colSt) self.r.plugin.config['outmsgcolor'] = colSt
for j in self.r.tab_messages.keys(): for j in self.r.tab_messages.keys():
self.r.tab_messages[j].tagOut.set_property("foreground", colSt) self.r.tab_messages[j].tagOut.set_property("foreground", colSt)
#Color for status messages #Color for status messages
colSt = '#'+(hex(self.colorStatus.red)+'0')[2:4]\ colSt = '#'+(hex(self.colorStatus.red)+'0')[2:4]\
+(hex(self.colorStatus.green)+'0')[2:4]\ +(hex(self.colorStatus.green)+'0')[2:4]\
+(hex(self.colorStatus.blue)+'0')[2:4] +(hex(self.colorStatus.blue)+'0')[2:4]
self.r.cfgParser.set('GtkGui', 'statusmsgcolor', colSt) self.r.plugin.config['statusmsgcolor'] = colSt
for j in self.r.tab_messages.keys(): for j in self.r.tab_messages.keys():
self.r.tab_messages[j].tagStatus.set_property("foreground", colSt) self.r.tab_messages[j].tagStatus.set_property("foreground", colSt)
#IconStyle #IconStyle
ist = self.combo_iconstyle.entry.get_text() ist = self.combo_iconstyle.entry.get_text()
self.r.cfgParser.set('GtkGui', 'iconstyle', ist) self.r.plugin.config['iconstyle'] = ist
self.r.iconstyle = ist self.r.iconstyle = ist
self.r.mkpixbufs() self.r.mkpixbufs()
#autopopup #autopopup
pp = self.chk_autopp.get_active() pp = self.chk_autopp.get_active()
if pp == True: if pp == True:
self.r.cfgParser.set('GtkGui', 'autopopup', '1') self.r.plugin.config['autopopup'] = 1
self.r.autopopup = 1 self.r.autopopup = 1
else: else:
self.r.cfgParser.set('GtkGui', 'autopopup', '0') self.r.plugin.config['autopopup'] = 0
self.r.autopopup = 0 self.r.autopopup = 0
#autoaway #autoaway
aw = self.chk_autoaway.get_active() aw = self.chk_autoaway.get_active()
if aw == True: if aw == True:
self.r.cfgParser.set('GtkGui', 'autoaway', '1') self.r.plugin.config['autoaway'] = 1
self.r.plugin.autoaway = 1 self.r.plugin.autoaway = 1
else: else:
self.r.cfgParser.set('GtkGui', 'autoaway', '0') self.r.plugin.config['autoaway'] = 0
self.r.plugin.autoaway = 0 self.r.plugin.autoaway = 0
aat = self.spin_autoawaytime.get_value_as_int() aat = self.spin_autoawaytime.get_value_as_int()
self.r.plugin.autoawaytime = aat self.r.plugin.autoawaytime = aat
self.r.cfgParser.set('GtkGui', 'autoawaytime', aat) self.r.plugin.config['autoawaytime'] = aat
#autoxa #autoxa
xa = self.chk_autoxa.get_active() xa = self.chk_autoxa.get_active()
if xa == True: if xa == True:
self.r.cfgParser.set('GtkGui', 'autoxa', '1') self.r.plugin.config['autoxa'] = 1
self.r.plugin.autoxa = 1 self.r.plugin.autoxa = 1
else: else:
self.r.cfgParser.set('GtkGui', 'autoxa', '0') self.r.plugin.config['autoxa'] = 0
self.r.plugin.autoxa = 0 self.r.plugin.autoxa = 0
axt = self.spin_autoxatime.get_value_as_int() axt = self.spin_autoxatime.get_value_as_int()
self.r.plugin.autoxatime = axt self.r.plugin.autoxatime = axt
self.r.cfgParser.set('GtkGui', 'autoxatime', axt) self.r.plugin.config['autoxatime'] = axt
if self.r.plugin.sleeper: if self.r.plugin.sleeper:
self.r.plugin.sleeper = common.sleepy.Sleepy(\ self.r.plugin.sleeper = common.sleepy.Sleepy(\
self.r.plugin.autoawaytime*60, self.r.plugin.autoxatime*60) self.r.plugin.autoawaytime*60, self.r.plugin.autoxatime*60)
self.r.queueOUT.put(('CONFIG', ('GtkGui', self.r.plugin.config)))
self.r.cfgParser.writeCfgFile()
self.r.cfgParser.parseCfgFile()
self.r.redraw_roster() self.r.redraw_roster()
@ -284,7 +275,7 @@ class prefs:
self.spin_autoxatime = xml.get_widget("spin_autoxatime") self.spin_autoxatime = xml.get_widget("spin_autoxatime")
#Color for incomming messages #Color for incomming messages
colSt = self.r.cfgParser.GtkGui_inmsgcolor colSt = self.r.plugin.config['inmsgcolor']
if not colSt: if not colSt:
colSt = '#ff0000' colSt = '#ff0000'
cmapIn = self.da_in.get_colormap() cmapIn = self.da_in.get_colormap()
@ -292,7 +283,7 @@ class prefs:
self.da_in.window.set_background(self.colorIn) self.da_in.window.set_background(self.colorIn)
#Color for outgoing messages #Color for outgoing messages
colSt = self.r.cfgParser.GtkGui_outmsgcolor colSt = self.r.plugin.config['outmsgcolor']
if not colSt: if not colSt:
colSt = '#0000ff' colSt = '#0000ff'
cmapOut = self.da_out.get_colormap() cmapOut = self.da_out.get_colormap()
@ -300,7 +291,7 @@ class prefs:
self.da_out.window.set_background(self.colorOut) self.da_out.window.set_background(self.colorOut)
#Color for status messages #Color for status messages
colSt = self.r.cfgParser.GtkGui_statusmsgcolor colSt = self.r.plugin.config['statusmsgcolor']
if not colSt: if not colSt:
colSt = '#00ff00' colSt = '#00ff00'
cmapStatus = self.da_status.get_colormap() cmapStatus = self.da_status.get_colormap()
@ -320,35 +311,35 @@ class prefs:
self.combo_iconstyle.entry.set_text(self.r.iconstyle) self.combo_iconstyle.entry.set_text(self.r.iconstyle)
#Autopopup #Autopopup
st = self.r.cfgParser.GtkGui_autopopup if self.r.plugin.config.has_key('autopopup'):
if not st: st = self.r.plugin.config['autopopup']
st = '0' else:
pp = string.atoi(st) st = 0
self.chk_autopp.set_active(pp) self.chk_autopp.set_active(st)
#Autoaway #Autoaway
st = self.r.cfgParser.GtkGui_autoaway if self.r.plugin.config.has_key('autoaway'):
if not st: st = self.r.plugin.config['autoaway']
st = '1' else:
aw = string.atoi(st) st = 1
self.chk_autoaway.set_active(aw) self.chk_autoaway.set_active(st)
st = self.r.cfgParser.GtkGui_autoawaytime if self.r.plugin.config.has_key('autoawaytime'):
if not st: st = self.r.plugin.config['autoawaytime']
st = '10' else:
ti = string.atoi(st) st = 10
self.spin_autoawaytime.set_value(ti) self.spin_autoawaytime.set_value(st)
#Autoxa #Autoxa
st = self.r.cfgParser.GtkGui_autoxa if self.r.plugin.config.has_key('autoxa'):
if not st: st = self.r.plugin.config['autoxa']
st = '1' else:
xa = string.atoi(st) st = 1
self.chk_autoxa.set_active(xa) self.chk_autoxa.set_active(st)
st = self.r.cfgParser.GtkGui_autoxatime if self.r.plugin.config.has_key('autoxatime'):
if not st: st = self.r.plugin.config['autoxatime']
st = '20' else:
ti = string.atoi(st) st = 20
self.spin_autoxatime.set_value(ti) self.spin_autoxatime.set_value(st)
xml.signal_connect('gtk_widget_destroy', self.delete_event) xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_but_col_clicked', \ xml.signal_connect('on_but_col_clicked', \
@ -460,7 +451,8 @@ class account_pref:
warning('You must enter a name for this account') warning('You must enter a name for this account')
return 0 return 0
if (jid == '') or (string.count(jid, '@') != 1): if (jid == '') or (string.count(jid, '@') != 1):
warning('You must enter a Jabber ID for this account\nFor example : login@hostname') warning('You must enter a Jabber ID for this account\n\
For example : login@hostname')
return 0 return 0
else: else:
(login, hostname) = string.split(jid, '@') (login, hostname) = string.split(jid, '@')
@ -468,12 +460,7 @@ class account_pref:
if self.mod: if self.mod:
#if we modify the name of the account #if we modify the name of the account
if name != self.acc: if name != self.acc:
self.accs.r.cfgParser.remove_section(self.acc) del self.accs.r.plugin.accounts[self.acc]
self.accs.r.accounts.remove(self.acc)
self.accs.r.cfgParser.add_section(name)
self.accs.r.accounts.append(name)
accountsStr = string.join(self.accs.accounts)
self.accs.r.cfgParser.set('Profile', 'accounts', accountsStr)
#if it's a new account #if it's a new account
else: else:
if name in self.accs.r.accounts: if name in self.accs.r.accounts:
@ -486,16 +473,11 @@ class account_pref:
self.entryRessource.get_text()))) self.entryRessource.get_text())))
self.check.set_active(FALSE) self.check.set_active(FALSE)
return 1 return 1
self.accs.r.cfgParser.add_section(name) self.accs.r.plugin.accounts[name] = {'name': login, 'hostname': hostname,\
self.accs.r.accounts.append(name) 'password': self.entryPass.get_text(), 'ressource': \
accountsStr = string.join(self.accs.accounts) self.entryRessource.get_text()}
self.accs.r.cfgParser.set('Profile', 'accounts', accountsStr) self.accs.r.queueOUT.put(('CONFIG', ('accounts', \
self.accs.r.cfgParser.set(name, 'name', login) self.accs.r.plugin.accounts)))
self.accs.r.cfgParser.set(name, 'hostname', hostname)
self.accs.r.cfgParser.set(name, 'password', self.entryPass.get_text())
self.accs.r.cfgParser.set(name, 'ressource', self.entryRessource.get_text())
self.accs.r.cfgParser.writeCfgFile()
self.accs.r.cfgParser.parseCfgFile()
self.accs.init_accounts() self.accs.init_accounts()
self.delete_event(self) self.delete_event(self)
@ -513,10 +495,9 @@ class account_pref:
self.mod = TRUE self.mod = TRUE
self.acc = infos['name'] self.acc = infos['name']
self.init_account(infos) self.init_account(infos)
self.check.set_sensitive(FALSE)
else: else:
self.mod = FALSE self.mod = FALSE
if self.mod:
self.check.set_sensitive(FALSE)
xml.signal_connect('gtk_widget_destroy', self.delete_event) xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_save_clicked', self.on_save_clicked) xml.signal_connect('on_save_clicked', self.on_save_clicked)
@ -532,9 +513,10 @@ class accounts:
"""initialize listStore with existing accounts""" """initialize listStore with existing accounts"""
model = self.treeview.get_model() model = self.treeview.get_model()
model.clear() model.clear()
for account in self.r.accounts: for account in self.r.plugin.accounts.keys():
iter = model.append() iter = model.append()
model.set(iter, 0, account, 1, self.r.cfgParser.__getattr__("%s" % account+"_hostname")) model.set(iter, 0, account, 1, \
self.r.plugin.accounts[account]["hostname"])
def on_row_activated(self, widget): def on_row_activated(self, widget):
"""Activate delete and modify buttons when a row is selected""" """Activate delete and modify buttons when a row is selected"""
@ -552,12 +534,8 @@ class accounts:
(mod, iter) = sel.get_selected() (mod, iter) = sel.get_selected()
model = self.treeview.get_model() model = self.treeview.get_model()
account = model.get_value(iter, 0) account = model.get_value(iter, 0)
self.r.cfgParser.remove_section(account) del self.r.plugin.accountsi[account]
self.r.accounts.remove(account) self.r.queueOUT.put(('CONFIG', ('accounts', self.r.plugin.accounts)))
accountsStr = string.join(self.r.accounts)
self.r.cfgParser.set('Profile', 'accounts', accountsStr)
self.r.cfgParser.writeCfgFile()
self.r.cfgParser.parseCfgFile()
self.init_accounts() self.init_accounts()
def on_modify_clicked(self, widget): def on_modify_clicked(self, widget):
@ -569,10 +547,10 @@ class accounts:
(mod, iter) = sel.get_selected() (mod, iter) = sel.get_selected()
account = model.get_value(iter, 0) account = model.get_value(iter, 0)
infos['name'] = account infos['name'] = account
infos['jid'] = self.r.cfgParser.__getattr__("%s" % account+"_name") + \ infos['jid'] = self.r.plugin.accounts[account]["name"] + \
'@' + self.r.cfgParser.__getattr__("%s" % account+"_hostname") '@' + self.r.plugin.accounts[account]["hostname"]
infos['password'] = self.r.cfgParser.__getattr__("%s" % account+"_password") infos['password'] = self.r.plugin.accounts[account]["password"]
infos['ressource'] = self.r.cfgParser.__getattr__("%s" % account+"_ressource") infos['ressource'] = self.r.plugin.accounts[account]["ressource"]
account_pref(self, infos) account_pref(self, infos)
def __init__(self, roster): def __init__(self, roster):
@ -590,7 +568,8 @@ class accounts:
self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0) self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0)
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
renderer.set_data('column', 1) renderer.set_data('column', 1)
self.treeview.insert_column_with_attributes(-1, 'Server', renderer, text=1) self.treeview.insert_column_with_attributes(-1, 'Server', \
renderer, text=1)
xml.signal_connect('gtk_widget_destroy', self.delete_event) xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_row_activated', self.on_row_activated) xml.signal_connect('on_row_activated', self.on_row_activated)
xml.signal_connect('on_new_clicked', self.on_new_clicked) xml.signal_connect('on_new_clicked', self.on_new_clicked)
@ -607,7 +586,8 @@ class confirm:
def req_usub(self, widget): def req_usub(self, widget):
"""When Ok button is clicked : """When Ok button is clicked :
Send a message to the core to remove the user and remove it from the roster""" Send a message to the core to remove the user
and remove it from the roster"""
model = self.r.tree.get_model() model = self.r.tree.get_model()
jid = model.get_value(self.iter, 2) jid = model.get_value(self.iter, 2)
self.r.queueOUT.put(('UNSUB', jid)) self.r.queueOUT.put(('UNSUB', jid))
@ -621,7 +601,8 @@ class confirm:
self.r = roster self.r = roster
self.iter = iter self.iter = iter
jid = self.r.tree.get_model().get_value(iter, 2) jid = self.r.tree.get_model().get_value(iter, 2)
xml.get_widget('label_confirm').set_text('Are you sure you want to remove ' + jid + ' from your roster ?') xml.get_widget('label_confirm').set_text(\
'Are you sure you want to remove ' + jid + ' from your roster ?')
xml.signal_connect('on_okbutton_clicked', self.req_usub) xml.signal_connect('on_okbutton_clicked', self.req_usub)
xml.signal_connect('gtk_widget_destroy', self.delete_event) xml.signal_connect('gtk_widget_destroy', self.delete_event)
@ -750,7 +731,8 @@ class browser:
self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0) self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0)
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
renderer.set_data('column', 1) renderer.set_data('column', 1)
self.treeview.insert_column_with_attributes(-1, 'Service', renderer, text=1) self.treeview.insert_column_with_attributes(-1, 'Service', \
renderer, text=1)
xml.signal_connect('gtk_widget_destroy', self.delete_event) xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_refresh_clicked', self.on_refresh) xml.signal_connect('on_refresh_clicked', self.on_refresh)
@ -787,7 +769,8 @@ class message:
buffer.insert_with_tags_by_name(end_iter, '<moi> ', 'outgoing') buffer.insert_with_tags_by_name(end_iter, '<moi> ', 'outgoing')
buffer.insert(end_iter, txt+'\n') buffer.insert(end_iter, txt+'\n')
else: else:
buffer.insert_with_tags_by_name(end_iter, '<' + self.user.name + '> ', 'incoming') buffer.insert_with_tags_by_name(end_iter, '<' + \
self.user.name + '> ', 'incoming')
buffer.insert(end_iter, txt+'\n') buffer.insert(end_iter, txt+'\n')
#scroll to the end of the textview #scroll to the end of the textview
self.conversation.scroll_to_mark(\ self.conversation.scroll_to_mark(\
@ -801,11 +784,13 @@ class message:
del self.r.tab_queues[self.user.jid] del self.r.tab_queues[self.user.jid]
for i in self.r.l_contact[self.user.jid]['iter']: for i in self.r.l_contact[self.user.jid]['iter']:
if self.r.pixbufs.has_key(self.user.show): if self.r.pixbufs.has_key(self.user.show):
self.r.tree.get_model().set_value(i, 0, self.r.pixbufs[self.user.show]) self.r.tree.get_model().set_value(i, 0, \
self.r.pixbufs[self.user.show])
def on_msg_key_press_event(self, widget, event): def on_msg_key_press_event(self, widget, event):
"""When a key is pressed : """When a key is pressed :
if enter is pressed without the shit key, message (if not empty) is sent and printed in the conversation""" if enter is pressed without the shit key, message (if not empty) is sent
and printed in the conversation"""
if event.keyval == gtk.keysyms.Return: if event.keyval == gtk.keysyms.Return:
if (event.state & gtk.gdk.SHIFT_MASK): if (event.state & gtk.gdk.SHIFT_MASK):
return 0 return 0
@ -828,11 +813,6 @@ class message:
deb, end = buffer.get_bounds() deb, end = buffer.get_bounds()
buffer.delete(deb, end) buffer.delete(deb, end)
def on_test(self, widget):
print self.window.get_size()
print self.hbox.need_resize
print self.hbox.resize_mode
def __init__(self, user, roster): def __init__(self, user, roster):
self.user = user self.user = user
self.r = roster self.r = roster
@ -854,19 +834,18 @@ class message:
xml.signal_connect('gtk_widget_destroy', self.delete_event) xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_clear_button_clicked', self.on_clear) xml.signal_connect('on_clear_button_clicked', self.on_clear)
xml.signal_connect('on_msg_key_press_event', self.on_msg_key_press_event) xml.signal_connect('on_msg_key_press_event', self.on_msg_key_press_event)
xml.signal_connect('on_check_resize', self.on_test)
self.tagIn = buffer.create_tag("incoming") self.tagIn = buffer.create_tag("incoming")
color = self.r.cfgParser.GtkGui_inmsgcolor color = self.r.plugin.config['inmsgcolor']
if not color: if not color:
color = '#ff0000' #red color = '#ff0000' #red
self.tagIn.set_property("foreground", color) self.tagIn.set_property("foreground", color)
self.tagOut = buffer.create_tag("outgoing") self.tagOut = buffer.create_tag("outgoing")
color = self.r.cfgParser.GtkGui_outmsgcolor color = self.r.plugin.config['outmsgcolor']
if not color: if not color:
color = '#0000ff' #blue color = '#0000ff' #blue
self.tagOut.set_property("foreground", color) self.tagOut.set_property("foreground", color)
self.tagStatus = buffer.create_tag("status") self.tagStatus = buffer.create_tag("status")
color = self.r.cfgParser.GtkGui_statusmsgcolor color = self.r.plugin.config['statusmsgcolor']
if not color: if not color:
color = '#00ff00' #green color = '#00ff00' #green
self.tagStatus.set_property("foreground", color) self.tagStatus.set_property("foreground", color)
@ -888,7 +867,8 @@ class roster:
if not self.l_group.has_key(g): if not self.l_group.has_key(g):
self.l_group[g] = {'iter':None, 'hide':False} self.l_group[g] = {'iter':None, 'hide':False}
if not self.l_group[g]['iter']: if not self.l_group[g]['iter']:
iterG = model.append(None, (self.pixbufs['closed'], g, 'group', FALSE, self.grpbgcolor, TRUE)) iterG = model.append(None, (self.pixbufs['closed'], g, \
'group', FALSE, self.grpbgcolor, TRUE))
self.l_group[g] = {'iter':iterG, 'hide':False} self.l_group[g] = {'iter':iterG, 'hide':False}
newgrp = 1 newgrp = 1
if g == 'Agents': if g == 'Agents':
@ -946,7 +926,8 @@ class roster:
show = tab[jid]['show'] show = tab[jid]['show']
if not show: if not show:
show = 'offline' show = 'offline'
user1 = user(ji, name, tab[jid]['groups'], show, tab[jid]['status'], tab[jid]['sub'], '') user1 = user(ji, name, tab[jid]['groups'], show, \
tab[jid]['status'], tab[jid]['sub'], '')
self.l_contact[ji] = {'user':user1, 'iter':[]} self.l_contact[ji] = {'user':user1, 'iter':[]}
for i in tab[jid]['groups'] : for i in tab[jid]['groups'] :
if not i in self.l_group.keys(): if not i in self.l_group.keys():
@ -990,7 +971,7 @@ class roster:
item.connect("activate", self.on_row_activated, path) item.connect("activate", self.on_row_activated, path)
item = gtk.MenuItem("Rename") item = gtk.MenuItem("Rename")
self.menu_c.append(item) self.menu_c.append(item)
# item.connect("activate", self.on_rename, iter) #item.connect("activate", self.on_rename, iter)
item = gtk.MenuItem() item = gtk.MenuItem()
self.menu_c.append(item) self.menu_c.append(item)
item = gtk.MenuItem("Subscription") item = gtk.MenuItem("Subscription")
@ -1003,7 +984,8 @@ class roster:
item.connect("activate", self.authorize, jid) item.connect("activate", self.authorize, jid)
item = gtk.MenuItem("Rerequest authorization from") item = gtk.MenuItem("Rerequest authorization from")
menu_sub.append(item) menu_sub.append(item)
item.connect("activate", self.req_sub, jid, 'I would like to add you to my contact list, please.') item.connect("activate", self.req_sub, jid, \
'I would like to add you to my contact list, please.')
item = gtk.MenuItem() item = gtk.MenuItem()
self.menu_c.append(item) self.menu_c.append(item)
@ -1036,17 +1018,12 @@ class roster:
"""Authorize a user""" """Authorize a user"""
self.queueOUT.put(('AUTH', jid)) self.queueOUT.put(('AUTH', jid))
# def rename(self, widget, jid, name):
# u = self.l_contact[jid]['user']
# u.name = name
# for i in self.l_contact[jid]['iter']:
# self.tree.get_model().set_value(i, 1, name)
def req_sub(self, widget, jid, txt): def req_sub(self, widget, jid, txt):
"""Request subscription to a user""" """Request subscription to a user"""
self.queueOUT.put(('SUB', (jid, txt))) self.queueOUT.put(('SUB', (jid, txt)))
if not self.l_contact.has_key(jid): if not self.l_contact.has_key(jid):
user1 = user(jid, jid, ['general'], 'requested', 'requested', 'sub', '') user1 = user(jid, jid, ['general'], 'requested', \
'requested', 'sub', '')
self.add_user(user1) self.add_user(user1)
def init_tree(self): def init_tree(self):
@ -1061,7 +1038,8 @@ class roster:
"""popup user's group's or agent menu""" """popup user's group's or agent menu"""
if (event.button == 3) & (event.type == gtk.gdk.BUTTON_PRESS): if (event.button == 3) & (event.type == gtk.gdk.BUTTON_PRESS):
try: try:
path, column, x, y = self.tree.get_path_at_pos(int(event.x), int(event.y)) path, column, x, y = self.tree.get_path_at_pos(int(event.x), \
int(event.y))
except TypeError: except TypeError:
return return
model = self.tree.get_model() model = self.tree.get_model()
@ -1083,14 +1061,13 @@ class roster:
def on_status_changed(self, widget): def on_status_changed(self, widget):
"""When we change our status""" """When we change our status"""
accountsStr = self.cfgParser.Profile_accounts
accounts = string.split(accountsStr, ' ')
if widget.name != 'online' and widget.name != 'offline': if widget.name != 'online' and widget.name != 'offline':
w = away_msg() w = away_msg()
txt = w.run() txt = w.run()
else: else:
txt = widget.name txt = widget.name
self.queueOUT.put(('STATUS',(widget.name, txt, accounts[0]))) self.queueOUT.put(('STATUS',(widget.name, txt, \
self.plugin.accounts.keys()[0])))
def on_prefs(self, widget): def on_prefs(self, widget):
"""When preferences is selected : """When preferences is selected :
@ -1168,7 +1145,8 @@ class roster:
else: else:
model.set_value(iter, 1, new_text) model.set_value(iter, 1, new_text)
self.l_contact[jid]['user'].name = new_text self.l_contact[jid]['user'].name = new_text
self.queueOUT.put(('UPDUSER', (jid, new_text, self.l_contact[jid]['user'].groups))) self.queueOUT.put(('UPDUSER', (jid, new_text, \
self.l_contact[jid]['user'].groups)))
def on_browse(self, widget): def on_browse(self, widget):
"""When browse agent is selected : """When browse agent is selected :
@ -1181,7 +1159,8 @@ class roster:
"""initialise pixbufs array""" """initialise pixbufs array"""
self.path = 'plugins/gtkgui/icons/' + self.iconstyle + '/' self.path = 'plugins/gtkgui/icons/' + self.iconstyle + '/'
self.pixbufs = {} self.pixbufs = {}
for state in ('online', 'away', 'xa', 'dnd', 'offline', 'requested', 'message', 'opened', 'closed'): for state in ('online', 'away', 'xa', 'dnd', 'offline', \
'requested', 'message', 'opened', 'closed', 'not in list'):
#open an animated gif file if it exists oterelse a xpm file #open an animated gif file if it exists oterelse a xpm file
if not os.path.exists(self.path + state + '.gif'): if not os.path.exists(self.path + state + '.gif'):
if not os.path.exists(self.path + state + '.xpm'): if not os.path.exists(self.path + state + '.xpm'):
@ -1202,18 +1181,17 @@ class roster:
def __init__(self, queueOUT, plug): def __init__(self, queueOUT, plug):
# FIXME : handle no file ... # FIXME : handle no file ...
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
self.cfgParser.parseCfgFile()
xml = gtk.glade.XML('plugins/gtkgui/gtkgui.glade', 'Gajim') xml = gtk.glade.XML('plugins/gtkgui/gtkgui.glade', 'Gajim')
self.window = xml.get_widget('Gajim') self.window = xml.get_widget('Gajim')
self.tree = xml.get_widget('treeview') self.tree = xml.get_widget('treeview')
self.plugin = plug self.plugin = plug
self.connected = 0 self.connected = 0
#(icon, name, jid, editable, background color, show_icon) #(icon, name, jid, editable, background color, show_icon)
model = gtk.TreeStore(gtk.gdk.Pixbuf, str, str, gobject.TYPE_BOOLEAN, str, gobject.TYPE_BOOLEAN) model = gtk.TreeStore(gtk.gdk.Pixbuf, str, str, \
gobject.TYPE_BOOLEAN, str, gobject.TYPE_BOOLEAN)
self.tree.set_model(model) self.tree.set_model(model)
self.init_tree() self.init_tree()
self.iconstyle = self.cfgParser.GtkGui_iconstyle self.iconstyle = self.plugin.config['iconstyle']
if not self.iconstyle: if not self.iconstyle:
self.iconstyle = 'sun' self.iconstyle = 'sun'
self.mkpixbufs() self.mkpixbufs()
@ -1239,12 +1217,9 @@ class roster:
self.optionmenu.set_history(6) self.optionmenu.set_history(6)
self.tab_messages = {} self.tab_messages = {}
self.tab_queues = {} self.tab_queues = {}
accountsStr = self.cfgParser.Profile_accounts
self.accounts = string.split(accountsStr, ' ')
showOffline = self.cfgParser.GtkGui_showoffline if self.plugin.config.has_key('showoffline'):
if showOffline: self.showOffline = self.plugin.config['showoffline']
self.showOffline = string.atoi(showOffline)
else: else:
self.showOffline = 0 self.showOffline = 0
@ -1291,6 +1266,16 @@ class roster:
class plugin: class plugin:
"""Class called by the core in a new thread""" """Class called by the core in a new thread"""
def wait(self, what):
"""Wait for a message from Core"""
#TODO: timeout, save messages that don't fit
while 1:
if not self.queueIN.empty():
ev = self.queueIN.get()
if ev[0] == what:
return ev[1]
time.sleep(0.1)
def read_queue(self): def read_queue(self):
"""Read queue from the core and execute commands from it""" """Read queue from the core and execute commands from it"""
global Wbrowser global Wbrowser
@ -1317,7 +1302,7 @@ class plugin:
self.r.chg_status(j, 'offline', 'Disconnected') self.r.chg_status(j, 'offline', 'Disconnected')
elif self.r.connected == 0: elif self.r.connected == 0:
self.r.connected = 1 self.r.connected = 1
self.r.plugin.sleeper = common.sleepy.Sleepy(\ self.sleeper = common.sleepy.Sleepy(\
self.autoawaytime*60, self.autoxatime*60) self.autoawaytime*60, self.autoxatime*60)
elif ev[0] == 'NOTIFY': elif ev[0] == 'NOTIFY':
@ -1339,11 +1324,13 @@ class plugin:
#Print status in chat window #Print status in chat window
if self.r.tab_messages.has_key(ji): if self.r.tab_messages.has_key(ji):
self.r.tab_messages[ji].print_conversation(\ self.r.tab_messages[ji].print_conversation(\
"%s is now %s (%s)" % (u.name, ev[1][1], ev[1][2]), 'status') "%s is now %s (%s)" % (u.name, ev[1][1], \
ev[1][2]), 'status')
if string.find(jid, "@") <= 0: if string.find(jid, "@") <= 0:
#It must be an agent #It must be an agent
if not self.r.l_contact.has_key(ji): if not self.r.l_contact.has_key(ji):
user1 = user(ji, ji, ['Agents'], ev[1][1], ev[1][2], 'from', res) user1 = user(ji, ji, ['Agents'], ev[1][1], \
ev[1][2], 'from', res)
self.r.add_user(user1) self.r.add_user(user1)
else: else:
#Update existing iter #Update existing iter
@ -1359,11 +1346,14 @@ class plugin:
else: else:
jid = ev[1][0] jid = ev[1][0]
autopopup = self.r.cfgParser.GtkGui_autopopup if self.config.has_key('autopopup'):
if autopopup: self.autopopup = self.config['autopopup']
self.autopopup = string.atoi(autopopup)
else: else:
self.autopopup = 0 self.autopopup = 0
if not self.r.l_contact.has_key(jid):
user1 = user(jid, jid, ['not in list'], \
'not in list', 'not in list', 'none', '')
self.r.add_user(user1)
if self.autopopup == 0 and not self.r.tab_messages.has_key(jid): if self.autopopup == 0 and not self.r.tab_messages.has_key(jid):
#We save it in a queue #We save it in a queue
if not self.r.tab_queues.has_key(jid): if not self.r.tab_queues.has_key(jid):
@ -1374,9 +1364,9 @@ class plugin:
self.r.tab_queues[jid].put((ev[1][1], tim)) self.r.tab_queues[jid].put((ev[1][1], tim))
else: else:
if not self.r.tab_messages.has_key(jid): if not self.r.tab_messages.has_key(jid):
#FIXME:message from unknown
if self.r.l_contact.has_key(jid): if self.r.l_contact.has_key(jid):
self.r.tab_messages[jid] = message(self.r.l_contact[jid]['user'], self.r) self.r.tab_messages[jid] = \
message(self.r.l_contact[jid]['user'], self.r)
if self.r.tab_messages.has_key(jid): if self.r.tab_messages.has_key(jid):
self.r.tab_messages[jid].print_conversation(ev[1][1]) self.r.tab_messages[jid].print_conversation(ev[1][1])
@ -1390,7 +1380,8 @@ class plugin:
for i in self.r.l_contact[u.jid]['iter']: for i in self.r.l_contact[u.jid]['iter']:
model.set_value(i, 1, u.name) model.set_value(i, 1, u.name)
else: else:
user1 = user(jid, jid, ['general'], 'online', 'online', 'to', ev[1]['ressource']) user1 = user(jid, jid, ['general'], 'online', \
'online', 'to', ev[1]['ressource'])
self.r.add_user(user1) self.r.add_user(user1)
warning("You are now authorized by " + jid) warning("You are now authorized by " + jid)
elif ev[0] == 'UNSUBSCRIBED': elif ev[0] == 'UNSUBSCRIBED':
@ -1406,16 +1397,9 @@ class plugin:
Wreg = agent_reg(ev[1][0], ev[1][1], self.r) Wreg = agent_reg(ev[1][0], ev[1][1], self.r)
#('ACC_OK', (hostname, login, pasword, name, ressource)) #('ACC_OK', (hostname, login, pasword, name, ressource))
elif ev[0] == 'ACC_OK': elif ev[0] == 'ACC_OK':
self.r.cfgParser.add_section(ev[1][3]) self.accounts[ev[1][3]] = {'ressource': ev[1][4], \
self.r.accounts.append(ev[1][3]) 'password': ev[1][2], 'hostname': ev[1][0], 'name': ev[1][1]}
accountsStr = string.join(self.r.accounts) self.r.queueOUT.put(('CONFIG', ('accounts', self.r.plugin.accounts)))
self.r.cfgParser.set('Profile', 'accounts', accountsStr)
self.r.cfgParser.set(ev[1][3], 'name', ev[1][1])
self.r.cfgParser.set(ev[1][3], 'hostname', ev[1][0])
self.r.cfgParser.set(ev[1][3], 'password', ev[1][2])
self.r.cfgParser.set(ev[1][3], 'ressource', ev[1][4])
self.r.cfgParser.writeCfgFile()
self.r.cfgParser.parseCfgFile()
if (Waccounts != 0): if (Waccounts != 0):
Waccounts.init_accounts() Waccounts.init_accounts()
elif ev[0] == 'QUIT': elif ev[0] == 'QUIT':
@ -1430,20 +1414,21 @@ class plugin:
self.sleeper.poll() self.sleeper.poll()
state = self.sleeper.getState() state = self.sleeper.getState()
if state != self.sleeper_state: if state != self.sleeper_state:
accountsStr = self.r.cfgParser.Profile_accounts
accounts = string.split(accountsStr, ' ')
if state == common.sleepy.STATE_AWAKE: if state == common.sleepy.STATE_AWAKE:
#we go online #we go online
self.r.optionmenu.set_history(0) self.r.optionmenu.set_history(0)
self.r.queueOUT.put(('STATUS',('online', '', accounts[0]))) self.r.queueOUT.put(('STATUS',('online', '', \
self.accounts.keys()[0])))
if state == common.sleepy.STATE_AWAY and self.autoaway: if state == common.sleepy.STATE_AWAY and self.autoaway:
#we go away #we go away
self.r.optionmenu.set_history(1) self.r.optionmenu.set_history(1)
self.r.queueOUT.put(('STATUS',('away', 'auto away (idle)', accounts[0]))) self.r.queueOUT.put(('STATUS',('away', \
'auto away (idle)', self.accounts.keys()[0])))
if state == common.sleepy.STATE_XAWAY and self.autoxa: if state == common.sleepy.STATE_XAWAY and self.autoxa:
#we go extanded away #we go extanded away
self.r.optionmenu.set_history(2) self.r.optionmenu.set_history(2)
self.r.queueOUT.put(('STATUS',('xa', 'auto away (idel)', accounts[0]))) self.r.queueOUT.put(('STATUS',('xa', \
'auto away (idel)', self.accounts.keys[0])))
self.sleeper_state = state self.sleeper_state = state
return 1 return 1
@ -1451,23 +1436,28 @@ class plugin:
gtk.threads_init() gtk.threads_init()
gtk.threads_enter() gtk.threads_enter()
self.queueIN = quIN self.queueIN = quIN
quOUT.put(('ASK_CONFIG', 'GtkGui'))
self.config = self.wait('CONFIG')
quOUT.put(('ASK_CONFIG', 'accounts'))
self.accounts = self.wait('CONFIG')
#TODO: if no config : default config and save it
self.r = roster(quOUT, self) self.r = roster(quOUT, self)
st = self.r.cfgParser.GtkGui_autoaway if self.config.has_key('autoaway'):
if not st: self.autoaway = self.config['autoaway']
st = '1' else:
self.autoaway = string.atoi(st) self.autoaway = 1
st = self.r.cfgParser.GtkGui_autoawaytime if self.config.has_key('autoawaytime'):
if not st: self.autoawaytime = self.config['autoawaytime']
st = '10' else:
self.autoawaytime = string.atoi(st) self.autoawaytime = 10
st = self.r.cfgParser.GtkGui_autoxa if self.config.has_key('autoxa'):
if not st: self.autoxa = self.config['autoxa']
st = '1' else:
self.autoxa = string.atoi(st) self.autoxa = 1
st = self.r.cfgParser.GtkGui_autoxatime if self.config.has_key('autoxatime'):
if not st: self.autoxatime = self.config['autoxatime']
st = '20' else:
self.autoxatime = string.atoi(st) self.autoxatime = 20
self.time = gtk.timeout_add(200, self.read_queue) self.time = gtk.timeout_add(200, self.read_queue)
gtk.timeout_add(1000, self.read_sleepy) gtk.timeout_add(1000, self.read_sleepy)
self.sleeper = None self.sleeper = None

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##
@ -29,17 +28,13 @@ class plugin:
def read_queue(self): def read_queue(self):
while 1: while 1:
while self.queueIN.empty() == 0: while self.queueIN.empty() == 0:
lognotsep = self.cfgParser.Logger_lognotsep if self.config.has_key('lognotsep'):
if lognotsep: lognotsep = self.config['lognotsep']
lognotsep = string.atoi(lognotsep)
else: else:
#default
lognotsep = 1 lognotsep = 1
lognotusr = self.cfgParser.Logger_lognotusr if self.config.has_key('lognotusr'):
if lognotusr: lognotusr = self.config['lognotusr']
lognotusr = string.atoi(lognotusr)
else: else:
#default
lognotusr = 1 lognotusr = 1
# tim = time.strftime("%d%m%y%H%M%S") # tim = time.strftime("%d%m%y%H%M%S")
tim = "%d" % time.time() tim = "%d" % time.time()
@ -74,12 +69,22 @@ class plugin:
fic.close() fic.close()
time.sleep(0.5) time.sleep(0.5)
def wait(self, what):
"""Wait for a message from Core"""
#TODO: timeout, save messages that don't fit
while 1:
if not self.queueIN.empty():
ev = self.queueIN.get()
if ev[0] == what:
return ev[1]
time.sleep(0.1)
def __init__(self, quIN, quOUT): def __init__(self, quIN, quOUT):
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
self.cfgParser.parseCfgFile()
self.queueIN = quIN self.queueIN = quIN
self.queueOUT = quOUT self.queueOUT = quOUT
#create ~/.gajim/logs if it doesn't exist quOUT.put(('ASK_CONFIG', 'Logger'))
self.config = self.wait('CONFIG')
#create ~/.gajim/logs/ if it doesn't exist
try: try:
os.stat(os.path.expanduser("~/.gajim")) os.stat(os.path.expanduser("~/.gajim"))
except OSError: except OSError:

View File

@ -4,7 +4,6 @@
## Gajim Team: ## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org> ## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org> ## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
## ##
## Copyright (C) 2003 Gajim Team ## Copyright (C) 2003 Gajim Team
## ##