[evolution-kolab] EPlugin: added EShellView utility functions to e-kolab-plugin-util.[hc]
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab] EPlugin: added EShellView utility functions to e-kolab-plugin-util.[hc]
- Date: Fri, 3 Aug 2012 16:44:45 +0000 (UTC)
commit 92c0fbd8eb4272e32b2bd0027f73b5931b1a82ff
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Fri Aug 3 18:03:43 2012 +0200
EPlugin: added EShellView utility functions to e-kolab-plugin-util.[hc]
* these functions originate from e-kolab-plugin-ui.c,
but are of more general utility (e.g. for the METADATA
and ACL editor tabs / popups)
src/eplugin/e-kolab-plugin-util.c | 259 ++++++++++++++++++++++++++++++++++++-
src/eplugin/e-kolab-plugin-util.h | 24 ++++
2 files changed, 282 insertions(+), 1 deletions(-)
---
diff --git a/src/eplugin/e-kolab-plugin-util.c b/src/eplugin/e-kolab-plugin-util.c
index 1ef8bd5..2d8a73f 100644
--- a/src/eplugin/e-kolab-plugin-util.c
+++ b/src/eplugin/e-kolab-plugin-util.c
@@ -30,6 +30,18 @@
#include <glib/gi18n-lib.h>
+#include <mail/em-config.h>
+#include <mail/em-folder-tree.h>
+
+#include <shell/e-shell-sidebar.h>
+#include <shell/e-shell-view.h>
+#include <shell/e-shell-window.h>
+
+#include <libedataserverui/libedataserverui.h>
+
+#include <libekolab/e-source-kolab-folder.h>
+#include <libekolabutil/kolab-util-camel.h>
+
#include "e-kolab-plugin-util.h"
/*----------------------------------------------------------------------------*/
@@ -39,6 +51,68 @@
/*----------------------------------------------------------------------------*/
/* internal statics (UI) */
+static gchar*
+kolab_plugin_util_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_assert (E_IS_SHELL_VIEW (shell_view));
+
+ have_kolab = e_kolab_plugin_util_ui_get_selected_store (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;
+}
+
+static gchar*
+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;
+ ESource *source = NULL;
+ ESourceResource *resource = NULL;
+ gboolean is_source = FALSE;
+
+ g_assert (E_IS_SHELL_VIEW (shell_view));
+
+ *is_kolab_account_node = FALSE;
+ *is_kolab_folder_node = FALSE;
+
+ is_source = e_kolab_plugin_util_ui_get_selected_source (shell_view,
+ &source);
+ if (! is_source)
+ goto exit;
+
+ if (! e_source_has_extension (source,
+ E_SOURCE_EXTENSION_KOLAB_FOLDER))
+ 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);
+
+ if (selected_path == NULL)
+ g_warning ("%s()[%u] selected path is NULL", __func__, __LINE__);
+ *is_kolab_folder_node = TRUE;
+
+ exit:
+ return selected_path;
+}
/*----------------------------------------------------------------------------*/
/* API functions (non-UI) */
@@ -76,7 +150,7 @@ e_kolab_plugin_util_ui_selected_folder_widget (const gchar *foldername,
gchar *labeltext = NULL;
gint row = 0;
- g_assert (foldername != NULL);
+ g_return_val_if_fail (foldername != NULL, NULL);
/* sourcname may be NULL */
grid = GTK_GRID (gtk_grid_new ());
@@ -116,4 +190,187 @@ e_kolab_plugin_util_ui_selected_folder_widget (const gchar *foldername,
return GTK_WIDGET (grid);
}
+gboolean
+e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
+ ESource **selected_source)
+{
+ ESource *source = NULL;
+ EShellSidebar *shell_sidebar = NULL;
+ ESourceSelector *selector = NULL;
+ ESourceBackend *extension = NULL;
+ const gchar *extension_name = NULL;
+ const gchar *backend_name = NULL;
+ gboolean is_kolab = FALSE;
+
+ g_return_val_if_fail (shell_view != NULL, FALSE);
+ g_return_val_if_fail (selected_source == NULL || *selected_source == NULL, FALSE);
+
+ shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
+ g_return_val_if_fail (shell_sidebar != NULL, FALSE);
+
+ g_object_get (shell_sidebar, "selector", &selector, NULL);
+ g_return_val_if_fail (selector != NULL, FALSE);
+
+ source = e_source_selector_ref_primary_selection (selector);
+ if (source == NULL)
+ goto exit;
+
+ extension_name = e_source_selector_get_extension_name (selector);
+ if (extension_name == NULL)
+ goto exit;
+
+ extension = e_source_get_extension (source, extension_name);
+ if (extension == NULL)
+ goto exit;
+
+ backend_name = e_source_backend_get_backend_name (extension);
+ if (backend_name == NULL)
+ goto exit;
+
+ /* check whether we have a Kolab ESource selected */
+ is_kolab = g_str_has_prefix (backend_name, KOLAB_CAMEL_PROVIDER_PROTOCOL);
+
+ exit:
+ g_object_unref (selector);
+
+ if (selected_source)
+ *selected_source = source;
+ else if (source)
+ g_object_unref (source);
+
+ return is_kolab;
+}
+
+gboolean
+e_kolab_plugin_util_ui_get_selected_store (EShellView *shell_view,
+ CamelKolabIMAPXStore **kstore,
+ gchar **selected_path)
+{
+ EShellSidebar *shell_sidebar = NULL;
+ EMFolderTree *folder_tree = NULL;
+ CamelStore *store = NULL;
+ CamelProvider *provider = NULL;
+ gchar *path = NULL;
+ gboolean have_sel = FALSE;
+ gboolean ok = FALSE;
+
+ 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, &store, &path) ||
+ em_folder_tree_store_root_selected (folder_tree, &store));
+
+ if (! have_sel)
+ goto exit;
+
+ if (store == NULL)
+ goto exit;
+
+ provider = camel_service_get_provider (CAMEL_SERVICE (store));
+
+ if (provider == NULL)
+ goto exit;
+
+ 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);
+ }
+
+ g_object_unref (folder_tree);
+
+ return ok;
+}
+
+gchar*
+e_kolab_plugin_util_ui_get_selected_path (EShellView *shell_view,
+ gboolean *is_kolab_account_node,
+ gboolean *is_kolab_folder_node)
+{
+ 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);
+
+ if (g_strcmp0 (view_name, "mail") == 0)
+ sel_path = kolab_plugin_util_ui_path_from_mail_view (shell_view,
+ is_kolab_account_node,
+ is_kolab_folder_node);
+ else
+ sel_path = kolab_plugin_util_ui_path_from_pim_view (shell_view,
+ is_kolab_account_node,
+ is_kolab_folder_node);
+ return sel_path;
+}
+
+gchar*
+e_kolab_plugin_util_ui_get_selected_sourcename (EShellView *shell_view)
+{
+ ESource *source = NULL;
+ gboolean is_source = FALSE;
+ const gchar *view_name = NULL;
+ gchar *sourcename = NULL;
+
+ g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
+
+ view_name = e_shell_view_get_name (shell_view);
+ if (g_strcmp0 (view_name, "mail") == 0)
+ return NULL;
+
+ is_source = e_kolab_plugin_util_ui_get_selected_source (shell_view,
+ &source);
+ if (is_source) {
+ sourcename = e_source_dup_uid (source);
+ g_object_unref (source);
+ }
+
+ return sourcename;
+}
+
+gchar*
+e_kolab_plugin_util_ui_get_selected_foldername (EShellView *shell_view)
+{
+ gchar *foldername = NULL;
+ gboolean is_kolab_account_node = FALSE;
+ gboolean is_kolab_folder_node = FALSE;
+
+ g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
+
+ foldername = e_kolab_plugin_util_ui_get_selected_path (shell_view,
+ &is_kolab_account_node,
+ &is_kolab_folder_node);
+
+ g_return_val_if_fail (foldername != NULL, NULL);
+
+ if (is_kolab_account_node || (! is_kolab_folder_node)) {
+ if (foldername != NULL)
+ g_free (foldername);
+ return NULL;
+ }
+
+ return foldername;
+}
+
/*----------------------------------------------------------------------------*/
diff --git a/src/eplugin/e-kolab-plugin-util.h b/src/eplugin/e-kolab-plugin-util.h
index 6679162..1d7b2cf 100644
--- a/src/eplugin/e-kolab-plugin-util.h
+++ b/src/eplugin/e-kolab-plugin-util.h
@@ -34,6 +34,10 @@
#include <glib.h>
#include <gtk/gtk.h>
+#include <shell/e-shell-view.h>
+
+#include <libekolab/camel-kolab-imapx-store.h>
+
/*----------------------------------------------------------------------------*/
GtkWidget*
@@ -44,6 +48,26 @@ GtkWidget*
e_kolab_plugin_util_ui_selected_folder_widget (const gchar *foldername,
const gchar *sourcename);
+gboolean
+e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
+ ESource **selected_source);
+
+gboolean
+e_kolab_plugin_util_ui_get_selected_store (EShellView *shell_view,
+ CamelKolabIMAPXStore **kstore,
+ gchar **selected_path);
+
+gchar*
+e_kolab_plugin_util_ui_get_selected_path (EShellView *shell_view,
+ gboolean *is_kolab_account_node,
+ gboolean *is_kolab_folder_node);
+
+gchar*
+e_kolab_plugin_util_ui_get_selected_sourcename (EShellView *shell_view);
+
+gchar*
+e_kolab_plugin_util_ui_get_selected_foldername (EShellView *shell_view);
+
/*----------------------------------------------------------------------------*/
#endif /* _E_KOLAB_PLUGIN_UTIL_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]