[evolution-kolab] CamelKolabIMAPXStore: stubbed in functions for (un)hiding PIM folders



commit de306403abe2e04a59055b8901098924fae27835
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Sep 14 18:50:30 2012 +0200

    CamelKolabIMAPXStore: stubbed in functions for (un)hiding PIM folders
    
    * in order to manipulate folder properties (type, ACL)
      from within Evo, we need to make visible the PIM folders
      in the email view

 src/libekolab/camel-kolab-imapx-store.c |  284 +++++++++++++++++++++++++++++--
 src/libekolab/camel-kolab-imapx-store.h |   18 ++
 2 files changed, 290 insertions(+), 12 deletions(-)
---
diff --git a/src/libekolab/camel-kolab-imapx-store.c b/src/libekolab/camel-kolab-imapx-store.c
index 313de8d..84609b5 100644
--- a/src/libekolab/camel-kolab-imapx-store.c
+++ b/src/libekolab/camel-kolab-imapx-store.c
@@ -72,6 +72,9 @@ struct _CamelKolabIMAPXStorePrivate {
 	GList *folder_names_do_care;
 	CamelKolabImapxMetadata *kmd; /* Kolab metadata (differs from IMAPX metadata!) */
 
+	GList *folder_names_unsubscribe;
+	gboolean show_all_folders;
+
 	gboolean is_initialized;
 };
 
@@ -128,6 +131,9 @@ camel_kolab_imapx_store_init (CamelKolabIMAPXStore *self)
 	/* metadata db and lookup table */
 	priv->kmd = camel_kolab_imapx_metadata_new ();
 
+	priv->folder_names_unsubscribe = NULL;
+	priv->show_all_folders = FALSE;
+
 	priv->is_initialized = FALSE;
 }
 
@@ -169,14 +175,8 @@ camel_kolab_imapx_store_finalize (GObject *object)
 	g_mutex_unlock (&(priv->kolab_finfo_lock));
 	g_mutex_clear (&(priv->kolab_finfo_lock));
 
-	if (priv->folder_names_do_care != NULL) {
-		GList *list_ptr = priv->folder_names_do_care;
-		while (list_ptr != NULL) {
-			g_free (list_ptr);
-			list_ptr = g_list_next (list_ptr);
-		}
-		g_free (priv->folder_names_do_care);
-	}
+	kolab_util_glib_glist_free (priv->folder_names_do_care);
+	kolab_util_glib_glist_free (priv->folder_names_unsubscribe);
 
 	/* Chain up to parent's finalize() method. */
 	G_OBJECT_CLASS (camel_kolab_imapx_store_parent_class)->finalize (object);
@@ -546,8 +546,6 @@ imapx_store_get_folder_info_sync (CamelKolabIMAPXStore *self,
 
 	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
 
-	g_mutex_lock (&(priv->kolab_finfo_lock));
-
 	fi = parent_store_class->get_folder_info_sync (CAMEL_STORE (self),
 	                                               top,
 	                                               flags,
@@ -556,6 +554,11 @@ imapx_store_get_folder_info_sync (CamelKolabIMAPXStore *self,
 	if (tmp_err != NULL)
 		goto exit;
 
+	if (priv->show_all_folders) {
+		k_fi = fi;
+		goto exit;
+	}
+
 	if (fi != NULL) {
 		if (get_all) {
 			k_fi = fi;
@@ -590,11 +593,159 @@ imapx_store_get_folder_info_sync (CamelKolabIMAPXStore *self,
 	if (tmp_err != NULL)
 		g_propagate_error (err, tmp_err);
 
-	g_mutex_unlock (&(priv->kolab_finfo_lock));
-
 	return k_fi;
 }
 
+static gboolean
+imapx_store_show_all_folders (CamelKolabIMAPXStore *self,
+                              GCancellable *cancellable,
+                              GError **err)
+{
+	CamelKolabIMAPXStorePrivate *priv = NULL;
+	CamelFolderInfo *fi = NULL;
+	CamelFolderInfo *k_fi = NULL;
+	CamelStoreGetFolderInfoFlags flags = 0;
+	GError *tmp_err = NULL;
+	gboolean ok = TRUE;
+
+	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
+
+	/* get info tree of all folders */
+	flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE | CAMEL_STORE_FOLDER_INFO_NO_VIRTUAL;
+	fi = parent_store_class->get_folder_info_sync (CAMEL_STORE (self),
+	                                               NULL,
+	                                               flags,
+	                                               cancellable,
+	                                               &tmp_err);
+	if (tmp_err != NULL)
+		goto exit;
+	if (fi == NULL)
+		goto exit;
+
+	/* get info tree of folders which are shown by default,
+	 * according to folder type configuration
+	 */
+	k_fi = imapx_store_folder_info_build_restricted (self,
+	                                                 fi,
+	                                                 TRUE,
+	                                                 cancellable,
+	                                                 &tmp_err);
+	if (tmp_err != NULL)
+		goto exit;
+
+	/* find and show (subscribe) the folders not shown
+	 * by default
+	 */
+	/* FIXME implement me */
+	g_warning ("%s: FIXME implement me", __func__);
+
+ exit:
+	if (fi != NULL)
+		camel_store_free_folder_info (CAMEL_STORE (self), fi);
+	if (k_fi != NULL)
+		camel_store_free_folder_info (CAMEL_STORE (self), k_fi);
+
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+
+	return ok;
+}
+
+static gboolean
+imapx_store_show_pim_only (CamelKolabIMAPXStore *self,
+                           GCancellable *cancellable,
+                           GError **err)
+{
+	CamelKolabIMAPXStorePrivate *priv = NULL;
+	GList *name_ptr = NULL;
+	GList *fi_lst = NULL;
+	GList *fi_ptr = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = TRUE;
+
+	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
+
+	/* if there are no PIM-folders which have been
+	 * subscribed by a previously set show_all, then
+	 * we're done
+	 */
+	if (priv->folder_names_unsubscribe == NULL)
+		return TRUE;
+
+	/* get all folder info first, so we can be sure
+	 * all is well before signaling unsubscription
+	 */
+	name_ptr = priv->folder_names_unsubscribe;
+	while (name_ptr != NULL) {
+		gchar *foldername = NULL;
+		CamelFolderInfo *fi = NULL;
+
+		foldername = (gchar *) name_ptr->data;
+		fi = camel_store_get_folder_info_sync (CAMEL_STORE (self),
+		                                       foldername,
+		                                       CAMEL_STORE_FOLDER_INFO_NO_VIRTUAL,
+		                                       cancellable,
+		                                       &tmp_err);
+		if (tmp_err != NULL)
+			goto exit;
+
+		/* need to keep folder infos in order, otherwise
+		 * we may mess up the Evo side_bar foldertree when
+		 * signaling
+		 */
+		fi_lst = g_list_append (fi_lst, fi);
+
+		name_ptr = g_list_next (name_ptr);
+	}
+
+	/* send the signals to unsubscribe the PIM folders
+	 * subscribed before, so they will vanish again
+	 */
+	fi_ptr = fi_lst;
+	while (fi_ptr != NULL) {
+		CamelFolderInfo *fi = (CamelFolderInfo *) fi_ptr->data;
+		camel_subscribable_folder_unsubscribed (CAMEL_SUBSCRIBABLE (self),
+		                                        fi);
+		fi_ptr = g_list_next (fi_ptr);
+	}
+
+ exit:
+	/* fi_lst is freed here (instead of right while signaling)
+	 * so it is also properly freed in case of errors during
+	 * getting the folder info
+	 */
+	fi_ptr = fi_lst;
+	while (fi_ptr != NULL) {
+		CamelFolderInfo *fi = (CamelFolderInfo *) fi_ptr->data;
+		camel_store_free_folder_info (CAMEL_STORE (self), fi);
+		fi_ptr = g_list_next (fi_ptr);
+	}
+	if (fi_lst != NULL)
+		g_list_free (fi_lst);
+
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+
+	if (ok) {
+		kolab_util_glib_glist_free (priv->folder_names_unsubscribe);
+		priv->folder_names_unsubscribe = NULL;
+	}
+
+	return ok;
+}
+
 /*----------------------------------------------------------------------------*/
 /* class functions */
 
@@ -664,6 +815,7 @@ kolab_imapx_store_get_folder_info_sync (CamelStore *self,
                                         GError **err)
 {
 	CamelKolabIMAPXStore *myself = NULL;
+	CamelKolabIMAPXStorePrivate *priv = NULL;
 	CamelFolderInfo *k_fi = NULL;
 
 	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
@@ -672,6 +824,9 @@ kolab_imapx_store_get_folder_info_sync (CamelStore *self,
 	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
 
 	myself = CAMEL_KOLAB_IMAPX_STORE (self);
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (myself);
+
+	g_mutex_lock (&(priv->kolab_finfo_lock));
 
 	k_fi = imapx_store_get_folder_info_sync (myself,
 	                                         top,
@@ -681,6 +836,8 @@ kolab_imapx_store_get_folder_info_sync (CamelStore *self,
 	                                         cancellable,
 	                                         err);
 
+	g_mutex_unlock (&(priv->kolab_finfo_lock));
+
 	return k_fi;
 }
 
@@ -691,6 +848,7 @@ kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
                                           GCancellable *cancellable,
                                           GError **err)
 {
+	CamelKolabIMAPXStorePrivate *priv = NULL;
 	CamelFolderInfo *k_fi = NULL;
 
 	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
@@ -698,6 +856,10 @@ kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, NULL);
 
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
+
+	g_mutex_lock (&(priv->kolab_finfo_lock));
+
 	k_fi = imapx_store_get_folder_info_sync (self,
 	                                         top,
 	                                         flags,
@@ -706,6 +868,8 @@ kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
 	                                         cancellable,
 	                                         err);
 
+	g_mutex_unlock (&(priv->kolab_finfo_lock));
+
 	return k_fi;
 }
 
@@ -966,6 +1130,67 @@ kolab_imapx_store_resect_folder_list (CamelKolabIMAPXStore *self)
 	return folder_list;
 }
 
+static gboolean
+kolab_imapx_store_get_show_all_folders (CamelKolabIMAPXStore *self)
+{
+	CamelKolabIMAPXStorePrivate *priv = NULL;
+	gboolean show_all = FALSE;
+
+	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
+
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
+
+	g_mutex_lock (&(priv->kolab_finfo_lock));
+
+	show_all = priv->show_all_folders;
+
+	g_mutex_unlock (&(priv->kolab_finfo_lock));
+
+	return show_all;
+}
+
+static gboolean
+kolab_imapx_store_set_show_all_folders (CamelKolabIMAPXStore *self,
+                                        gboolean show_all,
+                                        GCancellable *cancellable,
+                                        GError **err)
+{
+	CamelKolabIMAPXStorePrivate *priv = NULL;
+	GError *tmp_err = NULL;
+	gboolean ok = TRUE;
+
+	g_assert (CAMEL_IS_KOLAB_IMAPX_STORE (self));
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	priv = CAMEL_KOLAB_IMAPX_STORE_PRIVATE (self);
+
+	g_mutex_lock (&(priv->kolab_finfo_lock));
+
+	if (priv->show_all_folders == show_all)
+		goto exit;
+
+	if (show_all)
+		ok = imapx_store_show_all_folders (self,
+		                                   cancellable,
+		                                   &tmp_err);
+	else
+		ok = imapx_store_show_pim_only (self,
+		                                cancellable,
+		                                &tmp_err);
+
+	if (ok)
+		priv->show_all_folders = show_all;
+
+	if (tmp_err != NULL)
+		g_propagate_error (err, tmp_err);
+
+ exit:
+	g_mutex_unlock (&(priv->kolab_finfo_lock));
+
+	return ok;
+}
+
 /*----------------------------------------------------------------------------*/
 /* interface functions */
 
@@ -1185,6 +1410,8 @@ camel_kolab_imapx_store_class_init (CamelKolabIMAPXStoreClass *klass)
 	klass->get_folder_type = kolab_imapx_store_get_folder_type;
 	klass->get_folder_info_online = kolab_imapx_store_get_folder_info_online;
 	klass->resect_folder_list = kolab_imapx_store_resect_folder_list;
+	klass->get_show_all_folders = kolab_imapx_store_get_show_all_folders;
+	klass->set_show_all_folders = kolab_imapx_store_set_show_all_folders;
 }
 
 /*----------------------------------------------------------------------------*/
@@ -1291,5 +1518,38 @@ camel_kolab_imapx_store_resect_folder_list (CamelKolabIMAPXStore *self)
 	return list;
 }
 
+gboolean
+camel_kolab_imapx_store_get_show_all_folders (CamelKolabIMAPXStore *self)
+{
+	CamelKolabIMAPXStoreClass *klass = NULL;
+	gboolean show_all = FALSE;
+
+	g_return_val_if_fail (CAMEL_IS_KOLAB_IMAPX_STORE (self), FALSE);
+
+	klass = CAMEL_KOLAB_IMAPX_STORE_GET_CLASS (self);
+	show_all = klass->get_show_all_folders (self);
+
+	return show_all;
+}
+
+gboolean
+camel_kolab_imapx_store_set_show_all_folders (CamelKolabIMAPXStore *self,
+                                              gboolean show_all,
+                                              GCancellable *cancellable,
+                                              GError **err)
+{
+	CamelKolabIMAPXStoreClass *klass = NULL;
+	gboolean ok = FALSE;
+
+	g_return_val_if_fail (CAMEL_IS_KOLAB_IMAPX_STORE (self), FALSE);
+
+	klass = CAMEL_KOLAB_IMAPX_STORE_GET_CLASS (self);
+	ok = klass->set_show_all_folders (self,
+	                                  show_all,
+	                                  cancellable,
+	                                  err);
+	return ok;
+}
+
 /*----------------------------------------------------------------------------*/
 /*----------------------------------------------------------------------------*/
diff --git a/src/libekolab/camel-kolab-imapx-store.h b/src/libekolab/camel-kolab-imapx-store.h
index c4c28b7..273dff7 100644
--- a/src/libekolab/camel-kolab-imapx-store.h
+++ b/src/libekolab/camel-kolab-imapx-store.h
@@ -96,6 +96,13 @@ struct _CamelKolabIMAPXStoreClass {
 	                                            GError **err);
 
 	GList* (*resect_folder_list) (CamelKolabIMAPXStore *self);
+
+	gboolean (*get_show_all_folders) (CamelKolabIMAPXStore *self);
+
+	gboolean (*set_show_all_folders) (CamelKolabIMAPXStore *self,
+	                                  gboolean show_all,
+	                                  GCancellable *cancellable,
+	                                  GError **err);
 };
 
 GType camel_kolab_imapx_store_get_type (void);
@@ -133,6 +140,17 @@ camel_kolab_imapx_store_get_folder_info_online (CamelKolabIMAPXStore *self,
 GList*
 camel_kolab_imapx_store_resect_folder_list (CamelKolabIMAPXStore *self);
 
+/* Kolab extension */
+gboolean
+camel_kolab_imapx_store_get_show_all_folders (CamelKolabIMAPXStore *self);
+
+/* Kolab extension */
+gboolean
+camel_kolab_imapx_store_set_show_all_folders (CamelKolabIMAPXStore *self,
+                                              gboolean show_all,
+                                              GCancellable *cancellable,
+                                              GError **err);
+
 G_END_DECLS
 
 /*----------------------------------------------------------------------------*/



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