[evolution-kolab/ek-wip-porting: 6/8] KolabMailSynchronizer: pass in folder type information to transaction handlers



commit 6f68799409b844d1ae58bfec4aa9437fb333d5a1
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Fri Aug 31 17:44:08 2012 +0200

    KolabMailSynchronizer: pass in folder type information to transaction handlers
    
    * reflect the API change in the KolabMailImapClient
    * when operating on folders (not mail handles), we need
      to propagate folder type information through to
      the KolabMailImapClient
    * this is for folder creation, the complementary folder
      deletion operation will not need folder type info
      (deleting a folder is always possible, we do not
      need to know its type for that)

 src/libekolab/kolab-mail-synchronizer.c |   93 ++++++++++++++++++++----------
 src/libekolab/kolab-mail-synchronizer.h |    4 +
 2 files changed, 66 insertions(+), 31 deletions(-)
---
diff --git a/src/libekolab/kolab-mail-synchronizer.c b/src/libekolab/kolab-mail-synchronizer.c
index 77c00e9..bdd30fe 100644
--- a/src/libekolab/kolab-mail-synchronizer.c
+++ b/src/libekolab/kolab-mail-synchronizer.c
@@ -1584,6 +1584,7 @@ mail_synchronizer_push_sidecache (KolabMailSynchronizer *self,
 		                                                      KOLAB_MAIL_SYNCHRONIZER_TRANSACTION_TYPE_PUSH,
 		                                                      kmailhandle,
 		                                                      foldername,
+		                                                      KOLAB_FOLDER_TYPE_AUTO,
 		                                                      imap_summaries,
 		                                                      &record,
 		                                                      cancellable,
@@ -1597,6 +1598,7 @@ mail_synchronizer_push_sidecache (KolabMailSynchronizer *self,
 		                                                KOLAB_MAIL_SYNCHRONIZER_TRANSACTION_TYPE_PUSH,
 		                                                kmailhandle,
 		                                                foldername,
+		                                                KOLAB_FOLDER_TYPE_AUTO,
 		                                                record,
 		                                                &tmp_err);
 		if (tmp_err != NULL)
@@ -1647,6 +1649,7 @@ mail_synchronizer_push_sidecache (KolabMailSynchronizer *self,
 			                                                 KOLAB_MAIL_SYNCHRONIZER_TRANSACTION_TYPE_PUSH,
 			                                                 kmailhandle,
 			                                                 foldername,
+			                                                 KOLAB_FOLDER_TYPE_AUTO,
 			                                                 record,
 			                                                 &tmp_err);
 		else
@@ -1655,6 +1658,7 @@ mail_synchronizer_push_sidecache (KolabMailSynchronizer *self,
 			                                                KOLAB_MAIL_SYNCHRONIZER_TRANSACTION_TYPE_PUSH,
 			                                                kmailhandle,
 			                                                foldername,
+			                                                KOLAB_FOLDER_TYPE_AUTO,
 			                                                record,
 			                                                &tmp_err);
 	uid_cleanup:
@@ -1815,6 +1819,7 @@ kolab_mail_synchronizer_transaction_prepare (KolabMailSynchronizer *self,
                                              KolabMailSynchronizerTransactionTypeID ttid,
                                              KolabMailHandle *kmailhandle,
                                              const gchar *foldername,
+                                             KolabFolderTypeID foldertype,
                                              GHashTable *imap_summaries,
                                              KolabMailInfoDbRecord **record,
                                              GCancellable *cancellable,
@@ -1856,6 +1861,7 @@ kolab_mail_synchronizer_transaction_prepare (KolabMailSynchronizer *self,
 	if (kmailhandle != NULL)
 		g_assert (KOLAB_IS_MAIL_HANDLE (kmailhandle));
 	g_assert (foldername != NULL);
+	g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
 	/* imap_summaries may be NULL */
 	/* cancellable may be NULL */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
@@ -1864,33 +1870,35 @@ kolab_mail_synchronizer_transaction_prepare (KolabMailSynchronizer *self,
 
 	g_assert (priv->is_up == TRUE);
 
-	uid = g_strdup (kolab_mail_handle_get_uid (kmailhandle));
-	if (uid == NULL) {
-		g_set_error (&tmp_err,
-		             KOLAB_BACKEND_ERROR,
-		             KOLAB_BACKEND_ERROR_DATATYPE_INTERNAL,
-		             _("Internal inconsistency detected: PIM Object handle has no Kolab UID set"));
-		goto cleanup;
-	}
-	kmh_summary = kolab_mail_handle_get_summary (kmailhandle);
-
-	/* read InfoDb record for the UID in question
-	 * (if we don't have it already)
-	 */
-	if (*record == NULL) {
-		record_locally_created = TRUE;
-		*record = kolab_mail_info_db_query_record (priv->infodb,
-		                                           uid,
-		                                           foldername,
-		                                           &tmp_err);
-		if (tmp_err != NULL)
+	if (kmailhandle != NULL) {
+		uid = g_strdup (kolab_mail_handle_get_uid (kmailhandle));
+		if (uid == NULL) {
+			g_set_error (&tmp_err,
+			             KOLAB_BACKEND_ERROR,
+			             KOLAB_BACKEND_ERROR_DATATYPE_INTERNAL,
+			             _("Internal inconsistency detected: PIM Object handle has no Kolab UID set"));
 			goto cleanup;
+		}
+		kmh_summary = kolab_mail_handle_get_summary (kmailhandle);
+
+		/* read InfoDb record for the UID in question
+		 * (if we don't have it already)
+		 */
+		if (*record == NULL) {
+			record_locally_created = TRUE;
+			*record = kolab_mail_info_db_query_record (priv->infodb,
+			                                           uid,
+			                                           foldername,
+			                                           &tmp_err);
+			if (tmp_err != NULL)
+				goto cleanup;
+		}
+		if (*record == NULL)
+			/* new handle */
+			*record = kolab_mail_info_db_record_new ();
+		if ((*record)->summary == NULL)
+			(*record)->summary = kolab_mail_summary_clone (kmh_summary);
 	}
-	if (*record == NULL)
-		/* new handle */
-		*record = kolab_mail_info_db_record_new ();
-	if ((*record)->summary == NULL)
-		(*record)->summary = kolab_mail_summary_clone (kmh_summary);
 
 	/* TODO
 	 *
@@ -1904,11 +1912,25 @@ kolab_mail_synchronizer_transaction_prepare (KolabMailSynchronizer *self,
 	}
 
 	if (imap_summaries == NULL) {
-		/* empty server folder, no conflict possible */
+		/* empty server folder, no conflict possible
+		 * (or folder create/delete operation, also no conflict)
+		 */
 		can_act = TRUE;
 		goto cleanup;
 	}
 
+	/* if we're here, we do want to operate on a PIM object
+	 * not a folder (for folder operations, imap_summaries
+	 * is expected to be passed in as NULL, same for the
+	 * mail handle) - safeguarding...
+	 */
+	if (kmailhandle == NULL) {
+		g_warning ("%s()[%u]: PIM object operation requested, but mail handle is NULL, aborting",
+		           __func__, __LINE__);
+		can_act = FALSE;
+		goto cleanup;
+	}
+	
 	sync_id_ptr = kolab_settings_handler_get_value (priv->ksettings,
 	                                                KOLAB_SETTINGS_HANDLER_TBL_SYNCSTRATEGY,
 	                                                foldername,
@@ -2201,6 +2223,7 @@ kolab_mail_synchronizer_transaction_start (KolabMailSynchronizer *self,
                                            KolabMailSynchronizerTransactionTypeID ttid,
                                            KolabMailHandle *kmailhandle,
                                            const gchar *foldername,
+                                           KolabFolderTypeID foldertype,
                                            KolabMailInfoDbRecord *record,
                                            GError **err)
 {
@@ -2214,7 +2237,8 @@ kolab_mail_synchronizer_transaction_start (KolabMailSynchronizer *self,
 	if (kmailhandle != NULL)
 		g_assert (KOLAB_IS_MAIL_HANDLE (kmailhandle));
 	g_assert (foldername != NULL);
-	g_assert (record != NULL);
+	g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
+	(void)record; /* FIXME */ /* record may be NULL (in folder operations) */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
 	priv = KOLAB_MAIL_SYNCHRONIZER_PRIVATE (self);
@@ -2262,6 +2286,7 @@ kolab_mail_synchronizer_transaction_abort (KolabMailSynchronizer *self,
                                            KolabMailSynchronizerTransactionTypeID ttid,
                                            KolabMailHandle *kmailhandle,
                                            const gchar *foldername,
+                                           KolabFolderTypeID foldertype,
                                            KolabMailInfoDbRecord *record,
                                            GError **err)
 {
@@ -2275,7 +2300,8 @@ kolab_mail_synchronizer_transaction_abort (KolabMailSynchronizer *self,
 	if (kmailhandle != NULL)
 		g_assert (KOLAB_IS_MAIL_HANDLE (kmailhandle));
 	g_assert (foldername != NULL);
-	g_assert (record != NULL);
+	g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
+	(void)record; /* FIXME */ /* record may be NULL (in folder operations) */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
 	priv = KOLAB_MAIL_SYNCHRONIZER_PRIVATE (self);
@@ -2283,6 +2309,7 @@ kolab_mail_synchronizer_transaction_abort (KolabMailSynchronizer *self,
 	g_assert (priv->is_up == TRUE);
 
 	/* TODO implement me */
+	g_debug ("%s: TODO implement transaction abort", __func__);
 
 	return TRUE;
 }
@@ -2293,6 +2320,7 @@ kolab_mail_synchronizer_transaction_commit (KolabMailSynchronizer *self,
                                             KolabMailSynchronizerTransactionTypeID ttid,
                                             KolabMailHandle *kmailhandle,
                                             const gchar *foldername,
+                                            KolabFolderTypeID foldertype,
                                             KolabMailInfoDbRecord *record,
                                             GError **err)
 {
@@ -2314,7 +2342,8 @@ kolab_mail_synchronizer_transaction_commit (KolabMailSynchronizer *self,
 	if (kmailhandle != NULL)
 		g_assert (KOLAB_IS_MAIL_HANDLE (kmailhandle));
 	g_assert (foldername != NULL);
-	g_assert (record != NULL);
+	g_assert (foldertype < KOLAB_FOLDER_LAST_TYPE);
+	/* record may be NULL (in folder operations) */
 	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
 
 	priv = KOLAB_MAIL_SYNCHRONIZER_PRIVATE (self);
@@ -2323,10 +2352,12 @@ kolab_mail_synchronizer_transaction_commit (KolabMailSynchronizer *self,
 
 	/* folder operation transaction */
 	if (kmailhandle == NULL) {
-		g_warning ("%s: folder operations not yet implemented", __func__);
-		g_assert_not_reached ();
+		g_warning ("%s: FIXME implement folder operations commit", __func__);
+		return TRUE;
 	}
 
+	g_return_val_if_fail (record != NULL, FALSE);
+	
 	uid = kolab_mail_handle_get_uid (kmailhandle);
 
 	/* updates for store or push operations in online operation */
diff --git a/src/libekolab/kolab-mail-synchronizer.h b/src/libekolab/kolab-mail-synchronizer.h
index 93daae2..205b31c 100644
--- a/src/libekolab/kolab-mail-synchronizer.h
+++ b/src/libekolab/kolab-mail-synchronizer.h
@@ -217,6 +217,7 @@ kolab_mail_synchronizer_transaction_prepare (KolabMailSynchronizer *self,
                                              KolabMailSynchronizerTransactionTypeID ttid,
                                              KolabMailHandle *kmailhandle,
                                              const gchar *foldername,
+                                             KolabFolderTypeID foldertype,
                                              GHashTable *imap_summaries,
                                              KolabMailInfoDbRecord **record,
                                              GCancellable *cancellable,
@@ -227,6 +228,7 @@ kolab_mail_synchronizer_transaction_start (KolabMailSynchronizer *self,
                                            KolabMailSynchronizerTransactionTypeID ttid,
                                            KolabMailHandle *kmailhandle,
                                            const gchar *foldername,
+                                           KolabFolderTypeID foldertype,
                                            KolabMailInfoDbRecord *record,
                                            GError **err);
 gboolean
@@ -235,6 +237,7 @@ kolab_mail_synchronizer_transaction_abort (KolabMailSynchronizer *self,
                                            KolabMailSynchronizerTransactionTypeID ttid,
                                            KolabMailHandle *kmailhandle,
                                            const gchar *foldername,
+                                           KolabFolderTypeID foldertype,
                                            KolabMailInfoDbRecord *record,
                                            GError **err);
 gboolean
@@ -243,6 +246,7 @@ kolab_mail_synchronizer_transaction_commit (KolabMailSynchronizer *self,
                                             KolabMailSynchronizerTransactionTypeID ttid,
                                             KolabMailHandle *kmailhandle,
                                             const gchar *foldername,
+                                            KolabFolderTypeID foldertype,
                                             KolabMailInfoDbRecord *record,
                                             GError **err);
 



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