bigboard r7339 - in trunk/bigboard: . stocks/mail



Author: marinaz
Date: Tue May 13 23:41:12 2008
New Revision: 7339
URL: http://svn.gnome.org/viewvc/bigboard?rev=7339&view=rev

Log:
Display all enabled Google accounts in the MailStock.
Show one folder per account, and allow switching that folder.
For now, keep "Edit Google Accounts" button showing all the time.
Lots of blinginess still required.


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

Modified: trunk/bigboard/google_stock.py
==============================================================================
--- trunk/bigboard/google_stock.py	(original)
+++ trunk/bigboard/google_stock.py	Tue May 13 23:41:12 2008
@@ -15,15 +15,14 @@
 
 FAILED_TO_LOGIN_STRING = "Failed to login."
 FAILED_TO_CONNECT_STRING = "Cannot connect to Google."
-LOGIN_TO_GOOGLE_STRING = "Login to Google"
+LOGIN_TO_GOOGLE_STRING = "Edit Google Accounts"
 CHECKING_LOGIN_STRING = "Checking Login..."
 
 class GoogleStock(object):
     def __init__(self, action_id, **kwargs):
         super(GoogleStock, self).__init__(**kwargs)
         _logger.debug("in google stock init")
-        # A dictionary of authenticated google accounts, with keys that are used
-        # to identify those accounts within the stock.
+        # a set of enabled google accounts to be used in the stock
         self.googles = set()
         self.__googles_by_account = {} ## map accounts.Account => google.Google
 

Modified: trunk/bigboard/stocks/mail/MailStock.py
==============================================================================
--- trunk/bigboard/stocks/mail/MailStock.py	(original)
+++ trunk/bigboard/stocks/mail/MailStock.py	Tue May 13 23:41:12 2008
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
-import logging, re, time, urllib2
+import logging, re, time, urllib, urllib2
 
 import gobject, gtk
 import hippo
@@ -14,6 +14,8 @@
 import bigboard.google_stock as google_stock  
 from bigboard.big_widgets import CanvasHBox, CanvasVBox, Button, Header, PrelightingCanvasBox
 import bigboard.libbig as libbig
+from bigboard.libbig.struct import AutoStruct, AutoSignallingStruct
+
 #TODO: add a scrollable view for emails
 #import bigboard.scroll_ribbon as scroll_ribbon
 
@@ -55,6 +57,21 @@
     # Return the sanely filtered content
     return textContent.getvalue()
 
+def create_account_url(account):
+    account = urllib.unquote(account)
+    domain = account[account.find("@") + 1:]
+    if domain == "gmail.com":
+        return "http://mail.google.com/mail";
+    else:
+        return "https://mail.google.com/a/"; + domain
+
+class GoogleAccountInfo(AutoStruct):
+    def __init__(self):
+        super(GoogleAccountInfo, self).__init__({ 'google_account' : None, \
+                                                  'google_account_box' : hippo.CanvasBox(orientation=hippo.ORIENTATION_VERTICAL), \
+                                                  'current_folder' : 'inbox', \
+                                                  'logged_in_flag' : False })
+
 class LabelSlideout(ThemedSlideout):
     __gsignals__ = {
                     'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )),
@@ -136,10 +153,12 @@
         self.__slideout = None
         self.__last_slideout_event_time = None       
 
-        self.__current_gobj = None
-        self.__google_account = None
-        self.__folder = 'inbox'
-        self.__logged_in = False  
+        self.__google_accounts = {} # gobj -> GoogleAccountInfo  
+        self.__last_login_gobj = None
+        #self.__current_gobj = None
+        #self.__google_account = None
+        #self.__folder = 'inbox'
+        #self.__logged_in = False  
         
         self.__display_limit = 4
 
@@ -153,52 +172,75 @@
         return self._box
     
     def update_google_data(self, gobj):
-        self.__current_gobj = gobj
-        username = gobj.get_account().get_username()
-        password = gobj.get_account().get_password()
-        domain = gobj.get_account().get_url() 
-        self.__update_email_box(username, password, domain)
+        # self.__current_gobj = gobj
+        # username = gobj.get_account().get_username()
+        # password = gobj.get_account().get_password()
+        # domain = gobj.get_account().get_url() 
+        self.__update_email_box(gobj)
    
     def remove_google_data(self, gobj):
-        # sometimes we don't even get the self.__current_gobj because the polling task didn't start, so 
+        if self.__google_accounts.has_key(gobj):
+            self._box.remove(self.__google_accounts[gobj].get_google_account_box())
+            del self.__google_accounts[gobj]
+        
+        # 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 self.__current_gobj == gobj or len(self.googles) == 0: 
+        if len(self.googles) == 0: 
             self._box.remove_all()
             self._login_button.set_property('text', google_stock.LOGIN_TO_GOOGLE_STRING) 
             self._box.append(self._login_button)
-            self.__google_account = None
-            self.__logged_in = False
+            self.__google_accounts = {}
 
-    def __update_email_box (self, username, password, domain):       
+    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() 
+
+        if not self.__google_accounts.has_key(gobj):
+            self.__google_accounts[gobj] = GoogleAccountInfo()
+            self._box.append(self.__google_accounts[gobj].get_google_account_box())  
+ 
+        google_account = self.__google_accounts[gobj].get_google_account()
+        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 self.__google_account is None or username != self.__google_account.name or \
-               password != self.__google_account.password:
+            # 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))
-                self.__google_account = libgmail.GmailAccount(username, password, domain = domain)
-                self.__google_account.login()
-            elif not self.__logged_in:
-                self.__google_account.login()                
-
-            self.__logged_in = True
-
-            if self.__folder == 'inbox':
-                threads = self.__google_account.getMessagesByFolder(self.__folder)
-            elif self.__folder == 'unread':
-                threads = self.__google_account.getUnreadMessages()
+                google_account = libgmail.GmailAccount(username, password, domain = domain)
+                google_account.login()
+            elif not logged_in_flag:
+                google_account.login()                
+
+            logged_in_flag = True
+            self.__last_login_gobj = gobj
+
+            if current_folder == 'inbox':
+                threads = google_account.getMessagesByFolder(current_folder)
+            elif current_folder == 'unread':
+                threads = google_account.getUnreadMessages()
             else:
-                threads = self.__google_account.getMessagesByLabel(self.__folder)
+                _logger.debug("will get messages for label %s for account name %s domain %s" % (current_folder, google_account.name, google_account.domain))
+                threads = google_account.getMessagesByLabel(current_folder)
 
-            self._box.remove_all()
-            account = hippo.CanvasText(classes='header', text=self.__google_account.name)
-            self._box.append(account)
+            _logger.debug("done getting threads")
+            google_account_box.remove_all()
+            account = hippo.CanvasText(classes='header', text=gobj.get_account().get_username_as_google_email())
+            google_account_box.append(account)
             
             box = PrelightingCanvasBox()
-            box.connect("button-press-event", self.create_label_slideout, self.__google_account)
-            self._box.append(box)
-            label = hippo.CanvasText(text=self.__folder, font="14px Bold Italic")
+            box.connect("button-press-event", self.create_label_slideout, gobj)
+            google_account_box.append(box)
+            label = hippo.CanvasText(text=current_folder, font="14px Bold Italic")
             box.append(label)
             
             i = 0
@@ -209,31 +251,37 @@
                 
                 box = PrelightingCanvasBox()
                 box.connect("button-press-event", self.create_email_slideout, thread)
-                self._box.append(box)
+                google_account_box.append(box)
                 email = hippo.CanvasText(markup=subject, xalign=hippo.ALIGNMENT_START)
                 box.append(email)
                 i += 1
-            labelsDict = self.__google_account.getFolderCounts()
-            footer = hippo.CanvasText(classes='footer', text="%s unread" % labelsDict['inbox'], font="14px Bold Italic")
-            self._box.append(footer)
+            labelsDict = google_account.getFolderCounts()
+            footer = hippo.CanvasText(classes='footer', text="%s unread" % labelsDict[current_folder], font="14px Bold Italic")
+            google_account_box.append(footer)
             print "updated mailbox"
             
         except libgmail.GmailLoginFailure:
-            self._box.remove_all()
-            self.__logged_in = 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)
-                self._box.append(error)
+                google_account_box.append(error)
             self._login_button.set_property('text', google_stock.LOGIN_TO_GOOGLE_STRING) 
             self._box.append(self._login_button)
         except urllib2.URLError:
-            if not self.__logged_in:
-                self._box.remove_all()
-               
+            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)                
+                self._box.prepend(error)
+
+        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})                
 
     def show_slideout(self, widget):
         def on_slideout_close(s, action_taken):
@@ -248,13 +296,13 @@
             self.__slideout = None
             return
     
-    def create_label_slideout(self, widget, hippo_event, data):   
+    def create_label_slideout(self, widget, hippo_event, gobj):   
         if type(self.__slideout) is LabelSlideout and \
            self.__last_slideout_event_time == gtk.get_current_event_time():
             self.__slideout = None
             return 
-        self.__slideout = LabelSlideout(data)
-        self.__slideout.connect('changed', self.on_label_changed)
+        self.__slideout = LabelSlideout(self.__google_accounts[gobj].get_google_account())
+        self.__slideout.connect('changed', self.on_label_changed, gobj)
         self.show_slideout(widget)
     
     def create_email_slideout(self, widget, hippo_event, data):
@@ -265,9 +313,22 @@
         self.__slideout = EmailSlideout(data)
         self.show_slideout(widget)
     
-    def on_label_changed(self, slideout, label):
-        self.__folder = label
-        self.__update_email_box(self.__google_account.name, self.__google_account.password, self.__google_account.domain)
+    def on_label_changed(self, slideout, label, gobj):
+        _logger.debug("will get new folder for %s" % gobj.get_account().get_username_as_google_email())
+        self.__google_accounts[gobj].update({'current_folder' : label})
+        self.__update_email_box(gobj)
     
+    # TODO: move generic code to google_stock.py
     def __on_more_button(self):
-        libbig.show_url("http://mail.google.com/mail";)
+        done_with_sleep_state = 0
+        for google_account in self.googles:
+            if done_with_sleep_state == 1:
+                # in case the browser is just starting, we should wait a bit, otherwise
+                # Firefox produces this for the second link:  
+                # "Firefox is already running, but is not responding. To open a new window, 
+                #  you must first close the existing Firefox process, or restart your system."
+                time.sleep(2)
+                done_with_sleep_state = 2  
+            libbig.show_url(create_account_url(google_account.get_account().get_username_as_google_email()))
+            if done_with_sleep_state == 0:
+                done_with_sleep_state = 1



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