[evolution-kolab] EPlugin: new util functions for getting type and context from shell view



commit 5ec808d7d3f7e03e58cdea38477ab787ff15ef67
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Oct 19 19:09:20 2012 +0200

    EPlugin: new util functions for getting type and context from shell view
    
    * when operating on PIM sources, we need to deduce
      the KolabFolderTypeID and KolabFolderContextID
      from the EShellView, since we cannot ask our
      CamelKolabIMAPXStore in the PIM context

 src/eplugin/e-kolab-plugin-util.c |   74 ++++++++++++++++++++++++++++---------
 src/eplugin/e-kolab-plugin-util.h |    6 +++
 2 files changed, 62 insertions(+), 18 deletions(-)
---
diff --git a/src/eplugin/e-kolab-plugin-util.c b/src/eplugin/e-kolab-plugin-util.c
index e290f8e..428e6ea 100644
--- a/src/eplugin/e-kolab-plugin-util.c
+++ b/src/eplugin/e-kolab-plugin-util.c
@@ -91,7 +91,7 @@ kolab_plugin_util_ui_path_from_pim_view (EShellView *shell_view,
                                          gboolean *is_kolab_account_node,
                                          gboolean *is_kolab_folder_node)
 {
-	gchar *selected_path = NULL;
+	const gchar *selected_path = NULL;
 	ESource *source = NULL;
 	ESourceResource *resource = NULL;
 	gboolean is_source = FALSE;
@@ -106,24 +106,26 @@ kolab_plugin_util_ui_path_from_pim_view (EShellView *shell_view,
 	if (! is_source)
 		goto exit;
 
-	if (! e_source_has_extension (source,
-	                              E_SOURCE_EXTENSION_KOLAB_FOLDER))
+	if (! e_source_has_extension (source, E_SOURCE_EXTENSION_KOLAB_FOLDER)) {
+		g_warning ("%s()[%u] ESource of Kolab backend has no Kolab Folder Extension",
+		           __func__, __LINE__);
 		goto exit;
+	}
 
 	resource = E_SOURCE_RESOURCE (e_source_get_extension (source,
 	                                                      E_SOURCE_EXTENSION_KOLAB_FOLDER));
 
-	g_object_get (G_OBJECT (resource),
-	              "id",
-	              &selected_path,
-	              NULL);
+	selected_path = e_source_resource_get_identity (resource);
 
-	if (selected_path == NULL)
+	if (selected_path == NULL) {
 		g_warning ("%s()[%u] selected path is NULL", __func__, __LINE__);
+		goto exit;
+	}
+
 	*is_kolab_folder_node = TRUE;
 
  exit:
-	return selected_path;
+	return g_strdup (selected_path);
 }
 
 /*----------------------------------------------------------------------------*/
@@ -292,6 +294,47 @@ e_kolab_plugin_util_ui_dialog_set_button_sensitive (GtkDialog *dialog,
 	g_object_unref (btn);
 }
 
+KolabFolderTypeID
+e_kolab_plugin_util_ui_get_shell_type (EShellView *shell_view)
+{
+	KolabFolderTypeID ftype = KOLAB_FOLDER_TYPE_INVAL;
+	const gchar *vname = NULL;
+
+	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), KOLAB_FOLDER_TYPE_INVAL);
+
+	vname = e_shell_view_get_name (shell_view);
+	g_return_val_if_fail (vname != NULL, KOLAB_FOLDER_TYPE_INVAL);
+
+	if (g_strcmp0 (vname, "mail") == 0)
+		ftype = KOLAB_FOLDER_TYPE_EMAIL;
+	else if (g_strcmp0 (vname, "addressbook") == 0)
+		ftype = KOLAB_FOLDER_TYPE_CONTACT;
+	else if (g_strcmp0 (vname, "calendar") == 0)
+		ftype = KOLAB_FOLDER_TYPE_EVENT;
+	else if (g_strcmp0 (vname, "tasks") == 0)
+		ftype = KOLAB_FOLDER_TYPE_TASK;
+	else if (g_strcmp0 (vname, "memos") == 0)
+		ftype = KOLAB_FOLDER_TYPE_NOTE;
+	else
+		ftype = KOLAB_FOLDER_TYPE_INVAL;
+
+	return ftype;
+}
+
+KolabFolderContextID
+e_kolab_plugin_util_ui_get_shell_context (EShellView *shell_view)
+{
+	KolabFolderContextID context = KOLAB_FOLDER_CONTEXT_INVAL;
+	KolabFolderTypeID ftype = KOLAB_FOLDER_TYPE_INVAL;
+
+	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), KOLAB_FOLDER_CONTEXT_INVAL);
+
+	ftype = e_kolab_plugin_util_ui_get_shell_type (shell_view);
+	context = kolab_util_folder_type_map_to_context_id (ftype);
+
+	return context;
+}
+
 gboolean
 e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
                                             ESource **selected_source)
@@ -409,20 +452,15 @@ e_kolab_plugin_util_ui_get_selected_path (EShellView *shell_view,
                                           gboolean *is_kolab_folder_node,
                                           GError **err)
 {
+	KolabFolderContextID context = KOLAB_FOLDER_CONTEXT_INVAL;
 	gchar *sel_path = NULL;
-	const gchar *view_name = NULL;
 
 	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
 
-	/* TODO find a cleaner solution for this.
-	 *
-	 * Since it seems we cannot directly check for
-	 * the EShellView subtype, we use the view name
-	 * property to tell the types apart...
-	 */
-	view_name = e_shell_view_get_name (shell_view);
+	context = e_kolab_plugin_util_ui_get_shell_context (shell_view);
+	g_return_val_if_fail (context != KOLAB_FOLDER_CONTEXT_INVAL, NULL);
 
-	if (g_strcmp0 (view_name, "mail") == 0)
+	if (context == KOLAB_FOLDER_CONTEXT_EMAIL)
 		sel_path = kolab_plugin_util_ui_path_from_mail_view (shell_view,
 		                                                     is_kolab_account_node,
 		                                                     is_kolab_folder_node,
diff --git a/src/eplugin/e-kolab-plugin-util.h b/src/eplugin/e-kolab-plugin-util.h
index 9cfea5b..c206a4f 100644
--- a/src/eplugin/e-kolab-plugin-util.h
+++ b/src/eplugin/e-kolab-plugin-util.h
@@ -64,6 +64,12 @@ e_kolab_plugin_util_ui_dialog_set_button_sensitive (GtkDialog *dialog,
                                                     gboolean stock_check,
                                                     gboolean sensitive);
 
+KolabFolderTypeID
+e_kolab_plugin_util_ui_get_shell_type (EShellView *shell_view);
+
+KolabFolderContextID
+e_kolab_plugin_util_ui_get_shell_context (EShellView *shell_view);
+
 gboolean
 e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
                                             ESource **selected_source);



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