[gyrus/gyrus-python] Signed-off-by: Alejandro Valdes jimenez <avaldes amvj in utalca cl>
- From: Alejandro Valdes Jimenez <avaldes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gyrus/gyrus-python] Signed-off-by: Alejandro Valdes jimenez <avaldes amvj in utalca cl>
- Date: Wed, 8 Jul 2009 14:23:20 +0000 (UTC)
commit 995b850988388125e671be09569c0ee335a6ef00
Author: Francisco Rojas <frojas alumnos utalca cl>
Date: Wed Jul 8 10:13:19 2009 -0400
Signed-off-by: Alejandro Valdes jimenez <avaldes amvj in utalca cl>
modified: ChangeLog
modified: src/GyrusMailboxesTreeView.py
modified: src/gyrus.py
modified: src/gyrus_util.py
ChangeLog | 7 +
src/GyrusMailboxesTreeView.py | 80 +----------
src/gyrus.py | 329 ++++++++---------------------------------
src/gyrus_util.py | 13 ++-
4 files changed, 85 insertions(+), 344 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e53008a..1e81e6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
+2009-07-07 Francisco Rojas <frojas alumnos utalca cl>
+
+ * src/GyrusAdmin.py: add script
+
+
2009-06-12 Alejandro Valdes jimenez <avaldes gnome org>
* src/GyrusReport.py: add script.
+ * src/gyrus.py: separates GyrusAdmin from Gyrus
+ * src/gyrus_util.py: add is_only_numbers util function.
2009-06-12 Alejandro Valdes jimenez <avaldes gnome org>
diff --git a/src/GyrusMailboxesTreeView.py b/src/GyrusMailboxesTreeView.py
index 2f6301d..86b54ae 100644
--- a/src/GyrusMailboxesTreeView.py
+++ b/src/GyrusMailboxesTreeView.py
@@ -102,15 +102,13 @@ class GyrusMailboxesTreeView (gtk.TreeView):
model,iter = selection.get_selected()
if (iter):
- mailbox = model.get(iter,GyrusMailboxesStore.COLUMN_MAILBOX)[0]
+ mailbox = model.get_name_mailbox(iter)
self.mailbox_selected = mailbox
self.emit('mailbox-selection-change', mailbox)
def remove_mailbox (self):
''' Remove the selected mailbox'''
- print NAMESPACE + self.mailbox_selected
response = self.connection.delete(NAMESPACE + self.mailbox_selected)
- print response
if response[0] == 'OK':
return True,None
else:
@@ -208,77 +206,9 @@ class GyrusMailboxesTreeView (gtk.TreeView):
return False,response[1][0],free,quota
- def on_button_find_find_clicked(self, mailbox):
+ def clear(self):
+ self.get_model().clear()
+ col = self.get_column(0)
+ col.set_title(_("Mailboxs"))
- admin = self.get_current_gyrus_admin()
- key = self.comboboxentry_mailbox.get_active_text().strip()
-
- more_mailboxes = None
- wrap_around = None
- search_from_beginning = None
-
- if self.checkbutton_entire_word.get_active():
- mode = "MODE_ENTIRE_WORD"
- else:
- mode = "MODE_ANY"
-
- wrap_around = self.checkbutton_wrap_around.get_active()
-
- selection = admin.treeview_users.get_selection()
- model,iter = selection.get_selected()
-
- # If no item is selected, start the search from the begin
- if not iter:
- iter = model.get_iter_first()
- search_from_beginning = True
- else:
- iter = model.iter_next(iter)
-
- # end of items
- if not iter:
- iter = model.get_iter_first()
-
- search_from_beginning = False
-
- while True:
- value = model.get(iter,1)
-
- if mode == "MODE_ANY":
- res = value[0].find(key)
- if res >= 0:
- found = True
- else:
- found = False
- else:
- if value[0] == key:
- found = True
- else:
- found = False
-
- if found:
- selection = admin.treeview_users.get_selection()
- selection.select_iter(iter)
- path = model.get_path(iter)
- admin.treeview_users.set_cursor(path,None,False)
-
-
- # if 'wrap around' mode is selected allows starting over again
- iter = model.iter_next(iter)
- if iter:
- more_mailboxes = True
- else:
- more_mailboxes = False
-
- if not more_mailboxes and wrap_around and not search_from_beginning:
- iter = model.get_iter_first()
- more_mailboxes = True
- search_from_beginning = True
-
- if not found and more_mailboxes:
- pass
- else:
- break
-
- if not found:
- self.show_message (_("The text was not found in the mailbox list."),gtk.MESSAGE_INFO)
diff --git a/src/gyrus.py b/src/gyrus.py
index 29822ba..d8084f4 100644
--- a/src/gyrus.py
+++ b/src/gyrus.py
@@ -16,13 +16,11 @@ import config
from gyrus_constant import *
import gyrus_session
-import gyrus_print
import gyrus_util
-from GyrusMailboxesTreeView import GyrusMailboxesTreeView
-from GyrusAclTreeView import GyrusAclTreeView
from GyrusDialogFindMailbox import GyrusDialogFindMailbox
from GyrusReport import GyrusReport
+from GyrusAdmin import GyrusAdmin
@@ -95,30 +93,6 @@ perm = [None,
_("delete"),
_("admin")]
-class GyrusAdmin:
- def __init__ (self):
- table_page = None
- label_host = None
- label_port = None
- label_user = None
- entry_assigned = None
- entry_free = None
- entry_mailbox = None
- button_connect = None
- entry_quota_new = None
- button_quota_apply = None
- treeview_users = None
- treeview_acl = None
- image_cnx = None
- label_cnx = None
- cnx = None
- newname = None # temporal for validate name of new entry on acl
- newnameok = None # temporal for validate name of new entry on acl
- session_name = None
- session_host = None
- session_port = None
- session_user = None
- session_tls = None
class Gyrus:
def __init__ (self):
@@ -228,6 +202,16 @@ class Gyrus:
window.show_all()
return
+ def _on_connected(self, data=None):
+ self.actiongroup_window.set_sensitive(True)
+ self.actiongroup_server.set_sensitive(True)
+
+ def _on_disconnected(self, data=None):
+ self.actiongroup_window.set_sensitive (True)
+ self.actiongroup_server.set_sensitive (False)
+ self.actiongroup_mailbox.set_sensitive (False)
+ self.actiongroup_acl.set_sensitive (False)
+
def main(self):
"Begin cicle main"
gtk.main()
@@ -260,25 +244,20 @@ class Gyrus:
about.hide ()
return True
- def append_page_to_notebook(self,session):
+ def append_page_to_notebook(self, session):
# load a new instance of table_page
- admin = self.load_table_page()
-
- admin.entry_quota_new.set_properties(editable=False)
-
- admin.label_cnx.set_text(_("Connect"))
- admin.image_cnx.set_from_stock (gtk.STOCK_DISCONNECT,gtk.ICON_SIZE_BUTTON)
+ admin = GyrusAdmin(session)
# create a new page on notebook
hbox_image = gtk.HBox(False,0)
image = gtk.Image()
- image.set_from_stock('gtk-close','GTK_ICON_SIZE_MENU')
- hbox_image.pack_start(image,True,False,False)
+ image.set_from_stock('gtk-close', 'GTK_ICON_SIZE_MENU')
+ hbox_image.pack_start(image, True, False, False)
button = gtk.Button()
button.set_relief('GTK_RELIEF_NONE')
button.add(hbox_image)
- button.connect('clicked',self.on_button_page_clicked,admin)
+ button.connect('clicked', self.on_button_page_clicked, admin)
hbox_b = gtk.HBox(False,0)
label = gtk.Label(session.name)
@@ -290,43 +269,26 @@ class Gyrus:
button.show()
label.show()
- admin.label_host.set_label(session.host)
- admin.label_port.set_label(str(session.port))
- admin.label_user.set_label(session.user)
-
- admin.session_name = session.name
- admin.session_host = session.host
- admin.session_port = session.port
- admin.session_user = session.user
- admin.session_tls = session.tls
- admin.cnx = None
-
- admin.button_connect.connect ("clicked", self.on_button_connect_clicked,admin)
- admin.button_quota_apply.connect ("clicked", self.on_button_quota_apply_clicked,admin)
-
- #connect mailbox selection change
- admin.treeview_users.connect('mailbox-selection-change', self.on_users_selection_changed)
- admin.treeview_users.connect('mailbox-selection-change', admin.treeview_acl.on_users_selection_changed)
+ #notify to the actiongroup_windows that the conection is active
+ admin.connect('connected', self._on_connected)
+
+ #notify to the actiongroup_windows that is disconnected
+ admin.connect('disconnected', self._on_disconnected)
- #connect acl selection change
+ #notify to the actiongroup_acl that there is a acl selection.
admin.treeview_acl.connect('acl-selected', self.on_acl_selected)
- admin.treeview_users.show()
- admin.treeview_acl.show()
- admin.table_page.show()
-
- if admin.session_tls:
- admin.image_secure.set_from_stock (gtk.STOCK_DIALOG_AUTHENTICATION,gtk.ICON_SIZE_BUTTON)
- admin.image_secure.show()
- else:
- admin.image_secure.hide()
+ #notify to the actiongroup_users that there is a user selection.
+ selection = admin.treeview_users.get_selection()
+ selection.connect("changed", self.on_users_selection_changed)
+
+ admin.show()
# add new table at main array
- table = admin.table_page
- self.imap_server[table] = admin
+ self.imap_server[admin] = admin
#add new page to notebook
- page = self.notebook.append_page(admin.table_page,hbox_b)
+ page = self.notebook.append_page(admin,hbox_b)
self.notebook.set_current_page(page)
@@ -342,7 +304,6 @@ class Gyrus:
admin = self.get_current_gyrus_admin()
report = GyrusReport(admin)
-
def on_find_action (self,action):
admin = self.get_current_gyrus_admin()
GyrusDialogFindMailbox(admin)
@@ -380,17 +341,7 @@ class Gyrus:
admin = self.get_current_gyrus_admin()
admin.treeview_acl.rename_acl()
- def on_users_selection_changed(self, obj, mailbox, data=None):
- admin = self.get_current_gyrus_admin()
- res, msg, free, quota = obj.get_quota_of_mailbox(mailbox)
- if res == True:
- self.show_quota(admin, mailbox, quota, free)
- else:
- self.show_quota(admin, mailbox, 0, 0)
- gyrus_util.show_message(msg, gtk.MESSAGE_ERROR)
- self.actiongroup_mailbox.set_sensitive(True)
- admin.entry_quota_new.set_properties(editable=True)
-
+
def on_removemailbox_action(self,action):
admin = self.get_current_gyrus_admin()
@@ -412,7 +363,7 @@ class Gyrus:
def on_button_page_clicked (self,button,admin):
- page = self.notebook.page_num(admin.table_page)
+ page = self.notebook.page_num(admin)
self.notebook.remove_page(page)
page = self.notebook.get_current_page()
@@ -433,203 +384,49 @@ class Gyrus:
self.verify_sensitive_actiongroup (admin)
- def verify_sensitive_actiongroup (self,admin):
- #self.actiongroup_window.set_sensitive (True)
- #self.actiongroup_server.set_sensitive (True)
-
- selection = admin.treeview_users.get_selection()
- model,iter = selection.get_selected()
-
- if iter:
- self.actiongroup_mailbox.set_sensitive (True)
- else:
- self.actiongroup_mailbox.set_sensitive (False)
-
- selection = admin.treeview_acl.get_selection()
- model,iter = selection.get_selected()
- if iter:
- self.actiongroup_acl.set_sensitive (True)
- else:
- self.actiongroup_acl.set_sensitive (False)
-
-
-
- def load_table_page (self):
- glade_file = gtk.glade.XML (os.path.join (config.GLADEDIR, "page.glade"),"table_page",None)
-
- admin = GyrusAdmin()
-
- admin.table_page = glade_file.get_widget ("table_page")
- admin.label_host = glade_file.get_widget ("label_host")
- admin.label_port = glade_file.get_widget ("label_port")
- admin.label_user = glade_file.get_widget ("label_user")
- admin.label_cnx = glade_file.get_widget ("label_cnx")
- admin.image_cnx = glade_file.get_widget ("image_cnx")
- admin.image_secure = glade_file.get_widget ("image_secure")
- admin.button_connect = glade_file.get_widget ("button_connect")
- admin.entry_quota_new = glade_file.get_widget ("entry_quota_new")
- admin.button_quota_apply = glade_file.get_widget ("button_quota_apply")
-
- admin.treeview_users = GyrusMailboxesTreeView()
- scrolledwindow1 = glade_file.get_widget('scrolledwindow1')
- scrolledwindow1.add(admin.treeview_users)
-
- admin.treeview_acl = GyrusAclTreeView()
- scrolled_acl = glade_file.get_widget('scrolled_acl')
- scrolled_acl.add(admin.treeview_acl)
-
- admin.entry_mailbox = glade_file.get_widget ("entry_mailbox")
- admin.entry_assigned = glade_file.get_widget ("entry_assigned")
- admin.entry_free = glade_file.get_widget ("entry_free")
-
- return admin
-
+ def verify_sensitive_actiongroup (self, admin):
+ self.actiongroup_window.set_sensitive (True)
+ if admin.cnx is not None:
+ self.actiongroup_server.set_sensitive (True)
- def on_button_connect_clicked (self,button,admin):
+ selection = admin.treeview_users.get_selection()
+ model,iter = selection.get_selected()
- if admin.cnx == None:
- connected = False
- if (admin.session_tls):
- # TLS
- try:
- cnx = IMAP4_SSL(admin.session_host,int(admin.session_port))
- connected = True
- except:
- msgerr = _("Could not connect to secure server")
- connected = False
+ if iter:
+ self.actiongroup_mailbox.set_sensitive (True)
else:
- # Not TLS
- try:
- cnx = IMAP4(admin.session_host,int(admin.session_port))
- connected = True
- except:
- msgerr = _("Could not connect to server")
- connected = False
-
- if (connected):
- admin.cnx = cnx
-
- # authenticate user
- auth = self.autenthicate_user (admin)
-
- if (auth == True):
- admin.treeview_users.do_set_property('connection',cnx)
- admin.treeview_acl.do_set_property('connection',cnx)
- admin.treeview_users.get_list_of_mailbox()
-
- self.actiongroup_window.set_sensitive (True)
- self.actiongroup_server.set_sensitive (True)
+ self.actiongroup_mailbox.set_sensitive (False)
- admin.label_cnx.set_text(_("Disconnect"))
- admin.image_cnx.set_from_stock (gtk.STOCK_CONNECT,gtk.ICON_SIZE_BUTTON)
-
- elif (auth == False):
- gyrus_util.show_message (_("Could not logging"),gtk.MESSAGE_ERROR)
- admin.cnx = None
- else:
- admin.cnx = None
+ selection = admin.treeview_acl.get_selection()
+ model,iter = selection.get_selected()
+ if iter:
+ self.actiongroup_acl.set_sensitive (True)
else:
- gyrus_util.show_message (msgerr,gtk.MESSAGE_ERROR)
+ self.actiongroup_acl.set_sensitive (False)
else:
- admin.label_cnx.set_text(_("Connect"))
- admin.image_cnx.set_from_stock (gtk.STOCK_DISCONNECT,gtk.ICON_SIZE_BUTTON)
- self.actiongroup_window.set_sensitive (True)
- self.actiongroup_server.set_sensitive (False)
- self.actiongroup_mailbox.set_sensitive (False)
- self.actiongroup_acl.set_sensitive (False)
- self.clear_all_widget_of_admin(admin)
-
+ self.actiongroup_server.set_sensitive(False)
+ self.actiongroup_mailbox.set_sensitive(False)
+ self.actiongroup_acl.set_sensitive(False)
+
- def clear_all_widget_of_admin (self,admin):
- admin.cnx = None
- admin.treeview_acl.get_model().clear()
- admin.treeview_users.get_model().clear()
- col = admin.treeview_users.get_column(0)
- col.set_title(_("Mailboxs"))
-
-
- def is_only_numbers (self,value):
- if (re.match("[0-9]+$",value)):
- return True
- else:
- return False
-
- def on_acl_selected(self, obj, selected, data=None):
- if(selected):
+ def on_acl_selected(self, obj, selected):
+ if (selected):
self.actiongroup_acl.set_sensitive(True)
else:
self.actiongroup_acl.set_sensitive(False)
+
+ def on_users_selection_changed(self, selection):
+ model,iter = selection.get_selected()
- def on_button_quota_apply_clicked(self, button, admin):
- mailbox = admin.treeview_users.do_get_property('mailbox-selected')
-
- newquota = (admin.entry_quota_new.get_text()).strip()
-
- if (newquota):
- # filter only numbers
- if (self.is_only_numbers(newquota)):
- response, msgset = admin.treeview_users.set_quota_of_mailbox(mailbox, newquota)
-
- if (response == True):
- admin.entry_quota_new.set_text('')
-
- res, msg, free, quota = admin.treeview_users.get_quota_of_mailbox(mailbox)
- if res == True:
- self.show_quota(admin, mailbox, quota, free)
- else:
- self.show_quota(admin,mb,0,0)
- gyrus_util.show_message(msg,gtk.MESSAGE_ERROR)
-
- self.actiongroup_mailbox.set_sensitive(True)
- admin.entry_quota_new.set_properties(editable=True)
- else:
- gyrus_util.show_message(msgset, gtk.MESSAGE_ERROR)
-
- else:
- gyrus_util.show_message(_("This not a valid quota"), gtk.MESSAGE_ERROR)
- else:
- gyrus_util.show_message(_("This not a valid quota"), gtk.MESSAGE_ERROR)
-
- def autenthicate_user (self,admin):
- auth = False
-
- dialog_password,entry_password = self.load_dialog_password()
-
- result = dialog_password.run()
- if result == gtk.RESPONSE_OK:
- pwd = entry_password.get_text()
-
- try:
- admin.cnx.login (admin.session_user,pwd)
- auth = True
- except:
- auth = False
+ if (iter):
+ self.actiongroup_mailbox.set_sensitive(True)
else:
- auth = None
-
- dialog_password.destroy()
- return auth
-
-
- def load_dialog_password (self):
- glade_file = gtk.glade.XML (os.path.join (config.GLADEDIR, "page.glade"),"dialog_password",None)
-
- dialog_password = glade_file.get_widget ("dialog_password")
- entry_password = glade_file.get_widget ("entry_password")
-
- return dialog_password,entry_password
-
-
- def show_quota (self,admin,mb,quota,free):
- admin.entry_mailbox.set_text(mb)
- admin.entry_assigned.set_text(str(quota))
- admin.entry_free.set_text(str(free))
-
-
+ self.actiongroup_mailbox.set_sensitive(False)
+
+
def on_addmailbox_action(self, action):
admin = self.get_current_gyrus_admin()
self.load_dialog_edit_mailbox(admin)
-
def load_dialog_edit_mailbox(self, admin):
@@ -645,14 +442,13 @@ class Gyrus:
mailbox = entry_mailbox.get_text().strip()
quota = entry_quota.get_text()
- if (self.is_only_numbers(quota)):
+ if (gyrus_util.is_only_numbers(quota)):
# create mailbox
result, msg = admin.treeview_users.create_mailbox(mailbox)
if result == True:
# set quota to maillbox
- response, msgset = admin.treeview_users.set_quota_of_mailbox(mailbox,
- quota)
+ response, msgset = admin.treeview_users.set_quota_of_mailbox(mailbox, quota)
if response == False:
gyrus_util.show_message(setmsg, gtk.MESSAGE_ERROR)
@@ -664,8 +460,7 @@ class Gyrus:
gyrus_util.show_message (_("This not a valid quota"),gtk.MESSAGE_ERROR)
dialog.destroy()
-
-
+
if __name__ == "__main__":
gnome.init(config.PACKAGE,config.VERSION)
diff --git a/src/gyrus_util.py b/src/gyrus_util.py
index 3af2090..5957fb4 100644
--- a/src/gyrus_util.py
+++ b/src/gyrus_util.py
@@ -1,8 +1,17 @@
#!/usr/bin/env python
-import gtk, os
+import gtk
+import os
+import re
-def show_message (msg,type):
+def show_message (msg, type):
dialog = gtk.MessageDialog(None,gtk.DIALOG_MODAL, type,gtk.BUTTONS_OK, msg)
dialog.run()
dialog.destroy()
+
+def is_only_numbers (value):
+ """ if the value contains only numbers return True, otherwise False"""
+ if (re.match("[0-9]+$",value)):
+ return True
+ else:
+ return False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]