[evolution-kolab/ek-wip-gui: 9/22] EPlugin: added infrastructure for mail/pim folder context menus
- From: Christian Hilberg <chilberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-kolab/ek-wip-gui: 9/22] EPlugin: added infrastructure for mail/pim folder context menus
- Date: Mon, 20 Feb 2012 23:25:32 +0000 (UTC)
commit b3f677799074f2bfcfe570676c273491e8116355
Author: Christian Hilberg <hilberg kernelconcepts de>
Date: Mon Feb 13 16:43:27 2012 +0100
EPlugin: added infrastructure for mail/pim folder context menus
* added context menu entries for Kolab mail folders
and Kolab pim folders
* added entries: "Permissions..." and "Metadata..."
* added callback paths which end in the same functions
for mail and PIM (one function for folder permissions,
one for metadata)
src/eplugin/e-kolab-plugin-ui.c | 400 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 390 insertions(+), 10 deletions(-)
---
diff --git a/src/eplugin/e-kolab-plugin-ui.c b/src/eplugin/e-kolab-plugin-ui.c
index c6ffab3..43e93a2 100644
--- a/src/eplugin/e-kolab-plugin-ui.c
+++ b/src/eplugin/e-kolab-plugin-ui.c
@@ -28,10 +28,387 @@
#include <config.h>
+#include <glib/gi18n-lib.h>
+
+#include <libedataserverui/e-source-selector.h>
+
+#include <e-util/e-util.h>
+#include <e-util/e-dialog-utils.h>
+#include <e-util/e-plugin-ui.h>
+
+#include <shell/e-shell-sidebar.h>
+#include <shell/e-shell-view.h>
+#include <shell/e-shell-window.h>
+
+#include <mail/em-config.h>
+#include <mail/em-folder-tree.h>
+
+#include <libekolabutil/kolab-util-camel.h>
+#include <libekolabutil/kolab-util-types.h>
+
#include "e-kolab-plugin-ui.h"
/*----------------------------------------------------------------------------*/
+/* how many menu entries are defined; all calendar/tasks/memos/contacts
+ actions should have same count */
+#define KOLAB_ESOURCE_NUM_ENTRIES 2
+
+static void kolab_plugin_ui_action_folder_permissions_cb (GtkAction *action, EShellView *shell_view);
+static void kolab_plugin_ui_action_folder_metadata_cb (GtkAction *action, EShellView *shell_view);
+
+static GtkActionEntry mail_folder_context_entries[] = {
+ { "kolab-mail-folder-permissions",
+ "folder-new",
+ N_("Permissions..."),
+ NULL,
+ N_("Edit Kolab mail folder permissions"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_permissions_cb) },
+
+ { "kolab-mail-folder-metadata",
+ "folder-new",
+ N_("Metadata..."),
+ NULL,
+ N_("Edit Kolab mail folder metadata"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_metadata_cb) }
+};
+
+static GtkActionEntry calendar_context_entries[] = {
+
+ { "kolab-calendar-folder-permissions",
+ "folder-new",
+ N_("Permissions..."),
+ NULL,
+ N_("Edit Kolab calendar permissions"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_permissions_cb) },
+
+ { "kolab-calendar-folder-metadata",
+ "folder-new",
+ N_("Metadata..."),
+ NULL,
+ N_("Edit Kolab calendar metadata"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_metadata_cb) }
+};
+
+static GtkActionEntry memos_context_entries[] = {
+
+ { "kolab-memos-folder-permissions",
+ "folder-new",
+ N_("Permissions..."),
+ NULL,
+ N_("Edit Kolab memos permissions"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_permissions_cb) },
+
+ { "kolab-memos-folder-metadata",
+ "folder-new",
+ N_("Metadata..."),
+ NULL,
+ N_("Edit Kolab memos metadata"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_metadata_cb) }
+};
+
+static GtkActionEntry tasks_context_entries[] = {
+
+ { "kolab-tasks-folder-permissions",
+ "folder-new",
+ N_("Permissions..."),
+ NULL,
+ N_("Edit Kolab tasks permissions"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_permissions_cb) },
+
+ { "kolab-tasks-folder-metadata",
+ "folder-new",
+ N_("Metadata..."),
+ NULL,
+ N_("Edit Kolab tasks metadata"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_metadata_cb) }
+};
+
+static GtkActionEntry contacts_context_entries[] = {
+
+ { "kolab-contacts-folder-permissions",
+ "folder-new",
+ N_("Permissions..."),
+ NULL,
+ N_("Edit Kolab contacts permissions"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_permissions_cb) },
+
+ { "kolab-contacts-folder-metadata",
+ "folder-new",
+ N_("Metadata..."),
+ NULL,
+ N_("Edit Kolab contacts metadata"),
+ G_CALLBACK (kolab_plugin_ui_action_folder_metadata_cb) }
+};
+
+/*----------------------------------------------------------------------------*/
+/* internal statics (non-UI) */
+
+
+/*----------------------------------------------------------------------------*/
+/* internal statics (UI) */
+
+static void
+kolab_plugin_ui_action_folder_permissions_cb (GtkAction *action,
+ EShellView *shell_view)
+{
+ g_assert (action != NULL);
+ g_assert (E_IS_SHELL_VIEW (shell_view));
+
+ /* FIXME implement me */
+ g_warning ("%s: FIXME implement me", __func__);
+}
+
+static void
+kolab_plugin_ui_action_folder_metadata_cb (GtkAction *action,
+ EShellView *shell_view)
+{
+ g_assert (action != NULL);
+ g_assert (E_IS_SHELL_VIEW (shell_view));
+
+ /* FIXME implement me */
+ g_warning ("%s: FIXME implement me", __func__);
+}
+
+static gboolean
+kolab_plugin_ui_get_selected_source (EShellView *shell_view,
+ ESource **selected_source)
+{
+ ESource *source;
+ gchar *uri = NULL;
+ EShellSidebar *shell_sidebar;
+ ESourceSelector *selector = NULL;
+
+ 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_peek_primary_selection (selector);
+ uri = source ? e_source_get_uri (source) : NULL;
+ /* check whether we have a Kolab ESource selected */
+ if (uri && g_str_has_prefix (uri, KOLAB_URI_PREFIX))
+ source = g_object_ref (source);
+ else
+ source = NULL;
+
+ g_free (uri);
+ g_object_unref (selector);
+
+ if (selected_source)
+ *selected_source = source;
+ else if (source)
+ g_object_unref (source);
+
+ return source != NULL;
+}
+
+static void
+kolab_plugin_ui_enable_actions (GtkActionGroup *action_group,
+ const GtkActionEntry *entries,
+ guint n_entries,
+ gboolean can_show,
+ gboolean is_online)
+{
+ guint ii = 0;
+
+ g_return_if_fail (action_group != NULL);
+ g_return_if_fail (entries != NULL);
+
+ for (ii = 0; ii < n_entries; ii++) {
+ GtkAction *action;
+
+ action = gtk_action_group_get_action (action_group, entries[ii].name);
+ if (!action)
+ continue;
+
+ gtk_action_set_visible (action, can_show);
+ if (can_show)
+ gtk_action_set_sensitive (action, is_online);
+ }
+}
+
+static void
+kolab_plugin_ui_update_mail_entries_cb (EShellView *shell_view,
+ GtkActionEntry *entries)
+{
+ EShellWindow *shell_window = NULL;
+ GtkActionGroup *action_group = NULL;
+ GtkUIManager *ui_manager = NULL;
+ EShellSidebar *shell_sidebar = NULL;
+ EMFolderTree *folder_tree = NULL;
+ CamelStore *selected_store = NULL;
+ gchar *selected_path = NULL;
+ gboolean is_kolab_account_node = FALSE;
+ gboolean is_kolab_folder_node = FALSE;
+ gboolean is_online = FALSE;
+
+ g_assert (E_IS_SHELL_VIEW (shell_view));
+ g_assert (entries != NULL);
+
+ shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
+ g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
+ if (em_folder_tree_get_selected (folder_tree, &selected_store, &selected_path) ||
+ em_folder_tree_store_root_selected (folder_tree, &selected_store)) {
+ if (selected_store) {
+ CamelProvider *provider = camel_service_get_provider (CAMEL_SERVICE (selected_store));
+
+ if (provider && 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;
+ }
+
+ g_object_unref (selected_store);
+ }
+ }
+ g_object_unref (folder_tree);
+
+ g_free (selected_path);
+
+ shell_window = e_shell_view_get_shell_window (shell_view);
+ ui_manager = e_shell_window_get_ui_manager (shell_window);
+ action_group = e_lookup_action_group (ui_manager, "mail");
+
+ if (is_kolab_account_node || is_kolab_folder_node) {
+ EShellBackend *backend = NULL;
+ CamelSession *session = NULL;
+
+ backend = e_shell_view_get_shell_backend (shell_view);
+ g_object_get (G_OBJECT (backend), "session", &session, NULL);
+
+ is_online = session && camel_session_get_online (session);
+
+ if (session)
+ g_object_unref (session);
+ }
+
+ kolab_plugin_ui_enable_actions (action_group,
+ mail_folder_context_entries,
+ G_N_ELEMENTS (mail_folder_context_entries),
+ is_kolab_folder_node,
+ is_online);
+}
+
+static void
+kolab_plugin_ui_update_source_entries_cb (EShellView *shell_view,
+ GtkActionEntry *entries)
+{
+ GtkActionGroup *action_group = NULL;
+ EShell *shell = NULL;
+ EShellWindow *shell_window = NULL;
+ const gchar *group = NULL;
+ gboolean is_kolab_source = FALSE;
+ gboolean is_online = FALSE;
+
+ g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+ g_return_if_fail (entries != NULL);
+
+ if (strstr (entries->name, "calendar") != NULL)
+ group = "tasks";
+ else if (strstr (entries->name, "tasks") != NULL)
+ group = "tasks";
+ else if (strstr (entries->name, "memos") != NULL)
+ group = "memos";
+ else if (strstr (entries->name, "contacts") != NULL)
+ group = "contacts";
+ else
+ g_return_if_reached ();
+
+ is_kolab_source = kolab_plugin_ui_get_selected_source (shell_view, NULL);
+ shell_window = e_shell_view_get_shell_window (shell_view);
+ shell = e_shell_window_get_shell (shell_window);
+
+ /* this is a shortcut. we should actually query
+ * the online state from the backend
+ */
+ is_online = shell && e_shell_get_online (shell);
+ action_group = e_shell_window_get_action_group (shell_window, group);
+
+ kolab_plugin_ui_enable_actions (action_group,
+ entries,
+ KOLAB_ESOURCE_NUM_ENTRIES,
+ is_kolab_source,
+ is_online);
+
+ g_object_unref (action_group);
+}
+
+static void
+kolab_plugin_ui_setup_mail_actions (EShellView *shell_view)
+{
+ EShellWindow *shell_window;
+ GtkActionGroup *action_group;
+
+ g_assert (E_IS_SHELL_VIEW (shell_view));
+
+ shell_window = e_shell_view_get_shell_window (shell_view);
+ action_group = e_shell_window_get_action_group (shell_window, "mail");
+
+ /* Add actions to the "mail" action group. */
+ e_action_group_add_actions_localized (action_group,
+ GETTEXT_PACKAGE,
+ mail_folder_context_entries,
+ G_N_ELEMENTS (mail_folder_context_entries),
+ shell_view);
+
+ /* Decide whether we want this option to be visible or not */
+ g_signal_connect (shell_view,
+ "update-actions",
+ G_CALLBACK (kolab_plugin_ui_update_mail_entries_cb),
+ shell_view);
+
+ g_object_unref (action_group);
+}
+
+static void
+kolab_plugin_ui_setup_source_actions (EShellView *shell_view,
+ GtkActionEntry *entries,
+ guint n_entries)
+{
+ EShellWindow *shell_window;
+ const gchar *group;
+
+ g_assert (E_IS_SHELL_VIEW (shell_view));
+ g_return_if_fail (entries != NULL);
+ g_return_if_fail (n_entries > 0);
+ g_return_if_fail (n_entries == KOLAB_ESOURCE_NUM_ENTRIES);
+
+ if (strstr (entries->name, "calendar"))
+ group = "calendar";
+ else if (strstr (entries->name, "tasks"))
+ group = "tasks";
+ else if (strstr (entries->name, "memos"))
+ group = "memos";
+ else if (strstr (entries->name, "contacts"))
+ group = "contacts";
+ else
+ g_return_if_reached ();
+
+ shell_window = e_shell_view_get_shell_window (shell_view);
+
+ e_action_group_add_actions_localized (e_shell_window_get_action_group (shell_window, group),
+ GETTEXT_PACKAGE,
+ entries,
+ KOLAB_ESOURCE_NUM_ENTRIES,
+ shell_view);
+
+ g_signal_connect (shell_view,
+ "update-actions",
+ G_CALLBACK (kolab_plugin_ui_update_source_entries_cb),
+ entries);
+}
+
+/*----------------------------------------------------------------------------*/
+/* API functions (non-UI) */
+
+
+/*----------------------------------------------------------------------------*/
+/* API functions (UI) */
+
gboolean
e_kolab_plugin_ui_init_mail (GtkUIManager *ui_manager,
EShellView *shell_view)
@@ -39,8 +416,7 @@ e_kolab_plugin_ui_init_mail (GtkUIManager *ui_manager,
g_assert (GTK_IS_UI_MANAGER (ui_manager));
g_assert (E_IS_SHELL_VIEW (shell_view));
- g_debug ("%s: called.", __func__);
-
+ kolab_plugin_ui_setup_mail_actions (shell_view);
return TRUE;
}
@@ -51,8 +427,9 @@ e_kolab_plugin_ui_init_calendar (GtkUIManager *ui_manager,
g_assert (GTK_IS_UI_MANAGER (ui_manager));
g_assert (E_IS_SHELL_VIEW (shell_view));
- g_debug ("%s: called.", __func__);
-
+ kolab_plugin_ui_setup_source_actions (shell_view,
+ calendar_context_entries,
+ G_N_ELEMENTS (calendar_context_entries));
return TRUE;
}
@@ -63,8 +440,9 @@ e_kolab_plugin_ui_init_tasks (GtkUIManager *ui_manager,
g_assert (GTK_IS_UI_MANAGER (ui_manager));
g_assert (E_IS_SHELL_VIEW (shell_view));
- g_debug ("%s: called.", __func__);
-
+ kolab_plugin_ui_setup_source_actions (shell_view,
+ tasks_context_entries,
+ G_N_ELEMENTS (tasks_context_entries));
return TRUE;
}
@@ -75,8 +453,9 @@ e_kolab_plugin_ui_init_memos (GtkUIManager *ui_manager,
g_assert (GTK_IS_UI_MANAGER (ui_manager));
g_assert (E_IS_SHELL_VIEW (shell_view));
- g_debug ("%s: called.", __func__);
-
+ kolab_plugin_ui_setup_source_actions (shell_view,
+ memos_context_entries,
+ G_N_ELEMENTS (memos_context_entries));
return TRUE;
}
@@ -87,8 +466,9 @@ e_kolab_plugin_ui_init_contacts (GtkUIManager *ui_manager,
g_assert (GTK_IS_UI_MANAGER (ui_manager));
g_assert (E_IS_SHELL_VIEW (shell_view));
- g_debug ("%s: called.", __func__);
-
+ kolab_plugin_ui_setup_source_actions (shell_view,
+ contacts_context_entries,
+ G_N_ELEMENTS (contacts_context_entries));
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]