[evolution-kolab] EPlugin: added an EAlertBar to the Kolab Folder Properties dialog



commit a724b87eae84969774ebe59be7f67784a481c459
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Aug 3 18:17:56 2012 +0200

    EPlugin: added an EAlertBar to the Kolab Folder Properties dialog
    
    * errors when editing metadata or access control lists
      will be displayed therein
    * propagate EShellView and EAlertBar to the notebook
      tabs for folder permissions and metadata so they
      can get CamelStore (from EShellView) and dump errors
      for user display
    * removed code now living in e-kolab-plugin-util.c

 src/eplugin/e-kolab-plugin-ui.c |  300 ++++-----------------------------------
 1 files changed, 29 insertions(+), 271 deletions(-)
---
diff --git a/src/eplugin/e-kolab-plugin-ui.c b/src/eplugin/e-kolab-plugin-ui.c
index 152d711..d96d5d4 100644
--- a/src/eplugin/e-kolab-plugin-ui.c
+++ b/src/eplugin/e-kolab-plugin-ui.c
@@ -30,24 +30,15 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <libedataserverui/libedataserverui.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 <misc/e-alert-bar.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>
-#include <libekolabutil/kolab-util-camel.h>
 
 #include "e-kolab-folder-metadata.h"
 #include "e-kolab-folder-permissions.h"
@@ -116,6 +107,7 @@ typedef struct _KolabFolderPropUIWidgets KolabFolderPropUIWidgets;
 struct _KolabFolderPropUIWidgets {
 	GtkWidget *dialog;
 	/* sub-widgets of dialog */
+	GtkWidget *alert_bar;
 	GtkWidget *selected_folder;
 	GtkWidget *notebook;
 };
@@ -126,8 +118,6 @@ struct _KolabFolderPropUIData {
 	KolabFolderMetaUIData *meta_ui_data;
 	KolabFolderPermUIData *perm_ui_data;
 	KolabDataImapAccount *account;
-	gchar *selected_folder;
-	gchar *selected_source;
 };
 
 static void
@@ -151,8 +141,6 @@ kolab_folder_prop_ui_data_new ()
 	uidata->meta_ui_data = NULL;
 	uidata->perm_ui_data = NULL;
 	uidata->account = NULL;
-	uidata->selected_folder = NULL;
-	uidata->selected_source = NULL;
 
 	return uidata;
 }
@@ -172,10 +160,6 @@ kolab_folder_prop_ui_data_free (KolabFolderPropUIData *uidata)
 	e_kolab_folder_metadata_ui_free (uidata->meta_ui_data);
 	e_kolab_folder_permissions_ui_free (uidata->perm_ui_data);
 	kolab_data_imap_account_free (uidata->account);
-	if (uidata->selected_folder != NULL)
-		g_free (uidata->selected_folder);
-	if (uidata->selected_source != NULL)
-		g_free (uidata->selected_source);
 
 	g_free (uidata);
 }
@@ -221,231 +205,6 @@ kolab_folder_prop_ui_response_cb (GObject *dialog,
 /*----------------------------------------------------------------------------*/
 /* internal statics (UI) */
 
-static gboolean
-kolab_plugin_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;
-}
-
-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 *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;
-}
-
-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;
-}
-
-static gchar*
-kolab_plugin_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 = kolab_plugin_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;
-}
-
-static gchar*
-kolab_plugin_ui_get_selected_path (EShellView *shell_view,
-                                   gboolean *is_kolab_account_node,
-                                   gboolean *is_kolab_folder_node)
-{
-	gchar *selected_path = NULL;
-	const gchar *view_name = NULL;
-
-	g_assert (E_IS_SHELL_VIEW (shell_view));
-
-	/* 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)
-		selected_path = kolab_plugin_ui_path_from_mail_view (shell_view,
-		                                                     is_kolab_account_node,
-		                                                     is_kolab_folder_node);
-	else
-		selected_path = kolab_plugin_ui_path_from_pim_view (shell_view,
-		                                                    is_kolab_account_node,
-		                                                    is_kolab_folder_node);
-	return selected_path;
-}
-
-static gchar*
-kolab_plugin_ui_selected_folder_name (GtkAction *action,
-                                      EShellView *shell_view)
-{
-	gchar *foldername = NULL;
-	gboolean is_kolab_account_node = FALSE;
-	gboolean is_kolab_folder_node = FALSE;
-
-	g_assert (action != NULL);
-	g_assert (E_IS_SHELL_VIEW (shell_view));
-
-	foldername = kolab_plugin_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;
-}
-
 static void
 kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
                                             EShellView *shell_view)
@@ -454,12 +213,13 @@ kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
 	GObject *dialog = NULL;
 	GtkWidget *content = NULL;
 	GtkNotebook *notebook = NULL;
-	const gchar *view_name = NULL;
 	gchar *foldername = NULL;
 	gchar *sourcename = NULL;
 
-	foldername = kolab_plugin_ui_selected_folder_name (action,
-	                                                   shell_view);
+	g_return_if_fail (action != NULL);
+	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+
+	foldername = e_kolab_plugin_util_ui_get_selected_foldername (shell_view);
 	if (foldername == NULL) {
 		/* TODO this should not happen.
 		 *
@@ -473,28 +233,15 @@ kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
 		return;
 	}
 
-	view_name = e_shell_view_get_name (shell_view);
-
-	if (g_strcmp0 (view_name, "mail") != 0) {
-		/* get the sourcename for display in dialogs
-		 * if we're in a PIM shell_view
-		 */
-		ESource *source = NULL;
-		gboolean is_source = FALSE;
-
-		is_source = kolab_plugin_ui_get_selected_source (shell_view,
-		                                                 &source);
-		if (is_source)
-			sourcename = e_source_dup_uid (source);
-	}
+	/* sourcename may be NULL */
+	sourcename = e_kolab_plugin_util_ui_get_selected_sourcename (shell_view);
 
 	uidata = kolab_folder_prop_ui_data_new ();
+	uidata->widgets->alert_bar = e_alert_bar_new ();
 
 	uidata->widgets->selected_folder =
 		e_kolab_plugin_util_ui_selected_folder_widget (foldername,
 		                                               sourcename);
-	uidata->selected_folder = foldername;
-	uidata->selected_source = sourcename;
 
 	uidata->widgets->dialog =
 		gtk_dialog_new_with_buttons (_("Edit Kolab Folder Properties..."),
@@ -506,12 +253,20 @@ kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
 	gtk_window_set_resizable (GTK_WINDOW (uidata->widgets->dialog), FALSE);
 
 	uidata->meta_ui_data = e_kolab_folder_metadata_ui_new ();
-	uidata->meta_ui_data->selected_folder = g_strdup (foldername);
-	uidata->meta_ui_data->selected_source = g_strdup (sourcename);
+	uidata->meta_ui_data->shell_view = shell_view;
+	uidata->meta_ui_data->alert_bar = E_ALERT_BAR (uidata->widgets->alert_bar);
+	uidata->meta_ui_data->foldername = g_strdup (foldername);
+	uidata->meta_ui_data->sourcename = g_strdup (sourcename);
 
 	uidata->perm_ui_data = e_kolab_folder_permissions_ui_new ();
-	uidata->perm_ui_data->selected_folder = g_strdup (foldername);
-	uidata->perm_ui_data->selected_source = g_strdup (sourcename);
+	uidata->perm_ui_data->shell_view = shell_view;
+	uidata->perm_ui_data->alert_bar = E_ALERT_BAR (uidata->widgets->alert_bar);
+	uidata->perm_ui_data->foldername = g_strdup (foldername);
+	uidata->perm_ui_data->sourcename = g_strdup (sourcename);
+
+	g_free (foldername);
+	if (sourcename != NULL)
+		g_free (sourcename);
 
 	/* FIXME get account data here */
 	uidata->account = kolab_data_imap_account_new ();
@@ -521,6 +276,7 @@ kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
 	g_object_set_data_full (dialog, E_KOLAB_PROP_DLG_UIDATA, uidata, kolab_folder_prop_ui_data_destroy);
 
 	content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+	gtk_container_add (GTK_CONTAINER (content), uidata->widgets->alert_bar);
 	gtk_container_add (GTK_CONTAINER (content), uidata->widgets->selected_folder);
 	uidata->widgets->notebook = gtk_notebook_new ();
 	notebook = GTK_NOTEBOOK (uidata->widgets->notebook);
@@ -550,7 +306,7 @@ kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
 
 	/* TODO connect signals */
 
-	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
 
 	kolab_folder_prop_ui_widgets_enable (uidata->widgets, FALSE);
 
@@ -559,6 +315,7 @@ kolab_plugin_ui_action_kolab_properties_cb (GtkAction *action,
 	                                   FALSE);
 
 	gtk_widget_show_all (content);
+	gtk_widget_hide (uidata->widgets->alert_bar);
 	gtk_widget_show (uidata->widgets->dialog);
 }
 
@@ -602,9 +359,9 @@ kolab_plugin_ui_update_mail_entries_cb (EShellView *shell_view,
 	g_assert (E_IS_SHELL_VIEW (shell_view));
 	g_assert (entries != NULL);
 
-	selected_path = kolab_plugin_ui_get_selected_path (shell_view,
-	                                                   &is_kolab_account_node,
-	                                                   &is_kolab_folder_node);
+	selected_path = e_kolab_plugin_util_ui_get_selected_path (shell_view,
+	                                                          &is_kolab_account_node,
+	                                                          &is_kolab_folder_node);
 	g_free (selected_path);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
@@ -656,7 +413,8 @@ kolab_plugin_ui_update_source_entries_cb (EShellView *shell_view,
 	else
 		g_return_if_reached ();
 
-	is_kolab_source = kolab_plugin_ui_get_selected_source (shell_view, NULL);
+	is_kolab_source = e_kolab_plugin_util_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);
 



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