online-desktop r7258 - trunk/weblogindriver



Author: marinaz
Date: Thu Jun 26 00:19:42 2008
New Revision: 7258
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7258&view=rev

Log:
Connect to username change signal on loved accounts.


Modified:
   trunk/weblogindriver/web-login-driver

Modified: trunk/weblogindriver/web-login-driver
==============================================================================
--- trunk/weblogindriver/web-login-driver	(original)
+++ trunk/weblogindriver/web-login-driver	Thu Jun 26 00:19:42 2008
@@ -412,6 +412,8 @@
     self.__weblogin_accounts = set()
     self.__enabled_accounts = set()
 
+    self.__loved_data_model_accounts = set()
+
     # This is a mapping from object paths to OnlineAccount objects for all accounts.
     # It would have been nice to use the same id as the gconf key id, but we create
     # accounts before we add them to gconf, and also we create accounts for the
@@ -594,6 +596,7 @@
       self.AccountEnabled(account.GetObjectPath())     
            
   def __remove_gconf_dir(self, gconf_dir):
+    _logger.debug("will remove gconf dir")
     base_key = GCONF_BASE_DIR + '/' + gconf_dir
     success = self.__gconf.recursive_unset(base_key, gconf.UNSET_INCLUDING_SCHEMA_NAMES)
     _logger.debug("removed gconf dir %s success %s" % (base_key, success))
@@ -684,6 +687,7 @@
 
   def __update_loved_accounts(self, myself):
     new_accounts_by_kind = {} 
+    new_loved_data_model_accounts = set()
     if not hasattr(myself, 'lovedAccounts'):
       _logger.debug("No lovedAcccounts in DDM identity")
     elif len(myself.lovedAccounts) == 0:
@@ -693,6 +697,11 @@
         accountType = str(account.accountType).lower()
         _logger.debug("accountType is %s" % accountType)
         if accountType in ONLINE_ACCOUNT_KINDS:
+          new_loved_data_model_accounts.add(account)
+          if account not in self.__loved_data_model_accounts:
+            _logger.debug("This is a new loved account %s" % account.resource_id)
+            # makes sure we connect only once
+            account.connect(self.__update_loved_account, "username")
           if account.username:
             username = str(account.username)
             if accountType not in new_accounts_by_kind:
@@ -712,6 +721,23 @@
         if key != KIND_GOOGLE and key not in new_accounts_by_kind.keys():
             self.update_accounts_from_server(key, set())    
 
+    for account in self.__loved_data_model_accounts:
+      if account not in new_loved_data_model_accounts:
+        _logger.debug("Some old account is not in new accounts %s" % account.resource_id)
+        account.disconnect(self.__update_loved_accounts)
+
+    self.__loved_data_model_accounts = new_loved_data_model_accounts
+
+  def __update_loved_account(self, myself):    
+    # because we consider two accounts with different usernames as different accounts,
+    # we would have to associate accounts in self.__server_accounts with data model accounts
+    # to process this change individually, so at the moment it seems easier to just refresh 
+    # all accounts 
+    query = self.__model.query_resource(self.__model.self_resource, "lovedAccounts +")
+    query.add_handler(self.__update_loved_accounts)
+    query.add_error_handler(self.__on_datamodel_error)       
+    query.execute()
+
   def update_accounts_from_server(self, account_kind, new_accounts):
     existing_accounts = self.__get_server_accounts_by_kind(account_kind) 
 
@@ -737,14 +763,14 @@
         # we have a password for it
         self.__update_account(new_account_to_add)
 
+    self.__received_response_from_server.add(account_kind)
+
     # clear out accounts that are no longer found in the list of accounts of this kind from the server
     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(existing_account)
 
-    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 
     existing_accounts_in_gconf = self.__get_gconf_accounts_by_kind(account_kind) 
@@ -799,12 +825,13 @@
     for gconf_dir in gconf_info_keys:
       self.__try_ensure_and_update_account_for_gconf_dir(gconf_dir)
 
-    ## now update any old accounts that are no longer in gconf,
-    ## which should result in enabled=False
-    for a in self.__gconf_accounts:
+    ## now update any old accounts that are no longer in gconf
+    gconf_accounts = copy.copy(self.__gconf_accounts) 
+    for a in gconf_accounts:
       gconf_dir = a._get_gconf_dir()
       _logger.debug("processing gconf account for %s" % gconf_dir)
       if gconf_dir and gconf_dir not in self.__gconf_info:
+        _logger.debug("needs update") 
         self.__update_account(a)
         
   @defer_idle_func(timeout=400)        
@@ -895,6 +922,8 @@
       new_gconf_dir = True
       account._update_from_origin({"gconf_dir" : gconf_dir})
       self.__gconf_accounts.add(account)
+    elif gconf_dir not in self.__gconf_info: 
+      new_gconf_dir = True   
             
     base_key = GCONF_BASE_DIR + '/' + gconf_dir
 



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