Hide singleton providers from wizard providers list if already set up
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 23 Jan 2009 19:59:03 +0000 (19:59 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Fri, 23 Jan 2009 19:59:03 +0000 (19:59 +0000)
pmo-trunk-r7278

src/hildon2/modest-provider-picker.c
src/modest-account-mgr.c
src/modest-account-mgr.h

index 4fb130c..aef688c 100644 (file)
@@ -240,24 +240,34 @@ modest_provider_picker_fill (ModestProviderPicker *self,
        registry = modest_runtime_get_protocol_registry ();
        provider_protos = modest_protocol_registry_get_by_tag (registry, 
                                                               MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
-       tmp = provider_protos;
-       while (tmp) {
+       for (tmp = provider_protos; tmp != NULL; tmp = g_slist_next (tmp)) {
+
                GtkTreeIter iter;
                ModestProtocol *proto = MODEST_PROTOCOL (tmp->data);
                const gchar *name = modest_protocol_get_display_name (proto);
 
                /* only add store protocols, no need to duplicate them */
-               if (modest_protocol_registry_protocol_type_has_tag (registry, 
-                                                                   modest_protocol_get_type_id (proto),
-                                                                   MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS)) {
-                       gtk_list_store_append (liststore, &iter);
-                       gtk_list_store_set (liststore, &iter,
-                                           MODEL_COL_ID, modest_protocol_get_name (proto),
-                                           MODEL_COL_NAME, name,
-                                           MODEL_COL_ID_TYPE, MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL,
-                                           -1);
+               if (!modest_protocol_registry_protocol_type_has_tag (registry, 
+                                                                    modest_protocol_get_type_id (proto),
+                                                                    MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
+                       continue;
+                 
+               if (modest_protocol_registry_protocol_type_has_tag 
+                   (registry,
+                    modest_protocol_get_type_id (proto),
+                    MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
+                       /* Check if there's already an account configured with this account type */
+                       if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
+                                                                         modest_protocol_get_type_id (proto)))
+                               continue;
                }
-               tmp = g_slist_next (tmp);
+
+               gtk_list_store_append (liststore, &iter);
+               gtk_list_store_set (liststore, &iter,
+                                   MODEL_COL_ID, modest_protocol_get_name (proto),
+                                   MODEL_COL_NAME, name,
+                                   MODEL_COL_ID_TYPE, MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL,
+                                   -1);
        }
        g_slist_free (provider_protos);
        
index f77e247..913d7d4 100644 (file)
@@ -1650,3 +1650,28 @@ modest_account_mgr_set_display_name (ModestAccountMgr *self,
        if (notify)
                g_signal_emit (self, signals[DISPLAY_NAME_CHANGED_SIGNAL], 0, account_name);
 }
+
+gboolean 
+modest_account_mgr_singleton_protocol_exists (ModestAccountMgr *mgr,
+                                             ModestProtocolType protocol_type)
+{
+       GSList *account_names, *node;
+       gboolean found = FALSE;
+
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR (mgr), FALSE);
+       account_names = modest_account_mgr_account_names (mgr, TRUE);
+
+       for (node = account_names; node != NULL; node = g_slist_next (node)) {
+               ModestProtocolType current_protocol;
+
+               current_protocol = modest_account_mgr_get_store_protocol (mgr, (gchar *) node->data);
+               if (current_protocol == protocol_type) {
+                       found = TRUE;
+                       break;
+               }
+       }
+
+       modest_account_mgr_free_account_names (account_names);
+
+       return found;
+}
index f7b21ef..56bfb8f 100644 (file)
@@ -358,6 +358,8 @@ void  modest_account_mgr_set_display_name (ModestAccountMgr *self,
                                           const gchar *account_name,
                                           const gchar *display_name);
 
+gboolean modest_account_mgr_singleton_protocol_exists (ModestAccountMgr *mgr,
+                                                      ModestProtocolType protocol_type);
 
 G_END_DECLS