online-desktop r7280 - trunk/weblogindriver



Author: marinaz
Date: Mon Oct 27 22:27:51 2008
New Revision: 7280
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7280&view=rev

Log:
Add EnsureAccountType() method that can be used to ensure that the account type is known when the server is not available or to test a new account type without adding it on the server.

Handle account types returned from the server differently than account types added locally. In particular, don't try to add or remove an account with type that was not returned by the server on the server.

Don't try to save account changes on the server when the server is not available on start-up. 


Modified:
   trunk/weblogindriver/web-login-driver

Modified: trunk/weblogindriver/web-login-driver
==============================================================================
--- trunk/weblogindriver/web-login-driver	(original)
+++ trunk/weblogindriver/web-login-driver	Mon Oct 27 22:27:51 2008
@@ -311,6 +311,8 @@
 
 ONLINE_ACCOUNT_TYPES = {TYPE_GOOGLE : ("Google", "Gmail or Google Apps for Your Domain email")}
 
+ACCOUNT_TYPES_FROM_SERVER = set([TYPE_GOOGLE])
+
 class OnlineAccount(dbus.service.Object):
   def __init__(self, account_id, bus_name, account_type, username, password='', enabled=True, gconf_dir=None, resource_id=None):
     dbus.service.Object.__init__(self, object_path = '/onlineaccount/' + str(account_id), bus_name = bus_name)
@@ -410,6 +412,7 @@
   def __init__(self, bus_name):
     dbus.service.Object.__init__(self, bus_name, '/onlineaccounts')
     self.__bus_name = bus_name 
+    self.__received_account_types_from_server = False
     self.__received_response_from_server = False
 
     #TODO: do we need to pass in the server name, and if so how do we know here what to pass in? 
@@ -530,7 +533,7 @@
 
     if account in self.__server_accounts:
       self.__ensure_account_in_gconf(account)
-    elif self.__received_response_from_server:
+    elif self.__received_response_from_server and account.GetType() in ACCOUNT_TYPES_FROM_SERVER:
       #remove gconf dir if one exists
       if gconf_dir:
         self.__remove_gconf_dir(gconf_dir)  
@@ -637,7 +640,7 @@
         
     account_type = gconf_info['type']
     username = gconf_info['username']
-    if account_type not in ONLINE_ACCOUNT_TYPES.keys():
+    if self.__received_account_types_from_server and account_type not in ONLINE_ACCOUNT_TYPES.keys():
       _logger.error("unknown account type in gconf")
       self.__remove_gconf_dir(gconf_dir)
       return
@@ -676,9 +679,13 @@
           full_name = node.getAttribute("fullName")
           user_info_type = node.getAttribute("userInfoType")
           _logger.debug("parsing online account type name=%s full_name=%s" % (name, full_name))
-          ONLINE_ACCOUNT_TYPES[name]= (full_name, user_info_type)     
+          ONLINE_ACCOUNT_TYPES[name]= (full_name, user_info_type)
+          ACCOUNT_TYPES_FROM_SERVER.add(name)
+        self.__received_account_types_from_server = True    
     except urllib2.HTTPError, e:
       _logger.error("Failed to load %s : %s" % (url, e))
+    except urllib2.URLError, e2:
+      _logger.error("Failed to load %s : %s" % (url, e2))
 
   def __on_ready(self):
     _logger.debug("__on_ready got called")
@@ -689,7 +696,7 @@
     self.__get_online_accounts()
 
   def __get_online_accounts(self):
-    if self.__model.self_resource != None and self.__save_online_flag:
+    if self.__model.global_resource.online and self.__model.self_resource != None and self.__save_online_flag:
       _logger.debug("will get online desktop accounts")
       query = self.__model.query_resource(self.__model.self_resource, "googleEnabledEmails; lovedAccounts +")
       query.add_handler(self.__on_datamodel_response)
@@ -703,7 +710,9 @@
     _logger.error("datamodel error %s: %s", code, str)        
         
   def __on_datamodel_response(self, myself):    
-    _logger.debug("received data model response")
+    _logger.debug("received data model response, found the server")
+    if not self.__received_account_types_from_server:
+      self.__download_online_account_types()
     self.__received_response_from_server = True
     self.HaveOnlineUserFlagChanged(self.__received_response_from_server)
     myself.connect(self.__update_google_enabled_emails, 'googleEnabledEmails') 
@@ -793,9 +802,9 @@
         self.update_accounts_from_server(key, value)
 
     # remove accounts for all other types that are no longer returned by the server
-    for key in ONLINE_ACCOUNT_TYPES.keys():
-      if key != TYPE_GOOGLE and key not in new_accounts_by_type.keys():
-        self.update_accounts_from_server(key, set())   
+    for account_type in ACCOUNT_TYPES_FROM_SERVER:
+      if account_type != TYPE_GOOGLE and account_type not in new_accounts_by_type.keys():
+        self.update_accounts_from_server(account_type, set())   
 
     gconf_accounts = copy.copy(self.__gconf_accounts) 
     _logger.debug("will go through existing accounts")
@@ -1193,7 +1202,8 @@
     if account:         
       return_cb((account.GetObjectPath(), False, None))
     
-    if self.__save_online_flag:      
+    _logger.debug("received response from server %s", self.__received_response_from_server)
+    if self.__save_online_flag and self.__received_response_from_server and account_type in ACCOUNT_TYPES_FROM_SERVER:      
       query = self.__model.update(("http://mugshot.org/p/accounts";, "addOnlineAccount"), accountType=account_type, username=username)
       query.add_handler(on_server_account_added)
       query.add_error_handler(on_server_account_add_failed)        
@@ -1236,7 +1246,7 @@
     if account_type == TYPE_GOOGLE:
       resource_id = account.GetUsername()
 
-    if resource_id is not None and self.__save_online_flag:    
+    if resource_id is not None and self.__save_online_flag and self.__received_response_from_server and account_type in ACCOUNT_TYPES_FROM_SERVER:    
       query = self.__model.update(("http://mugshot.org/p/accounts";, "removeOnlineAccount"), accountType=account_type, resourceId=resource_id)
       query.add_handler(on_server_account_removed)
       query.add_error_handler(on_server_account_remove_failed)        
@@ -1286,9 +1296,23 @@
     _logger.debug("in GetAllAccountTypes")
     return ONLINE_ACCOUNT_TYPES
 
+  @dbus.service.method(OA_BUS_IFACE_STR,                      
+                       in_signature="sss")
+  def EnsureAccountType(self, type_name, type_full_name, type_user_info_type):  
+    # we don't overwrite the information we already have (that was possibly received from
+    # the server or added by another application), but we add an account type if it doesn't
+    # exist
+    if type_name not in ONLINE_ACCOUNT_TYPES:
+      for (name, (full_name, user_info_type)) in ONLINE_ACCOUNT_TYPES.items():
+        if type_full_name == full_name:
+          raise dbus.DBusException("Account type with this full name already exists and is associated with a short name " +  name) 
+      ONLINE_ACCOUNT_TYPES[type_name]= (type_full_name, type_user_info_type)
+      
   @dbus.service.method(OA_BUS_IFACE_STR,
                        in_signature="u")
   def OpenAccountsDialog(self, event_time):
+    if not self.__received_account_types_from_server:
+      self.__download_online_account_types()
     global _dialog
     if _dialog:
       _dialog.destroy()
@@ -1298,6 +1322,8 @@
   @dbus.service.method(OA_BUS_IFACE_STR,
                        in_signature="asu")
   def OpenAccountsDialogWithTypes(self, account_types, event_time):
+    if not self.__received_account_types_from_server:
+      self.__download_online_account_types()
     global _dialog
     if _dialog:
       _dialog.destroy()



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