bigboard r7270 - trunk/bigboard



Author: marinaz
Date: Wed Mar 19 23:03:10 2008
New Revision: 7270
URL: http://svn.gnome.org/viewvc/bigboard?rev=7270&view=rev

Log:
Break out adding a new set of server accounts into a separate function in preparation for supporting different accounts provided by server.

Add new sample accounts, like Twitter and Remember The Milk, which are not yet supported. 


Modified:
   trunk/bigboard/accounts.py

Modified: trunk/bigboard/accounts.py
==============================================================================
--- trunk/bigboard/accounts.py	(original)
+++ trunk/bigboard/accounts.py	Wed Mar 19 23:03:10 2008
@@ -19,6 +19,12 @@
         self.__id = id
         self.__provided_by_server = provided_by_server
 
+    def __copy__(self):
+        return AccountKind(self.__id, self.__provided_by_server)
+
+    def __deepcopy__(self, memo):
+        return AccountKind(copy.deepcopy(self.__id, memo), copy.deepcopy(self.__provided_by_server, memo))
+
     def get_id(self):
         return self.__id
 
@@ -29,9 +35,11 @@
         return "<AccountKind:%s, provided_by_server:%s>" % (self.get_id(), self.get_provided_by_server())
 
 KIND_GOOGLE = AccountKind("google", True)
+KIND_TWITTER = AccountKind("twitter", True)
+KIND_RTM = AccountKind("rtm", False) # RTM = Remember The Milk
 
 def kind_from_string(s):
-    for kind in [KIND_GOOGLE]:
+    for kind in [KIND_GOOGLE, KIND_TWITTER, KIND_RTM]:
         if s == kind.get_id():
             return kind
     return None
@@ -53,6 +61,13 @@
 
         _logger.debug("Created account %s" % (str(self)))
 
+    def __copy__(self):
+        return Account(self.__kind, self.__username, self.__password, self.__url, self.__enabled, self.__gconf_dir)
+
+    def __deepcopy__(self, memo):
+        return Account(copy.deepcopy(self.__kind, memo), copy.deepcopy(self.__username, memo), copy.deepcopy(self.__password, memo), \
+                       copy.deepcopy(self.__url, memo), copy.deepcopy(self.__enabled, memo), copy.deepcopy(self.__gconf_dir, memo))
+
     def get_kind(self):
         return self.__kind
 
@@ -143,7 +158,7 @@
     def __init__(self, *args, **kwargs):
         super(Accounts, self).__init__(*args, **kwargs)
 
-        self.__received_response_from_server = False
+        self.__received_response_from_server = set()
 
         self.__model = globals.get_data_model()
         self.__model.add_ready_handler(self.__on_ready)
@@ -222,7 +237,7 @@
         gconf_dir = account._get_gconf_dir()
         if account.get_kind().get_provided_by_server() and (account in self.__server_accounts):
             self.__ensure_account_in_gconf(account)
-        elif account.get_kind().get_provided_by_server() and (account not in self.__server_accounts) and self.__received_response_from_server:
+        elif account.get_kind().get_provided_by_server() and (account not in self.__server_accounts) and (account.get_kind() in self.__received_response_from_server):
             #remove gconf dir if one exists, set enabled field to False
             if gconf_dir:
                 self.__remove_gconf_dir(gconf_dir)  
@@ -346,6 +361,8 @@
     def __on_ready(self):
         if self.__model.self_resource != None:
             _logger.debug("will get online desktop accounts")
+            # TODO: get Twitter accounts here too, in the future, have the
+            # stocks dictate what we get here 
             query = self.__model.query_resource(self.__model.self_resource, "googleEnabledEmails +")
             query.add_handler(self.__on_google_enabled_emails)
             query.add_error_handler(self.__on_datamodel_error)        
@@ -360,58 +377,68 @@
         self.__update_google_enabled_emails(myself)
 
     def __update_google_enabled_emails(self, myself):
+        new_google_accounts = set() 
         if not hasattr(myself, 'googleEnabledEmails'):
             _logger.debug("No googleEnabledEmails in DDM identity")
-            self.__received_response_from_server = True
+        elif len(myself.googleEnabledEmails) == 0:
+            _logger.debug("DDM identity has 0 googleEnabledEmails")
+        else:
+            for email in myself.googleEnabledEmails:                        
+                (username, url) = email.split('@', 1)
+                username = str(username)
+                url = str(url) 
+                _logger.debug("got a googleEnabledEmail %s username: %s url: %s", email, username, url)        
+                new_google_accounts.add(Account(KIND_GOOGLE, username=username, url=url))
+            
+        self.update_accounts_from_server(KIND_GOOGLE, new_google_accounts)
+     
+    def update_accounts_from_server(self, account_kind, new_accounts):
+        if not account_kind.get_provided_by_server():
+            _logger.error("update_accounts_from_server was called with an account kind that we don't get from server: %s" % account_kind)
             return
 
-        google_accounts = self.__get_server_accounts_by_kind(KIND_GOOGLE) 
-
-        if len(myself.googleEnabledEmails) == 0:
-            _logger.debug("DDM identity has 0 googleEnabledEmails")
+        existing_accounts = self.__get_server_accounts_by_kind(account_kind) 
 
-        for email in myself.googleEnabledEmails:                        
-            (username, url) = email.split('@', 1)
-            username = str(username)
-            url = str(url) 
-            _logger.debug("got a googleEnabledEmail %s username: %s url: %s", email, username, url)        
-              
+        for new_account in new_accounts:                        
             # if acccount already in the list of server_accounts, don't do anything
             # if it is new, add it, and update information for it
             # if it is no longer reurned by the server, remove it and remove it from other
             # lists, including gconf
             account_found = False
-            for a in google_accounts:
-                if a.get_kind() == KIND_GOOGLE and a.get_username() == username and \
-                   (a.get_url() == url or a.get_url() == "gmail.com"):
+            for existing_account in existing_accounts:
+                if existing_account.get_username() == new_account.get_username() and \
+                   existing_account.get_url() == new_account.get_url():
                    # we found it, we don't need to change anything about it
                    account_found = True
-                   google_accounts.remove(a)
+                   existing_accounts.remove(existing_account)
                    break
              
             if not account_found:             
                 # TODO: decide if we want to check if account is among weblogin_accounts
-                account = Account(KIND_GOOGLE, username=username, url=url)   
-                self.__server_accounts.add(account)
+                # TODO: should use the deepcopy account, but right now it doesn't work for some reason 
+                new_account_to_add = copy.deepcopy(new_account)
+                _logger.debug("new account is %s" % new_account)
+                _logger.debug("new account to add is %s" % new_account_to_add)
+                self.__server_accounts.add(new_account)
                 # this will add the account to gconf and enabled accounts, and check if 
                 # we have a password for it
-                self.__update_account(account)
+                self.__update_account(new_account)
 
         # clear out accounts that are no longer found in the list of accounts of this kind from the server
-        for a in google_accounts:
-            self.__server_accounts.remove(a)
+        for existing_account in existing_accounts:
+            self.__server_accounts.remove(existing_account)
             # this should remove the account from gconf and gconf_accounts
-            self.__update_account(a)
+            self.__update_account(existing_account)
 
-        self.__received_response_from_server = True
+        self.__received_response_from_server.add(account_kind)
 
         # make sure that all accounts in gconf correspond to the ones returned from the server;
         # this will remove old accounts from gconf 
-        google_accounts_in_gconf = self.__get_gconf_accounts_by_kind(KIND_GOOGLE) 
-        _logger.debug("google_accounts_in_gconf size %d" % len(google_accounts_in_gconf))
-        for a in google_accounts_in_gconf:
-            self.__update_account(a)       
-             
+        existing_accounts_in_gconf = self.__get_gconf_accounts_by_kind(account_kind) 
+        _logger.debug("existing_accounts_in_gconf of type %s: %d" % (account_kind, len(existing_accounts_in_gconf)))
+        for gconf_account in existing_accounts_in_gconf:
+            self.__update_account(gconf_account) 
+
     def __get_gconf_info(self, gconf_dir):
         base_key = "/apps/bigboard/accounts/" + gconf_dir
         gconf_info = {}



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