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



Author: marinaz
Date: Mon Oct 20 22:07:54 2008
New Revision: 7270
URL: http://svn.gnome.org/viewvc/online-desktop?rev=7270&view=rev

Log:
Allow adding new online accounts in the accounts dialog.
Send the updates to the server and display errors to the user, if any.


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

Modified: trunk/Makefile-weblogindriver.am
==============================================================================
--- trunk/Makefile-weblogindriver.am	(original)
+++ trunk/Makefile-weblogindriver.am	Mon Oct 20 22:07:54 2008
@@ -11,7 +11,8 @@
 weblogindriver_PYTHON = weblogindriver/weblogindriver/__init__.py \
 	weblogindriver/weblogindriver/accounts_dialog.py \
 	weblogindriver/weblogindriver/keyring.py \
-        weblogindriver/weblogindriver/gutil.py
+        weblogindriver/weblogindriver/gutil.py \
+        weblogindriver/weblogindriver/ddm_util.py
 
 bin_SCRIPTS += weblogindriver/web-login-driver
 EXTRA_DIST += weblogindriver/web-login-driver

Modified: trunk/weblogindriver/web-login-driver
==============================================================================
--- trunk/weblogindriver/web-login-driver	(original)
+++ trunk/weblogindriver/web-login-driver	Mon Oct 20 22:07:54 2008
@@ -672,7 +672,6 @@
     self.__download_online_account_types()
     if self.__model.self_resource != None:
       _logger.debug("will get online desktop accounts")
-      # TODO: get all gnomeExternalAccounts here later, googleEnabledEmails is just one case
       query = self.__model.query_resource(self.__model.self_resource, "googleEnabledEmails; lovedAccounts +")
       query.add_handler(self.__on_datamodel_response)
       query.add_error_handler(self.__on_datamodel_error)        
@@ -1022,21 +1021,47 @@
       ## this should notice a new password
       self.__update_account(account)
 
-  # return a tuple with an account object path as the first element, and a boolean indicating if a new account was created
+  # returns a tuple with an account object path as the first element, and a boolean indicating if a new account was created as a second element, and a feedback message as a third element
   @dbus.service.method(OA_BUS_IFACE_STR,                      
                        in_signature="ss",
-                       out_signature="(ob)")
-  def GetOrCreateAccount(self, account_type, username):        
+                       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):
+      # 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
+      # with the same type and username to be in account sets here, so we need to sort that out
+      
+      if account_type == TYPE_GOOGLE:
+        # we should not create a Google account right away because it needs to be verified
+        return_cb((None, True, "Please check your e-mail to verify the account."))
+      else:
+        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)) 
+
+    def on_server_account_add_failed(error_type, error_message):
+      # we use return_cb instead of error_cb because the error_message we return 
+      # would normally be a message with feedback
+      _logger.error("Add failed %s %s" % (str(error_type), error_message))
+      return_cb((None, False, error_message))
+
     account_type = str(account_type)
     username = str(username) 
+
+    if account_type == TYPE_GOOGLE and username.find("@") < 0:
+        username = username + "@gmail.com" 
+
     account = self.__find_account_in_gconf(account_type, username)
     if account:         
-      return (account.GetObjectPath(), False)
+      return_cb((account.GetObjectPath(), False, None))
           
-    account = self.__create_online_account(account_type, username)
-    self.__ensure_account_in_gconf(account)     
-    self.__update_account(account) # this might find a password for the account and emit AccountEnabled signal 
-    return (account.GetObjectPath(), True)
+    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)        
+    query.execute()
  
   def get_existing_account(self, account_object_path):
     if self.__all_accounts.has_key(account_object_path):

Modified: trunk/weblogindriver/weblogindriver/accounts_dialog.py
==============================================================================
--- trunk/weblogindriver/weblogindriver/accounts_dialog.py	(original)
+++ trunk/weblogindriver/weblogindriver/accounts_dialog.py	Mon Oct 20 22:07:54 2008
@@ -107,24 +107,25 @@
         remove_image = gtk.Image()
         remove_image.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_BUTTON)
         self.__remove_button.set_image(remove_image) 
-        self.__remove_button.set_sensitive(False)
+        # self.__remove_button.set_sensitive(False)
         self.__remove_button.connect('clicked',
                                    self.__on_account_remove_clicked)
         remove_button_box.pack_end(self.__remove_button, expand=False, fill=False)
 
-        self.__remove_link_box = gtk.HBox()
-        self.__remove_link = Link()
-        self.__remove_link.set_text("Remove account online")
-        self.__remove_link.set_enabled(False)
-        self.__remove_link.connect("clicked", self.__open_account_page)
-        self.__remove_link_box.pack_end(self.__remove_link, expand=False, fill=False)
+        self.__account_page_link_box = gtk.HBox()
+        self.__account_page_link = Link()
+        self.__account_page_link.set_text("Visit Account Page")
+        # self.__account_page_link.set_enabled(False)
+        self.__account_page_link.connect("clicked", self.__open_account_page)
+        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.__remove_link_box, False, False)   
+        self.__existing_accounts_vbox.pack_start(self.__account_page_link_box, False, False)   
 
         # stuff below gets added to the "Add Account" tab
 
         self.__account_types_model = gtk.ListStore(gobject.TYPE_STRING)
+        self.__account_types_model.set_sort_column_id(0, gtk.SORT_ASCENDING)
         self.__account_types_combo = gtk.ComboBox(self.__account_types_model)
         self.__new_account_vbox.pack_start(self.__account_types_combo, True, False)
         account_types_textrender = gtk.CellRendererText()
@@ -135,10 +136,9 @@
         self.__all_account_types = self.__online_accounts_service.GetAllAccountTypes()
         _logger.debug("will get accounts types 2")
      
-        # TODO: once we save accounts added locally on server, we will allow adding all account types
-        # in the dialog, but for now we don't allow adding any
-        # for type_full_name in self.__all_account_types.values():
-        #     self.__account_types_model.append([type_full_name])
+        for (account_type, type_full_name) in self.__all_account_types.items():
+            if (not self.__account_types) or account_type in self.__account_types:
+                self.__account_types_model.append([type_full_name])
             
         # Setting padding to 1 here is a hack to get the content of both tabs to be aligned,
         # we'll need to change this when it will become possible to add new account types to
@@ -170,24 +170,21 @@
         self.__add_button.connect('clicked',
                                    self.__on_new_username_added)
         self.__add_button_box.pack_end(self.__add_button, expand=False, fill=False)
-        self.__new_account_vbox.pack_start(self.__add_button_box, False, False, padding=padding)
+        self.__new_account_vbox.pack_start(self.__add_button_box, False, False, padding=padding)   
+
+        self.__account_page_link_box_2 = gtk.HBox()
+        self.__account_page_link_2 = Link()
+        self.__account_page_link_2.set_text("Visit Account Page")
+        # self.__account_page_link_2.set_enabled(False)
+        self.__account_page_link_2.connect("clicked", self.__open_account_page)
 
-        self.__add_link_box = gtk.HBox()
-        self.__add_link = Link()
-        self.__add_link.connect("clicked", self.__open_account_page)
         if len(self.__account_types_model) > 0:
             self.__account_types_combo.set_active(0)
-            self.__add_link.set_text("Add other accounts online")
-            self.__add_link_box.pack_end(self.__add_link, expand=False, fill=False)
-            self.__outer_new_account_vbox.pack_end(self.__add_link_box, False, False)
+            self.__account_page_link_box_2.pack_end(self.__account_page_link_2, expand=False, fill=False)
+            self.__outer_new_account_vbox.pack_end(self.__account_page_link_box_2, False, False)
         else:  
-            if self.__account_types and len(self.__account_types) == 1 and \
-               self.__account_types[0] in self.__all_account_types.keys():           
-                self.__add_link.set_text("Add " + self.__all_account_types[self.__account_types[0]] + " accounts online")
-            else:
-                self.__add_link.set_text("Add accounts online")
-            self.__add_link_box.pack_start(self.__add_link)
-            self.__new_account_vbox.pack_start(self.__add_link_box)
+            self.__account_page_link_box_2.pack_start(self.__account_page_link_2)
+            self.__new_account_vbox.pack_start(self.__account_page_link_box_2)
    
         self.__model_tree_iter_by_account = {}
         self.__current_account = None
@@ -275,7 +272,7 @@
             self.__undo_button.hide()
             self.__apply_button.hide()
             self.__remove_button.hide()
-            self.__remove_link_box.hide()
+            # self.__account_page_link_box.hide()
             self.__existing_accounts_label.set_text("No existing accounts") 
             self.__existing_accounts_label.set_alignment(0.5, 0.0)
         else:
@@ -296,9 +293,6 @@
                 # TODO: this will trigger __on_password_entry_changed, make sure that is harmless
                 self.__password_entry.set_text(self.__current_account.GetPassword())
                 self.__check_box.set_active(self.__current_account.GetEnabled())
-                # TODO: set the remove button to be sensitive once we enable removing accounts on server
-                self.__remove_button.set_sensitive(False) 
-                self.__remove_link.set_enabled(True)
                 return
         _logger.error("new edited account was not found in self.__model_tree_iter_by_account")
 
@@ -325,12 +319,56 @@
   
     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
 
     def __on_new_username_changed(self, widget):
         # in the future can check if the input is of the desired form here
         username_entered = (len(self.__username_entry.get_text().strip()) > 0)  
         self.__add_button.set_sensitive(username_entered)        
 
+    # account_tuple consists of object_path, new_account_flag, feedback_message
+    def return_cb(self, account_tuple):
+        object_path = account_tuple[0]
+        new_account_flag = account_tuple[1]
+        feedback_message = account_tuple[2]
+        
+        if (feedback_message is not None and len(feedback_message) > 0) or (object_path is None and not new_account_flag):
+            message_dialog = None
+            if object_path is None and (not new_account_flag): 
+                # feedback_message is an error
+                message_dialog = gtk.MessageDialog(parent=self, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, message_format="Could not add an account")
+            else:
+                # feedback_message is a just there to provide extra info
+                message_dialog = gtk.MessageDialog(parent=self, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK, message_format="Information note")
+                self.__username_entry.set_text("")
+            
+            message_dialog.set_default_response(gtk.BUTTONS_OK)
+            message_dialog.format_secondary_text(feedback_message)
+            message_dialog.run()
+            message_dialog.destroy()
+        else: 
+            self.__username_entry.set_text("")
+            self.__notebook.set_current_page(0)
+                
+        # we set the newly added account to be an active iter even if we are not switching to the existing accounts view
+        # because we are showing a warning 
+        if object_path is not None: 
+            if self.__model_tree_iter_by_account.has_key(object_path):
+                # the key will already exist only if the account already existed (new_account_flag should be False in that case)
+                # we could show a message to the user about it, but it is probably more helpful to just show them that account
+                # in the existing accounts view
+                account_iter = self.__model_tree_iter_by_account[object_path]                
+                self.__accounts_combo.set_active_iter(account_iter)
+            else:
+                # acounts system will emit a signal that will cause __on_account_added to be called again, 
+                # but it's ok to call this from here so that we can switch to the new account in the combo box right away
+                self.__on_account_added(object_path)
+                account_iter = self.__model_tree_iter_by_account[object_path]   
+                self.__accounts_combo.set_active_iter(account_iter)
+
+    def error_cb(self, error):
+        pass
+
     def __on_new_username_added(self, widget):
         text = self.__username_entry.get_text()
         username_entered = (len(text.strip()) > 0)
@@ -339,22 +377,9 @@
             return
         
         current_iter = self.__account_types_combo.get_active_iter()
-        for (account_type, type_full_name) in self.__all_account_types:
+        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:
-                account_tuple = self.__online_accounts_service.GetOrCreateAccount(account_type, text)
-                self.__username_entry.set_text("")
-                self.__notebook.set_current_page(0)
-                # TODO: Display a special message if the account aready existed (account_tuple[1] is False), also
-                # the key should be self.__model_tree_iter_by_account only in that case
-                if self.__model_tree_iter_by_account.has_key(account_tuple[0]):
-                    account_iter = self.__model_tree_iter_by_account[account_tuple[0]]                
-                    self.__accounts_combo.set_active_iter(account_iter)
-                else:
-                    # acounts system will emit a signal that will cause __on_account_added to be called again, 
-                    # but it's ok to call this from here so that we can switch to the new account in the combo box right away
-                    self.__on_account_added(account_tuple[0])
-                    account_iter = self.__model_tree_iter_by_account[account_tuple[0]]   
-                    self.__accounts_combo.set_active_iter(account_iter)
+                self.__online_accounts_service.GetOrCreateAccount(account_type, text, self.return_cb, self.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]