[evolution-data-server/wip/camel-more-gobject] Added 'dirty' and 'folder-flagged' stamps and some changes of the 'load' function



commit d5e69834bb839cf879b0ba82e7978d9bd77a2e28
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 7 16:51:15 2016 +0200

    Added 'dirty' and 'folder-flagged' stamps and some changes of the 'load' function

 camel/camel-folder-summary.c |    1 +
 camel/camel-message-info.c   |  130 ++++++++++++++++++++++++++++++++++++++++-
 camel/camel-message-info.h   |    4 +
 3 files changed, 131 insertions(+), 4 deletions(-)
---
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index ecc0451..77420fd 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -615,6 +615,7 @@ message_info_from_db (CamelFolderSummary *summary,
                                part[i] = 0;
                                camel_flag_set (&mi->user_flags, label, TRUE);
                                label = &(part[i + 1]);
+                               part[i] = ' ';
                        }
                }
                camel_flag_set (&mi->user_flags, label, TRUE);
diff --git a/camel/camel-message-info.c b/camel/camel-message-info.c
index f89d975..3c60201 100644
--- a/camel/camel-message-info.c
+++ b/camel/camel-message-info.c
@@ -37,13 +37,17 @@ struct _xCamelMessageInfoPrivate {
        gboolean dirty;         /* whether requires save to local disk/summary */
        const gchar *uid;       /* allocated in the string pool */
        gboolean loading;
+       guint dirty_stamp;
+       guint folder_flagged_stamp;
 };
 
 enum {
        PROP_0,
        PROP_SUMMARY,
        PROP_DIRTY,
+       PROP_DIRTY_STAMP,
        PROP_FOLDER_FLAGGED,
+       PROP_FOLDER_FLAGGED_STAMP,
        PROP_LOADING,
        PROP_UID,
        PROP_FLAGS,
@@ -202,6 +206,7 @@ message_info_load (xCamelMessageInfo *mi,
                                if (label && *label)
                                        camel_named_flags_insert (user_flags, label);
                                label = &(part[ii + 1]);
+                               part[ii] = ' ';
                        }
                }
                if (label && *label)
@@ -225,12 +230,14 @@ message_info_load (xCamelMessageInfo *mi,
                        name = camel_message_info_util_bdata_get_string (&part, NULL);
                        value = camel_message_info_util_bdata_get_string (&part, NULL);
 
-                       if (name && value)
-                               camel_name_value_array_set_named (user_tags, TRUE, name, value);
+                       if (name)
+                               camel_name_value_array_set_named (user_tags, TRUE, name, value ? value : "");
 
                        g_free (name);
                        g_free (value);
                }
+
+               xcamel_message_info_take_user_tags (mi, user_tags);
        }
 
        return TRUE;
@@ -452,10 +459,18 @@ message_info_get_property (GObject *object,
                g_value_set_boolean (value, xcamel_message_info_get_dirty (mi));
                return;
 
+       case PROP_DIRTY_STAMP:
+               g_value_set_uint (value, xcamel_message_info_get_dirty_stamp (mi));
+               return;
+
        case PROP_FOLDER_FLAGGED:
                g_value_set_boolean (value, xcamel_message_info_get_folder_flagged (mi));
                return;
 
+       case PROP_FOLDER_FLAGGED_STAMP:
+               g_value_set_uint (value, xcamel_message_info_get_folder_flagged_stamp (mi));
+               return;
+
        case PROP_LOADING:
                g_value_set_boolean (value, xcamel_message_info_get_loading (mi));
                return;
@@ -625,6 +640,25 @@ xcamel_message_info_class_init (xCamelMessageInfoClass *class)
                        G_PARAM_READWRITE));
 
        /**
+        * xCamelMessageInfo:dirty-stamp
+        *
+        * The 'dirty-stamp' is a stamp of the 'dirty' flag. This stamp changes whenever
+        * anything would mark the @mi 'dirty', regardless the @mi being already dirty.
+        * It can be used to recognize changes on the 'dirty' flag during the time.
+        *
+        * Since: 3.24
+        **/
+       g_object_class_install_property (
+               object_class,
+               PROP_DIRTY_STAMP,
+               g_param_spec_uint (
+                       "dirty-stamp",
+                       "Dirty Stamp",
+                       NULL,
+                       0, G_MAXUINT, 0,
+                       G_PARAM_READABLE));
+
+       /**
         * xCamelMessageInfo:folder-flagged
         *
         * Flag, whether the info is changed and requires save to
@@ -645,6 +679,26 @@ xcamel_message_info_class_init (xCamelMessageInfoClass *class)
                        G_PARAM_READWRITE));
 
        /**
+        * xCamelMessageInfo:folder-flagged-stamp
+        *
+        * The 'folder-flagged-stamp' is a stamp of the 'folder-flagged' flag. This stamp
+        * changes whenever anything would mark the @mi 'folder-flagged', regardless the @mi
+        * being already 'folder-flagged'. It can be used to recognize changes
+        * on the 'folder-flagged' flag during the time.
+        *
+        * Since: 3.24
+        **/
+       g_object_class_install_property (
+               object_class,
+               PROP_FOLDER_FLAGGED_STAMP,
+               g_param_spec_uint (
+                       "folder-flagged-stamp",
+                       "Folder Flagged Stamp",
+                       NULL,
+                       0, G_MAXUINT, 0,
+                       G_PARAM_READABLE));
+
+       /**
         * xCamelMessageInfo:loading
         *
         * Flag, whether the info is currently loading. It is used to avoid
@@ -1205,7 +1259,8 @@ xcamel_message_info_get_dirty (const xCamelMessageInfo *mi)
  * @dirty: a dirty state to set
  *
  * Marks the @mi as dirty, which means a save to the local summary
- * is required.
+ * is required. In case the @dirty is %TRUE and the @mi is not loading,
+ * the 'dirty-stamp' changes too.
  *
  * Since: 3.24
  **/
@@ -1218,10 +1273,15 @@ xcamel_message_info_set_dirty (const xCamelMessageInfo *mi,
        g_return_if_fail (XCAMEL_IS_MESSAGE_INFO (mi));
 
        xcamel_message_info_property_lock (mi);
+
        changed = (!mi->priv->dirty) != (!dirty);
        if (changed)
                mi->priv->dirty = dirty;
        loading = mi->priv->loading;
+
+       if (dirty && !loading)
+               mi->priv->dirty_stamp++;
+
        xcamel_message_info_property_unlock (mi);
 
        if (changed && !loading) {
@@ -1240,6 +1300,32 @@ xcamel_message_info_set_dirty (const xCamelMessageInfo *mi,
 }
 
 /**
+ * xcamel_message_info_get_dirty_stamp:
+ * @mi: a #CamelMessageInfo
+ *
+ * The 'dirty-stamp' is a stamp of the 'dirty' flag. This stamp changes whenever
+ * anything would mark the @mi 'dirty', regardless the @mi being already dirty.
+ * It can be used to recognize changes on the 'dirty' flag during the time.
+ *
+ * Returns: Stamp of the 'dirty' flag.
+ *
+ * Since: 3.24
+ **/
+guint
+xcamel_message_info_get_dirty_stamp (const xCamelMessageInfo *mi)
+{
+       guint result;
+
+       g_return_val_if_fail (XCAMEL_IS_MESSAGE_INFO (mi), ~0);
+
+       xcamel_message_info_property_lock (mi);
+       result = mi->priv->dirty_stamp;
+       xcamel_message_info_property_unlock (mi);
+
+       return result;
+}
+
+/**
  * xcamel_message_info_get_folder_flagged:
  * @mi: a #CamelMessageInfo
  *
@@ -1293,6 +1379,33 @@ xcamel_message_info_set_folder_flagged (xCamelMessageInfo *mi,
 }
 
 /**
+ * xcamel_message_info_get_folder_flagged_stamp:
+ * @mi: a #CamelMessageInfo
+ *
+ * The 'folder-flagged-stamp' is a stamp of the 'folder-flagged' flag. This stamp
+ * changes whenever anything would mark the @mi as 'folder-flagged', regardless
+ * the @mi being already 'folder-flagged'. It can be used to recognize changes
+ * on the 'folder-flagged' flag during the time.
+ *
+ * Returns: Stamp of the 'folder-flagged' flag.
+ *
+ * Since: 3.24
+ **/
+guint
+xcamel_message_info_get_folder_flagged_stamp (const xCamelMessageInfo *mi)
+{
+       guint result;
+
+       g_return_val_if_fail (XCAMEL_IS_MESSAGE_INFO (mi), ~0);
+
+       xcamel_message_info_property_lock (mi);
+       result = mi->priv->folder_flagged_stamp;
+       xcamel_message_info_property_unlock (mi);
+
+       return result;
+}
+
+/**
  * xcamel_message_info_get_loading:
  * @mi: a #CamelMessageInfo
  *
@@ -1469,7 +1582,9 @@ xcamel_message_info_get_flags (const xCamelMessageInfo *mi)
  *
  * If the @mi changed, the 'dirty' flag and the 'folder-flagged' flag are
  * set automatically, unless the @mi is loading. There is also emitted
- * folder's "changed" signal for this @mi, if necessary.
+ * folder's "changed" signal for this @mi, if necessary. In case
+ * the CAMEL_MESSAGE_FOLDER_FLAGGED flag would be set and the @mi is
+ * not loading, the 'folder-flagged-stamp' changes too.
  *
  * Returns: Whether the flags changed.
  *
@@ -1490,8 +1605,15 @@ xcamel_message_info_set_flags (xCamelMessageInfo *mi,
        g_return_val_if_fail (klass->set_flags != NULL, FALSE);
 
        xcamel_message_info_property_lock (mi);
+
        changed = klass->set_flags (mi, mask, set);
        loading = mi->priv->loading;
+
+       if (!loading &&
+           (mask & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0 &&
+           (set & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0)
+               mi->priv->folder_flagged_stamp++;
+
        xcamel_message_info_property_unlock (mi);
 
        if (changed && !loading) {
diff --git a/camel/camel-message-info.h b/camel/camel-message-info.h
index ef73a6f..5df819d 100644
--- a/camel/camel-message-info.h
+++ b/camel/camel-message-info.h
@@ -215,11 +215,15 @@ void              xcamel_message_info_property_unlock
 gboolean       xcamel_message_info_get_dirty   (const xCamelMessageInfo *mi);
 void           xcamel_message_info_set_dirty   (const xCamelMessageInfo *mi,
                                                 gboolean dirty);
+guint          xcamel_message_info_get_dirty_stamp
+                                               (const xCamelMessageInfo *mi);
 gboolean       xcamel_message_info_get_folder_flagged
                                                (const xCamelMessageInfo *mi);
 gboolean       xcamel_message_info_set_folder_flagged
                                                (xCamelMessageInfo *mi,
                                                 gboolean folder_flagged);
+guint          xcamel_message_info_get_folder_flagged_stamp
+                                               (const xCamelMessageInfo *mi);
 gboolean       xcamel_message_info_get_loading (const xCamelMessageInfo *mi);
 void           xcamel_message_info_set_loading (const xCamelMessageInfo *mi,
                                                 gboolean loading);


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