[evolution-kolab] EPlugin: implemented sync stategy get/set



commit 5198804517b3ca387667d1480580d27955c7b648
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Oct 19 20:19:59 2012 +0200

    EPlugin: implemented sync stategy get/set
    
    * implemented getting the current sync strategy
      from a Kolab ESource
    * implemented writing a changed sync strategy
      back to a Kolab ESource

 src/eplugin/e-kolab-folder-metadata.c |   81 +++++++++++++++++++++++++++++++--
 1 files changed, 76 insertions(+), 5 deletions(-)
---
diff --git a/src/eplugin/e-kolab-folder-metadata.c b/src/eplugin/e-kolab-folder-metadata.c
index bb2d686..8d26736 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/e-source-kolab-folder.h>
 #include <libekolab/kolab-util-backend.h>
 
 #include <libekolabutil/kolab-util-error.h>
@@ -104,6 +105,73 @@ kolab_folder_metadata_ui_syncstrategy_fillbox (KolabFolderMetaUIData *uidata)
 	                          KOLAB_SYNC_STRATEGY_DEFAULT);
 }
 
+static KolabSyncStrategyID
+kolab_folder_metadata_ui_syncstrategy_get (KolabFolderMetaUIData *uidata)
+{
+	KolabSyncStrategyID strategy = KOLAB_SYNC_STRATEGY_DEFAULT;
+	ESource *source = NULL;
+	ESourceResource *resource = NULL;
+	gboolean is_kolab = FALSE;
+
+	g_return_val_if_fail (uidata != NULL, KOLAB_SYNC_STRATEGY_DEFAULT);
+	g_return_val_if_fail (E_IS_SHELL_VIEW (uidata->shell_view), KOLAB_SYNC_STRATEGY_DEFAULT);
+
+	is_kolab = e_kolab_plugin_util_ui_get_selected_source (uidata->shell_view,
+	                                                       &source);
+	g_return_val_if_fail (is_kolab, KOLAB_SYNC_STRATEGY_DEFAULT);
+
+	resource = E_SOURCE_RESOURCE (e_source_get_extension (source,
+	                                                      E_SOURCE_EXTENSION_KOLAB_FOLDER));
+	strategy = e_source_kolab_folder_get_sync_strategy (E_SOURCE_KOLAB_FOLDER (resource));
+
+	g_object_unref (source);
+
+	return strategy;
+}
+
+static gboolean
+kolab_folder_metadata_ui_syncstrategy_set (KolabFolderMetaUIData *uidata,
+                                           GCancellable *cancellable,
+                                           GError **err)
+{
+	ESource *source = NULL;
+	ESourceResource *resource = NULL;
+	gboolean is_kolab = FALSE;
+	GError *tmp_err = NULL;
+	gboolean ok = TRUE;
+
+	g_return_val_if_fail (uidata != NULL, FALSE);
+	g_return_val_if_fail (E_IS_SHELL_VIEW (uidata->shell_view), FALSE);
+	/* cancellable may be NULL */
+	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
+
+	is_kolab = e_kolab_plugin_util_ui_get_selected_source (uidata->shell_view,
+	                                                       &source);
+	if (! is_kolab) {
+		g_warning ("%s()[%u] expected Kolab source, got something else, skipping",
+		           __func__, __LINE__);
+		goto exit;
+	}
+
+	resource = E_SOURCE_RESOURCE (e_source_get_extension (source,
+	                                                      E_SOURCE_EXTENSION_KOLAB_FOLDER));
+	e_source_kolab_folder_set_sync_strategy (E_SOURCE_KOLAB_FOLDER (resource),
+	                                         uidata->metadata->strategy);
+	ok = e_source_write_sync (source,
+	                          cancellable,
+	                          &tmp_err);
+ exit:
+	if (tmp_err != NULL) {
+		g_propagate_error (err, tmp_err);
+		ok = FALSE;
+	}
+
+	if (source != NULL)
+		g_object_unref (source);
+
+	return ok;
+}
+
 static void
 kolab_folder_metadata_ui_foldertype_cb (GtkRadioButton *btn,
                                         gpointer userdata)
@@ -457,6 +525,7 @@ e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *uidata,
                                         GError **err)
 {
 	CamelKolabIMAPXStore *kstore = NULL;
+	KolabSyncStrategyID strategy = KOLAB_SYNC_STRATEGY_DEFAULT;
 	gchar *selected_path = NULL;
 	GError *tmp_err = NULL;
 	gboolean ok = TRUE;
@@ -506,8 +575,8 @@ e_kolab_folder_metadata_ui_query_store (KolabFolderMetaUIData *uidata,
 	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__);
+	strategy = kolab_folder_metadata_ui_syncstrategy_get (uidata);
+	uidata->metadata->strategy = strategy;
 
  exit:
 
@@ -578,11 +647,13 @@ e_kolab_folder_metadata_ui_write_store (KolabFolderMetaUIData *uidata,
 	                                                   &tmp_err);
  email_skip:
 
-	if (uidata->shell_context != KOLAB_FOLDER_CONTEXT_CALENDAR)
+	if (! ((uidata->shell_context == KOLAB_FOLDER_CONTEXT_CALENDAR) ||
+	       (uidata->shell_context == KOLAB_FOLDER_CONTEXT_CONTACT)))
 		goto exit;
 
-	g_warning ("%s()[%u] FIXME implement write-back of PIM options",
-	           __func__, __LINE__);
+	ok = kolab_folder_metadata_ui_syncstrategy_set (uidata,
+	                                                cancellable,
+	                                                &tmp_err);
  exit:
 
 	if (tmp_err != NULL) {



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