bigboard r7340 - in trunk/bigboard: . libgmail stocks/mail



Author: marinaz
Date: Fri May 16 17:54:34 2008
New Revision: 7340
URL: http://svn.gnome.org/viewvc/bigboard?rev=7340&view=rev

Log:
Sort out when we display login failure messages and the login button.


Modified:
   trunk/bigboard/google.py
   trunk/bigboard/google_stock.py
   trunk/bigboard/libgmail/libgmail.py
   trunk/bigboard/stocks/mail/MailStock.py

Modified: trunk/bigboard/google.py
==============================================================================
--- trunk/bigboard/google.py	(original)
+++ trunk/bigboard/google.py	Fri May 16 17:54:34 2008
@@ -341,7 +341,7 @@
 
 class CheckGoogleTask(libbig.polling.Task):
     def __init__(self, google):
-        libbig.polling.Task.__init__(self, 1000 * 120, initial_interval=0) # initial_interval=1000*5
+        libbig.polling.Task.__init__(self, 1000 * 20, initial_interval=0) # initial_interval=1000*5
         self.__google = google
         self.__actions = {} ## hash from id to [add count, GooglePollAction object]
 
@@ -440,8 +440,7 @@
 
     def get_current_auth_credentials_known_bad(self):
         return self.__account.get_username_as_google_email() == '' or \
-               self.__account.get_password() == '' or \
-             self.__last_auth_attempt_failed
+               self.__last_auth_attempt_failed
 
     def __on_account_changed(self):
         auth_changed = False

Modified: trunk/bigboard/google_stock.py
==============================================================================
--- trunk/bigboard/google_stock.py	(original)
+++ trunk/bigboard/google_stock.py	Fri May 16 17:54:34 2008
@@ -15,7 +15,8 @@
 
 FAILED_TO_LOGIN_STRING = "Failed to login."
 FAILED_TO_CONNECT_STRING = "Cannot connect to Google."
-LOGIN_TO_GOOGLE_STRING = "Edit Google Accounts"
+LOGIN_TO_GOOGLE_STRING = "Login to Google"
+EDIT_GOOGLE_ACCOUNTS_STRING = "Edit Google Accounts"
 CHECKING_LOGIN_STRING = "Checking Login..."
 
 class GoogleStock(object):

Modified: trunk/bigboard/libgmail/libgmail.py
==============================================================================
--- trunk/bigboard/libgmail/libgmail.py	(original)
+++ trunk/bigboard/libgmail/libgmail.py	Fri May 16 17:54:34 2008
@@ -85,7 +85,8 @@
     the embedded Javascript.
     
     """
-    print "pageContent %s" % pageContent 
+    if LG_DEBUG:
+        print "pageContent %s" % pageContent 
     lines = pageContent.splitlines()
     data = '\n'.join([x for x in lines if x and x[0] in ['D', ')', ',', ']']])
     #data = data.replace(',,',',').replace(',,',',')

Modified: trunk/bigboard/stocks/mail/MailStock.py
==============================================================================
--- trunk/bigboard/stocks/mail/MailStock.py	(original)
+++ trunk/bigboard/stocks/mail/MailStock.py	Fri May 16 17:54:34 2008
@@ -71,6 +71,11 @@
                                                   'google_account_box' : hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL), \
                                                   'current_folder' : 'inbox', \
                                                   'logged_in_flag' : False })
+    def __str__(self):
+        if self.get_google_account():
+            return "Google Account Username: " + str(self.get_google_account().name) + " Domain: " + str(self.get_google_account().domain) + " Current folder: " + self.get_current_folder() + " Logged in: " + str(self.get_logged_in_flag())
+        else: 
+            return "Google Account: None Current folder: " + self.get_current_folder() + " Logged in: " + str(self.get_logged_in_flag())
 
 class LabelSlideout(ThemedSlideout):
     __gsignals__ = {
@@ -162,7 +167,11 @@
         
         self.__display_limit = 4
 
-        self._box.append(self._login_button)
+        self.__failed_to_connect_message = hippo.CanvasText(text=google_stock.FAILED_TO_CONNECT_STRING, size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
+
+        self._box.prepend(self._login_button)
+        self._box.prepend(self.__failed_to_connect_message)
+        self._box.set_child_visible(self.__failed_to_connect_message, False) 
         
         self._add_more_button(self.__on_more_button)
         _logger.debug("done with mail stock init")
@@ -186,16 +195,20 @@
         # sometimes we don't even get the self.__google_accounts because the polling task didn't start, so 
         # if all self.googles are removed, we should make sure to have the "Login to Google" button showing 
         if len(self.googles) == 0: 
-            self._box.remove_all()
+            self._box.remove_all() # we should have removed all emails individually, but let's do this just in case
             self._login_button.set_property('text', google_stock.LOGIN_TO_GOOGLE_STRING) 
-            self._box.append(self._login_button)
+            self._box.prepend(self._login_button)
+            self._box.prepend(self.__failed_to_connect_message)
+            self._box.set_child_visible(self.__failed_to_connect_message, False) 
             self.__google_accounts = {}
 
     def __update_email_box (self, gobj):       
         _logger.debug("will update mailbox")
         username = gobj.get_account().get_username()
         password = gobj.get_account().get_password()
-        domain = gobj.get_account().get_url() 
+        domain = gobj.get_account().get_url()
+        if domain and (len(domain) == 0 or domain == "gmail.com"):
+            domain = None  
 
         if not self.__google_accounts.has_key(gobj):
             self.__google_accounts[gobj] = GoogleAccountInfo()
@@ -205,24 +218,30 @@
         google_account_box = self.__google_accounts[gobj].get_google_account_box()
         current_folder = self.__google_accounts[gobj].get_current_folder()
         logged_in_flag = self.__google_accounts[gobj].get_logged_in_flag()      
-           
+
         try:
+            if password == '':
+                raise libgmail.GmailLoginFailure, 'No password for a Google account.'
+
             # creating a new GmailAccount is needed in case self.__last_login_gobj != gobj because
             # otherwise the page content we get says that top.location was the account that we last
             # logged in to, and doesn't contain the information for the GmailAccount we are using;
             # just calling the login() function again doesn't work
             if google_account is None or username != google_account.name or \
-               password != google_account.password or self.__last_login_gobj != gobj:
-                if domain and (len(domain) == 0 or domain == "gmail.com"):
-                    domain = None 
-                _logger.debug("username %s domain %s" % (username, domain))
+               password != google_account.password or domain != google_account.domain or self.__last_login_gobj != gobj:                 
+                _logger.debug("username %s domain %s password %s" % (username, domain, password))
                 google_account = libgmail.GmailAccount(username, password, domain = domain)
                 google_account.login()
             elif not logged_in_flag:
                 google_account.login()                
 
+            labelsDict = google_account.getFolderCounts()
+            # this is how we know there was a login problem with GAFYD accounts   
+            if not labelsDict:    
+                 raise libgmail.GmailLoginFailure, 'Failed to login to Google.'
+
             logged_in_flag = True
-            self.__last_login_gobj = gobj
+            self._box.set_child_visible(self.__failed_to_connect_message, False)
 
             if current_folder == 'inbox':
                 threads = google_account.getMessagesByFolder(current_folder)
@@ -255,34 +274,56 @@
                 email = hippo.CanvasText(markup=subject, xalign=hippo.ALIGNMENT_START)
                 box.append(email)
                 i += 1
-            labelsDict = google_account.getFolderCounts()
+
             footer = hippo.CanvasText(classes='footer', text="%s unread" % labelsDict[current_folder], font="14px Bold Italic")
-            google_account_box.append(footer)
+            google_account_box.append(footer)                
             print "updated mailbox"
             
         except libgmail.GmailLoginFailure:
+            self._box.set_child_visible(self.__failed_to_connect_message, False) 
             google_account_box.remove_all()
             account = hippo.CanvasText(classes='header', text=gobj.get_account().get_username_as_google_email())
             google_account_box.append(account)
             
             logged_in_flag = False
-            if self._login_button.get_property("text") == google_stock.CHECKING_LOGIN_STRING:
-                error = hippo.CanvasText(text=google_stock.FAILED_TO_LOGIN_STRING, size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
-                google_account_box.append(error)
-            self._login_button.set_property('text', google_stock.LOGIN_TO_GOOGLE_STRING) 
-            self._box.append(self._login_button)
+            #if self._login_button.get_property("text") == google_stock.CHECKING_LOGIN_STRING:
+            error = hippo.CanvasText(text=google_stock.FAILED_TO_LOGIN_STRING, size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
+            google_account_box.append(error)
         except urllib2.URLError:
             if not logged_in_flag:
                 google_account_box.remove_all()
                 account = hippo.CanvasText(classes='header', text=gobj.get_account().get_username_as_google_email())
-                google_account_box.append(account)               
-            if len(self._box.get_children()) == 0 or \
-               self._box.get_children()[0].get_property("text") != google_stock.FAILED_TO_CONNECT_STRING:
-                error = hippo.CanvasText(text=google_stock.FAILED_TO_CONNECT_STRING, size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
-                self._box.prepend(error)
+                google_account_box.append(account) 
+ 
+            self._box.set_child_visible(self.__failed_to_connect_message, True) 
 
         self.__google_accounts[gobj].update({'google_account' : google_account, 'google_account_box' : google_account_box, 'current_folder' : current_folder, 'logged_in_flag' : logged_in_flag})                
 
+        # set self.__last_login_gobj out here even if the login was unsuccessful, because that still has a way in
+        # which it can affect things 
+        self.__last_login_gobj = gobj
+
+        all_accounts_logged_in = True 
+        at_least_one_account_logged_in = False             
+        for google_account_info in self.__google_accounts.values():
+            _logger.debug("checking google accounts info %s" % google_account_info)
+            if not at_least_one_account_logged_in and google_account_info.get_logged_in_flag():
+                at_least_one_account_logged_in = True
+            if not google_account_info.get_logged_in_flag():
+                all_accounts_logged_in = False
+                if at_least_one_account_logged_in:
+                    break
+ 
+        if all_accounts_logged_in:           
+            _logger.debug("will remove login button")
+            self._box.set_child_visible(self._login_button, False)
+        elif at_least_one_account_logged_in:
+            self._login_button.set_property('text', google_stock.EDIT_GOOGLE_ACCOUNTS_STRING) 
+            self._box.set_child_visible(self._login_button, True)
+        else:
+            self._login_button.set_property('text', google_stock.LOGIN_TO_GOOGLE_STRING) 
+            self._box.set_child_visible(self._login_button, True)
+        
     def show_slideout(self, widget):
         def on_slideout_close(s, action_taken):
             self.__last_slideout_event_time = gtk.get_current_event_time() 



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