[evolution-kolab/ek-wip-porting-imapx] libekolabutil: added folder type functions



commit fee4e4df3b6088550ee26062548ed6dd6d41f478
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Sat Dec 3 20:09:32 2011 +0100

    libekolabutil: added folder type functions
    
    * kolab_util_folder_type_get_id() :
      map a Kolab folder type annotation string
      to a numerical value (KolabFolderTypeID)
    * kolab_util_folder_type_get_string() :
      map a KolabFolderTypeID to a Kolab folder
      type annotation string

 src/libekolabutil/kolab-util-folder.c |  107 +++++++++++++++++++++++++++++++++
 src/libekolabutil/kolab-util-folder.h |   19 +++++-
 2 files changed, 124 insertions(+), 2 deletions(-)
---
diff --git a/src/libekolabutil/kolab-util-folder.c b/src/libekolabutil/kolab-util-folder.c
index 31951a8..3f79dd9 100644
--- a/src/libekolabutil/kolab-util-folder.c
+++ b/src/libekolabutil/kolab-util-folder.c
@@ -31,9 +31,114 @@
 
 /*----------------------------------------------------------------------------*/
 
+static gchar *kolab_folder_type_inv_map[] = {
+	"---INVALID---",	/* KOLAB_FOLDER_TYPE_INVAL */
+	"---UNKNOWN---",	/* KOLAB_FOLDER_TYPE_UNKNOWN */
+
+	"mail",			/* KOLAB_FOLDER_TYPE_EMAIL */
+	"mail.inbox",		/* KOLAB_FOLDER_TYPE_EMAIL_INBOX */
+	"mail.drafts",		/* KOLAB_FOLDER_TYPE_EMAIL_DRAFTS */
+	"mail.sentitems",	/* KOLAB_FOLDER_TYPE_EMAIL_SENTITEMS */
+	"mail.junkemail",	/* KOLAB_FOLDER_TYPE_EMAIL_JUNKEMAIL */
+
+	"event",		/* KOLAB_FOLDER_TYPE_EVENT */
+	"event.default",	/* KOLAB_FOLDER_TYPE_EVENT_DEFAULT */
+	"journal",		/* KOLAB_FOLDER_TYPE_JOURNAL */
+	"journal.default",	/* KOLAB_FOLDER_TYPE_JOURNAL_DEFAULT */
+	"task",			/* KOLAB_FOLDER_TYPE_TASK */
+	"task.default",		/* KOLAB_FOLDER_TYPE_TASK_DEFAULT */
+	"note",			/* KOLAB_FOLDER_TYPE_NOTE */
+	"note.default",		/* KOLAB_FOLDER_TYPE_NOTE_DEFAULT */
+
+	"contact",		/* KOLAB_FOLDER_TYPE_CONTACT */
+	"contact.default"	/* KOLAB_FOLDER_TYPE_CONTACT_DEFAULT */
+};
+
+static KolabFolderTypeID kolab_folder_type_nums[KOLAB_FOLDER_LAST_TYPE];
+static GHashTable *kolab_folder_type_map = NULL;
+static gboolean kolab_util_folder_is_initialized = FALSE;
+
+/*----------------------------------------------------------------------------*/
+
+static void
+kolab_util_folder_type_map_init (void)
+{
+	gint ii = 0;
+	kolab_folder_type_map = g_hash_table_new (g_str_hash, g_str_equal);
+	for (ii = 0; ii < KOLAB_FOLDER_LAST_TYPE; ii++) {
+		kolab_folder_type_nums[ii] = ii;
+		g_hash_table_insert (kolab_folder_type_map,
+		                     kolab_folder_type_inv_map[ii],
+		                     &(kolab_folder_type_nums[ii]));
+	}
+}
+
+static void
+kolab_util_folder_type_map_uninit (void)
+{
+	g_hash_table_destroy (kolab_folder_type_map);
+	kolab_folder_type_map = NULL;
+}
+
+/*----------------------------------------------------------------------------*/
+
+void
+kolab_util_folder_init (void)
+{
+	if (kolab_util_folder_is_initialized)
+		return;
+	
+	kolab_util_folder_type_map_init ();
+
+	kolab_util_folder_is_initialized = TRUE;
+}
+
+void
+kolab_util_folder_shutdown (void)
+{
+	if (! kolab_util_folder_is_initialized)
+		return;
+	
+	kolab_util_folder_type_map_uninit ();
+
+	kolab_util_folder_is_initialized = FALSE;
+}
+
+KolabFolderTypeID
+kolab_util_folder_type_get_id (const gchar *typestring)
+{
+	/* when looking up a value from kolab_folder_type_map, store
+	 * it in gpointer, check for NULL, then dereference and cast
+	 * to KolabFolderTypeID
+	 */
+	gpointer map_entry = NULL;
+	KolabFolderTypeID id = KOLAB_FOLDER_TYPE_INVAL;
+
+	g_assert (kolab_util_folder_is_initialized);
+	g_assert (typestring != NULL);
+
+	map_entry = g_hash_table_lookup (kolab_folder_type_map, typestring);
+
+	if (map_entry == NULL)
+		return KOLAB_FOLDER_TYPE_INVAL;
+
+	id = *((KolabFolderTypeID*)map_entry);
+	return id;
+}
+
+const gchar*
+kolab_util_folder_type_get_string (KolabFolderTypeID foldertype)
+{
+	g_assert (kolab_util_folder_is_initialized);
+	g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
+	return kolab_folder_type_inv_map[foldertype];
+}
+
 KolabFolderContextID
 kolab_util_folder_type_map_to_context_id (KolabFolderTypeID type_id)
 {
+	g_assert (kolab_util_folder_is_initialized);
+
 	/* TODO better handling here */
 	g_assert ((type_id > KOLAB_FOLDER_TYPE_INVAL) &&
 	          (type_id < KOLAB_FOLDER_LAST_TYPE));
@@ -53,6 +158,8 @@ gboolean
 kolab_util_folder_type_match_with_context_id (KolabFolderTypeID type_id,
                                               KolabFolderContextID context_id)
 {
+	g_assert (kolab_util_folder_is_initialized);
+
 	/* TODO better handling here */
 	g_assert ((type_id > KOLAB_FOLDER_TYPE_INVAL) &&
 	          (type_id < KOLAB_FOLDER_LAST_TYPE));
diff --git a/src/libekolabutil/kolab-util-folder.h b/src/libekolabutil/kolab-util-folder.h
index 387b90d..6d78d58 100644
--- a/src/libekolabutil/kolab-util-folder.h
+++ b/src/libekolabutil/kolab-util-folder.h
@@ -94,8 +94,23 @@ typedef enum {
 
 /*----------------------------------------------------------------------------*/
 
-KolabFolderContextID kolab_util_folder_type_map_to_context_id (KolabFolderTypeID type_id);
-gboolean kolab_util_folder_type_match_with_context_id (KolabFolderTypeID type_id, KolabFolderContextID context_id);
+void
+kolab_util_folder_init (void);
+
+void
+kolab_util_folder_shutdown (void);
+
+KolabFolderTypeID
+kolab_util_folder_type_get_id (const gchar *typestring);
+
+const gchar*
+kolab_util_folder_type_get_string (KolabFolderTypeID foldertype);
+
+KolabFolderContextID
+kolab_util_folder_type_map_to_context_id (KolabFolderTypeID type_id);
+
+gboolean
+kolab_util_folder_type_match_with_context_id (KolabFolderTypeID type_id, KolabFolderContextID context_id);
 
 /*----------------------------------------------------------------------------*/
 



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