[evolution-kolab] EPlugin: add query/store operations for metadata



commit 6b34807b7929fe03f8c3b548728a46dca23c4717
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Sep 14 18:53:33 2012 +0200

    EPlugin: add query/store operations for metadata
    
    * prototyped API to query current metadata for a folder
      and set up the UI accordingly
    * rework of the UI code

 src/eplugin/e-kolab-folder-metadata.c |  215 +++++++++++++++++++++++++++++++--
 src/eplugin/e-kolab-folder-metadata.h |   26 +++--
 2 files changed, 222 insertions(+), 19 deletions(-)
---
diff --git a/src/eplugin/e-kolab-folder-metadata.c b/src/eplugin/e-kolab-folder-metadata.c
index 73b72aa..b31c839 100644
--- a/src/eplugin/e-kolab-folder-metadata.c
+++ b/src/eplugin/e-kolab-folder-metadata.c
@@ -30,6 +30,10 @@
 
 #include <glib/gi18n-lib.h>
 
+#include <libekolab/camel-kolab-imapx-store.h>
+#include <libekolabutil/kolab-util-error.h>
+
+#include "e-kolab-plugin-util.h"
 #include "e-kolab-folder-metadata.h"
 
 /*----------------------------------------------------------------------------*/
@@ -39,6 +43,77 @@
 /*----------------------------------------------------------------------------*/
 /* internal statics (UI) */
 
+static void
+kolab_folder_metadata_ui_create_folder_type_map (KolabFolderMetaUIData *uidata)
+{
+	GHashTable *map = NULL;
+
+	g_assert (uidata != NULL);
+	g_assert (uidata->widgets != NULL);
+
+	map = g_hash_table_new_full (g_direct_hash,
+	                             g_direct_equal,
+	                             NULL,  /* radio button addresses as keys */
+	                             NULL); /* numeric Kolab folder types as values */;
+
+	g_hash_table_insert (map,
+	                     uidata->widgets->radio_btn_type[0],
+	                     GUINT_TO_POINTER (KOLAB_FOLDER_TYPE_EMAIL));
+	g_hash_table_insert (map,
+	                     uidata->widgets->radio_btn_type[1],
+	                     GUINT_TO_POINTER (KOLAB_FOLDER_TYPE_EVENT));
+	g_hash_table_insert (map,
+	                     uidata->widgets->radio_btn_type[2],
+	                     GUINT_TO_POINTER (KOLAB_FOLDER_TYPE_NOTE));
+	g_hash_table_insert (map,
+	                     uidata->widgets->radio_btn_type[3],
+	                     GUINT_TO_POINTER (KOLAB_FOLDER_TYPE_TASK));
+	g_hash_table_insert (map,
+	                     uidata->widgets->radio_btn_type[4],
+	                     GUINT_TO_POINTER (KOLAB_FOLDER_TYPE_CONTACT));
+
+	if (uidata->widgets->folder_type_map != NULL)
+		g_hash_table_destroy (uidata->widgets->folder_type_map);
+	uidata->widgets->folder_type_map = map;
+}
+
+static void
+kolab_folder_metadata_ui_foldertype_cb (GtkRadioButton *btn,
+                                        gpointer userdata)
+{
+	KolabFolderMetaUIData *uidata = NULL;
+	KolabFolderTypeID foldertype = KOLAB_FOLDER_TYPE_INVAL;
+	gpointer type = NULL;
+
+	g_return_if_fail (GTK_IS_RADIO_BUTTON (btn));
+	g_return_if_fail (userdata != NULL);
+
+	uidata = (KolabFolderMetaUIData *) userdata;
+	g_return_if_fail (uidata->widgets != NULL);
+
+	type = g_hash_table_lookup (uidata->widgets->folder_type_map,
+	                            (gpointer) btn);
+	if (type != NULL)
+		foldertype = GPOINTER_TO_UINT (type);
+
+	g_warning ("%s: folder type id: %i", __func__, foldertype); /* FIXME remove */
+}
+
+static void
+kolab_folder_metadata_ui_show_all_cb (GtkToggleButton *btn,
+                                      gpointer userdata)
+{
+	KolabFolderMetaUIData *uidata = NULL;
+
+	g_return_if_fail (GTK_IS_TOGGLE_BUTTON (btn));
+	g_return_if_fail (userdata != NULL);
+
+	uidata = (KolabFolderMetaUIData *) userdata;
+	g_return_if_fail (uidata->metadata != NULL);
+
+	uidata->metadata->show_all = !(uidata->metadata->show_all);
+	g_warning ("%s: called", __func__); /* FIXME remove */
+}
 
 /*----------------------------------------------------------------------------*/
 /* API functions (non-UI) */
@@ -55,11 +130,13 @@ e_kolab_folder_metadata_ui_new (void)
 	GtkWidget *grid = NULL;
 	GtkWidget *btn_loco = NULL;
 	GtkWidget *btn = NULL;
+	gint ii = 0;
 
 	uidata->shell_view = NULL;
 	uidata->alert_bar = NULL;
 
 	uidata->widgets = g_new0 (KolabFolderMetaUIWidgets, 1);
+	uidata->metadata = kolab_data_folder_metadata_new ();
 
 	grid = gtk_grid_new ();
 	gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
@@ -80,36 +157,43 @@ e_kolab_folder_metadata_ui_new (void)
 	gtk_container_set_border_width (GTK_CONTAINER (grid), 16);
 	gtk_container_add (GTK_CONTAINER (uidata->widgets->frame_type_select), grid);
 
+	/* mail */
 	btn_loco = gtk_radio_button_new_with_label (NULL, C_("Kolab Folder Type",
 	                                                     "Mail"));
-	uidata->widgets->radio_btn_type_mail = btn_loco;
+	uidata->widgets->radio_btn_type[0] = btn_loco;
 	uidata->widgets->radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (btn_loco));
 	gtk_container_add (GTK_CONTAINER (grid), btn_loco);
 
+	/* calendar */
 	btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
 	                                                   C_("Kolab Folder Type",
 	                                                      "Calendar"));
-	uidata->widgets->radio_btn_type_calendar = btn;
+	uidata->widgets->radio_btn_type[1] = btn;
 	gtk_container_add (GTK_CONTAINER (grid), btn);
 
+	/* memos */
 	btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
 	                                                   C_("Kolab Folder Type",
 	                                                      "Memos"));
-	uidata->widgets->radio_btn_type_memos = btn;
+	uidata->widgets->radio_btn_type[2] = btn;
 	gtk_container_add (GTK_CONTAINER (grid), btn);
 
+	/* tasks */
 	btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
 	                                                   C_("Kolab Folder Type",
 	                                                      "Tasks"));
-	uidata->widgets->radio_btn_type_tasks = btn;
+	uidata->widgets->radio_btn_type[3] = btn;
 	gtk_container_add (GTK_CONTAINER (grid), btn);
 
+	/* contacts */
 	btn = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (btn_loco),
 	                                                   C_("Kolab Folder Type",
 	                                                      "Contacts"));
-	uidata->widgets->radio_btn_type_contacts = btn;
+	uidata->widgets->radio_btn_type[4] = btn;
 	gtk_container_add (GTK_CONTAINER (grid), btn);
 
+	kolab_folder_metadata_ui_create_folder_type_map (uidata);
+
 	/* "Show all folders" */
 
 	widget = gtk_frame_new (C_("Kolab Folder Metadata",
@@ -127,8 +211,21 @@ e_kolab_folder_metadata_ui_new (void)
 	                           "Show all PIM folders in this Kolab account"));
 	gtk_container_add (GTK_CONTAINER (uidata->widgets->chk_btn_show_all), widget);
 
-	/* FIXME connect signals */
-	g_warning ("%s: FIXME connect signals", __func__);
+	uidata->widgets->chk_btn_show_all_handler_id =
+		g_signal_connect (uidata->widgets->chk_btn_show_all,
+		                  "toggled",
+		                  G_CALLBACK (kolab_folder_metadata_ui_show_all_cb),
+		                  uidata);
+
+	/* folder type radio buttons */
+
+	for (ii = 0; ii < 5; ii++) {
+		uidata->widgets->radio_btn_handler_id[ii] =
+			g_signal_connect (uidata->widgets->radio_btn_type[ii],
+			                  "toggled",
+			                  G_CALLBACK (kolab_folder_metadata_ui_foldertype_cb),
+			                  uidata);
+	}
 
 	return uidata;
 }
@@ -142,10 +239,14 @@ e_kolab_folder_metadata_ui_free (KolabFolderMetaUIData *uidata)
 	/* the actual widgets will have been deleted already,
 	 * so just deleting the struct shell here
 	 */
-	if (uidata->widgets != NULL)
+	if (uidata->widgets != NULL) {
+		if (uidata->widgets->folder_type_map != NULL)
+			g_hash_table_destroy (uidata->widgets->folder_type_map);
 		g_free (uidata->widgets);
+	}
 
 	kolab_data_folder_metadata_free (uidata->metadata);
+
 	if (uidata->foldername != NULL)
 		g_free (uidata->foldername);
 	if (uidata->sourcename != NULL)
@@ -157,20 +258,112 @@ e_kolab_folder_metadata_ui_free (KolabFolderMetaUIData *uidata)
 void
 e_kolab_folder_metadata_ui_update_from_uidata (KolabFolderMetaUIData *uidata)
 {
+	GtkWidget *widget = NULL;
+	guint handler_id = 0;
+
 	g_return_if_fail (uidata != NULL);
+	g_return_if_fail (uidata->metadata != NULL);
+	g_return_if_fail (uidata->widgets != NULL);
+
+	/* When updating the state of the UI here,
+	 * we need to always make sure not to trigger
+	 * signals which we may have handlers for.
+	 * Updating the UI this way is meant to happen
+	 * before the user actually uses it.
+	 */
+
+	/* whether to show all PIM folders in email view */
+
+	widget = uidata->widgets->chk_btn_show_all;
+	g_return_if_fail (GTK_IS_CHECK_BUTTON (widget));
+	handler_id = uidata->widgets->chk_btn_show_all_handler_id;
+
+	g_signal_handler_block (widget, handler_id);
+	if (uidata->metadata->show_all) {
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
+		                              TRUE);
+		g_debug ("%s: set toggle button active", __func__);
+	} else {
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
+		                              FALSE);
+		g_debug ("%s: set toggle button inactive", __func__);
+	}
+	g_signal_handler_unblock (widget, handler_id);
+
+	/* radio button group (current folder type) */
 
 	g_warning ("%s: FIXME implement me", __func__);
 }
 
 gboolean
-e_kolab_folder_metadata_ui_query_metadata (KolabFolderMetaUIData *uidata,
-                                           GCancellable *cancellable,
-                                           GError **err)
+e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *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);
+
+	g_return_val_if_fail (E_IS_SHELL_VIEW (uidata->shell_view), FALSE);
+	g_return_val_if_fail (uidata->metadata != NULL, FALSE);
+
+	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!"));
+		goto exit;
+	}
+
+	uidata->metadata->foldername = selected_path;
+	uidata->metadata->show_all =
+		camel_kolab_imapx_store_get_show_all_folders (kstore);
+	uidata->metadata->foldertype =
+		camel_kolab_imapx_store_get_folder_type (kstore,
+		                                         selected_path,
+		                                         TRUE,
+		                                         cancellable,
+		                                         &tmp_err);
+ exit:
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+
+	if (kstore != NULL)
+		g_object_unref (kstore);
+
+	return ok;
+}
+
+gboolean
+e_kolab_folder_metadata_ui_write_store (KolabFolderMetaUIData *uidata,
+                                        GCancellable *cancellable,
+                                        GError **err)
 {
 	g_return_val_if_fail (uidata != NULL, FALSE);
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
+	g_return_val_if_fail (E_IS_SHELL_VIEW (uidata->shell_view), FALSE);
+	g_return_val_if_fail (uidata->metadata != NULL, FALSE);
+
 	g_warning ("%s: FIXME implement me", __func__);
 	return TRUE;
 }
diff --git a/src/eplugin/e-kolab-folder-metadata.h b/src/eplugin/e-kolab-folder-metadata.h
index ce4eae9..0010abc 100644
--- a/src/eplugin/e-kolab-folder-metadata.h
+++ b/src/eplugin/e-kolab-folder-metadata.h
@@ -46,15 +46,21 @@ struct _KolabFolderMetaUIWidgets {
 	GtkWidget *container;
 	/* sub-widgets of container - folder type */
 	GtkWidget *frame_type_select;
+	GHashTable *folder_type_map;
 	GSList *radio_group;
-	GtkWidget *radio_btn_type_mail;
-	GtkWidget *radio_btn_type_calendar;
-	GtkWidget *radio_btn_type_memos;
-	GtkWidget *radio_btn_type_tasks;
-	GtkWidget *radio_btn_type_contacts;
+	guint radio_btn_handler_id[5];
+	GtkWidget *radio_btn_type[5];
+#if 0
+	GtkWidget *radio_btn_type_mail;     /* 0 */
+	GtkWidget *radio_btn_type_calendar; /* 1 */
+	GtkWidget *radio_btn_type_memos;    /* 2 */
+	GtkWidget *radio_btn_type_tasks;    /* 3 */
+	GtkWidget *radio_btn_type_contacts; /* 4 */
+#endif
 	/* sub-widgets of container - folder options */
 	GtkWidget *frame_options;
 	GtkWidget *chk_btn_show_all;
+	guint chk_btn_show_all_handler_id;
 };
 
 typedef struct _KolabFolderMetaUIData KolabFolderMetaUIData;
@@ -79,9 +85,13 @@ void
 e_kolab_folder_metadata_ui_update_from_uidata (KolabFolderMetaUIData *uidata);
 
 gboolean
-e_kolab_folder_metadata_ui_query_metadata (KolabFolderMetaUIData *uidata,
-                                           GCancellable *cancellable,
-                                           GError **err);
+e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *uidata,
+                                        GCancellable *cancellable,
+                                        GError **err);
+gboolean
+e_kolab_folder_metadata_ui_write_store (KolabFolderMetaUIData *uidata,
+                                        GCancellable *cancellable,
+                                        GError **err);
 
 /*----------------------------------------------------------------------------*/
 



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