[evolution-kolab/ek-wip-acl] EPlugin: separated out CamelStore getter from selected path getter



commit e7ae953637187cb6e13004469dfa26b494ec55d8
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Jul 31 20:09:38 2012 +0200

    EPlugin: separated out CamelStore getter from selected path getter
    
    * moved code which gets the CamelKolabIMAPXStore from
      the EShellView into a separate function
    * use this new function inside the selected_path getter
      where the former code used to live in
    * we will need this to enable the metadata / acl dialogs
      to retrieve the CamelKolabIMAPXStore so they can
      operate on the IMAP folders
    * this will only work in the frontend, so the backends
      will need to cope with the server-side changes
      (for ACL, this is transparent, for ANNOTATEMORE we
      will need to involve the collection backend to remove
      the ESources for no-longer-matching folder types)

 src/eplugin/e-kolab-plugin-ui.c |   72 ++++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 19 deletions(-)
---
diff --git a/src/eplugin/e-kolab-plugin-ui.c b/src/eplugin/e-kolab-plugin-ui.c
index 5d69c5c..152d711 100644
--- a/src/eplugin/e-kolab-plugin-ui.c
+++ b/src/eplugin/e-kolab-plugin-ui.c
@@ -43,6 +43,7 @@
 #include <mail/em-config.h>
 #include <mail/em-folder-tree.h>
 
+#include <libekolab/camel-kolab-imapx-store.h>
 #include <libekolab/kolab-data-imap-account.h>
 #include <libekolab/kolab-util-backend.h>
 #include <libekolab/e-source-kolab-folder.h>
@@ -272,48 +273,81 @@ kolab_plugin_ui_get_selected_source (EShellView *shell_view,
 	return is_kolab;
 }
 
-static gchar*
-kolab_plugin_ui_path_from_mail_view (EShellView *shell_view,
-                                     gboolean *is_kolab_account_node,
-                                     gboolean *is_kolab_folder_node)
+static gboolean
+kolab_plugin_ui_store_from_mail_view (EShellView *shell_view,
+                                      CamelKolabIMAPXStore **kstore,
+                                      gchar **selected_path)
 {
 	EShellSidebar *shell_sidebar = NULL;
 	EMFolderTree *folder_tree = NULL;
-	CamelStore *selected_store = NULL;
+	CamelStore *store = NULL;
 	CamelProvider *provider = NULL;
-	gchar *selected_path = NULL;
+	gchar *path = NULL;
 	gboolean have_sel = FALSE;
+	gboolean ok = FALSE;
 
-	g_assert (E_IS_SHELL_VIEW (shell_view));
+	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
+	g_return_val_if_fail (kstore != NULL && *kstore == NULL, FALSE);
+	g_return_val_if_fail (selected_path != NULL && *selected_path == NULL, FALSE);
 
 	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
+	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), FALSE);
+
 	g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
+	g_return_val_if_fail (EM_IS_FOLDER_TREE (folder_tree), FALSE);
 
-	have_sel = (em_folder_tree_get_selected (folder_tree, &selected_store, &selected_path) ||
-	            em_folder_tree_store_root_selected (folder_tree, &selected_store));
+	have_sel = (em_folder_tree_get_selected (folder_tree, &store, &path) ||
+	            em_folder_tree_store_root_selected (folder_tree, &store));
 
 	if (! have_sel)
 		goto exit;
 
-	if (selected_store == NULL)
+	if (store == NULL)
 		goto exit;
 
-	provider = camel_service_get_provider (CAMEL_SERVICE (selected_store));
+	provider = camel_service_get_provider (CAMEL_SERVICE (store));
 
 	if (provider == NULL)
-		goto skip;
+		goto exit;
 
-	if (g_ascii_strcasecmp (provider->protocol, KOLAB_CAMEL_PROVIDER_PROTOCOL) == 0) {
-		*is_kolab_account_node = !selected_path || !*selected_path;
-		*is_kolab_folder_node = !*is_kolab_account_node;
+	if (g_ascii_strcasecmp (provider->protocol, KOLAB_CAMEL_PROVIDER_PROTOCOL) == 0)
+		ok = TRUE;
+ exit:
+	if (ok) {
+		*selected_path = path;
+		*kstore = CAMEL_KOLAB_IMAPX_STORE (store);
+	} else {
+		if (path != NULL)
+			g_free (path);
+		if (store != NULL)
+			g_object_unref (store);
 	}
 
- skip:
-	g_object_unref (selected_store);
-
- exit:
 	g_object_unref (folder_tree);
 
+	return ok;
+}
+
+static gchar*
+kolab_plugin_ui_path_from_mail_view (EShellView *shell_view,
+                                     gboolean *is_kolab_account_node,
+                                     gboolean *is_kolab_folder_node)
+{
+	CamelKolabIMAPXStore *kstore = NULL;
+	gchar *selected_path = NULL;
+	gboolean have_kolab = FALSE;
+
+	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), FALSE);
+
+	have_kolab = kolab_plugin_ui_store_from_mail_view (shell_view,
+	                                                   &kstore,
+	                                                   &selected_path);
+	if (have_kolab) {
+		*is_kolab_account_node = !selected_path || !*selected_path;
+		*is_kolab_folder_node = !*is_kolab_account_node;
+		g_object_unref (kstore);
+	}
+
 	return selected_path;
 }
 



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