online-desktop r7271 - in trunk/weblogindriver: . weblogindriver



Author: marinaz
Date: Tue Oct 21 05:47:50 2008
New Revision: 7271
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7271&view=rev

Log:
Make RemoveAccount method remove an account on the server.

Keep account resource_id in the OnlineAccount object. Set it for external accounts, but not for Google accounts. Use it when removing an account on the server.

Enable removing an account from the accounts dialog and displaying an error alert if an error is returned.


Modified:
   trunk/weblogindriver/web-login-driver
   trunk/weblogindriver/weblogindriver/accounts_dialog.py

Modified: trunk/weblogindriver/web-login-driver
==============================================================================
--- trunk/weblogindriver/web-login-driver	(original)
+++ trunk/weblogindriver/web-login-driver	Tue Oct 21 05:47:50 2008
@@ -312,7 +312,7 @@
 ONLINE_ACCOUNT_TYPES = {TYPE_GOOGLE : "Google"}
 
 class OnlineAccount(dbus.service.Object):
-  def __init__(self, account_id, bus_name, account_type, username, password='', enabled=True, gconf_dir=None):
+  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)
     # TODO: check if dbus.service.Object really doesn't have bus_name as a field
     self.__account_id = account_id
@@ -322,19 +322,20 @@
     self.__password = password
     self.__enabled = enabled
     self.__gconf_dir = gconf_dir
+    self.__resource_id = resource_id # present only for accounts we got through the data model
 
     _logger.debug("Created account %s" % (str(self)))
 
   # copy and deepcopy might not make much sense for this class, since each instance of the class should have
   # a unique account_id
   def __copy__(self):
-    return OnlineAccount(self.__account_id, self.__bus_name, self.__account_type, self.__username, self.__password, self.__enabled, self.__gconf_dir)
+    return OnlineAccount(self.__account_id, self.__bus_name, self.__account_type, self.__username, self.__password, self.__enabled, self.__gconf_dir, self.__resource_id)
 
   def __deepcopy__(self, memo):
     return OnlineAccount(copy.deepcopy(self.__account_id, memo), copy.deepcopy(self.__bus_name, memo), \
                          copy.deepcopy(self.__account_type, memo), copy.deepcopy(self.__username, memo), \
                          copy.deepcopy(self.__password, memo), copy.deepcopy(self.__enabled, memo), \
-                         copy.deepcopy(self.__gconf_dir, memo))
+                         copy.deepcopy(self.__gconf_dir, memo), copy.deepcopy(self.__resource_id, memo))
 
   @dbus.service.method(OA_BUS_IFACE_STR,
                        out_signature="s")
@@ -369,11 +370,16 @@
   def _get_gconf_dir(self):
     return self.__gconf_dir
 
+  def _get_resource_id(self):
+    if self.__resource_id is not None and len(self.__resource_id) < 1:
+      return None
+    return self.__resource_id
+
   def _update_from_origin(self, new_props):
     _logger.debug("updating account from origin")
     changed = False
     for (key,value) in new_props.items():
-      if key not in ["password", "enabled", "gconf_dir"]:
+      if key not in ["password", "enabled", "gconf_dir", "resource_id"]:
         _logger.error("key %s is unknown or can't be changed" % key)
         continue    
 
@@ -396,7 +402,7 @@
       self.Changed()
 
   def __str__(self):
-    return "<Account userame:%s, type:%s, gconf_dir:%s, enabled:%s>" % (self.GetUsername(), self.GetType(), self._get_gconf_dir(), self.GetEnabled())
+    return "<Account userame:%s, type:%s, gconf_dir:%s, enabled:%s, resource_id:%s>" % (self.GetUsername(), self.GetType(), self._get_gconf_dir(), self.GetEnabled(), self._get_resource_id())
 
 _dialog = None
 
@@ -731,7 +737,7 @@
             username = str(account.username)
             if accountType not in new_accounts_by_type:
               new_accounts_by_type[accountType] = set()
-            new_accounts_by_type[accountType].add(self.__create_online_account(accountType, username))          
+            new_accounts_by_type[accountType].add(self.__create_online_account(accountType, username, resource_id=str(account.resource_id)))          
             _logger.debug("got username %s", username)        
           else:
             _logger.warn("account.username for the account type %s we expect data for is None" % accountType)
@@ -765,7 +771,7 @@
 
   def update_accounts_from_server(self, account_type, new_accounts):
     existing_accounts = self.__get_server_accounts_by_type(account_type) 
-
+    
     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
@@ -773,16 +779,21 @@
       # lists, including gconf
       account_found = False
       for existing_account in existing_accounts:
-        if existing_account.GetUsername() == new_account.GetUsername():
-          # we found it, we don't need to change anything about it
+        if (existing_account._get_resource_id() is not None and existing_account._get_resource_id() == new_account._get_resource_id()) or (existing_account._get_resource_id() is None and existing_account.GetUsername() == new_account.GetUsername()):
+          # we found it, make sure it has the resource_id set
+          existing_account._update_from_origin({"resource_id" : new_account._get_resource_id()})
           account_found = True
           existing_accounts.remove(existing_account)
           break
              
       if not account_found:             
         new_account_to_add = self.__find_account_in_gconf(new_account.GetType(), new_account.GetUsername())
-        if new_account_to_add is None:
+
+        if new_account_to_add is None or (new_account_to_add._get_resource_id() is not None and new_account_to_add._get_resource_id() != new_account._get_resource_id()):
           new_account_to_add = new_account # we used to use copy.deepcopy here, not sure we need it
+        else:
+          new_account_to_add._update_from_origin({"resource_id" : new_account._get_resource_id()})
+ 
         self.__server_accounts.add(new_account_to_add)
         # this will add the account to gconf and enabled accounts, and check if 
         # we have a password for it
@@ -1027,7 +1038,7 @@
                        out_signature="(obs)",
                        async_callbacks=('return_cb', 'error_cb'))
   def GetOrCreateAccount(self, account_type, username, return_cb, error_cb):        
-    def on_server_account_added(feedback_message):
+    def on_server_account_added(result):
       # TODO: might want to double check existing server accounts for an account with this type and username if it is possible it was added
       # faster with an update to lovedAccounts
       # Also, we are currently not preventing accounts with the same type and username from existing on the server, but we are not expecting accounts
@@ -1040,7 +1051,7 @@
         account = self.__create_online_account(account_type, username)   
         self.__server_accounts.add(account)
         self.__update_account(account) # this will ensure that the account is in gconf, try to find a password for the account, and emit AccountEnabled signal 
-        return_cb((account.GetObjectPath(), True, feedback_message)) 
+        return_cb((account.GetObjectPath(), True, "")) 
 
     def on_server_account_add_failed(error_type, error_message):
       # we use return_cb instead of error_cb because the error_message we return 
@@ -1071,22 +1082,42 @@
       return None 
 
   @dbus.service.method(OA_BUS_IFACE_STR,                      
-                       in_signature="o")
-  def RemoveAccount(self, account):
+                       in_signature="o",
+                       async_callbacks=('return_cb', 'error_cb'))
+  def RemoveAccount(self, account_object_path, return_cb, error_cb):
+    def on_server_account_removed(result):
+      return_cb()
+
+    def on_server_account_remove_failed(error_type, error_message):
+      _logger.error("Remove failed %s %s" % (str(error_type), error_message))
+      error_cb(error_message)
+
     account = None
     if self.__all_accounts.has_key(account_object_path):
       account = self.__all_accounts[account_object_path]
     else:
-      _logger.error("SaveAccountChanges was called with an unknown object path %s" % account_object_path)
-      return
-
-    _logger.debug("will remove account with gconf_dir %s" % account._get_gconf_dir())  
-    self.__remove_gconf_dir(account._get_gconf_dir())
-    # TODO: also remove the account on the server 
-    if account in self.__server_accounts:
+      error_message = "RemoveAccount was called with an unknown object path %s" % (account_object_path,)
+      _logger.error(error_message)
+      error_cb(error_message)
+
+    _logger.debug("will remove account with gconf_dir %s" % account._get_gconf_dir())      
+    account_type = account.GetType()
+    resource_id = account._get_resource_id()
+    if account_type == TYPE_GOOGLE:
+      resource_id = account.GetUsername()
+
+    if resource_id is not None:    
+      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)        
+      query.execute()
+    else:
+      self.__remove_gconf_dir(account._get_gconf_dir())
+      if account in self.__server_accounts:
+        _logger.warn("Account %s was in self.__server_accounts, but did not have a resource_id" % str(account)) 
         self.__server_accounts.remove(account)
-    # self.__update_account will remove the account from self.__all_accounts 
-    self.__update_account(account)
+      self.__update_account(account) # this will remove the account from self.__all_accounts 
+      return_cb()
 
   @dbus.service.method(OA_BUS_IFACE_STR,                      
                        out_signature="ao")

Modified: trunk/weblogindriver/weblogindriver/accounts_dialog.py
==============================================================================
--- trunk/weblogindriver/weblogindriver/accounts_dialog.py	(original)
+++ trunk/weblogindriver/weblogindriver/accounts_dialog.py	Tue Oct 21 05:47:50 2008
@@ -120,7 +120,7 @@
         self.__account_page_link_box.pack_end(self.__account_page_link, expand=False, fill=False)
 
         self.__existing_accounts_vbox.pack_start(remove_button_box, False, False, padding=5)
-        self.__existing_accounts_vbox.pack_start(self.__account_page_link_box, False, False)   
+        self.__outer_existing_accounts_vbox.pack_end(self.__account_page_link_box, False, False)   
 
         # stuff below gets added to the "Add Account" tab
 
@@ -316,10 +316,19 @@
     def __on_account_settings_reset(self, widget):
         self.__password_entry.set_text(self.__current_account.GetPassword())
         self.__check_box.set_active(self.__current_account.GetEnabled())
-  
+
+    def account_remove_return_cb(self):
+        pass
+
+    def account_remove_error_cb(self, error):
+        message_dialog = gtk.MessageDialog(parent=self, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format="Could not remove an account")
+        message_dialog.set_default_response(gtk.BUTTONS_OK)
+        message_dialog.format_secondary_text(error)
+        message_dialog.run()
+        message_dialog.destroy()        
+
     def __on_account_remove_clicked(self, widget):
-        self.__online_accounts_service.RemoveAccount(self.__current_account.GetObjectPath())
-        # TODO: have RemoveAccount return an error if one happened and dispplay it
+        self.__online_accounts_service.RemoveAccount(self.__current_account.GetObjectPath(), self.account_remove_return_cb, self.account_remove_error_cb)
 
     def __on_new_username_changed(self, widget):
         # in the future can check if the input is of the desired form here
@@ -327,7 +336,7 @@
         self.__add_button.set_sensitive(username_entered)        
 
     # account_tuple consists of object_path, new_account_flag, feedback_message
-    def return_cb(self, account_tuple):
+    def account_add_return_cb(self, account_tuple):
         object_path = account_tuple[0]
         new_account_flag = account_tuple[1]
         feedback_message = account_tuple[2]
@@ -366,7 +375,7 @@
                 account_iter = self.__model_tree_iter_by_account[object_path]   
                 self.__accounts_combo.set_active_iter(account_iter)
 
-    def error_cb(self, error):
+    def account_add_error_cb(self, error):
         pass
 
     def __on_new_username_added(self, widget):
@@ -379,7 +388,7 @@
         current_iter = self.__account_types_combo.get_active_iter()
         for (account_type, type_full_name) in self.__all_account_types.items():
             if self.__account_types_model.get_value(current_iter, 0) == type_full_name:
-                self.__online_accounts_service.GetOrCreateAccount(account_type, text, self.return_cb, self.error_cb)
+                self.__online_accounts_service.GetOrCreateAccount(account_type, text, self.account_add_return_cb, self.account_add_error_cb)
                 return 
                 
         _logger.warn("Did not find an account type that matched the account type in the dropdown %s" % self.__account_types_model.get_value(current_iter, 0))



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