accounts' window

This commit is contained in:
Yann Leboulanger 2003-12-11 22:26:29 +00:00
parent 67a110118d
commit 42ae1c5d73
3 changed files with 228 additions and 31 deletions

View File

@ -24,8 +24,9 @@ import os
log = logging.getLogger('common.options')
class OptionsParser:
class OptionsParser(ConfigParser.ConfigParser):
def __init__(self, fname):
ConfigParser.ConfigParser.__init__(self)
self.__fname = os.path.expanduser(fname)
# END __init__
@ -36,13 +37,12 @@ class OptionsParser:
print 'error cannot open file %s\n' % (self.__fname);
return
self.__config = ConfigParser.ConfigParser()
self.__config.readfp(self.__fd)
self.__sections = self.__config.sections()
self.readfp(self.__fd)
self.__sections = self.sections()
for section in self.__sections:
for option in self.__config.options(section):
value = self.__config.get(section, option, 1)
for option in self.options(section):
value = self.get(section, option, 1)
setattr(self, str(section) + '_' + \
str(option), value)
# END parseCfgFile
@ -63,7 +63,7 @@ class OptionsParser:
def writeCfgFile(self):
try:
self.__config.write(open(self.__fname, 'w'))
self.write(open(self.__fname, 'w'))
except:
log.debug("Can't write config %s" % self.__fname)
return 0

View File

@ -619,6 +619,7 @@
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Wed, 10 Dec 2003 22:31:27 GMT"/>
<child>
<widget class="GtkVBox" id="vbox5">
@ -637,14 +638,14 @@
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="account_treeview">
<widget class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<signal name="button_press_event" handler="on_account_treeview_button_press_event" last_modification_time="Wed, 22 Oct 2003 20:23:24 GMT"/>
<signal name="cursor_changed" handler="on_row_activated" last_modification_time="Wed, 10 Dec 2003 23:14:58 GMT"/>
</widget>
</child>
</widget>
@ -681,13 +682,13 @@
<property name="spacing">20</property>
<child>
<widget class="GtkButton" id="account_new_button">
<widget class="GtkButton" id="new_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-new</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_account_new_clicked" last_modification_time="Wed, 22 Oct 2003 20:21:31 GMT"/>
<signal name="clicked" handler="on_new_clicked" last_modification_time="Thu, 11 Dec 2003 17:06:22 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
@ -697,13 +698,14 @@
</child>
<child>
<widget class="GtkButton" id="account_delete_button">
<widget class="GtkButton" id="delete_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="label">gtk-delete</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_delete_clicked" last_modification_time="Thu, 11 Dec 2003 17:06:43 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
@ -713,11 +715,12 @@
</child>
<child>
<widget class="GtkButton" id="account_modify_button">
<widget class="GtkButton" id="modify_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_modify_clicked" last_modification_time="Thu, 11 Dec 2003 17:07:02 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment1">
@ -914,6 +917,7 @@ David Ferlier (david@yazzy.org)</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Thu, 11 Dec 2003 17:04:49 GMT"/>
<child>
<widget class="GtkVBox" id="vbox7">
@ -921,6 +925,60 @@ David Ferlier (david@yazzy.org)</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox23">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">7</property>
<child>
<widget class="GtkLabel" id="label_name">
<property name="visible">True</property>
<property name="label" translatable="yes">Name : </property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="entry_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char" translatable="yes">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">2</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkNotebook" id="notebook1">
<property name="border_width">5</property>
@ -967,7 +1025,7 @@ David Ferlier (david@yazzy.org)</property>
</child>
<child>
<widget class="GtkEntry" id="jabberid_entry">
<widget class="GtkEntry" id="entry_jid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
@ -1012,7 +1070,7 @@ David Ferlier (david@yazzy.org)</property>
</child>
<child>
<widget class="GtkEntry" id="password_entry">
<widget class="GtkEntry" id="entry_password">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
@ -1057,7 +1115,7 @@ David Ferlier (david@yazzy.org)</property>
</child>
<child>
<widget class="GtkEntry" id="ressource_entry">
<widget class="GtkEntry" id="entry_ressource">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
@ -1292,28 +1350,40 @@ David Ferlier (david@yazzy.org)</property>
</child>
<child>
<widget class="GtkAlignment" id="alignment3">
<property name="border_width">10</property>
<widget class="GtkHButtonBox" id="hbuttonbox6">
<property name="border_width">7</property>
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0.2</property>
<property name="yscale">1</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<property name="spacing">20</property>
<child>
<widget class="GtkButton" id="button7">
<widget class="GtkButton" id="button_save">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-save</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_save_clicked" last_modification_time="Thu, 11 Dec 2003 17:13:15 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_close">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="gtk_widget_destroy" last_modification_time="Thu, 11 Dec 2003 17:13:05 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>

View File

@ -30,6 +30,7 @@ import Queue
import common.optparser
CONFPATH = "~/.gajimrc"
Wbrowser = 0
Waccounts = 0
class user:
def __init__(self, *args):
@ -87,13 +88,133 @@ class about:
self.Wabout = self.xml.get_widget("About")
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
class accounts:
class account_pref:
def delete_event(self, widget):
self.window.destroy()
def __init__(self):
self.xml = gtk.glade.XML('plugins/gtkgui/gtkgui.glade', 'Accounts')
def init_account(self, infos):
if infos.has_key('name'):
self.xml.get_widget("entry_name").set_text(infos['name'])
if infos.has_key('jid'):
self.xml.get_widget("entry_jid").set_text(infos['jid'])
if infos.has_key('password'):
self.xml.get_widget("entry_password").set_text(infos['password'])
if infos.has_key('ressource'):
self.xml.get_widget("entry_ressource").set_text(infos['ressource'])
def on_save_clicked(self, widget):
# accountsStr = self.cfgParser.Profile_accounts
# accounts = string.split(accountsStr, ' ')
name = self.xml.get_widget("entry_name").get_text()
if (name == ''):
return 0
if self.mod:
if name != self.acc:
self.cfgParser.remove_section(self.acc)
self.accs.accounts.remove(self.acc)
self.cfgParser.add_section(name)
self.accs.accounts.append(name)
accountsStr = string.join(self.accs.accounts)
self.cfgParser.set('Profile', 'accounts', accountsStr)
else:
if name in self.accs.accounts:
return 0
else:
self.cfgParser.add_section(name)
self.accs.accounts.append(name)
accountsStr = string.join(self.accs.accounts)
self.cfgParser.set('Profile', 'accounts', accountsStr)
(login, hostname) = string.split(self.xml.get_widget("entry_jid").get_text(), '@')
self.cfgParser.set(name, 'name', login)
self.cfgParser.set(name, 'hostname', hostname)
self.cfgParser.set(name, 'password', self.xml.get_widget("entry_password").get_text())
self.cfgParser.set(name, 'ressource', self.xml.get_widget("entry_ressource").get_text())
self.cfgParser.writeCfgFile()
self.cfgParser.parseCfgFile()
self.accs.init_accounts()
#info must be a dictionnary
def __init__(self, accs, infos = {}):
self.xml = gtk.glade.XML('plugins/gtkgui/gtkgui.glade', 'Account')
self.window = self.xml.get_widget("Account")
self.cfgParser = accs.cfgParser
self.accs = accs
if infos:
self.mod = TRUE
self.acc = infos['name']
self.init_account(infos)
else:
self.mod = FALSE
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_save_clicked', self.on_save_clicked)
class accounts:
def delete_event(self, widget):
global Waccounts
Waccounts = 0
self.window.destroy()
def init_accounts(self):
self.model.clear()
for account in self.accounts:
iter = self.model.append()
self.model.set(iter, 0, account, 1, self.cfgParser.__getattr__("%s" % account+"_hostname"))
def on_row_activated(self, widget):
self.modButt.set_sensitive(TRUE)
self.delButt.set_sensitive(TRUE)
def on_new_clicked(self, widget):
account_pref(self)
def on_delete_clicked(self, widget):
sel = self.treeview.get_selection()
(mod, iter) = sel.get_selected()
account = self.model.get_value(iter, 0)
self.cfgParser.remove_section(account)
self.accounts.remove(account)
accountsStr = string.join(self.accounts)
self.cfgParser.set('Profile', 'accounts', accountsStr)
self.cfgParser.writeCfgFile()
self.cfgParser.parseCfgFile()
self.init_accounts()
def on_modify_clicked(self, widget):
infos = {}
sel = self.treeview.get_selection()
(mod, iter) = sel.get_selected()
account = self.model.get_value(iter, 0)
infos['name'] = account
infos['jid'] = self.cfgParser.__getattr__("%s" % account+"_name") + \
'@' + self.cfgParser.__getattr__("%s" % account+"_hostname")
infos['password'] = self.cfgParser.__getattr__("%s" % account+"_password")
infos['ressource'] = self.cfgParser.__getattr__("%s" % account+"_ressource")
account_pref(self, infos)
def __init__(self, accounts):
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
self.cfgParser.parseCfgFile()
self.xml = gtk.glade.XML('plugins/gtkgui/gtkgui.glade', 'Accounts')
self.window = self.xml.get_widget("Accounts")
self.treeview = self.xml.get_widget("treeview")
self.modButt = self.xml.get_widget("modify_button")
self.delButt = self.xml.get_widget("delete_button")
self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.treeview.set_model(self.model)
#columns
renderer = gtk.CellRendererText()
renderer.set_data('column', 0)
self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0)
renderer = gtk.CellRendererText()
renderer.set_data('column', 1)
self.treeview.insert_column_with_attributes(-1, 'Server', renderer, text=1)
self.accounts = accounts
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_row_activated', self.on_row_activated)
self.xml.signal_connect('on_new_clicked', self.on_new_clicked)
self.xml.signal_connect('on_delete_clicked', self.on_delete_clicked)
self.xml.signal_connect('on_modify_clicked', self.on_modify_clicked)
self.init_accounts()
class confirm:
def delete_event(self, widget):
@ -467,7 +588,9 @@ class roster:
window_confirm = confirm(self, iter)
def on_status_changed(self, widget):
self.queueOUT.put(('STATUS',(widget.name, "Account1")))
accountsStr = self.cfgParser.Profile_accounts
accounts = string.split(accountsStr, ' ')
self.queueOUT.put(('STATUS',(widget.name, accounts[0])))
if (not self.showOffline) and widget.name == 'offline':
self.treestore.clear()
@ -478,7 +601,9 @@ class roster:
window_about = about()
def on_accounts(self, widget):
window_accounts = accounts()
global Waccounts
if not Waccounts:
Waccounts = accounts(self.accounts)
def on_quit(self, widget):
self.queueOUT.put(('QUIT',''))
@ -572,6 +697,8 @@ class roster:
self.optionmenu.set_history(6)
self.tab_messages = {}
self.tab_queues = {}
accountsStr = self.cfgParser.Profile_accounts
self.accounts = string.split(accountsStr, ' ')
showOffline = self.cfgParser.GtkGui_showoffline
if showOffline: