[evolution-data-server/wip/offline-cache] Replace true/false parameters with more descriptive enums
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/offline-cache] Replace true/false parameters with more descriptive enums
- Date: Tue, 21 Mar 2017 17:32:03 +0000 (UTC)
commit c5131048073ef8abfc07c6c4adcf4ab958562d69
Author: Milan Crha <mcrha redhat com>
Date: Fri Feb 3 12:15:58 2017 +0100
Replace true/false parameters with more descriptive enums
plus some other fine-tuning and changes.
src/addressbook/libedata-book/e-book-cache.c | 45 ++--
src/addressbook/libedata-book/e-book-cache.h | 8 +-
src/libebackend/e-cache.c | 263 ++++++++-------------
src/libebackend/e-cache.h | 64 ++++--
tests/libedata-book/test-cache-cursor-calculate.c | 12 +-
tests/libedata-book/test-cache-offline.c | 106 ++++----
tests/libedata-book/test-cache-utils.c | 4 +-
7 files changed, 233 insertions(+), 269 deletions(-)
---
diff --git a/src/addressbook/libedata-book/e-book-cache.c b/src/addressbook/libedata-book/e-book-cache.c
index 778bdfd..ff4808c 100644
--- a/src/addressbook/libedata-book/e-book-cache.c
+++ b/src/addressbook/libedata-book/e-book-cache.c
@@ -1298,7 +1298,7 @@ ebc_upgrade (EBookCache *book_cache,
{
gboolean success;
- success = e_cache_foreach_update (E_CACHE (book_cache), FALSE, NULL,
+ success = e_cache_foreach_update (E_CACHE (book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
ebc_upgrade_cb, NULL, cancellable, error);
/* Store the new locale & country code */
@@ -4199,7 +4199,7 @@ e_book_cache_migrate (ECache *cache,
if (!contact)
continue;
- success = e_book_cache_put_contact (book_cache, contact, data->extra, FALSE,
cancellable, error);
+ success = e_book_cache_put_contact (book_cache, contact, data->extra,
E_CACHE_IS_ONLINE, cancellable, error);
}
}
@@ -4664,9 +4664,9 @@ e_book_cache_ref_collator (EBookCache *book_cache)
/**
* e_book_cache_put_contact:
* @book_cache: An #EBookCache
- * @contact: EContact to be added
- * @extra: Extra data to store in association with this contact
- * @is_offline: Whether putting this contact in offline
+ * @contact: an #EContact to be added
+ * @extra: extra data to store in association with this contact
+ * @offline_flag: one of #ECacheOfflineFlag, whether putting this contact in offline
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
@@ -4681,7 +4681,7 @@ gboolean
e_book_cache_put_contact (EBookCache *book_cache,
EContact *contact,
const gchar *extra,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error)
{
@@ -4694,7 +4694,7 @@ e_book_cache_put_contact (EBookCache *book_cache,
contacts = g_slist_append (NULL, contact);
extras = g_slist_append (NULL, (gpointer) extra);
- success = e_book_cache_put_contacts (book_cache, contacts, extras, is_offline, cancellable, error);
+ success = e_book_cache_put_contacts (book_cache, contacts, extras, offline_flag, cancellable, error);
g_slist_free (contacts);
g_slist_free (extras);
@@ -4707,7 +4707,7 @@ e_book_cache_put_contact (EBookCache *book_cache,
* @book_cache: An #EBookCache
* @contacts: (element-type EContact): A list of contacts to add to @book_cache
* @extras: (nullable) (element-type utf8): A list of extra data to store in association with the @contacts
- * @is_offline: Whether putting these contacts in offline
+ * @offline_flag: one of #ECacheOfflineFlag offline_flag, whether putting these contacts in offline
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
@@ -4725,7 +4725,7 @@ gboolean
e_book_cache_put_contacts (EBookCache *book_cache,
const GSList *contacts,
const GSList *extras,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error)
{
@@ -4763,10 +4763,7 @@ e_book_cache_put_contacts (EBookCache *book_cache,
ebc_fill_other_columns (book_cache, contact, other_columns);
- if (is_offline)
- success = e_cache_put_offline (cache, uid, rev, vcard, other_columns, cancellable,
error);
- else
- success = e_cache_put (cache, uid, rev, vcard, other_columns, cancellable, error);
+ success = e_cache_put (cache, uid, rev, vcard, other_columns, offline_flag, cancellable,
error);
g_free (vcard);
g_free (rev);
@@ -4787,7 +4784,7 @@ e_book_cache_put_contacts (EBookCache *book_cache,
* e_book_cache_remove_contact:
* @book_cache: An #EBookCache
* @uid: the uid of the contact to remove
- * @is_offline: Whether removing this contact in offline
+ * @offline_flag: one of #ECacheOfflineFlag, whether removing this contact in offline
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
@@ -4800,7 +4797,7 @@ e_book_cache_put_contacts (EBookCache *book_cache,
gboolean
e_book_cache_remove_contact (EBookCache *book_cache,
const gchar *uid,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error)
{
@@ -4812,7 +4809,7 @@ e_book_cache_remove_contact (EBookCache *book_cache,
uids = g_slist_append (NULL, (gpointer) uid);
- success = e_book_cache_remove_contacts (book_cache, uids, is_offline, cancellable, error);
+ success = e_book_cache_remove_contacts (book_cache, uids, offline_flag, cancellable, error);
g_slist_free (uids);
@@ -4823,7 +4820,7 @@ e_book_cache_remove_contact (EBookCache *book_cache,
* e_book_cache_remove_contacts:
* @book_cache: An #EBookCache
* @uids: (element-type utf8): a #GSList of uids indicating which contacts to remove
- * @is_offline: Whether removing this contact in offline
+ * @offline_flag: one of #ECacheOfflineFlag, whether removing these contacts in offline
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
@@ -4836,7 +4833,7 @@ e_book_cache_remove_contact (EBookCache *book_cache,
gboolean
e_book_cache_remove_contacts (EBookCache *book_cache,
const GSList *uids,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error)
{
@@ -4854,10 +4851,7 @@ e_book_cache_remove_contacts (EBookCache *book_cache,
for (link = uids; success && link; link = g_slist_next (link)) {
const gchar *uid = link->data;
- if (is_offline)
- success = e_cache_remove_offline (cache, uid, cancellable, error);
- else
- success = e_cache_remove (cache, uid, cancellable, error);
+ success = e_cache_remove (cache, uid, offline_flag, cancellable, error);
}
e_cache_unlock (cache, success ? E_CACHE_UNLOCK_COMMIT : E_CACHE_UNLOCK_ROLLBACK);
@@ -5001,7 +4995,7 @@ e_book_cache_set_contact_extra (EBookCache *book_cache,
g_return_val_if_fail (E_IS_BOOK_CACHE (book_cache), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
- if (!e_cache_contains (E_CACHE (book_cache), uid, TRUE)) {
+ if (!e_cache_contains (E_CACHE (book_cache), uid, E_CACHE_INCLUDE_DELETED)) {
g_set_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND, _("Object “%s” not found"), uid);
return FALSE;
}
@@ -5053,7 +5047,7 @@ e_book_cache_get_contact_extra (EBookCache *book_cache,
g_return_val_if_fail (E_IS_BOOK_CACHE (book_cache), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
- if (!e_cache_contains (E_CACHE (book_cache), uid, TRUE)) {
+ if (!e_cache_contains (E_CACHE (book_cache), uid, E_CACHE_INCLUDE_DELETED)) {
g_set_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND, _("Object “%s” not found"), uid);
return FALSE;
}
@@ -5898,7 +5892,8 @@ e_book_cache_clear_offline_changes_locked (ECache *cache,
g_return_val_if_fail (E_CACHE_CLASS (e_book_cache_parent_class)->clear_offline_changes_locked !=
NULL, FALSE);
/* First check whether there are any locally deleted objects at all */
- if (e_cache_count (cache, TRUE, cancellable, error) > e_cache_count (cache, FALSE, cancellable,
error))
+ if (e_cache_get_count (cache, E_CACHE_INCLUDE_DELETED, cancellable, error) >
+ e_cache_get_count (cache, E_CACHE_EXCLUDE_DELETED, cancellable, error))
success = ebc_delete_from_aux_tables_offline_deleted (cache, cancellable, error);
else
success = TRUE;
diff --git a/src/addressbook/libedata-book/e-book-cache.h b/src/addressbook/libedata-book/e-book-cache.h
index 71cd432..994a429 100644
--- a/src/addressbook/libedata-book/e-book-cache.h
+++ b/src/addressbook/libedata-book/e-book-cache.h
@@ -188,23 +188,23 @@ ECollator * e_book_cache_ref_collator (EBookCache *book_cache);
gboolean e_book_cache_put_contact (EBookCache *book_cache,
EContact *contact,
const gchar *extra,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error);
gboolean e_book_cache_put_contacts (EBookCache *book_cache,
const GSList *contacts,
const GSList *extras,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error);
gboolean e_book_cache_remove_contact (EBookCache *book_cache,
const gchar *uid,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error);
gboolean e_book_cache_remove_contacts (EBookCache *book_cache,
const GSList *uids,
- gboolean is_offline,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error);
gboolean e_book_cache_get_contact (EBookCache *book_cache,
diff --git a/src/libebackend/e-cache.c b/src/libebackend/e-cache.c
index 7b22b7c..47a5832 100644
--- a/src/libebackend/e-cache.c
+++ b/src/libebackend/e-cache.c
@@ -84,6 +84,8 @@ G_DEFINE_BOXED_TYPE (ECacheColumnInfo, e_cache_column_info, e_cache_column_info_
/**
* e_cache_offline_change_new:
* @uid: a unique object identifier
+ * @revision: (nullable): a revision of the object
+ * @object: (nullable): object itself
* @state: an #EOfflineState
*
* Creates a new #ECacheOfflineChange with the offline @state
@@ -96,6 +98,8 @@ G_DEFINE_BOXED_TYPE (ECacheColumnInfo, e_cache_column_info, e_cache_column_info_
**/
ECacheOfflineChange *
e_cache_offline_change_new (const gchar *uid,
+ const gchar *revision,
+ const gchar *object,
EOfflineState state)
{
ECacheOfflineChange *change;
@@ -104,6 +108,8 @@ e_cache_offline_change_new (const gchar *uid,
change = g_new0 (ECacheOfflineChange, 1);
change->uid = g_strdup (uid);
+ change->revision = g_strdup (revision);
+ change->object = g_strdup (object);
change->state = state;
return change;
@@ -125,7 +131,7 @@ e_cache_offline_change_copy (const ECacheOfflineChange *change)
if (!change)
return NULL;
- return e_cache_offline_change_new (change->uid, change->state);
+ return e_cache_offline_change_new (change->uid, change->revision, change->object, change->state);
}
/**
@@ -144,6 +150,8 @@ e_cache_offline_change_free (gpointer change)
if (chng) {
g_free (chng->uid);
+ g_free (chng->revision);
+ g_free (chng->object);
g_free (chng);
}
}
@@ -831,7 +839,7 @@ e_cache_count_rows_cb (ECache *cache,
* e_cache_contains:
* @cache: an #ECache
* @uid: a unique identifier of an object
- * @include_deleted: set to %TRUE, when check also objects marked as locally deleted
+ * @deleted_flag: one of #ECacheDeletedFlag enum
*
* Checkes whether the @cache contains an object with
* the given @uid.
@@ -843,14 +851,14 @@ e_cache_count_rows_cb (ECache *cache,
gboolean
e_cache_contains (ECache *cache,
const gchar *uid,
- gboolean include_deleted)
+ ECacheDeletedFlag deleted_flag)
{
guint nrows = 0;
g_return_val_if_fail (E_IS_CACHE (cache), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
- if (include_deleted) {
+ if (deleted_flag == E_CACHE_INCLUDE_DELETED) {
e_cache_sqlite_exec_printf (cache,
"SELECT " E_CACHE_COLUMN_UID " FROM " E_CACHE_TABLE_OBJECTS
" WHERE " E_CACHE_COLUMN_UID " = %Q"
@@ -1027,14 +1035,16 @@ e_cache_put_locked (ECache *cache,
* @revision: (nullable): a revision of the object
* @object: the object itself
* @other_columns: (nullable) (element-type utf8 utf8): what other columns to set; can be %NULL
+ * @offline_flag: one of #ECacheOfflineFlag, whether putting this object in offline
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
- * Stores an object into the cache. This sets the object's offline state
- * to #E_OFFLINE_STATE_SYNCED, like to be fully synchronized with the server,
- * regardless of its previous offline state. Use e_cache_put_offline() to
- * add objects in offline mode. Overwriting locally deleted object behaves
- * like an addition of a completely new object.
+ * Stores an object into the cache. Depending on @offline_flag, this update
+ * the object's offline state accordingly. When the @offline_flag is set
+ * to %E_CACHE_IS_ONLINE, then it's set to #E_OFFLINE_STATE_SYNCED, like
+ * to be fully synchronized with the server, regardless of its previous
+ * offline state. Overwriting locally deleted object behaves like an addition
+ * of a completely new object.
*
* Returns: Whether succeeded.
*
@@ -1046,23 +1056,44 @@ e_cache_put (ECache *cache,
const gchar *revision,
const gchar *object,
GHashTable *other_columns,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error)
{
- gboolean success, is_replace;
+ EOfflineState offline_state;
+ gboolean success = TRUE, is_replace;
g_return_val_if_fail (E_IS_CACHE (cache), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
g_return_val_if_fail (object != NULL, FALSE);
- g_rec_mutex_lock (&cache->priv->lock);
+ e_cache_lock (cache, E_CACHE_LOCK_WRITE);
- is_replace = e_cache_contains (cache, uid, FALSE);
+ if (offline_flag == E_CACHE_IS_ONLINE) {
+ is_replace = e_cache_contains (cache, uid, E_CACHE_EXCLUDE_DELETED);
+ offline_state = E_OFFLINE_STATE_SYNCED;
+ } else {
+ is_replace = e_cache_contains (cache, uid, E_CACHE_INCLUDE_DELETED);
+ if (is_replace) {
+ GError *local_error = NULL;
- success = e_cache_put_locked (cache, uid, revision, object, other_columns,
- E_OFFLINE_STATE_SYNCED, is_replace, cancellable, error);
+ offline_state = e_cache_get_offline_state (cache, uid, cancellable, &local_error);
- g_rec_mutex_unlock (&cache->priv->lock);
+ if (local_error) {
+ success = FALSE;
+ g_propagate_error (error, local_error);
+ } else if (offline_state != E_OFFLINE_STATE_LOCALLY_CREATED) {
+ offline_state = E_OFFLINE_STATE_LOCALLY_MODIFIED;
+ }
+ } else {
+ offline_state = E_OFFLINE_STATE_LOCALLY_CREATED;
+ }
+ }
+
+ success = success && e_cache_put_locked (cache, uid, revision, object, other_columns,
+ offline_state, is_replace, cancellable, error);
+
+ e_cache_unlock (cache, success ? E_CACHE_UNLOCK_COMMIT : E_CACHE_UNLOCK_ROLLBACK);
return success;
}
@@ -1071,12 +1102,14 @@ e_cache_put (ECache *cache,
* e_cache_remove:
* @cache: an #ECache
* @uid: a unique identifier of an object
+ * @offline_flag: one of #ECacheOfflineFlag, whether removing the object in offline
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
- * Removes the object with the given @uid from the @cache. It removes also any
- * information about locally made offline changes. Use e_cache_remove_offline()
- * to still remember the removed object for later use with e_cache_get_offline_changes().
+ * Removes the object with the given @uid from the @cache. Based on the @offline_flag,
+ * it can remove also any information about locally made offline changes. Removing
+ * the object with %E_CACHE_IS_OFFLINE will still remember it for later use
+ * with e_cache_get_offline_changes().
*
* Returns: Whether succeeded.
*
@@ -1085,11 +1118,12 @@ e_cache_put (ECache *cache,
gboolean
e_cache_remove (ECache *cache,
const gchar *uid,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error)
{
ECacheClass *klass;
- gboolean success;
+ gboolean success = TRUE;
g_return_val_if_fail (E_IS_CACHE (cache), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
@@ -1100,7 +1134,29 @@ e_cache_remove (ECache *cache,
e_cache_lock (cache, E_CACHE_LOCK_WRITE);
- success = klass->remove_locked (cache, uid, cancellable, error);
+ if (offline_flag == E_CACHE_IS_ONLINE) {
+ success = klass->remove_locked (cache, uid, cancellable, error);
+ } else {
+ EOfflineState offline_state;
+
+ offline_state = e_cache_get_offline_state (cache, uid, cancellable, error);
+ if (offline_state == E_OFFLINE_STATE_UNKNOWN) {
+ success = FALSE;
+ } else if (offline_state == E_OFFLINE_STATE_LOCALLY_CREATED) {
+ success = klass->remove_locked (cache, uid, cancellable, error);
+ } else {
+ g_signal_emit (cache,
+ signals[BEFORE_REMOVE],
+ 0,
+ uid, cancellable, error,
+ &success);
+
+ if (success) {
+ success = e_cache_set_offline_state (cache, uid,
+ E_OFFLINE_STATE_LOCALLY_DELETED, cancellable, error);
+ }
+ }
+ }
e_cache_unlock (cache, success ? E_CACHE_UNLOCK_COMMIT : E_CACHE_UNLOCK_ROLLBACK);
@@ -1136,7 +1192,7 @@ e_cache_remove_all (ECache *cache,
e_cache_lock (cache, E_CACHE_LOCK_WRITE);
- success = e_cache_get_uids (cache, TRUE, &uids, NULL, cancellable, error);
+ success = e_cache_get_uids (cache, E_CACHE_INCLUDE_DELETED, &uids, NULL, cancellable, error);
if (success && uids)
success = klass->remove_all_locked (cache, uids, cancellable, error);
@@ -1192,9 +1248,9 @@ e_cache_get_int64_cb (ECache *cache,
}
/**
- * e_cache_count:
+ * e_cache_get_count:
* @cache: an #ECache
- * @include_deleted: set to %TRUE, when count also objects marked as locally deleted
+ * @deleted_flag: one of #ECacheDeletedFlag enum
* @cancellable: optional #GCancellable object, or %NULL
* @error: return location for a #GError, or %NULL
*
@@ -1203,16 +1259,16 @@ e_cache_get_int64_cb (ECache *cache,
* Since: 3.26
**/
guint
-e_cache_count (ECache *cache,
- gboolean include_deleted,
- GCancellable *cancellable,
- GError **error)
+e_cache_get_count (ECache *cache,
+ ECacheDeletedFlag deleted_flag,
+ GCancellable *cancellable,
+ GError **error)
{
guint64 nobjects = 0;
g_return_val_if_fail (E_IS_CACHE (cache), 0);
- if (include_deleted) {
+ if (deleted_flag == E_CACHE_INCLUDE_DELETED) {
e_cache_sqlite_exec_printf (cache,
"SELECT COUNT(*) FROM " E_CACHE_TABLE_OBJECTS,
e_cache_get_uint64_cb, &nobjects, cancellable, error);
@@ -1263,7 +1319,7 @@ e_cache_gather_rows_data_cb (ECache *cache,
/**
* e_cache_get_uids:
* @cache: an #ECache
- * @include_deleted: set to %TRUE, when consider also objects marked as locally deleted
+ * @deleted_flag: one of #ECacheDeletedFlag enum
* @out_uids: (out) (transfer full) (element-type utf8): a pointer to #GSList to store the found uid to
* @out_revisions: (out) (transfer full) (element-type utf8) (nullable): a pointer to #GSList to store
* the found revisions to, or %NULL
@@ -1285,7 +1341,7 @@ e_cache_gather_rows_data_cb (ECache *cache,
**/
gboolean
e_cache_get_uids (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
GSList **out_uids,
GSList **out_revisions,
GCancellable *cancellable,
@@ -1300,14 +1356,14 @@ e_cache_get_uids (ECache *cache,
gr.out_revisions = out_revisions;
gr.out_objects = NULL;
- return e_cache_foreach (cache, include_deleted, NULL,
+ return e_cache_foreach (cache, deleted_flag, NULL,
e_cache_gather_rows_data_cb, &gr, cancellable, error);
}
/**
* e_cache_get_objects:
* @cache: an #ECache
- * @include_deleted: set to %TRUE, when consider also objects marked as locally deleted
+ * @deleted_flag: one of #ECacheDeletedFlag enum
* @out_objects: (out) (transfer full) (element-type utf8): a pointer to #GSList to store the found objects
to
* @out_revisions: (out) (transfer full) (element-type utf8) (nullable): a pointer to #GSList to store
* the found revisions to, or %NULL
@@ -1329,7 +1385,7 @@ e_cache_get_uids (ECache *cache,
**/
gboolean
e_cache_get_objects (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
GSList **out_objects,
GSList **out_revisions,
GCancellable *cancellable,
@@ -1344,7 +1400,7 @@ e_cache_get_objects (ECache *cache,
gr.out_revisions = out_revisions;
gr.out_objects = out_objects;
- return e_cache_foreach (cache, include_deleted, NULL,
+ return e_cache_foreach (cache, deleted_flag, NULL,
e_cache_gather_rows_data_cb, &gr, cancellable, error);
}
@@ -1414,7 +1470,7 @@ e_cache_foreach_cb (ECache *cache,
/**
* e_cache_foreach:
* @cache: an #ECache
- * @include_deleted: set to %TRUE, when consider also objects marked as locally deleted
+ * @deleted_flag: one of #ECacheDeletedFlag enum
* @where_clause: (nullable): an optional SQLite WHERE clause part, or %NULL
* @func: an #ECacheForeachFunc function to call for each object
* @user_data: user data for the @func
@@ -1422,7 +1478,7 @@ e_cache_foreach_cb (ECache *cache,
* @error: return location for a #GError, or %NULL
*
* Calls @func for each found object, which satisfies the criteria
- * for both @include_deleted and @where_clause.
+ * for both @deleted_flag and @where_clause.
*
* Note the @func should not call any SQLite commands, because it's invoked
* within a SELECT statement execution.
@@ -1433,7 +1489,7 @@ e_cache_foreach_cb (ECache *cache,
**/
gboolean
e_cache_foreach (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
const gchar *where_clause,
ECacheForeachFunc func,
gpointer user_data,
@@ -1452,13 +1508,13 @@ e_cache_foreach (ECache *cache,
if (where_clause) {
g_string_append (stmt, " WHERE ");
- if (include_deleted) {
+ if (deleted_flag == E_CACHE_INCLUDE_DELETED) {
g_string_append (stmt, where_clause);
} else {
g_string_append_printf (stmt, E_CACHE_COLUMN_STATE "!=%d AND (%s)",
E_OFFLINE_STATE_LOCALLY_DELETED, where_clause);
}
- } else if (!include_deleted) {
+ } else if (deleted_flag != E_CACHE_INCLUDE_DELETED) {
g_string_append_printf (stmt, " WHERE " E_CACHE_COLUMN_STATE "!=%d",
E_OFFLINE_STATE_LOCALLY_DELETED);
}
@@ -1598,7 +1654,7 @@ e_cache_foreach_update_cb (ECache *cache,
/**
* e_cache_foreach_update:
* @cache: an #ECache
- * @include_deleted: set to %TRUE, when consider also objects marked as locally deleted
+ * @deleted_flag: one of #ECacheDeletedFlag enum
* @where_clause: (nullable): an optional SQLite WHERE clause part, or %NULL
* @func: an #ECacheUpdateFunc function to call for each object
* @user_data: user data for the @func
@@ -1606,7 +1662,7 @@ e_cache_foreach_update_cb (ECache *cache,
* @error: return location for a #GError, or %NULL
*
* Calls @func for each found object, which satisfies the criteria for both
- * @include_deleted and @where_clause, letting the caller update values where
+ * @deleted_flag and @where_clause, letting the caller update values where
* necessary. The return value of @func is used to determine whether the call
* was successful, not whether there are any changes to be saved. If anything
* fails during the call then the all changes are reverted.
@@ -1617,7 +1673,7 @@ e_cache_foreach_update_cb (ECache *cache,
**/
gboolean
e_cache_foreach_update (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
const gchar *where_clause,
ECacheUpdateFunc func,
gpointer user_data,
@@ -1640,13 +1696,13 @@ e_cache_foreach_update (ECache *cache,
if (where_clause) {
g_string_append (stmt_begin, " WHERE ");
- if (include_deleted) {
+ if (deleted_flag == E_CACHE_INCLUDE_DELETED) {
g_string_append (stmt_begin, where_clause);
} else {
g_string_append_printf (stmt_begin, E_CACHE_COLUMN_STATE "!=%d AND (%s)",
E_OFFLINE_STATE_LOCALLY_DELETED, where_clause);
}
- } else if (!include_deleted) {
+ } else if (deleted_flag != E_CACHE_INCLUDE_DELETED) {
g_string_append_printf (stmt_begin, " WHERE " E_CACHE_COLUMN_STATE "!=%d",
E_OFFLINE_STATE_LOCALLY_DELETED);
} else {
has_where = FALSE;
@@ -1742,117 +1798,6 @@ e_cache_foreach_update (ECache *cache,
}
/**
- * e_cache_put_offline:
- * @cache: an #ECache
- * @uid: a unique identifier of an object
- * @revision: (nullable): a revision of the object
- * @object: the object itself
- * @other_columns: (nullable) (element-type utf8 utf8): what other columns to set; can be %NULL
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Stores an object into the cache with an appropriate offline state.
- * Use e_cache_put() to store an object into the @cache as fully
- * synchronized. Use e_cache_get_offline_changes() to get list of offline changes.
- *
- * Returns: Whether succeded.
- *
- * Since: 3.26
- **/
-gboolean
-e_cache_put_offline (ECache *cache,
- const gchar *uid,
- const gchar *revision,
- const gchar *object,
- GHashTable *other_columns,
- GCancellable *cancellable,
- GError **error)
-{
- EOfflineState offline_state;
- gboolean success = TRUE, is_replace;
-
- g_return_val_if_fail (E_IS_CACHE (cache), FALSE);
- g_return_val_if_fail (uid != NULL, FALSE);
- g_return_val_if_fail (object != NULL, FALSE);
-
- g_rec_mutex_lock (&cache->priv->lock);
-
- is_replace = e_cache_contains (cache, uid, TRUE);
- if (is_replace) {
- GError *local_error = NULL;
-
- offline_state = e_cache_get_offline_state (cache, uid, cancellable, &local_error);
-
- if (local_error) {
- success = FALSE;
- g_propagate_error (error, local_error);
- } else if (offline_state != E_OFFLINE_STATE_LOCALLY_CREATED) {
- offline_state = E_OFFLINE_STATE_LOCALLY_MODIFIED;
- }
- } else {
- offline_state = E_OFFLINE_STATE_LOCALLY_CREATED;
- }
-
- success = success && e_cache_put_locked (cache, uid, revision, object, other_columns,
- offline_state, is_replace, cancellable, error);
-
- g_rec_mutex_unlock (&cache->priv->lock);
-
- return success;
-}
-
-/**
- * e_cache_remove_offline:
- * @cache: an #ECache
- * @uid: a unique identifier of an object
- * @cancellable: optional #GCancellable object, or %NULL
- * @error: return location for a #GError, or %NULL
- *
- * Marks the object with the given @uid as removed offline, eventually removes
- * it when it had been created in the offline. Use e_cache_get_offline_changes()
- * to get list of offline changes.
- *
- * Returns: Whether succeeded.
- *
- * Since: 3.26
- **/
-gboolean
-e_cache_remove_offline (ECache *cache,
- const gchar *uid,
- GCancellable *cancellable,
- GError **error)
-{
- EOfflineState offline_state;
- gboolean success = TRUE;
-
- g_return_val_if_fail (E_IS_CACHE (cache), FALSE);
-
- g_rec_mutex_lock (&cache->priv->lock);
-
- offline_state = e_cache_get_offline_state (cache, uid, cancellable, error);
- if (offline_state == E_OFFLINE_STATE_UNKNOWN) {
- success = FALSE;
- } else if (offline_state == E_OFFLINE_STATE_LOCALLY_CREATED) {
- success = e_cache_remove (cache, uid, cancellable, error);
- } else {
- g_signal_emit (cache,
- signals[BEFORE_REMOVE],
- 0,
- uid, cancellable, error,
- &success);
-
- if (success) {
- success = e_cache_set_offline_state (cache, uid,
- E_OFFLINE_STATE_LOCALLY_DELETED, cancellable, error);
- }
- }
-
- g_rec_mutex_unlock (&cache->priv->lock);
-
- return success;
-}
-
-/**
* e_cache_get_offline_state:
* @cache: an #ECache
* @uid: a unique identifier of an object
@@ -1877,7 +1822,7 @@ e_cache_get_offline_state (ECache *cache,
g_return_val_if_fail (E_IS_CACHE (cache), E_OFFLINE_STATE_UNKNOWN);
g_return_val_if_fail (uid != NULL, E_OFFLINE_STATE_UNKNOWN);
- if (!e_cache_contains (cache, uid, TRUE)) {
+ if (!e_cache_contains (cache, uid, E_CACHE_INCLUDE_DELETED)) {
g_set_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND, _("Object “%s” not found"), uid);
return offline_state;
}
@@ -1917,7 +1862,7 @@ e_cache_set_offline_state (ECache *cache,
g_return_val_if_fail (E_IS_CACHE (cache), FALSE);
g_return_val_if_fail (uid != NULL, FALSE);
- if (!e_cache_contains (cache, uid, TRUE)) {
+ if (!e_cache_contains (cache, uid, E_CACHE_INCLUDE_DELETED)) {
g_set_error (error, E_CACHE_ERROR, E_CACHE_ERROR_NOT_FOUND, _("Object “%s” not found"), uid);
return FALSE;
}
@@ -1947,7 +1892,7 @@ e_cache_get_offline_changes_cb (ECache *cache,
if (offline_state == E_OFFLINE_STATE_LOCALLY_CREATED ||
offline_state == E_OFFLINE_STATE_LOCALLY_MODIFIED ||
offline_state == E_OFFLINE_STATE_LOCALLY_DELETED) {
- *pchanges = g_slist_prepend (*pchanges, e_cache_offline_change_new (uid, offline_state));
+ *pchanges = g_slist_prepend (*pchanges, e_cache_offline_change_new (uid, revision, object,
offline_state));
}
return TRUE;
@@ -1982,7 +1927,7 @@ e_cache_get_offline_changes (ECache *cache,
stmt = e_cache_sqlite_stmt_printf (E_CACHE_COLUMN_STATE "!=%d", E_OFFLINE_STATE_SYNCED);
- if (!e_cache_foreach (cache, TRUE, stmt, e_cache_get_offline_changes_cb, &changes, cancellable,
error)) {
+ if (!e_cache_foreach (cache, E_CACHE_INCLUDE_DELETED, stmt, e_cache_get_offline_changes_cb, &changes,
cancellable, error)) {
g_slist_free_full (changes, e_cache_offline_change_free);
changes = NULL;
}
diff --git a/src/libebackend/e-cache.h b/src/libebackend/e-cache.h
index 14a1f50..7c113a4 100644
--- a/src/libebackend/e-cache.h
+++ b/src/libebackend/e-cache.h
@@ -96,6 +96,8 @@ typedef enum {
typedef struct {
gchar *uid;
+ gchar *revision;
+ gchar *object;
EOfflineState state;
} ECacheOfflineChange;
@@ -104,6 +106,8 @@ typedef struct {
GType e_cache_offline_change_get_type (void) G_GNUC_CONST;
ECacheOfflineChange *
e_cache_offline_change_new (const gchar *uid,
+ const gchar *revision,
+ const gchar *object,
EOfflineState state);
ECacheOfflineChange *
e_cache_offline_change_copy (const ECacheOfflineChange *change);
@@ -132,7 +136,7 @@ void e_cache_column_info_free (/* ECacheColumnInfo */ gpointer
info);
*
* Indicates the type of lock requested in e_cache_lock().
*
- * Since: 3.24
+ * Since: 3.26
**/
typedef enum {
E_CACHE_LOCK_READ,
@@ -147,7 +151,7 @@ typedef enum {
*
* Indicates what type of action to take while unlocking the cache with e_cache_unlock().
*
- * Since: 3.24
+ * Since: 3.26
**/
typedef enum {
E_CACHE_UNLOCK_NONE,
@@ -155,6 +159,35 @@ typedef enum {
E_CACHE_UNLOCK_ROLLBACK
} ECacheUnlockAction;
+/**
+ * ECacheDeletedFlag:
+ * @E_CACHE_EXCLUDE_DELETED: Do not include locally deleted objects
+ * @E_CACHE_INCLUDE_DELETED: Include locally deleted objects
+ *
+ * Declares whether to exclude or include locally deleted objects.
+ *
+ * Since: 3.26
+ **/
+typedef enum {
+ E_CACHE_EXCLUDE_DELETED = 0,
+ E_CACHE_INCLUDE_DELETED
+} ECacheDeletedFlag;
+
+/**
+ * ECacheOfflineFlag:
+ * @E_CACHE_IS_ONLINE: The operation is done in online
+ * @E_CACHE_IS_OFFLINE: The operation is done in offline
+ *
+ * Declares whether the operation is done in online or offline.
+ * This influences the offline state of the related obejcts.
+ *
+ * Since: 3.26
+ **/
+typedef enum {
+ E_CACHE_IS_ONLINE = 0,
+ E_CACHE_IS_OFFLINE
+} ECacheOfflineFlag;
+
typedef struct _ECache ECache;
typedef struct _ECacheClass ECacheClass;
typedef struct _ECachePrivate ECachePrivate;
@@ -321,7 +354,7 @@ void e_cache_set_revision (ECache *cache,
void e_cache_erase (ECache *cache);
gboolean e_cache_contains (ECache *cache,
const gchar *uid,
- gboolean include_deleted);
+ ECacheDeletedFlag deleted_flag);
gchar * e_cache_get (ECache *cache,
const gchar *uid,
gchar **out_revision,
@@ -333,40 +366,42 @@ gboolean e_cache_put (ECache *cache,
const gchar *revision,
const gchar *object,
GHashTable *other_columns,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error);
gboolean e_cache_remove (ECache *cache,
const gchar *uid,
+ ECacheOfflineFlag offline_flag,
GCancellable *cancellable,
GError **error);
gboolean e_cache_remove_all (ECache *cache,
GCancellable *cancellable,
GError **error);
-guint e_cache_count (ECache *cache,
- gboolean include_deleted,
+guint e_cache_get_count (ECache *cache,
+ ECacheDeletedFlag deleted_flag,
GCancellable *cancellable,
GError **error);
gboolean e_cache_get_uids (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
GSList **out_uids,
GSList **out_revisions,
GCancellable *cancellable,
GError **error);
gboolean e_cache_get_objects (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
GSList **out_objects,
GSList **out_revisions,
GCancellable *cancellable,
GError **error);
gboolean e_cache_foreach (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
const gchar *where_clause,
ECacheForeachFunc func,
gpointer user_data,
GCancellable *cancellable,
GError **error);
gboolean e_cache_foreach_update (ECache *cache,
- gboolean include_deleted,
+ ECacheDeletedFlag deleted_flag,
const gchar *where_clause,
ECacheUpdateFunc func,
gpointer user_data,
@@ -374,17 +409,6 @@ gboolean e_cache_foreach_update (ECache *cache,
GError **error);
/* Offline support */
-gboolean e_cache_put_offline (ECache *cache,
- const gchar *uid,
- const gchar *revision,
- const gchar *object,
- GHashTable *other_columns,
- GCancellable *cancellable,
- GError **error);
-gboolean e_cache_remove_offline (ECache *cache,
- const gchar *uid,
- GCancellable *cancellable,
- GError **error);
EOfflineState e_cache_get_offline_state (ECache *cache,
const gchar *uid,
GCancellable *cancellable,
diff --git a/tests/libedata-book/test-cache-cursor-calculate.c
b/tests/libedata-book/test-cache-cursor-calculate.c
index e594457..6bb1407 100644
--- a/tests/libedata-book/test-cache-cursor-calculate.c
+++ b/tests/libedata-book/test-cache-cursor-calculate.c
@@ -259,7 +259,7 @@ test_cursor_calculate_after_modification (TCUCursorFixture *fixture,
if (!e_book_cache_put_contact (((TCUFixture *) fixture)->book_cache,
fixture->contacts[19 - 1],
e_contact_get_const (fixture->contacts[19 - 1], E_CONTACT_UID),
- FALSE, NULL, &error))
+ E_CACHE_IS_ONLINE, NULL, &error))
g_error ("Failed to modify contact: %s", error->message);
/* Rename Müller -> Sade Adu */
@@ -268,7 +268,7 @@ test_cursor_calculate_after_modification (TCUCursorFixture *fixture,
if (!e_book_cache_put_contact (((TCUFixture *) fixture)->book_cache,
fixture->contacts[20 - 1],
e_contact_get_const (fixture->contacts[20 - 1], E_CONTACT_UID),
- FALSE, NULL, &error))
+ E_CACHE_IS_ONLINE, NULL, &error))
g_error ("Failed to modify contact: %s", error->message);
/* Check new position */
@@ -409,7 +409,7 @@ test_cursor_calculate_filtered_after_modification (TCUCursorFixture *fixture,
if (!e_book_cache_put_contact (((TCUFixture *) fixture)->book_cache,
fixture->contacts[18 - 1],
e_contact_get_const (fixture->contacts[18 - 1], E_CONTACT_UID),
- FALSE, NULL, &error))
+ E_CACHE_IS_ONLINE, NULL, &error))
g_error ("Failed to modify contact: %s", error->message);
/* 'black-birds' -> Sade Adu */
@@ -418,7 +418,7 @@ test_cursor_calculate_filtered_after_modification (TCUCursorFixture *fixture,
if (!e_book_cache_put_contact (((TCUFixture *) fixture)->book_cache,
fixture->contacts[17 - 1],
e_contact_get_const (fixture->contacts[17 - 1], E_CONTACT_UID),
- FALSE, NULL, &error))
+ E_CACHE_IS_ONLINE, NULL, &error))
g_error ("Failed to modify contact: %s", error->message);
/* Check new position */
@@ -572,7 +572,7 @@ test_cursor_calculate_descending_after_modification (TCUCursorFixture *fixture,
if (!e_book_cache_put_contact (((TCUFixture *) fixture)->book_cache,
fixture->contacts[19 - 1],
e_contact_get_const (fixture->contacts[19 - 1], E_CONTACT_UID),
- FALSE, NULL, &error))
+ E_CACHE_IS_ONLINE, NULL, &error))
g_error ("Failed to modify contact: %s", error->message);
/* Rename Müller -> Sade Adu */
@@ -581,7 +581,7 @@ test_cursor_calculate_descending_after_modification (TCUCursorFixture *fixture,
if (!e_book_cache_put_contact (((TCUFixture *) fixture)->book_cache,
fixture->contacts[20 - 1],
e_contact_get_const (fixture->contacts[20 - 1], E_CONTACT_UID),
- FALSE, NULL, &error))
+ E_CACHE_IS_ONLINE, NULL, &error))
g_error ("Failed to modify contact: %s", error->message);
/* Check new position */
diff --git a/tests/libedata-book/test-cache-offline.c b/tests/libedata-book/test-cache-offline.c
index 9bce4d8..e02943d 100644
--- a/tests/libedata-book/test-cache-offline.c
+++ b/tests/libedata-book/test-cache-offline.c
@@ -387,8 +387,8 @@ test_verify_storage (TCUFixture *fixture,
offline_state = test_check_offline_state (fixture, uid, expect_offline_state);
if (offline_state == E_OFFLINE_STATE_UNKNOWN) {
- g_assert (!e_cache_contains (E_CACHE (fixture->book_cache), uid, TRUE));
- g_assert (!e_cache_contains (E_CACHE (fixture->book_cache), uid, FALSE));
+ g_assert (!e_cache_contains (E_CACHE (fixture->book_cache), uid, E_CACHE_EXCLUDE_DELETED));
+ g_assert (!e_cache_contains (E_CACHE (fixture->book_cache), uid, E_CACHE_INCLUDE_DELETED));
test_check_offline_changes (fixture, NULL);
return;
}
@@ -466,7 +466,7 @@ test_offline_basics (TCUFixture *fixture,
uid = e_contact_get_const (contact, E_CONTACT_UID);
g_assert_nonnull (uid);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
g_assert (e_book_cache_set_contact_extra (fixture->book_cache, uid, "extra-0", NULL, &error));
@@ -496,10 +496,10 @@ test_offline_basics (TCUFixture *fixture,
test_check_offline_changes (fixture, uid, states[ii], NULL);
if (states[ii] == E_OFFLINE_STATE_LOCALLY_DELETED) {
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error),
==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache),
E_CACHE_EXCLUDE_DELETED, NULL, &error), ==, 2);
g_assert_no_error (error);
- g_assert (!e_cache_contains (E_CACHE (fixture->book_cache), uid, FALSE));
+ g_assert (!e_cache_contains (E_CACHE (fixture->book_cache), uid,
E_CACHE_EXCLUDE_DELETED));
g_assert (e_book_cache_set_contact_extra (fixture->book_cache, uid, "extra-1", NULL,
&error));
g_assert_no_error (error);
@@ -514,18 +514,18 @@ test_offline_basics (TCUFixture *fixture,
/* Search when locally deleted */
test_basic_search (fixture, EXPECT_DEFAULT);
} else {
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error),
==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache),
E_CACHE_EXCLUDE_DELETED, NULL, &error), ==, 3);
g_assert_no_error (error);
- g_assert (e_cache_contains (E_CACHE (fixture->book_cache), uid, FALSE));
+ g_assert (e_cache_contains (E_CACHE (fixture->book_cache), uid,
E_CACHE_EXCLUDE_DELETED));
/* Search when locally available */
test_basic_search (fixture, EXPECT_CUSTOM_1);
}
- g_assert (e_cache_contains (E_CACHE (fixture->book_cache), uid, TRUE));
+ g_assert (e_cache_contains (E_CACHE (fixture->book_cache), uid, E_CACHE_INCLUDE_DELETED));
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED,
NULL, &error), ==, 3);
g_assert_no_error (error);
}
@@ -534,7 +534,7 @@ test_offline_basics (TCUFixture *fixture,
/* Edit in online */
e_contact_set (contact, E_CONTACT_REV, "rev-1");
- g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, FALSE, NULL, &error));
+ g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, E_CACHE_IS_ONLINE, NULL,
&error));
g_assert_no_error (error);
test_verify_storage (fixture, uid, "rev-1", NULL, E_OFFLINE_STATE_SYNCED);
@@ -542,20 +542,20 @@ test_offline_basics (TCUFixture *fixture,
e_contact_set (contact, E_CONTACT_REV, "rev-2");
- g_assert (e_book_cache_put_contact (fixture->book_cache, contact, "extra-2", FALSE, NULL, &error));
+ g_assert (e_book_cache_put_contact (fixture->book_cache, contact, "extra-2", E_CACHE_IS_ONLINE, NULL,
&error));
g_assert_no_error (error);
test_verify_storage (fixture, uid, "rev-2", "extra-2", E_OFFLINE_STATE_SYNCED);
test_check_offline_changes (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
/* Search before delete */
test_basic_search (fixture, EXPECT_CUSTOM_1);
/* Delete in online */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, FALSE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_ONLINE, NULL, &error));
g_assert_no_error (error);
g_assert (!e_cache_set_offline_state (E_CACHE (fixture->book_cache), uid,
E_OFFLINE_STATE_LOCALLY_MODIFIED, NULL, &error));
@@ -565,8 +565,8 @@ test_offline_basics (TCUFixture *fixture,
test_verify_storage (fixture, uid, NULL, NULL, E_OFFLINE_STATE_UNKNOWN);
test_check_offline_changes (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 2);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 2);
g_assert_no_error (error);
g_assert (!e_book_cache_set_contact_extra (fixture->book_cache, uid, "extra-3", NULL, &error));
@@ -605,7 +605,7 @@ test_offline_add_one (TCUFixture *fixture,
test_check_offline_state (fixture, uid, E_OFFLINE_STATE_UNKNOWN);
/* Add a contact in offline */
- g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, TRUE, NULL, &error));
+ g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, E_CACHE_IS_OFFLINE,
NULL, &error));
g_assert_no_error (error);
} else {
uid = case_name;
@@ -617,7 +617,7 @@ test_offline_add_one (TCUFixture *fixture,
test_check_offline_state (fixture, uid, E_OFFLINE_STATE_UNKNOWN);
}
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==,
expect_total);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, expect_total);
g_assert_no_error (error);
test_basic_search (fixture, flags);
@@ -637,7 +637,7 @@ test_offline_add (TCUFixture *fixture,
/* Add in online */
test_fill_cache (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -668,7 +668,7 @@ test_offline_add_edit (TCUFixture *fixture,
/* Add in online */
test_fill_cache (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -684,7 +684,7 @@ test_offline_add_edit (TCUFixture *fixture,
/* Modify added in offline */
e_contact_set (contact, E_CONTACT_REV, "rev-2");
- g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, TRUE, NULL, &error));
+ g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, E_CACHE_IS_OFFLINE, NULL,
&error));
g_assert_no_error (error);
test_offline_add_one (fixture, "simple-1", 4, EXPECT_SIMPLE_1 | EXPECT_CUSTOM_1 | SKIP_CONTACT_PUT,
NULL);
@@ -709,7 +709,7 @@ test_offline_add_delete (TCUFixture *fixture,
/* Add in online */
test_fill_cache (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -727,7 +727,7 @@ test_offline_add_delete (TCUFixture *fixture,
/* Delete added in offline */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_OFFLINE, NULL, &error));
g_assert_no_error (error);
test_offline_add_one (fixture, "simple-1", 3, EXPECT_CUSTOM_1 | SKIP_CONTACT_PUT, NULL);
@@ -748,7 +748,7 @@ test_offline_add_delete_add (TCUFixture *fixture,
/* Add in online */
test_fill_cache (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -765,7 +765,7 @@ test_offline_add_delete_add (TCUFixture *fixture,
g_assert_nonnull (uid);
/* Delete added in offline */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_OFFLINE, NULL, &error));
g_assert_no_error (error);
test_offline_add_one (fixture, "simple-1", 3, EXPECT_CUSTOM_1 | SKIP_CONTACT_PUT, NULL);
@@ -791,7 +791,7 @@ test_offline_add_resync (TCUFixture *fixture,
/* Add in online */
test_fill_cache (fixture, NULL);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -807,7 +807,7 @@ test_offline_add_resync (TCUFixture *fixture,
g_assert (e_cache_clear_offline_changes (E_CACHE (fixture->book_cache), NULL, &error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 4);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 4);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_SIMPLE_1 | EXPECT_CUSTOM_1);
@@ -830,7 +830,7 @@ test_offline_edit_common (TCUFixture *fixture,
uid = e_contact_get_const (contact, E_CONTACT_UID);
g_assert_nonnull (uid);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -839,10 +839,10 @@ test_offline_edit_common (TCUFixture *fixture,
/* Modify in offline */
e_contact_set (contact, E_CONTACT_REV, "rev-2");
- g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, TRUE, NULL, &error));
+ g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, E_CACHE_IS_OFFLINE, NULL,
&error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_edit_saved (fixture, uid, "rev-2");
@@ -877,11 +877,11 @@ test_offline_edit_delete (TCUFixture *fixture,
test_offline_edit_common (fixture, &uid);
/* Delete the modified contact in offline */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_OFFLINE, NULL, &error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 2);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_DEFAULT);
@@ -911,7 +911,7 @@ test_offline_edit_resync (TCUFixture *fixture,
g_assert (e_cache_clear_offline_changes (E_CACHE (fixture->book_cache), NULL, &error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_CUSTOM_1);
@@ -936,18 +936,18 @@ test_offline_delete (TCUFixture *fixture,
uid = e_contact_get_const (contact, E_CONTACT_UID);
g_assert_nonnull (uid);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
test_check_offline_state (fixture, uid, E_OFFLINE_STATE_SYNCED);
/* Delete in offline */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_OFFLINE, NULL, &error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 2);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_DEFAULT);
@@ -974,7 +974,7 @@ test_offline_delete_add (TCUFixture *fixture,
uid = e_contact_get_const (contact, E_CONTACT_UID);
g_assert_nonnull (uid);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
@@ -982,11 +982,11 @@ test_offline_delete_add (TCUFixture *fixture,
/* Delete locally created in offline */
test_offline_add_one (fixture, "simple-1", 4, EXPECT_SIMPLE_1 | EXPECT_CUSTOM_1, NULL);
- g_assert (e_book_cache_remove_contact (fixture->book_cache, "simple-1", TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, "simple-1", E_CACHE_IS_OFFLINE, NULL,
&error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_CUSTOM_1);
@@ -995,11 +995,11 @@ test_offline_delete_add (TCUFixture *fixture,
test_check_offline_state (fixture, "simple-1", E_OFFLINE_STATE_UNKNOWN);
/* Delete synced in offline */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_OFFLINE, NULL, &error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 2);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_DEFAULT);
@@ -1022,11 +1022,11 @@ test_offline_delete_add (TCUFixture *fixture,
/* Modify the previous contact and add it again */
e_contact_set (contact, E_CONTACT_REV, "rev-3");
- g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, TRUE, NULL, &error));
+ g_assert (e_book_cache_put_contact (fixture->book_cache, contact, NULL, E_CACHE_IS_OFFLINE, NULL,
&error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 4);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 4);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 4);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 4);
g_assert_no_error (error);
test_check_edit_saved (fixture, uid, "rev-3");
@@ -1057,18 +1057,18 @@ test_offline_delete_resync (TCUFixture *fixture,
uid = e_contact_get_const (contact, E_CONTACT_UID);
g_assert_nonnull (uid);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_check_offline_changes (fixture, NULL);
test_check_offline_state (fixture, uid, E_OFFLINE_STATE_SYNCED);
/* Delete in offline */
- g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, TRUE, NULL, &error));
+ g_assert (e_book_cache_remove_contact (fixture->book_cache, uid, E_CACHE_IS_OFFLINE, NULL, &error));
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 2);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 3);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 3);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_DEFAULT);
@@ -1081,8 +1081,8 @@ test_offline_delete_resync (TCUFixture *fixture,
e_cache_clear_offline_changes (E_CACHE (fixture->book_cache), NULL, &error);
g_assert_no_error (error);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), FALSE, NULL, &error), ==, 2);
- g_assert_cmpint (e_cache_count (E_CACHE (fixture->book_cache), TRUE, NULL, &error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_EXCLUDE_DELETED, NULL,
&error), ==, 2);
+ g_assert_cmpint (e_cache_get_count (E_CACHE (fixture->book_cache), E_CACHE_INCLUDE_DELETED, NULL,
&error), ==, 2);
g_assert_no_error (error);
test_basic_search (fixture, EXPECT_DEFAULT);
diff --git a/tests/libedata-book/test-cache-utils.c b/tests/libedata-book/test-cache-utils.c
index dbcd31a..8759df7 100644
--- a/tests/libedata-book/test-cache-utils.c
+++ b/tests/libedata-book/test-cache-utils.c
@@ -91,7 +91,7 @@ tcu_add_contact_from_test_case (TCUFixture *fixture,
contact = tcu_new_contact_from_test_case (case_name);
- if (!e_book_cache_put_contact (fixture->book_cache, contact, case_name, FALSE, NULL, &error))
+ if (!e_book_cache_put_contact (fixture->book_cache, contact, case_name, E_CACHE_IS_ONLINE, NULL,
&error))
g_error ("Failed to add contact: %s", error->message);
if (ret_contact)
@@ -244,7 +244,7 @@ tcu_cursor_fixture_setup (TCUCursorFixture *fixture,
fixture->contacts[ii] = g_object_ref (contact);
}
- if (!e_book_cache_put_contacts (base_fixture->book_cache, contacts, extra_list, FALSE, NULL, &error))
{
+ if (!e_book_cache_put_contacts (base_fixture->book_cache, contacts, extra_list, E_CACHE_IS_ONLINE,
NULL, &error)) {
/* Dont complain here, we re-use the same addressbook for multiple tests
* and we can't add the same contacts twice
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]