[gyrus/gyrus-python] Signed-off-by: Alejandro Valdes jimenez <avaldes amvj in utalca cl>



commit cca3b6cf4c60631cf7b028b75f643a8ba1ac39e9
Author: Francisco Rojas <frojas alumnos utalca cl>
Date:   Wed Jul 8 10:06:47 2009 -0400

    Signed-off-by: Alejandro Valdes jimenez <avaldes amvj in utalca cl>
    
    new file:   GyrusAdmin.py

 src/GyrusAdmin.py |  247 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 247 insertions(+), 0 deletions(-)
---
diff --git a/src/GyrusAdmin.py b/src/GyrusAdmin.py
new file mode 100644
index 0000000..4304b3d
--- /dev/null
+++ b/src/GyrusAdmin.py
@@ -0,0 +1,247 @@
+#!/usr/bin/env python
+#
+#       GyrusAdmin.py Cyrus Administrator. Administrator Object. 
+#
+#       GYRUS -- GNOME Cyrus Administrator. 
+#       
+#       Copyright 2009 Francisco Rojas <frojas alumnos utalca cl>
+#       
+#       This program is free software; you can redistribute it and/or modify
+#       it under the terms of the GNU General Public License as published by
+#       the Free Software Foundation; either version 2 of the License, or
+#       (at your option) any later version.
+#       
+#       This program is distributed in the hope that it will be useful,
+#       but WITHOUT ANY WARRANTY; without even the implied warranty of
+#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#       GNU General Public License for more details.
+#       
+#       You should have received a copy of the GNU General Public License
+#       along with this program; if not, write to the Free Software
+#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+#       MA 02110-1301, USA.
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+import gtk.glade
+import gnome
+import gobject
+import os
+import re
+import sys
+from imaplib import *
+from gettext import gettext as _
+
+import config
+
+import gyrus_util
+
+from GyrusMailboxesTreeView import GyrusMailboxesTreeView
+from GyrusAclTreeView import GyrusAclTreeView
+
+class GyrusAdmin(gtk.VBox):
+    __gsignals__ = {
+        'connected' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                            ()),
+        'disconnected' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                            ())
+        }
+    
+    def __init__(self, session):
+        gobject.GObject.__init__(self)
+        #gtk.VBox._init__()
+        self._get_widgets()
+        
+        self._connect_signals()
+        
+        self.label_host.set_label(session.host)
+        self.label_port.set_label(str(session.port))
+        self.label_user.set_label(session.user)
+
+        self.session_name = session.name
+        self.session_host = session.host
+        self.session_port = session.port
+        self.session_user = session.user
+        self.session_tls = session.tls
+        
+        self.cnx = None
+        if self.session_tls:
+            self.image_secure.set_from_stock (gtk.STOCK_DIALOG_AUTHENTICATION,gtk.ICON_SIZE_BUTTON)
+            self.image_secure.show()
+        else:
+            self.image_secure.hide()
+        
+        
+        
+    
+    def _connect_signals(self):
+        self.button_connect.connect ("clicked", self._on_button_connect_clicked)
+        self.button_quota_apply.connect ("clicked", self._on_button_quota_apply_clicked)
+
+        #connect mailbox selection change  
+        self.treeview_users.connect('mailbox-selection-change', self._on_users_selection_changed)
+        self.treeview_users.connect('mailbox-selection-change', self.treeview_acl.on_users_selection_changed)    
+    
+    def _get_widgets(self):
+        glade_file = gtk.glade.XML (os.path.join (config.GLADEDIR, 'page.glade'),'table_page',None)
+
+        self.label_host = glade_file.get_widget('label_host')
+        self.label_port = glade_file.get_widget('label_port')
+        self.label_user = glade_file.get_widget('label_user')
+        self.label_cnx = glade_file.get_widget('label_cnx')
+        self.image_cnx = glade_file.get_widget('image_cnx')
+        self.image_secure = glade_file.get_widget('image_secure')
+        self.button_connect = glade_file.get_widget('button_connect')
+        self.entry_quota_new = glade_file.get_widget('entry_quota_new')
+        self.button_quota_apply = glade_file.get_widget('button_quota_apply')
+        
+        self.entry_quota_new.set_properties(editable=False)
+        
+        self.treeview_users = GyrusMailboxesTreeView()
+        scrolledwindow1 = glade_file.get_widget('scrolledwindow1')
+        scrolledwindow1.add(self.treeview_users)
+        self.treeview_users.show()
+        self.treeview_acl = GyrusAclTreeView()
+        scrolled_acl = glade_file.get_widget('scrolled_acl')
+        scrolled_acl.add(self.treeview_acl)  
+        self.treeview_acl.show()
+        
+        self.entry_mailbox = glade_file.get_widget('entry_mailbox')
+        self.entry_assigned = glade_file.get_widget('entry_assigned')
+        self.entry_free = glade_file.get_widget('entry_free')
+        
+        table = glade_file.get_widget('table_page');
+        self.pack_start(table)
+    
+    def do_connected(self):
+        self.label_cnx.set_text(_('Disconnect'))
+        self.image_cnx.set_from_stock (gtk.STOCK_CONNECT,gtk.ICON_SIZE_BUTTON)
+        
+    def do_disconnected(self):
+        self.label_cnx.set_text(_('Connect'))
+        self.image_cnx.set_from_stock (gtk.STOCK_DISCONNECT,gtk.ICON_SIZE_BUTTON)
+        self.clear_all()
+    
+    def _on_button_connect_clicked(self, button, data=None):
+
+        if self.cnx == None:
+            connected = False
+            if (self.session_tls):
+                # TLS
+                try:
+                    cnx = IMAP4_SSL(self.session_host,int(self.session_port))
+                    connected = True
+                except:
+                    msgerr = _('Could not connect to secure server')
+                    connected = False
+            else:
+                # Not TLS
+                try:
+                    cnx = IMAP4(self.session_host,int(self.session_port))
+                    connected = True
+                except:
+                    msgerr = _('Could not connect to server')
+                    connected = False
+        
+            if (connected):
+                self.cnx = cnx
+
+                # authenticate user
+                auth = self.autenthicate_user()
+
+                if (auth == True):
+                    self.treeview_users.do_set_property('connection',cnx)
+                    self.treeview_acl.do_set_property('connection',cnx)
+                    self.treeview_users.get_list_of_mailbox()
+                    
+                    self.emit('connected')
+
+                elif (auth == False):
+                    gyrus_util.show_message (_('Could not logging'),gtk.MESSAGE_ERROR)
+                    self.cnx = None
+                else:
+                    self.cnx = None
+            else:
+                gyrus_util.show_message (msgerr,gtk.MESSAGE_ERROR)
+        else:
+            self.emit('disconnected')
+            
+    def autenthicate_user(self):
+        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:
+                self.cnx.login(self.session_user, pwd)
+                auth = True
+            except:
+                auth = False
+        else:
+            auth = None
+
+        dialog_password.destroy()
+        return auth
+
+    def clear_all(self):
+        self.cnx = None
+        self.treeview_acl.get_model().clear()
+        self.treeview_users.clear()
+        self.show_quota('', '', '')
+        
+
+    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, mailbox, quota, free):
+        """set the quota of the mailbox in the labels"""
+        self.entry_mailbox.set_text(mailbox)
+        self.entry_assigned.set_text(str(quota))
+        self.entry_free.set_text(str(free))
+
+    def _on_users_selection_changed(self, obj, mailbox, data=None):
+        res, msg, free, quota = obj.get_quota_of_mailbox(mailbox)
+        if res == True:
+            self.show_quota(mailbox, quota, free)
+        else:
+            self.show_quota(admin, mailbox, 0, 0)
+            gyrus_util.show_message(msg, gtk.MESSAGE_ERROR)
+        self.entry_quota_new.set_properties(editable=True)
+
+    def _on_button_quota_apply_clicked(self, button, data=None):
+        mailbox = self.treeview_users.do_get_property('mailbox-selected')
+
+        newquota = (self.entry_quota_new.get_text()).strip()
+
+        if (newquota):
+            # filter only numbers
+            if (gyrus_util.is_only_numbers(newquota)):
+                response, msgset = self.treeview_users.set_quota_of_mailbox(mailbox, newquota)
+
+                if (response == True):
+                    self.entry_quota_new.set_text('')
+
+                    res, msg, free, quota = self.treeview_users.get_quota_of_mailbox(mailbox)
+                    if res == True:
+                        self.show_quota(mailbox, quota, free)
+                    else:
+                        self.show_quota(mailbox, 0, 0)
+                        gyrus_util.show_message(msg,gtk.MESSAGE_ERROR)
+                    self.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)
+
+gobject.type_register(GyrusAdmin)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]