[evolution-kolab] EPlugin: add error handling to store getter



commit 4f04d9469a46da8473cc28d2d4e56923c0871b69
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Mon Oct 15 17:33:59 2012 +0200

    EPlugin: add error handling to store getter
    
    * added GError to CamelKolabIMAPXStore getter util
      function
    * propagate the error, adapt users of the getter
      to the new GError param

 src/eplugin/e-kolab-folder-metadata.c    |   26 ++++++--------
 src/eplugin/e-kolab-folder-permissions.c |   57 +++++++++++++++++++++---------
 src/eplugin/e-kolab-plugin-ui.c          |   14 +++++---
 src/eplugin/e-kolab-plugin-util.c        |   39 ++++++++++++++++-----
 src/eplugin/e-kolab-plugin-util.h        |    9 +++--
 5 files changed, 96 insertions(+), 49 deletions(-)
---
diff --git a/src/eplugin/e-kolab-folder-metadata.c b/src/eplugin/e-kolab-folder-metadata.c
index b6e8733..89e11ad 100644
--- a/src/eplugin/e-kolab-folder-metadata.c
+++ b/src/eplugin/e-kolab-folder-metadata.c
@@ -378,24 +378,20 @@ e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *uidata,
 	g_return_val_if_fail (E_IS_SHELL_VIEW (uidata->shell_view), FALSE);
 	g_return_val_if_fail (uidata->metadata != NULL, FALSE);
 
+	/* If we cannot get the store here, it means
+	 * that the store associated with the selected
+	 * path is not a CamelKolabIMAPXStore. This
+	 * should not happen at this point (if the store
+	 * in question is not a Kolab store, then no
+	 * Kolab folder options context menu entry should
+	 * have been shown).
+	 */
 	ok = e_kolab_plugin_util_ui_get_selected_store (uidata->shell_view,
 	                                                &kstore,
-	                                                &selected_path);
-	if (! ok) {
-		/* If we cannot get the store here, it means
-		 * that the store associated with the selected
-		 * path is not a CamelKolabIMAPXStore. This
-		 * should not happen at this point (if the store
-		 * in question is not a Kolab store, then no
-		 * Kolab folder options context menu entry should
-		 * have been shown).
-		 */
-		g_set_error (&tmp_err,
-		             KOLAB_CAMEL_KOLAB_ERROR,
-		             KOLAB_CAMEL_KOLAB_ERROR_GENERIC,
-		             _("Could not get the Kolab store from shell view!"));
+	                                                &selected_path,
+	                                                &tmp_err);
+	if (! ok)
 		goto exit;
-	}
 
 	/* FIXME we have the foldername duped in uidata->foldername */
 	uidata->metadata->foldername = selected_path;
diff --git a/src/eplugin/e-kolab-folder-permissions.c b/src/eplugin/e-kolab-folder-permissions.c
index bd7ecd3..05f2ccc 100644
--- a/src/eplugin/e-kolab-folder-permissions.c
+++ b/src/eplugin/e-kolab-folder-permissions.c
@@ -1012,24 +1012,20 @@ e_kolab_folder_permissions_ui_query_store (KolabFolderPermUIData *uidata,
 	g_return_val_if_fail (uidata->permissions != NULL, FALSE);
 	g_return_val_if_fail (uidata->permissions->acl == NULL, FALSE);
 
+	/* If we cannot get the store here, it means
+	 * that the store associated with the selected
+	 * path is not a CamelKolabIMAPXStore. This
+	 * should not happen at this point (if the store
+	 * in question is not a Kolab store, then no
+	 * Kolab folder options context menu entry should
+	 * have been shown).
+	 */
 	ok = e_kolab_plugin_util_ui_get_selected_store (uidata->shell_view,
 	                                                &kstore,
-	                                                &selected_path);
-	if (! ok) {
-		/* If we cannot get the store here, it means
-		 * that the store associated with the selected
-		 * path is not a CamelKolabIMAPXStore. This
-		 * should not happen at this point (if the store
-		 * in question is not a Kolab store, then no
-		 * Kolab folder options context menu entry should
-		 * have been shown).
-		 */
-		g_set_error (&tmp_err,
-		             KOLAB_CAMEL_KOLAB_ERROR,
-		             KOLAB_CAMEL_KOLAB_ERROR_GENERIC,
-		             _("Could not get the Kolab store from shell view!"));
+	                                                &selected_path,
+	                                                &tmp_err);
+	if (! ok)
 		goto exit;
-	}
 
 	uidata->permissions->acl =
 		camel_kolab_imapx_store_get_folder_permissions (kstore,
@@ -1067,6 +1063,11 @@ e_kolab_folder_permissions_ui_write_store (KolabFolderPermUIData *uidata,
                                            GCancellable *cancellable,
                                            GError **err)
 {
+	CamelKolabIMAPXStore *kstore = NULL;
+	gchar *selected_path = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = FALSE;
+
 	g_return_val_if_fail (uidata != NULL, FALSE);
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
@@ -1077,8 +1078,30 @@ e_kolab_folder_permissions_ui_write_store (KolabFolderPermUIData *uidata,
 	if (! uidata->changed)
 		return TRUE;
 
-	g_warning ("%s: FIXME implement me", __func__);
-	return TRUE;
+	ok = e_kolab_plugin_util_ui_get_selected_store (uidata->shell_view,
+	                                                &kstore,
+	                                                &selected_path,
+	                                                &tmp_err);
+	if (! ok)
+		goto exit;
+
+	if (g_strcmp0 (uidata->foldername, selected_path) != 0)
+		g_warning ("%s()[%u] foldername change: stored '%s' vs. current '%s'",
+		           __func__, __LINE__, uidata->foldername, selected_path);
+
+	ok = camel_kolab_imapx_store_set_folder_permissions (kstore,
+	                                                     uidata->foldername,
+	                                                     uidata->permissions->acl,
+	                                                     cancellable,
+	                                                     &tmp_err);
+ exit:
+
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+
+	return ok;
 }
 
 /*----------------------------------------------------------------------------*/
diff --git a/src/eplugin/e-kolab-plugin-ui.c b/src/eplugin/e-kolab-plugin-ui.c
index d22a840..355fbe7 100644
--- a/src/eplugin/e-kolab-plugin-ui.c
+++ b/src/eplugin/e-kolab-plugin-ui.c
@@ -297,11 +297,13 @@ kolab_folder_prop_ui_dialog_data_new (EShellView *shell_view)
 	KolabFolderPropUIData *uidata = NULL;
 	gchar *foldername = NULL;
 	gchar *sourcename = NULL;
+	GError *tmp_err = NULL;
 
 	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
 
-	foldername = e_kolab_plugin_util_ui_get_selected_foldername (shell_view);
-	if (foldername == NULL) {
+	foldername = e_kolab_plugin_util_ui_get_selected_foldername (shell_view,
+	                                                             &tmp_err);
+	if (tmp_err != NULL) {
 		/* TODO this should not happen.
 		 *
 		 * If the selected folder is NULL here, it means
@@ -309,8 +311,9 @@ kolab_folder_prop_ui_dialog_data_new (EShellView *shell_view)
 		 * be a context menu entry in this case in the
 		 * first place.
 		 */
-		g_warning ("%s()[%u]: Selected folder is no Kolab folder node",
-		           __func__, __LINE__);
+		g_warning ("%s()[%u]: %s",
+		           __func__, __LINE__, tmp_err->message);
+		g_error_free (tmp_err);
 		return NULL;
 	}
 
@@ -572,7 +575,8 @@ kolab_plugin_ui_update_mail_entries_cb (EShellView *shell_view,
 
 	selected_path = e_kolab_plugin_util_ui_get_selected_path (shell_view,
 	                                                          &is_kolab_account_node,
-	                                                          &is_kolab_folder_node);
+	                                                          &is_kolab_folder_node,
+	                                                          NULL);
 	g_free (selected_path);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
diff --git a/src/eplugin/e-kolab-plugin-util.c b/src/eplugin/e-kolab-plugin-util.c
index 5797e52..7d7230b 100644
--- a/src/eplugin/e-kolab-plugin-util.c
+++ b/src/eplugin/e-kolab-plugin-util.c
@@ -40,6 +40,7 @@
 
 #include <libekolab/e-source-kolab-folder.h>
 #include <libekolabutil/kolab-util-camel.h>
+#include <libekolabutil/kolab-util-error.h>
 
 #include "e-kolab-plugin-util.h"
 
@@ -57,17 +58,25 @@
 static gchar*
 kolab_plugin_util_ui_path_from_mail_view (EShellView *shell_view,
                                           gboolean *is_kolab_account_node,
-                                          gboolean *is_kolab_folder_node)
+                                          gboolean *is_kolab_folder_node,
+                                          GError **err)
 {
 	CamelKolabIMAPXStore *kstore = NULL;
 	gchar *selected_path = NULL;
 	gboolean have_kolab = FALSE;
+	GError *tmp_err = NULL;
 
 	g_assert (E_IS_SHELL_VIEW (shell_view));
 
 	have_kolab = e_kolab_plugin_util_ui_get_selected_store (shell_view,
 	                                                        &kstore,
-	                                                        &selected_path);
+	                                                        &selected_path,
+	                                                        &tmp_err);
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		return NULL;
+	}
+
 	if (have_kolab) {
 		*is_kolab_account_node = !selected_path || !*selected_path;
 		*is_kolab_folder_node = !*is_kolab_account_node;
@@ -315,7 +324,8 @@ e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
 gboolean
 e_kolab_plugin_util_ui_get_selected_store (EShellView *shell_view,
                                            CamelKolabIMAPXStore **kstore,
-                                           gchar **selected_path)
+                                           gchar **selected_path,
+                                           GError **err)
 {
 	EShellSidebar *shell_sidebar = NULL;
 	EMFolderTree *folder_tree = NULL;
@@ -356,6 +366,10 @@ e_kolab_plugin_util_ui_get_selected_store (EShellView *shell_view,
 		*selected_path = path;
 		*kstore = CAMEL_KOLAB_IMAPX_STORE (store);
 	} else {
+		g_set_error (err,
+		             KOLAB_CAMEL_KOLAB_ERROR,
+		             KOLAB_CAMEL_KOLAB_ERROR_GENERIC,
+		             _("Could not get the Kolab store from shell view!"));
 		if (path != NULL)
 			g_free (path);
 		if (store != NULL)
@@ -370,7 +384,8 @@ e_kolab_plugin_util_ui_get_selected_store (EShellView *shell_view,
 gchar*
 e_kolab_plugin_util_ui_get_selected_path (EShellView *shell_view,
                                           gboolean *is_kolab_account_node,
-                                          gboolean *is_kolab_folder_node)
+                                          gboolean *is_kolab_folder_node,
+                                          GError **err)
 {
 	gchar *sel_path = NULL;
 	const gchar *view_name = NULL;
@@ -388,7 +403,8 @@ e_kolab_plugin_util_ui_get_selected_path (EShellView *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);
+		                                                     is_kolab_folder_node,
+		                                                     err);
 	else
 		sel_path = kolab_plugin_util_ui_path_from_pim_view (shell_view,
 		                                                    is_kolab_account_node,
@@ -421,19 +437,24 @@ e_kolab_plugin_util_ui_get_selected_sourcename (EShellView *shell_view)
 }
 
 gchar*
-e_kolab_plugin_util_ui_get_selected_foldername (EShellView *shell_view)
+e_kolab_plugin_util_ui_get_selected_foldername (EShellView *shell_view,
+                                                GError **err)
 {
 	gchar *foldername = NULL;
 	gboolean is_kolab_account_node = FALSE;
 	gboolean is_kolab_folder_node = FALSE;
+	GError *tmp_err = NULL;
 
 	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);
+	                                                       &is_kolab_folder_node,
+	                                                       &tmp_err);
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		return NULL;
+	}
 
 	if (is_kolab_account_node || (! is_kolab_folder_node)) {
 		if (foldername != NULL)
diff --git a/src/eplugin/e-kolab-plugin-util.h b/src/eplugin/e-kolab-plugin-util.h
index 497b9a6..6706521 100644
--- a/src/eplugin/e-kolab-plugin-util.h
+++ b/src/eplugin/e-kolab-plugin-util.h
@@ -68,18 +68,21 @@ e_kolab_plugin_util_ui_get_selected_source (EShellView *shell_view,
 gboolean
 e_kolab_plugin_util_ui_get_selected_store (EShellView *shell_view,
                                            CamelKolabIMAPXStore **kstore,
-                                           gchar **selected_path);
+                                           gchar **selected_path,
+                                           GError **err);
 
 gchar*
 e_kolab_plugin_util_ui_get_selected_path (EShellView *shell_view,
                                           gboolean *is_kolab_account_node,
-                                          gboolean *is_kolab_folder_node);
+                                          gboolean *is_kolab_folder_node,
+                                          GError **err);
 
 gchar*
 e_kolab_plugin_util_ui_get_selected_sourcename (EShellView *shell_view);
 
 gchar*
-e_kolab_plugin_util_ui_get_selected_foldername (EShellView *shell_view);
+e_kolab_plugin_util_ui_get_selected_foldername (EShellView *shell_view,
+                                                GError **err);
 
 EAlert*
 e_kolab_plugin_util_ui_alert_new_from_gerror (GError *err);



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