[evolution-etesync/Add-notes-feature] I#1 - Add support for notes




commit a8f2cbc4ddf96ebbb7a75633c6b28059c64af9f4
Author: Nour E-Din El-Nhass <nouredinosama gmail com>
Date:   Wed Mar 31 22:40:58 2021 +0200

    I#1 - Add support for notes

 src/addressbook/e-book-backend-etesync.c     |   8 +-
 src/calendar/e-cal-backend-etesync-factory.c |  36 ++++-
 src/calendar/e-cal-backend-etesync.c         |  28 ++--
 src/common/e-etesync-connection.c            | 220 ++++++++++++++++++++++++---
 src/common/e-etesync-connection.h            |   3 +
 src/common/e-etesync-defines.h               |   1 +
 src/common/e-etesync-utils.c                 |   7 +-
 src/common/e-etesync-utils.h                 |   8 +-
 src/evolution/e-cal-config-etesync.c         |   6 +
 src/registry/e-etesync-backend.c             |  55 +++++--
 10 files changed, 327 insertions(+), 45 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-etesync.c b/src/addressbook/e-book-backend-etesync.c
index 5fa2a4a..84657f3 100644
--- a/src/addressbook/e-book-backend-etesync.c
+++ b/src/addressbook/e-book-backend-etesync.c
@@ -279,10 +279,10 @@ ebb_etesync_save_contact_sync (EBookMetaBackend *meta_backend,
 
        if (overwrite_existing) {
                success = e_etesync_connection_item_upload_sync (connection, E_BACKEND (meta_backend), 
bbetesync->priv->col_obj,
-                               E_ETESYNC_ITEM_ACTION_MODIFY, content, uid, extra, out_new_extra, 
cancellable, error);
+                               E_ETESYNC_ITEM_ACTION_MODIFY, content, uid, extra, NULL, out_new_extra, 
cancellable, error);
        } else {
                success = e_etesync_connection_item_upload_sync (connection, E_BACKEND (meta_backend), 
bbetesync->priv->col_obj,
-                               E_ETESYNC_ITEM_ACTION_CREATE, content, uid, NULL, out_new_extra, cancellable, 
error);
+                               E_ETESYNC_ITEM_ACTION_CREATE, content, uid, NULL, NULL, out_new_extra, 
cancellable, error);
        }
 
        g_free (content);
@@ -314,7 +314,7 @@ ebb_etesync_remove_contact_sync (EBookMetaBackend *meta_backend,
        g_rec_mutex_lock (&bbetesync->priv->etesync_lock);
 
        success = e_etesync_connection_item_upload_sync (connection, E_BACKEND (meta_backend), 
bbetesync->priv->col_obj,
-                               E_ETESYNC_ITEM_ACTION_DELETE, NULL, uid, extra, NULL, cancellable, error);
+                               E_ETESYNC_ITEM_ACTION_DELETE, NULL, uid, extra, NULL, NULL, cancellable, 
error);
 
        g_rec_mutex_unlock (&bbetesync->priv->etesync_lock);
 
@@ -394,6 +394,7 @@ ebb_etesync_create_modify_contacts_sync (EBookBackendSync *backend,
                                                                                  bbetesync->priv->col_obj,
                                                                                  E_ETESYNC_ADDRESSBOOK,
                                                                                  (const gchar *const*) 
content,
+                                                                                 NULL,
                                                                                  batch_length, /* length of 
content */
                                                                                  E_CACHE (book_cache), /* 
uses book_cache if type is addressbook */
                                                                                  &batch_info,
@@ -545,6 +546,7 @@ ebb_etesync_remove_contacts_sync (EBookBackendSync *backend,
                                                                  bbetesync->priv->col_obj,
                                                                  E_ETESYNC_ADDRESSBOOK,
                                                                  (const gchar *const*) content,
+                                                                 NULL,
                                                                  batch_length, /* length of content */
                                                                  E_CACHE (book_cache), /* uses book_cache if 
type is addressbook */
                                                                  &batch_info,
diff --git a/src/calendar/e-cal-backend-etesync-factory.c b/src/calendar/e-cal-backend-etesync-factory.c
index 940c503..42b5297 100644
--- a/src/calendar/e-cal-backend-etesync-factory.c
+++ b/src/calendar/e-cal-backend-etesync-factory.c
@@ -20,6 +20,9 @@ typedef ECalBackendFactoryClass ECalBackendEteSyncEventsFactoryClass;
 typedef ECalBackendFactory ECalBackendEteSyncTodosFactory;
 typedef ECalBackendFactoryClass ECalBackendEteSyncTodosFactoryClass;
 
+typedef ECalBackendFactory ECalBackendEteSyncJournalFactory;
+typedef ECalBackendFactoryClass ECalBackendEteSyncJournalFactoryClass;
+
 static EModule *e_module;
 
 /* Module Entry Points */
@@ -29,7 +32,7 @@ void e_module_unload (GTypeModule *type_module);
 /* Forward Declarations */
 GType e_cal_backend_etesync_events_factory_get_type (void);
 GType e_cal_backend_etesync_todos_factory_get_type (void);
-
+GType e_cal_backend_etesync_journal_factory_get_type (void);
 
 G_DEFINE_DYNAMIC_TYPE (
        ECalBackendEteSyncEventsFactory,
@@ -41,6 +44,11 @@ G_DEFINE_DYNAMIC_TYPE (
        e_cal_backend_etesync_todos_factory,
        E_TYPE_CAL_BACKEND_FACTORY)
 
+G_DEFINE_DYNAMIC_TYPE (
+       ECalBackendEteSyncJournalFactory,
+       e_cal_backend_etesync_journal_factory,
+       E_TYPE_CAL_BACKEND_FACTORY)
+
 static void
 e_cal_backend_etesync_events_factory_class_init (ECalBackendFactoryClass *class)
 {
@@ -89,6 +97,31 @@ e_cal_backend_etesync_todos_factory_init (ECalBackendFactory *factory)
 {
 }
 
+static void
+e_cal_backend_etesync_journal_factory_class_init (ECalBackendFactoryClass *class)
+{
+       EBackendFactoryClass *backend_factory_class;
+
+       backend_factory_class = E_BACKEND_FACTORY_CLASS (class);
+       backend_factory_class->e_module = e_module;
+       backend_factory_class->share_subprocess = TRUE;
+
+       class->factory_name = FACTORY_NAME;
+       class->component_kind = I_CAL_VJOURNAL_COMPONENT;
+       class->backend_type = E_TYPE_CAL_BACKEND_ETESYNC;
+}
+
+static void
+e_cal_backend_etesync_journal_factory_class_finalize (ECalBackendFactoryClass *class)
+{
+}
+
+static void
+e_cal_backend_etesync_journal_factory_init (ECalBackendFactory *factory)
+{
+}
+
+
 G_MODULE_EXPORT void
 e_module_load (GTypeModule *type_module)
 {
@@ -101,6 +134,7 @@ e_module_load (GTypeModule *type_module)
 
        e_cal_backend_etesync_events_factory_register_type (type_module);
        e_cal_backend_etesync_todos_factory_register_type (type_module);
+       e_cal_backend_etesync_journal_factory_register_type (type_module);
 }
 
 G_MODULE_EXPORT void
diff --git a/src/calendar/e-cal-backend-etesync.c b/src/calendar/e-cal-backend-etesync.c
index 4742672..bce30e2 100644
--- a/src/calendar/e-cal-backend-etesync.c
+++ b/src/calendar/e-cal-backend-etesync.c
@@ -291,10 +291,10 @@ ecb_etesync_save_component_sync (ECalMetaBackend *meta_backend,
 
        if (overwrite_existing) {
                success = e_etesync_connection_item_upload_sync (connection, E_BACKEND (meta_backend), 
cbetesync->priv->col_obj,
-                       E_ETESYNC_ITEM_ACTION_MODIFY, content, uid, extra, out_new_extra, cancellable, error);
+                       E_ETESYNC_ITEM_ACTION_MODIFY, content, uid, extra, NULL, out_new_extra, cancellable, 
error);
        } else {
                success = e_etesync_connection_item_upload_sync (connection, E_BACKEND (meta_backend), 
cbetesync->priv->col_obj,
-                       E_ETESYNC_ITEM_ACTION_CREATE, content, uid, NULL, out_new_extra, cancellable, error);
+                       E_ETESYNC_ITEM_ACTION_CREATE, content, uid, NULL, out_new_uid, out_new_extra, 
cancellable, error);
        }
 
        g_free (content);
@@ -327,7 +327,7 @@ ecb_etesync_remove_component_sync (ECalMetaBackend *meta_backend,
        g_rec_mutex_lock (&cbetesync->priv->etesync_lock);
 
        success = e_etesync_connection_item_upload_sync (connection, E_BACKEND (meta_backend), 
cbetesync->priv->col_obj,
-                               E_ETESYNC_ITEM_ACTION_DELETE, NULL, uid, extra, NULL, cancellable, error);
+                               E_ETESYNC_ITEM_ACTION_DELETE, NULL, uid, extra, NULL, NULL, cancellable, 
error);
 
        g_rec_mutex_unlock (&cbetesync->priv->etesync_lock);
 
@@ -511,6 +511,7 @@ ecb_etesync_modify_objects_sync (ECalBackendSync *backend,
 
        /* extract the components and mass-add them to the server "batch by batch" */
        while (l && success) {
+               gchar *data_uids[E_ETESYNC_ITEM_PUSH_LIMIT];
                gchar **content;
                GSList *batch_out_old_components = NULL; /* ECalComponent* */
                GSList *batch_out_new_components= NULL; /* ECalComponent* */
@@ -549,10 +550,10 @@ ecb_etesync_modify_objects_sync (ECalBackendSync *backend,
                        } else
                                content[ii] = i_cal_component_as_ical_string (icomp);
 
-                       comp_uid = i_cal_component_get_uid (icomp);
+                       data_uids[ii] = g_strdup (i_cal_component_get_uid (icomp));
                        batch_out_new_components = g_slist_prepend (batch_out_new_components, 
e_cal_component_clone (comp));
 
-                       if (e_cal_cache_get_components_by_uid (cal_cache, comp_uid, &instances, NULL, NULL))
+                       if (e_cal_cache_get_components_by_uid (cal_cache, data_uids[ii], &instances, NULL, 
NULL))
                                batch_out_old_components = g_slist_concat (batch_out_old_components, 
instances);
 
                        g_object_unref (comp);
@@ -566,7 +567,8 @@ ecb_etesync_modify_objects_sync (ECalBackendSync *backend,
                                                                          cbetesync->priv->col_obj,
                                                                          E_ETESYNC_CALENDAR,
                                                                          (const gchar *const*) content,
-                                                                         batch_length, /* length of content 
*/
+                                                                         (const gchar *const*) data_uids,
+                                                                         batch_length, /* length of batch */
                                                                          E_CACHE (cal_cache), /* uses 
cal_cache if type is calendar */
                                                                          &batch_info,
                                                                          cancellable,
@@ -583,8 +585,10 @@ ecb_etesync_modify_objects_sync (ECalBackendSync *backend,
                        }
                }
 
-               for (ii = 0; ii < batch_length; ii++)
+               for (ii = 0; ii < batch_length; ii++) {
                        g_free (content[ii]);
+                       g_free (data_uids[ii]);
+               }
                g_slice_free1 (E_ETESYNC_ITEM_PUSH_LIMIT * sizeof (gchar *), content);
        }
 
@@ -644,6 +648,7 @@ ecb_etesync_remove_objects_sync (ECalBackendSync *backend,
 
        /* extract the components and mass-add them to the server "batch by batch" */
        while (l && success) {
+               gchar *data_uids[E_ETESYNC_ITEM_PUSH_LIMIT];
                gchar **content;
                GSList *batch_out_old_components = NULL; /* ECalComponent* */
                GSList *batch_info = NULL; /* ECalMetaBackendInfo* */
@@ -659,6 +664,7 @@ ecb_etesync_remove_objects_sync (ECalBackendSync *backend,
                        if (e_cal_cache_get_components_by_uid (cal_cache, e_cal_component_id_get_uid 
(l->data), &instances, cancellable, NULL)) {
                                vcal = e_cal_meta_backend_merge_instances (E_CAL_META_BACKEND (cbetesync), 
instances, TRUE);
                                content[ii] = i_cal_component_as_ical_string (vcal);
+                               data_uids[ii] = g_strdup (e_cal_component_id_get_uid (l->data));
                                g_object_unref (vcal);
                        } else {
                                success = FALSE;
@@ -677,7 +683,8 @@ ecb_etesync_remove_objects_sync (ECalBackendSync *backend,
                                                                          cbetesync->priv->col_obj,
                                                                          E_ETESYNC_CALENDAR,
                                                                          (const gchar *const*) content,
-                                                                         batch_length, /* length of content 
*/
+                                                                         (const gchar *const*) data_uids,
+                                                                         batch_length, /* length of batch */
                                                                          E_CACHE (cal_cache), /* uses 
cal_cache if type is calendar */
                                                                          &batch_info,
                                                                          cancellable,
@@ -692,8 +699,10 @@ ecb_etesync_remove_objects_sync (ECalBackendSync *backend,
                        }
                }
 
-               for (ii = 0; ii < batch_length; ii++)
+               for (ii = 0; ii < batch_length; ii++) {
                        g_free (content[ii]);
+                       g_free (data_uids[ii]);
+               }
                g_slice_free1 (E_ETESYNC_ITEM_PUSH_LIMIT * sizeof (gchar *), content);
        }
 
@@ -733,6 +742,7 @@ ecb_etesync_get_backend_property (ECalBackend *cal_backend,
                        E_CAL_STATIC_CAPABILITY_TASK_CAN_RECUR,
                        E_CAL_STATIC_CAPABILITY_COMPONENT_COLOR,
                        E_CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS,
+                       E_CAL_STATIC_CAPABILITY_SIMPLE_MEMO,
                        e_cal_meta_backend_get_capabilities (E_CAL_META_BACKEND (cbetesync)),
                        NULL);
        }  else if (g_str_equal (prop_name, E_CAL_BACKEND_PROPERTY_ALARM_EMAIL_ADDRESS)) {
diff --git a/src/common/e-etesync-connection.c b/src/common/e-etesync-connection.c
index 338bafd..c3a9646 100644
--- a/src/common/e-etesync-connection.c
+++ b/src/common/e-etesync-connection.c
@@ -573,6 +573,62 @@ e_etesync_connection_collection_delete_upload_sync (EEteSyncConnection *connecti
 }
 
 /* ------------------- Book and calendar common function ------------------- */
+static gchar *
+e_etesync_connection_notes_new_ical_string (glong creation_date,
+                                           glong last_modified,
+                                           const gchar *uid,
+                                           const gchar *revision,
+                                           const gchar *summary,
+                                           const gchar *description)
+{
+       ICalComponent *icomp;
+       ICalTime *itt;
+       glong tt;
+       gchar *ical_str;
+
+       icomp = i_cal_component_new_vjournal ();
+
+       if (creation_date > 0)
+               tt = creation_date;
+       else if (last_modified > 0)
+               tt = last_modified;
+       else
+               tt = (time_t) time (NULL);
+
+       itt = i_cal_time_new_from_timet_with_zone ((time_t) tt, FALSE, i_cal_timezone_get_utc_timezone ());
+       i_cal_component_take_property (icomp, i_cal_property_new_created (itt));
+       g_object_unref (itt);
+
+       if (last_modified > 0)
+               tt = last_modified;
+       else
+               tt = (time_t) time (NULL);
+
+       itt = i_cal_time_new_from_timet_with_zone ((time_t) tt, FALSE, i_cal_timezone_get_utc_timezone ());
+       i_cal_component_take_property (icomp, i_cal_property_new_lastmodified (itt));
+       g_object_unref (itt);
+
+       i_cal_component_set_uid (icomp, uid);
+
+       if (summary && g_str_has_suffix (summary, ".txt")) {
+               gchar *tmp;
+
+               tmp = g_strndup (summary, strlen (summary) - 4);
+               i_cal_component_set_summary (icomp, tmp);
+               g_free (tmp);
+       } else if (summary && *summary) {
+               i_cal_component_set_summary (icomp, summary);
+       }
+
+       if (description)
+               i_cal_component_set_description (icomp, description);
+
+       ical_str = i_cal_component_as_ical_string (icomp);
+
+       g_object_unref (icomp);
+
+       return ical_str;
+}
 
 static gboolean
 e_etesync_connection_chunk_itemlist_fetch_sync (EtebaseItemManager *item_mgr,
@@ -619,6 +675,7 @@ e_etesync_connection_list_existing_sync (EEteSyncConnection *connection,
        gchar *stoken = NULL;
        gboolean done = FALSE;
        gboolean success = TRUE;
+       ESource *source;
 
        *out_existing_objects = NULL;
        *out_new_sync_tag = NULL;
@@ -630,6 +687,7 @@ e_etesync_connection_list_existing_sync (EEteSyncConnection *connection,
                return FALSE;
        }
 
+       source = e_backend_get_source (E_BACKEND (backend));
        item_mgr = etebase_collection_manager_get_item_manager (connection->priv->col_mgr, col_obj);
 
        while (!done) {
@@ -677,9 +735,29 @@ e_etesync_connection_list_existing_sync (EEteSyncConnection *connection,
                                                } else if (type == E_ETESYNC_CALENDAR) {
                                                        ECalMetaBackendInfo *nfo;
 
-                                                       /* create ECalMetaBackendInfo * to be stored in 
GSList, data_uid is component uid */
-                                                       e_etesync_utils_get_component_uid_revision (content ? 
content : buf, &data_uid, &revision);
-                                                       nfo = e_cal_meta_backend_info_new (data_uid, 
revision, content ? content : buf, item_cache_b64);
+                                                       if (e_source_has_extension (source, 
E_SOURCE_EXTENSION_MEMO_LIST)) {
+                                                               EtebaseItemMetadata *item_meta;
+                                                               const gchar *summery;
+                                                               gchar *ical_str;
+                                                               glong now;
+
+                                                               item_meta = etebase_item_get_meta (item);
+                                                               summery = etebase_item_metadata_get_name 
(item_meta);
+                                                               data_uid = g_strdup (etebase_item_get_uid 
(item));
+                                                               e_etesync_utils_get_time_now (&now);
+
+                                                               //change plain text to a icomp vjournal object
+                                                               ical_str = 
e_etesync_connection_notes_new_ical_string (now, now, data_uid, NULL, summery, content ? content : buf);
+                                                               nfo = e_cal_meta_backend_info_new (data_uid, 
NULL, ical_str, item_cache_b64);
+
+                                                               g_free (ical_str);
+                                                               etebase_item_metadata_destroy (item_meta);
+                                                       } else {
+                                                               /* create ECalMetaBackendInfo * to be stored 
in GSList, data_uid is component uid */
+                                                               e_etesync_utils_get_component_uid_revision 
(content ? content : buf, &data_uid, &revision);
+                                                               nfo = e_cal_meta_backend_info_new (data_uid, 
revision, content ? content : buf, item_cache_b64);
+                                                       }
+
                                                        *out_existing_objects = g_slist_prepend 
(*out_existing_objects, nfo);
                                                }
 
@@ -733,6 +811,7 @@ e_etesync_connection_get_changes_sync (EEteSyncConnection *connection,
        gchar *stoken;
        gboolean done = FALSE;
        gboolean success = TRUE;
+       ESource *source;
 
        stoken = g_strdup (last_sync_tag);
 
@@ -743,6 +822,7 @@ e_etesync_connection_get_changes_sync (EEteSyncConnection *connection,
                return FALSE;
        }
 
+       source = e_backend_get_source (E_BACKEND (backend));
        item_mgr = etebase_collection_manager_get_item_manager (connection->priv->col_mgr, col_obj);
 
        while (!done) {
@@ -802,10 +882,29 @@ e_etesync_connection_get_changes_sync (EEteSyncConnection *connection,
                                        } else if (type == E_ETESYNC_CALENDAR) {
                                                ECalMetaBackendInfo *nfo;
 
-                                               /* create ECalMetaBackendInfo * to be stored in GSList, data 
uid is compounent uid */
-                                               e_etesync_utils_get_component_uid_revision (content ? content 
: buf, &data_uid, &revision);
+                                               if (e_source_has_extension (source, 
E_SOURCE_EXTENSION_MEMO_LIST)) {
+                                                       EtebaseItemMetadata *item_meta;
+                                                       const gchar *summery;
+                                                       gchar *ical_str;
+                                                       glong now;
+
+                                                       item_meta = etebase_item_get_meta (item);
+                                                       summery = etebase_item_metadata_get_name (item_meta);
+                                                       data_uid = g_strdup (etebase_item_get_uid (item));
+                                                       e_etesync_utils_get_time_now (&now);
+
+                                                       //change plain text to a icomp vjournal object
+                                                       ical_str = e_etesync_connection_notes_new_ical_string 
(now, now, data_uid, NULL, summery, content ? content : buf);
+                                                       nfo = e_cal_meta_backend_info_new (data_uid, NULL, 
ical_str, item_cache_b64);
+
+                                                       g_free (ical_str);
+                                                       etebase_item_metadata_destroy (item_meta);
+                                               } else {
+                                                       /* create ECalMetaBackendInfo * to be stored in 
GSList, data uid is compounent uid */
+                                                       e_etesync_utils_get_component_uid_revision (content ? 
content : buf, &data_uid, &revision);
+                                                       nfo = e_cal_meta_backend_info_new (data_uid, 
revision, content ? content : buf, item_cache_b64);
+                                               }
 
-                                               nfo = e_cal_meta_backend_info_new (data_uid, revision, 
content ? content : buf, item_cache_b64);
                                                is_exist = e_cache_contains (cache, data_uid, 
E_CACHE_EXCLUDE_DELETED);
 
                                                /* data with uid exist, then it is modified or deleted, else 
it is new data */
@@ -863,6 +962,7 @@ e_etesync_connection_item_upload_sync (EEteSyncConnection *connection,
                                       const gchar *content,
                                       const gchar *uid,
                                       const gchar *extra, /* item_cache_b64 */
+                                      gchar **out_new_uid,
                                       gchar **out_new_extra,
                                       GCancellable *cancellable,
                                       GError **error)
@@ -870,6 +970,7 @@ e_etesync_connection_item_upload_sync (EEteSyncConnection *connection,
        EtebaseItemManager *item_mgr;
        gboolean success = TRUE;
        const gchar *item_cache_b64 = extra;
+       ESource *source;
 
        g_return_val_if_fail (connection != NULL, FALSE);
        g_return_val_if_fail (col_obj != NULL, FALSE);
@@ -879,22 +980,42 @@ e_etesync_connection_item_upload_sync (EEteSyncConnection *connection,
 
        g_rec_mutex_lock (&connection->priv->connection_lock);
 
+       source = e_backend_get_source (E_BACKEND (backend));
        item_mgr = etebase_collection_manager_get_item_manager (connection->priv->col_mgr, col_obj);
 
        if (item_mgr) {
                EtebaseItemMetadata *item_metadata = NULL;
                EtebaseItem *item;
                time_t now;
+               gchar *item_name, *item_content; /* Added to support EteSync notes type */
 
+               item_name = g_strdup (uid);
+               item_content = g_strdup (content);
                e_etesync_utils_get_time_now (&now);
 
+               /* If it is etesync note item, then set the EteSyncitem metadata name (uid) to summery in 
VJOURNAL
+                  and set the EteSyncItem content to the description in VJOURNAL */
+               if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)
+                   && action != E_ETESYNC_ITEM_ACTION_DELETE) {
+                       ICalComponent *icomp = i_cal_component_new_from_string (content);
+
+                       g_free (item_name);
+                       g_free (item_content);
+
+                       item_name = g_strdup (i_cal_component_get_summary (icomp)); /* set data_uid to 
summary */
+                       item_content = g_strdup (i_cal_component_get_description (icomp)); /* set content to 
description */
+                       item_content = item_content ? item_content : g_strdup ("");
+
+                       g_object_unref (icomp);
+               }
+
                if (action == E_ETESYNC_ITEM_ACTION_CREATE) {
                        item_metadata = etebase_item_metadata_new ();
 
-                       etebase_item_metadata_set_name (item_metadata, uid);
+                       etebase_item_metadata_set_name (item_metadata, item_name);
                        etebase_item_metadata_set_mtime (item_metadata, &now);
 
-                       item = etebase_item_manager_create (item_mgr, item_metadata, content, strlen 
(content));
+                       item = etebase_item_manager_create (item_mgr, item_metadata, item_content, strlen 
(item_content));
                } else {
                        item = e_etesync_utils_etebase_item_from_base64 (item_cache_b64, item_mgr);
                        if (!item) {
@@ -904,11 +1025,12 @@ e_etesync_connection_item_upload_sync (EEteSyncConnection *connection,
                        } else {
                                item_metadata = etebase_item_get_meta (item);
 
+                               etebase_item_metadata_set_name (item_metadata, item_name);
                                etebase_item_metadata_set_mtime (item_metadata, &now);
                                etebase_item_set_meta(item, item_metadata);
 
                                if (action == E_ETESYNC_ITEM_ACTION_MODIFY)
-                                       etebase_item_set_content (item, content, strlen (content));
+                                       etebase_item_set_content (item, item_content, strlen (item_content));
                                else if (action == E_ETESYNC_ITEM_ACTION_DELETE)
                                        etebase_item_delete (item);
                        }
@@ -934,11 +1056,20 @@ e_etesync_connection_item_upload_sync (EEteSyncConnection *connection,
                        if (out_new_extra)
                                *out_new_extra = success ? e_etesync_utils_etebase_item_to_base64 (item, 
item_mgr) : NULL;
 
+                       /* Set the new uid for notes from the EteSyncitem uid, as EteSync notes item doesn't 
contain
+                          uid in it's content as other etesync types (calendar, tasks, contacts) */
+                       if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)
+                           && out_new_uid
+                           && action == E_ETESYNC_ITEM_ACTION_CREATE)
+                               *out_new_uid = g_strdup (etebase_item_get_uid (item));
+
                        if (item_metadata)
                                etebase_item_metadata_destroy (item_metadata);
                        etebase_item_destroy (item);
                }
 
+               g_free (item_name);
+               g_free (item_content);
                etebase_item_manager_destroy (item_mgr);
        }
 
@@ -954,6 +1085,7 @@ e_etesync_connection_batch_modify_delete_sync (EEteSyncConnection *connection,
                                               const EteSyncAction action,
                                               const EteSyncType type,
                                               const gchar *const *content,
+                                              const gchar *const *data_uids,
                                               guint content_len,
                                               ECache *cache,
                                               GSList **out_batch_info,
@@ -962,6 +1094,7 @@ e_etesync_connection_batch_modify_delete_sync (EEteSyncConnection *connection,
 {
        EtebaseItemManager *item_mgr;
        gboolean success = TRUE;
+       ESource *source;
 
        g_return_val_if_fail (connection != NULL, FALSE);
        g_return_val_if_fail (col_obj != NULL, FALSE);
@@ -971,6 +1104,7 @@ e_etesync_connection_batch_modify_delete_sync (EEteSyncConnection *connection,
 
        g_rec_mutex_lock (&connection->priv->connection_lock);
 
+       source = e_backend_get_source (E_BACKEND (backend));
        item_mgr = etebase_collection_manager_get_item_manager (connection->priv->col_mgr, col_obj);
 
        if (item_mgr) {
@@ -990,7 +1124,12 @@ e_etesync_connection_batch_modify_delete_sync (EEteSyncConnection *connection,
                                e_etesync_utils_get_contact_uid_revision (content[ii], &data_uid, &revision);
                                e_book_cache_get_contact_extra (E_BOOK_CACHE (cache), data_uid, 
&item_cache_b64, NULL, NULL);
                        } else if (type == E_ETESYNC_CALENDAR) {/* Calendar */
-                               e_etesync_utils_get_component_uid_revision (content[ii], &data_uid, 
&revision);
+
+                               if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST))
+                                       data_uid = g_strdup (data_uids[ii]);
+                               else
+                                       e_etesync_utils_get_component_uid_revision (content[ii], &data_uid, 
&revision);
+
                                e_cal_cache_get_component_extra (E_CAL_CACHE (cache), data_uid, NULL, 
&item_cache_b64, NULL, NULL);
                        }
 
@@ -1006,9 +1145,26 @@ e_etesync_connection_batch_modify_delete_sync (EEteSyncConnection *connection,
                                etebase_item_metadata_set_mtime (item_metadata, &now);
                                etebase_item_set_meta(items[ii], item_metadata);
 
-                               if (action == E_ETESYNC_ITEM_ACTION_MODIFY) /* Modify */
-                                       etebase_item_set_content (items[ii], content[ii], strlen 
(content[ii]));
-                               else if (action == E_ETESYNC_ITEM_ACTION_DELETE) /* Delete */
+                               if (action == E_ETESYNC_ITEM_ACTION_MODIFY) {/* Modify */
+
+                                       if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)) { 
/* notes */
+                                               ICalComponent *icomp;
+                                               const gchar *notes_item_content; /* notes_item_content is add 
to support EteSync notes */
+
+                                               icomp = i_cal_component_new_from_string (content[ii]);
+                                               notes_item_content = i_cal_component_get_description (icomp);
+                                               notes_item_content = notes_item_content ? notes_item_content 
: "";
+
+                                               etebase_item_metadata_set_name (item_metadata, 
i_cal_component_get_summary (icomp));
+                                               etebase_item_set_meta(items[ii], item_metadata);
+
+                                               etebase_item_set_content (items[ii], notes_item_content, 
strlen (notes_item_content));
+
+                                               g_object_unref (icomp);
+                                       } else { /* Events and Tasks */
+                                               etebase_item_set_content (items[ii], content[ii], strlen 
(content[ii]));
+                                       }
+                               } else if (action == E_ETESYNC_ITEM_ACTION_DELETE) /* Delete */
                                        etebase_item_delete (items[ii]);
 
                                g_free (item_cache_b64);
@@ -1074,6 +1230,7 @@ e_etesync_connection_batch_create_sync (EEteSyncConnection *connection,
 {
        EtebaseItemManager *item_mgr;
        gboolean success = TRUE;
+       ESource *source;
 
        g_return_val_if_fail (connection != NULL, FALSE);
        g_return_val_if_fail (col_obj != NULL, FALSE);
@@ -1083,6 +1240,7 @@ e_etesync_connection_batch_create_sync (EEteSyncConnection *connection,
 
        g_rec_mutex_lock (&connection->priv->connection_lock);
 
+       source = e_backend_get_source (E_BACKEND (backend));
        item_mgr = etebase_collection_manager_get_item_manager (connection->priv->col_mgr, col_obj);
 
        if (item_mgr) {
@@ -1094,20 +1252,37 @@ e_etesync_connection_batch_create_sync (EEteSyncConnection *connection,
 
                for (ii = 0; ii < content_len; ii++) {
                        EtebaseItemMetadata *item_metadata = NULL;
-                       gchar *data_uid = NULL, *revision = NULL;
+                       gchar *data_uid = NULL, *revision = NULL, *notes_item_content = NULL; /* 
notes_item_content is add to support EteSync notes */
                        gchar *item_cache_b64;
 
                        if (type == E_ETESYNC_ADDRESSBOOK) /* Contact */
                                e_etesync_utils_get_contact_uid_revision (content[ii], &data_uid, &revision);
-                       else if (type == E_ETESYNC_CALENDAR) /* Calendar */
-                               e_etesync_utils_get_component_uid_revision (content[ii], &data_uid, 
&revision);
+                       else if (type == E_ETESYNC_CALENDAR) { /* Calendar */
+                               if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)) { /* Notes 
*/
+                                       ICalComponent *icomp = i_cal_component_new_from_string (content[ii]);
+
+                                       data_uid = g_strdup (i_cal_component_get_summary (icomp));
+                                       notes_item_content = g_strdup (i_cal_component_get_description 
(icomp));
+                                       notes_item_content = notes_item_content ? notes_item_content : 
g_strdup ("");
+
+                                       g_object_unref (icomp);
+                               } else { /* Events and Tasks */
+                                       e_etesync_utils_get_component_uid_revision (content[ii], &data_uid, 
&revision);
+                               }
+                       }
 
                        item_metadata = etebase_item_metadata_new ();
 
                        etebase_item_metadata_set_name (item_metadata, data_uid);
                        etebase_item_metadata_set_mtime (item_metadata, &now);
 
-                       items[ii] = etebase_item_manager_create (item_mgr, item_metadata, content[ii], strlen 
(content[ii]));
+                       if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)) { /* Notes */
+                               items[ii] = etebase_item_manager_create (item_mgr, item_metadata, 
notes_item_content, strlen (notes_item_content));
+                               g_free (notes_item_content);
+                       } else { /* Addressbook, Calendar, Task */
+                               items[ii] = etebase_item_manager_create (item_mgr, item_metadata, 
content[ii], strlen (content[ii]));
+                       }
+
                        item_cache_b64 = e_etesync_utils_etebase_item_to_base64 (items[ii], item_mgr);
 
                        if (type == E_ETESYNC_ADDRESSBOOK) { /* Contact */
@@ -1118,6 +1293,11 @@ e_etesync_connection_batch_create_sync (EEteSyncConnection *connection,
                        } else if (type == E_ETESYNC_CALENDAR) { /* Calendar */
                                ECalMetaBackendInfo *nfo;
 
+                               if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)) { /* Notes 
*/
+                                       g_free (data_uid);
+                                       data_uid = g_strdup (etebase_item_get_uid (items[ii]));
+                               }
+
                                nfo = e_cal_meta_backend_info_new (data_uid, revision, content[ii], 
item_cache_b64);
                                *out_batch_info = g_slist_prepend (*out_batch_info, nfo);
                        }
@@ -1159,13 +1339,14 @@ e_etesync_connection_batch_modify_sync (EEteSyncConnection *connection,
                                        const EtebaseCollection *col_obj,
                                        const EteSyncType type,
                                        const gchar *const *content,
+                                       const gchar *const *data_uids,
                                        guint content_len,
                                        ECache *cache,
                                        GSList **out_batch_info,
                                        GCancellable *cancellable,
                                        GError **error)
 {
-       return e_etesync_connection_batch_modify_delete_sync (connection, backend, col_obj, 
E_ETESYNC_ITEM_ACTION_MODIFY, type, content, content_len, cache, out_batch_info, cancellable, error);
+       return e_etesync_connection_batch_modify_delete_sync (connection, backend, col_obj, 
E_ETESYNC_ITEM_ACTION_MODIFY, type, content, data_uids, content_len, cache, out_batch_info, cancellable, 
error);
 }
 
 gboolean
@@ -1174,13 +1355,14 @@ e_etesync_connection_batch_delete_sync (EEteSyncConnection *connection,
                                        const EtebaseCollection *col_obj,
                                        const EteSyncType type,
                                        const gchar *const *content,
+                                       const gchar *const *data_uids,
                                        guint content_len,
                                        ECache *cache,
                                        GSList **out_batch_info,
                                        GCancellable *cancellable,
                                        GError **error)
 {
-       return e_etesync_connection_batch_modify_delete_sync (connection, backend, col_obj, 
E_ETESYNC_ITEM_ACTION_DELETE, type, content, content_len, cache, out_batch_info, cancellable, error);
+       return e_etesync_connection_batch_modify_delete_sync (connection, backend, col_obj, 
E_ETESYNC_ITEM_ACTION_DELETE, type, content, data_uids, content_len, cache, out_batch_info, cancellable, 
error);
 }
 
 /*----------------------------GObject functions----------------------*/
diff --git a/src/common/e-etesync-connection.h b/src/common/e-etesync-connection.h
index ea2291d..5b5c9bd 100644
--- a/src/common/e-etesync-connection.h
+++ b/src/common/e-etesync-connection.h
@@ -129,6 +129,7 @@ gboolean    e_etesync_connection_item_upload_sync
                                                 const gchar *content,
                                                 const gchar *uid,
                                                 const gchar *extra,
+                                                gchar **out_new_uid,
                                                 gchar **out_new_extra,
                                                 GCancellable *cancellable,
                                                 GError **error);
@@ -148,6 +149,7 @@ gboolean    e_etesync_connection_batch_modify_sync
                                                 const EtebaseCollection *col_obj,
                                                 const EteSyncType type,
                                                 const gchar *const *content,
+                                                const gchar *const *data_uids,
                                                 guint content_len,
                                                 ECache *cache,
                                                 GSList **out_batch_info,
@@ -159,6 +161,7 @@ gboolean    e_etesync_connection_batch_delete_sync
                                                 const EtebaseCollection *col_obj,
                                                 const EteSyncType type,
                                                 const gchar *const *content,
+                                                const gchar *const *data_uids,
                                                 guint content_len,
                                                 ECache *cache,
                                                 GSList **out_batch_info,
diff --git a/src/common/e-etesync-defines.h b/src/common/e-etesync-defines.h
index 1a48db8..9630cf4 100644
--- a/src/common/e-etesync-defines.h
+++ b/src/common/e-etesync-defines.h
@@ -24,6 +24,7 @@ typedef enum {
 #define E_ETESYNC_COLLECTION_TYPE_CALENDAR "etebase.vevent"
 #define E_ETESYNC_COLLECTION_TYPE_ADDRESS_BOOK "etebase.vcard"
 #define E_ETESYNC_COLLECTION_TYPE_TASKS "etebase.vtodo"
+#define E_ETESYNC_COLLECTION_TYPE_NOTES "etebase.md.note"
 
 #define E_ETESYNC_COLLECTION_DEFAULT_COLOR "#8BC34A"
 
diff --git a/src/common/e-etesync-utils.c b/src/common/e-etesync-utils.c
index 6752c07..fa1f62e 100644
--- a/src/common/e-etesync-utils.c
+++ b/src/common/e-etesync-utils.c
@@ -15,11 +15,13 @@
 static const gchar *const collection_supported_types[] = {
                        E_ETESYNC_COLLECTION_TYPE_ADDRESS_BOOK,
                        E_ETESYNC_COLLECTION_TYPE_CALENDAR,
-                       E_ETESYNC_COLLECTION_TYPE_TASKS };
+                       E_ETESYNC_COLLECTION_TYPE_TASKS,
+                       E_ETESYNC_COLLECTION_TYPE_NOTES};
 static const gchar *const collection_supported_types_default_names[] = {
                        "My Contacts",
                        "My Calendar",
-                       "My Tasks" };
+                       "My Tasks",
+                       "My Notes"};
 
 void
 e_etesync_utils_get_time_now (time_t *now)
@@ -47,6 +49,7 @@ e_etesync_utils_get_component_uid_revision (const gchar *content,
                ICalComponentKind kind = i_cal_component_isa (subcomp);
 
                if (kind == I_CAL_VEVENT_COMPONENT ||
+                   kind == I_CAL_VJOURNAL_COMPONENT ||
                    kind == I_CAL_VTODO_COMPONENT) {
                        if (!*out_component_uid){
                                *out_component_uid = g_strdup (i_cal_component_get_uid (subcomp));
diff --git a/src/common/e-etesync-utils.h b/src/common/e-etesync-utils.h
index 11e35bb..bb4bdbe 100644
--- a/src/common/e-etesync-utils.h
+++ b/src/common/e-etesync-utils.h
@@ -11,7 +11,13 @@
 #include <libedataserver/libedataserver.h>
 #include <etebase.h>
 
-#define EETESYNC_UTILS_SUPPORTED_TYPES_SIZE 3
+#define EETESYNC_UTILS_SUPPORTED_TYPES_SIZE 4
+
+// Collection indexs in 'collection_supported_types'
+#define COLLECTION_INDEX_TYPE_ADDRESSBOOK 0
+#define COLLECTION_INDEX_TYPE_CALENDAR 1
+#define COLLECTION_INDEX_TYPE_TASKS 2
+#define COLLECTION_INDEX_TYPE_NOTES 3
 
 G_BEGIN_DECLS
 
diff --git a/src/evolution/e-cal-config-etesync.c b/src/evolution/e-cal-config-etesync.c
index f29952f..bb07fd5 100644
--- a/src/evolution/e-cal-config-etesync.c
+++ b/src/evolution/e-cal-config-etesync.c
@@ -35,6 +35,7 @@ cal_config_etesync_allow_creation (ESourceConfigBackend *backend)
        switch (source_type) {
                case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
                case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
+               case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
                        allow_creation = TRUE;
                        break;
 
@@ -90,6 +91,11 @@ cal_config_etesync_commit_changes (ESourceConfigBackend *backend,
                                col_type = E_ETESYNC_COLLECTION_TYPE_TASKS;
                        }
 
+                       if (e_source_has_extension (scratch_source, E_SOURCE_EXTENSION_MEMO_LIST)) {
+                               extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+                               col_type = E_ETESYNC_COLLECTION_TYPE_NOTES;
+                       }
+
                        if (col_type) {
                                ESourceBackend *source_backend;
                                ESourceEteSync *etesync_extension;
diff --git a/src/registry/e-etesync-backend.c b/src/registry/e-etesync-backend.c
index d2d4423..db91193 100644
--- a/src/registry/e-etesync-backend.c
+++ b/src/registry/e-etesync-backend.c
@@ -60,6 +60,7 @@ etesync_backend_update_enabled (ESource *data_source,
 
        if (e_source_has_extension (data_source, E_SOURCE_EXTENSION_CALENDAR) ||
            e_source_has_extension (data_source, E_SOURCE_EXTENSION_TASK_LIST) ||
+           e_source_has_extension (data_source, E_SOURCE_EXTENSION_MEMO_LIST) ||
            e_source_has_extension (data_source, E_SOURCE_EXTENSION_ADDRESS_BOOK)) {
                part_enabled = !collection_extension
                                || e_source_collection_get_calendar_enabled (collection_extension)
@@ -152,6 +153,8 @@ etesync_backend_new_child (EEteSyncBackend *backend,
                extension_name = E_SOURCE_EXTENSION_TASK_LIST;
        } else if (g_str_equal (type, E_ETESYNC_COLLECTION_TYPE_ADDRESS_BOOK)) {
                extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+       } else if (g_str_equal (type, E_ETESYNC_COLLECTION_TYPE_NOTES)) {
+               extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
        } else {
                g_object_unref (source);
                return NULL;
@@ -251,8 +254,10 @@ etesync_check_create_modify (EEteSyncBackend *backend,
                        extension_name = E_SOURCE_EXTENSION_CALENDAR;
                if (e_source_has_extension (source, E_SOURCE_EXTENSION_TASK_LIST))
                        extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+               if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST))
+                       extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
 
-               /* If extention_name has be set then this is a calendar or task which both have colors
+               /* If extention_name has be set then this is a calendar or task or memos which both have 
colors
                   address-book doesn't have color */
                if (extension_name) {
                        source_backend = e_source_get_extension (source, extension_name);
@@ -499,28 +504,53 @@ etesync_backend_sync_folders_sync (EEteSyncBackend *backend,
        if (is_first_time) {
                EtebaseCollectionListResponse *col_list;
                EtebaseFetchOptions *fetch_options;
+               const gchar *const *collection_supported_types;
+               const gchar *const *collection_supported_types_default_names;
+               const gchar *collection_default_supported_types[3];
+               gint ii;
 
                fetch_options = etebase_fetch_options_new();
                etebase_fetch_options_set_prefetch(fetch_options, ETEBASE_PREFETCH_OPTION_MEDIUM);
                etebase_fetch_options_set_stoken (fetch_options, NULL);
                etebase_fetch_options_set_limit (fetch_options, 1);
 
+               collection_supported_types = e_etesync_util_get_collection_supported_types ();
+               collection_supported_types_default_names = 
e_etesync_util_get_collection_supported_types_default_names ();
+
+               // Check default type (contacts, calendar and tasks)
+               collection_default_supported_types[0] = 
collection_supported_types[COLLECTION_INDEX_TYPE_ADDRESSBOOK];
+               collection_default_supported_types[1] = 
collection_supported_types[COLLECTION_INDEX_TYPE_CALENDAR];
+               collection_default_supported_types[2] = 
collection_supported_types[COLLECTION_INDEX_TYPE_TASKS];
+
                col_list =  etebase_collection_manager_list_multi 
(e_etesync_connection_get_collection_manager (connection),
-                                                                  
e_etesync_util_get_collection_supported_types (),
-                                                                  EETESYNC_UTILS_SUPPORTED_TYPES_SIZE,
+                                                                  collection_default_supported_types,
+                                                                  3,
                                                                   fetch_options);
 
                if (etebase_collection_list_response_get_data_length (col_list) == 0) {
-                       gint ii = 0;
                        const gchar *temp_stoken;
-                       const gchar *const *collection_supported_types;
-                       const gchar *const *collection_supported_types_default_names;
 
-                       collection_supported_types = e_etesync_util_get_collection_supported_types ();
-                       collection_supported_types_default_names = 
e_etesync_util_get_collection_supported_types_default_names ();
+                       for (ii = COLLECTION_INDEX_TYPE_ADDRESSBOOK; ii <= COLLECTION_INDEX_TYPE_TASKS; ii++)
+                               temp_stoken = etesync_backend_create_and_add_collection_sync (backend, 
server, collection_supported_types[ii],
+                                                                                             
collection_supported_types_default_names[ii], cancellable);
 
-                       for (ii = 0; ii < EETESYNC_UTILS_SUPPORTED_TYPES_SIZE; ii++)
-                               temp_stoken = etesync_backend_create_and_add_collection_sync (backend, 
server, collection_supported_types[ii], collection_supported_types_default_names[ii], cancellable);
+                       if (temp_stoken) {
+                               g_free (stoken);
+                               stoken = g_strdup (temp_stoken);
+                       }
+               }
+
+               // Check (Notes) type
+               etebase_collection_list_response_destroy (col_list);
+               col_list = etebase_collection_manager_list (e_etesync_connection_get_collection_manager 
(connection),
+                                                           E_ETESYNC_COLLECTION_TYPE_NOTES,
+                                                           fetch_options);
+
+               if (etebase_collection_list_response_get_data_length (col_list) == 0) {
+                       const gchar *temp_stoken;
+
+                       temp_stoken = etesync_backend_create_and_add_collection_sync (backend, server, 
collection_supported_types[COLLECTION_INDEX_TYPE_NOTES],
+                                                                                     
collection_supported_types_default_names[COLLECTION_INDEX_TYPE_NOTES], cancellable);
 
                        if (temp_stoken) {
                                g_free (stoken);
@@ -592,6 +622,11 @@ etesync_backend_create_resource_sync (ECollectionBackend *backend,
                col_type = E_ETESYNC_COLLECTION_TYPE_TASKS;
        }
 
+       if (e_source_has_extension (source, E_SOURCE_EXTENSION_MEMO_LIST)) {
+               extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+               col_type = E_ETESYNC_COLLECTION_TYPE_NOTES;
+       }
+
        if (col_type == NULL) {
                success = FALSE;
        }


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