[evolution-kolab] EPlugin: skip trying to read/write folder type if in PIM context



commit 89610ff39028270d26605cc687b2d67faa46551f
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Oct 19 19:15:48 2012 +0200

    EPlugin: skip trying to read/write folder type if in PIM context
    
    * if the "Kolab Folder Properties..." dialog is opened
       from within a PIM EShellView, we do not read folder types
       and do not write any back
    * this operation is limited to email view, where we have
      the CamelKolabIMAPXStore to commence the operation
    * we also do not get/set the "show all folders" option,
      as it makes sense in the email context only

 src/eplugin/e-kolab-folder-metadata.c |  172 +++++++++++++++++++++++++++------
 src/eplugin/e-kolab-folder-metadata.h |    5 +
 2 files changed, 147 insertions(+), 30 deletions(-)
---
diff --git a/src/eplugin/e-kolab-folder-metadata.c b/src/eplugin/e-kolab-folder-metadata.c
index 5046fec..bb2d686 100644
--- a/src/eplugin/e-kolab-folder-metadata.c
+++ b/src/eplugin/e-kolab-folder-metadata.c
@@ -32,6 +32,7 @@
 #include <glib-object.h>
 
 #include <libekolab/camel-kolab-imapx-store.h>
+#include <libekolab/kolab-util-backend.h>
 
 #include <libekolabutil/kolab-util-error.h>
 #include <libekolabutil/kolab-util-folder.h>
@@ -81,6 +82,29 @@ kolab_folder_metadata_ui_create_folder_type_map (KolabFolderMetaUIData *uidata)
 }
 
 static void
+kolab_folder_metadata_ui_syncstrategy_fillbox (KolabFolderMetaUIData *uidata)
+{
+	GtkComboBoxText *box = NULL;
+	const gchar *strategy = NULL;
+	KolabSyncStrategyID ii = 0;
+
+	g_assert (uidata != NULL);
+	g_assert (uidata->widgets != NULL);
+
+	box = GTK_COMBO_BOX_TEXT (uidata->widgets->cbox_syncstrategy);
+
+	for (ii = 0; ii < KOLAB_SYNC_LAST_STRATEGY; ii++) {
+		strategy = kolab_util_backend_get_sync_strategy_desc (ii);
+		gtk_combo_box_text_insert_text (box,
+		                                (gint) ii,
+		                                strategy);
+	}
+
+	gtk_combo_box_set_active (GTK_COMBO_BOX (box),
+	                          KOLAB_SYNC_STRATEGY_DEFAULT);
+}
+
+static void
 kolab_folder_metadata_ui_foldertype_cb (GtkRadioButton *btn,
                                         gpointer userdata)
 {
@@ -115,6 +139,32 @@ kolab_folder_metadata_ui_foldertype_cb (GtkRadioButton *btn,
 }
 
 static void
+kolab_folder_metadata_ui_syncstrategy_cb (GtkComboBoxText *box,
+                                          gpointer userdata)
+{
+	GtkWidget *ok_btn = NULL;
+	KolabFolderMetaUIData *uidata = NULL;
+	gint active = 0;
+
+	g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (box));
+	g_return_if_fail (userdata != NULL);
+
+	uidata = (KolabFolderMetaUIData *) userdata;
+	g_return_if_fail (uidata->metadata != NULL);
+
+	active = gtk_combo_box_get_active (GTK_COMBO_BOX (box));
+	uidata->metadata->strategy = (KolabFolderTypeID) active;
+	uidata->changed_syncstrategy = TRUE;
+
+	ok_btn = e_kolab_plugin_util_ui_dialog_ref_button (uidata->dialog,
+	                                                   GTK_STOCK_OK,
+	                                                   TRUE);
+	g_return_if_fail (GTK_IS_BUTTON (ok_btn));
+	gtk_widget_set_sensitive (ok_btn, TRUE);
+	g_object_unref (ok_btn);
+}
+
+static void
 kolab_folder_metadata_ui_show_all_cb (GtkToggleButton *btn,
                                       gpointer userdata)
 {
@@ -157,11 +207,13 @@ e_kolab_folder_metadata_ui_new (void)
 
 	/* documenting initial settings */
 	uidata->shell_view = NULL;
+	uidata->shell_context = KOLAB_FOLDER_CONTEXT_INVAL;
 	uidata->alert_bar = NULL;
 	uidata->dialog = NULL;
 	uidata->foldername = NULL;
 	uidata->sourcename = NULL;
 	uidata->changed_metadata = FALSE;
+	uidata->changed_syncstrategy = FALSE;
 	uidata->changed_visibility = FALSE;
 
 	uidata->widgets = g_new0 (KolabFolderMetaUIWidgets, 1);
@@ -223,7 +275,7 @@ e_kolab_folder_metadata_ui_new (void)
 
 	kolab_folder_metadata_ui_create_folder_type_map (uidata);
 
-	/* "Show all folders" */
+	/* folder options */
 
 	widget = gtk_frame_new (C_("Kolab Folder Metadata",
 	                           "Kolab Folder Options"));
@@ -231,25 +283,37 @@ e_kolab_folder_metadata_ui_new (void)
 	gtk_container_add (GTK_CONTAINER (uidata->widgets->container), widget);
 	uidata->widgets->frame_options = widget;
 
+	grid = gtk_grid_new ();
+	gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+	gtk_container_set_border_width (GTK_CONTAINER (grid), 4);
+	gtk_container_add (GTK_CONTAINER (uidata->widgets->frame_options), grid);
+
+	/* option: folder sync conflict resolution strategy */
+	widget = gtk_label_new (C_("Sync Conflict Resolution",
+	                           "Strategy for resolving PIM conflicts when synchronizing\n"
+	                           "with the Kolab server"));
+	gtk_misc_set_alignment (GTK_MISC (widget), 0.0f, 0.66f);
+	gtk_misc_set_padding (GTK_MISC (widget), 4, 4);
+	gtk_container_add (GTK_CONTAINER (grid), widget);
+	widget = gtk_combo_box_text_new ();
+	uidata->widgets->cbox_syncstrategy = widget;
+	gtk_container_add (GTK_CONTAINER (grid), uidata->widgets->cbox_syncstrategy);
+	kolab_folder_metadata_ui_syncstrategy_fillbox (uidata);
+
+	/* show all folders */
+
 	widget = gtk_check_button_new ();
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
-	gtk_container_set_border_width (GTK_CONTAINER (widget), 6);
-	gtk_container_add (GTK_CONTAINER (uidata->widgets->frame_options), widget);
+	gtk_container_set_border_width (GTK_CONTAINER (widget), 4);
 	uidata->widgets->chk_btn_show_all = widget;
 	widget = gtk_label_new (C_("Kolab Folder Options",
 	                           "Show all PIM folders in this Kolab account"));
 	gtk_container_add (GTK_CONTAINER (uidata->widgets->chk_btn_show_all), widget);
+	gtk_container_add (GTK_CONTAINER (uidata->widgets->container), uidata->widgets->chk_btn_show_all);
 
-	/* "show all folders" switch */
-
-	uidata->widgets->chk_btn_show_all_handler_id =
-		g_signal_connect (G_OBJECT (uidata->widgets->chk_btn_show_all),
-		                  "toggled",
-		                  G_CALLBACK (kolab_folder_metadata_ui_show_all_cb),
-		                  uidata);
+	/* signals */
 
 	/* folder type radio buttons */
-
 	for (ii = 0; ii < KOLAB_FOLDER_META_UI_NUM_TYPES; ii++) {
 		uidata->widgets->radio_btn_handler_id[ii] =
 			g_signal_connect (G_OBJECT (uidata->widgets->radio_btn_type[ii]),
@@ -258,6 +322,19 @@ e_kolab_folder_metadata_ui_new (void)
 			                  uidata);
 	}
 
+	/* sync strategy combo box */
+	uidata->widgets->cbox_syncstrategy_id =
+		g_signal_connect (G_OBJECT (uidata->widgets->cbox_syncstrategy),
+		                  "changed",
+		                  G_CALLBACK (kolab_folder_metadata_ui_syncstrategy_cb),
+		                  uidata);
+
+	/* "show all folders" switch */
+	uidata->widgets->chk_btn_show_all_handler_id =
+		g_signal_connect (G_OBJECT (uidata->widgets->chk_btn_show_all),
+		                  "toggled",
+		                  G_CALLBACK (kolab_folder_metadata_ui_show_all_cb),
+		                  uidata);
 	return uidata;
 }
 
@@ -306,24 +383,6 @@ e_kolab_folder_metadata_ui_update_from_uidata (KolabFolderMetaUIData *uidata)
 	 * 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) */
 	for (ii = 0; ii < KOLAB_FOLDER_META_UI_NUM_TYPES; ii++) {
 		g_signal_handler_block (uidata->widgets->radio_btn_type[ii],
@@ -364,6 +423,32 @@ e_kolab_folder_metadata_ui_update_from_uidata (KolabFolderMetaUIData *uidata)
 		g_signal_handler_unblock (uidata->widgets->radio_btn_type[ii],
 		                          uidata->widgets->radio_btn_handler_id[ii]);
 	}
+
+	/* PIM options */
+
+	/* option: sync conflict strategy */
+	widget = uidata->widgets->cbox_syncstrategy;
+	g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (widget));
+	handler_id = uidata->widgets->cbox_syncstrategy_id;
+	g_signal_handler_block (widget, handler_id);
+	gtk_combo_box_set_active (GTK_COMBO_BOX (widget),
+	                          (gint) uidata->metadata->strategy);
+	g_signal_handler_unblock (widget, handler_id);
+
+	/* 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);
+	else
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
+		                              FALSE);
+	g_signal_handler_unblock (widget, handler_id);
 }
 
 gboolean
@@ -374,7 +459,7 @@ e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *uidata,
 	CamelKolabIMAPXStore *kstore = NULL;
 	gchar *selected_path = NULL;
 	GError *tmp_err = NULL;
-	gboolean ok = FALSE;
+	gboolean ok = TRUE;
 
 	g_return_val_if_fail (uidata != NULL, FALSE);
 	/* cancellable may be NULL */
@@ -383,6 +468,9 @@ 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 (uidata->shell_context != KOLAB_FOLDER_CONTEXT_EMAIL)
+		goto skip_email;
+
 	/* If we cannot get the store here, it means
 	 * that the store associated with the selected
 	 * path is not a CamelKolabIMAPXStore. This
@@ -408,7 +496,21 @@ e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *uidata,
 		                                         TRUE,
 		                                         cancellable,
 		                                         &tmp_err);
+ skip_email:
+
+	if (! ((uidata->shell_context == KOLAB_FOLDER_CONTEXT_CALENDAR) ||
+	       (uidata->shell_context == KOLAB_FOLDER_CONTEXT_CONTACT)))
+		goto exit;
+
+	uidata->metadata->foldername = g_strdup (uidata->foldername);
+	uidata->metadata->foldertype =
+		e_kolab_plugin_util_ui_get_shell_type (uidata->shell_view);
+
+	g_warning ("%s()[%u] FIXME implement read-in of PIM options",
+	           __func__, __LINE__);
+
  exit:
+
 	if (tmp_err != NULL) {
 		g_propagate_error (err, tmp_err);
 		ok = FALSE;
@@ -437,6 +539,9 @@ e_kolab_folder_metadata_ui_write_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 (uidata->shell_context != KOLAB_FOLDER_CONTEXT_EMAIL)
+		goto email_skip;
+
 	if (! (uidata->changed_metadata || uidata->changed_visibility))
 		return TRUE;
 
@@ -471,6 +576,13 @@ e_kolab_folder_metadata_ui_write_store (KolabFolderMetaUIData *uidata,
 	                                                   uidata->metadata->show_all,
 	                                                   cancellable,
 	                                                   &tmp_err);
+ email_skip:
+
+	if (uidata->shell_context != KOLAB_FOLDER_CONTEXT_CALENDAR)
+		goto exit;
+
+	g_warning ("%s()[%u] FIXME implement write-back of PIM options",
+	           __func__, __LINE__);
  exit:
 
 	if (tmp_err != NULL) {
diff --git a/src/eplugin/e-kolab-folder-metadata.h b/src/eplugin/e-kolab-folder-metadata.h
index 619b533..852863e 100644
--- a/src/eplugin/e-kolab-folder-metadata.h
+++ b/src/eplugin/e-kolab-folder-metadata.h
@@ -56,6 +56,9 @@ struct _KolabFolderMetaUIWidgets {
 	GtkWidget *radio_btn_type[KOLAB_FOLDER_META_UI_NUM_TYPES];
 	/* sub-widgets of container - folder options */
 	GtkWidget *frame_options;
+	GtkWidget *cbox_syncstrategy;
+	gulong cbox_syncstrategy_id;
+	/* sub-widgets of container - misc */
 	GtkWidget *chk_btn_show_all;
 	gulong chk_btn_show_all_handler_id;
 };
@@ -63,6 +66,7 @@ struct _KolabFolderMetaUIWidgets {
 typedef struct _KolabFolderMetaUIData KolabFolderMetaUIData;
 struct _KolabFolderMetaUIData {
 	EShellView *shell_view;
+	KolabFolderContextID shell_context;
 	EAlertBar *alert_bar;
 	GtkDialog *dialog;
 	KolabFolderMetaUIWidgets *widgets;
@@ -70,6 +74,7 @@ struct _KolabFolderMetaUIData {
 	gchar *foldername;
 	gchar *sourcename;
 	gboolean changed_metadata;
+	gboolean changed_syncstrategy;
 	gboolean changed_visibility;
 };
 



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