[libgdata/gbsneto/task-position] tasks: Turn 'position' and 'parent' into writable properties



commit 0f481847c30b166b7cfb9d8ca13efc4bd8885f39
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Sep 16 13:43:09 2018 -0300

    tasks: Turn 'position' and 'parent' into writable properties
    
    This will be used by GNOME To Do through Evolution-Data-Server
    to manipulate the position of the task in the list.
    
    Additional test checks were added to ensure the propeties behave
    as expected.

 docs/reference/gdata-sections.txt       |  2 ++
 gdata/gdata-core.symbols                |  2 ++
 gdata/services/tasks/gdata-tasks-task.c | 58 ++++++++++++++++++++++++++++++---
 gdata/services/tasks/gdata-tasks-task.h |  2 ++
 gdata/tests/tasks.c                     | 14 ++++++--
 5 files changed, 71 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 06fd3c87..dbd1dd4a 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -2553,7 +2553,9 @@ GDataTasksTask
 GDataTasksTaskClass
 gdata_tasks_task_new
 gdata_tasks_task_get_parent
+gdata_tasks_task_set_parent
 gdata_tasks_task_get_position
+gdata_tasks_task_set_position
 gdata_tasks_task_get_notes
 gdata_tasks_task_set_notes
 gdata_tasks_task_get_status
diff --git a/gdata/gdata-core.symbols b/gdata/gdata-core.symbols
index fd7c7dff..29e94fdb 100644
--- a/gdata/gdata-core.symbols
+++ b/gdata/gdata-core.symbols
@@ -984,7 +984,9 @@ gdata_documents_document_get_thumbnail_uri
 gdata_tasks_task_get_type
 gdata_tasks_task_new
 gdata_tasks_task_get_parent
+gdata_tasks_task_set_parent
 gdata_tasks_task_get_position
+gdata_tasks_task_set_position
 gdata_tasks_task_get_notes
 gdata_tasks_task_set_notes
 gdata_tasks_task_get_status
diff --git a/gdata/services/tasks/gdata-tasks-task.c b/gdata/services/tasks/gdata-tasks-task.c
index 00490b89..7f80cdea 100644
--- a/gdata/services/tasks/gdata-tasks-task.c
+++ b/gdata/services/tasks/gdata-tasks-task.c
@@ -99,7 +99,9 @@ gdata_tasks_task_class_init (GDataTasksTaskClass *klass)
        /**
         * GDataTasksTask:parent:
         *
-        * Parent task identifier. This field is omitted if it is a top-level task. This field is read-only.
+        * Parent task identifier. This field is omitted if it is a top-level task.
+        *
+        * Since 0.17.11, this property is writable.
         *
         * Since: 0.15.0
         */
@@ -107,7 +109,7 @@ gdata_tasks_task_class_init (GDataTasksTaskClass *klass)
                                         g_param_spec_string ("parent",
                                         "Parent of task", "Identifier of parent task.",
                                         NULL,
-                                        G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+                                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
        /**
         * GDataTasksTask:position:
@@ -115,7 +117,9 @@ gdata_tasks_task_class_init (GDataTasksTaskClass *klass)
         * String indicating the position of the task among its sibling tasks under the same parent task
         * or at the top level. If this string is greater than another task's corresponding position string
         * according to lexicographical ordering, the task is positioned after the other task under the same
-        * parent task (or at the top level). This field is read-only.
+        * parent task (or at the top level).
+        *
+        * Since 0.17.11, this property is writable.
         *
         * Since: 0.15.0
         */
@@ -123,7 +127,7 @@ gdata_tasks_task_class_init (GDataTasksTaskClass *klass)
                                         g_param_spec_string ("position",
                                         "Position of task", "Position of the task among sibling tasks using 
lexicographical order.",
                                         NULL,
-                                        G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+                                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
        /**
         * GDataTasksTask:notes:
@@ -296,7 +300,11 @@ gdata_tasks_task_set_property (GObject *object, guint property_id, const GValue
                        gdata_tasks_task_set_is_deleted (self, g_value_get_boolean (value));
                        break;
                case PROP_PARENT:
+                       gdata_tasks_task_set_parent (self, g_value_get_string (value));
+                       break;
                case PROP_POSITION:
+                       gdata_tasks_task_set_position (self, g_value_get_string (value));
+                       break;
                case PROP_HIDDEN:
                /* Read-only */
                default:
@@ -416,6 +424,27 @@ gdata_tasks_task_get_parent (GDataTasksTask *self)
        return self->priv->parent;
 }
 
+/**
+ * gdata_tasks_task_set_parent:
+ * @self: a #GDataTasksTask
+ * @parent: (nullable): parent of the task
+ *
+ * Sets the #GDataTasksTask:parent property.
+ *
+ * Since: 0.17.11
+ */
+void
+gdata_tasks_task_set_parent (GDataTasksTask *self, const gchar *parent)
+{
+       gchar *local_parent;
+       g_return_if_fail (GDATA_IS_TASKS_TASK (self));
+
+       local_parent = self->priv->parent;
+       self->priv->parent = g_strdup (parent);
+       g_free (local_parent);
+       g_object_notify (G_OBJECT (self), "parent");
+}
+
 /**
  * gdata_tasks_task_get_position:
  * @self: a #GDataTasksTask
@@ -433,6 +462,27 @@ gdata_tasks_task_get_position (GDataTasksTask *self)
        return self->priv->position;
 }
 
+/**
+ * gdata_tasks_task_set_position:
+ * @self: a #GDataTasksTask
+ * @position: position of the task in the list
+ *
+ * Sets the #GDataTasksTask:position property.
+ *
+ * Since: 0.17.11
+ */
+void
+gdata_tasks_task_set_position (GDataTasksTask *self, const gchar *position)
+{
+       gchar *local_position;
+       g_return_if_fail (GDATA_IS_TASKS_TASK (self));
+
+       local_position = self->priv->position;
+       self->priv->position = g_strdup (position);
+       g_free (local_position);
+       g_object_notify (G_OBJECT (self), "position");
+}
+
 /**
  * gdata_tasks_task_get_notes:
  * @self: a #GDataTasksTask
diff --git a/gdata/services/tasks/gdata-tasks-task.h b/gdata/services/tasks/gdata-tasks-task.h
index 7ceb0bcb..2f28b9c8 100644
--- a/gdata/services/tasks/gdata-tasks-task.h
+++ b/gdata/services/tasks/gdata-tasks-task.h
@@ -98,7 +98,9 @@ GType gdata_tasks_task_get_type (void) G_GNUC_CONST;
 GDataTasksTask *gdata_tasks_task_new (const gchar *id) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
 
 const gchar *gdata_tasks_task_get_parent (GDataTasksTask *self) G_GNUC_PURE;
+void gdata_tasks_task_set_parent (GDataTasksTask *self, const gchar *parent);
 const gchar *gdata_tasks_task_get_position (GDataTasksTask *self) G_GNUC_PURE;
+void gdata_tasks_task_set_position (GDataTasksTask *self, const gchar *position);
 const gchar *gdata_tasks_task_get_notes (GDataTasksTask *self) G_GNUC_PURE;
 void gdata_tasks_task_set_notes (GDataTasksTask *self, const gchar *notes);
 const gchar *gdata_tasks_task_get_status (GDataTasksTask *self) G_GNUC_PURE;
diff --git a/gdata/tests/tasks.c b/gdata/tests/tasks.c
index 2e9a03ef..6f3073ad 100644
--- a/gdata/tests/tasks.c
+++ b/gdata/tests/tasks.c
@@ -256,6 +256,8 @@ test_task_properties (void)
        gdata_tasks_task_set_due (task, 1409419209);
        gdata_tasks_task_set_completed (task, 1409419200);  /* 9 seconds to spare! */
        gdata_tasks_task_set_is_deleted (task, FALSE);
+       gdata_tasks_task_set_position (task, "0");
+       gdata_tasks_task_set_parent (task, NULL);
 
        /* Check the properties of the object */
        g_object_get (G_OBJECT (task),
@@ -278,7 +280,7 @@ test_task_properties (void)
        g_assert_cmpstr (title, ==, "some-title");
        g_assert_cmpint (updated, ==, -1);
        g_assert_cmpstr (parent, ==, NULL);
-       g_assert_cmpstr (position, ==, NULL);
+       g_assert_cmpstr (position, ==, "0");
        g_assert_cmpstr (notes, ==, "some-notes");
        g_assert_cmpstr (status, ==, GDATA_TASKS_STATUS_NEEDS_ACTION);
        g_assert_cmpint (due, ==, 1409419209);
@@ -302,11 +304,13 @@ test_task_properties (void)
                      "due", (gint64) 1409419200,
                      "completed", (gint64) 1409419200,  /* no time to spare! */
                      "is-deleted", TRUE,
+                     "parent", "parent-uid",
+                     "position", "1",
                      NULL);
 
        /* Check the properties using the getters. */
-       g_assert_cmpstr (gdata_tasks_task_get_parent (task), ==, NULL);
-       g_assert_cmpstr (gdata_tasks_task_get_position (task), ==, NULL);
+       g_assert_cmpstr (gdata_tasks_task_get_parent (task), ==, "parent-uid");
+       g_assert_cmpstr (gdata_tasks_task_get_position (task), ==, "1");
        g_assert_cmpstr (gdata_tasks_task_get_notes (task), ==, "more-notes");
        g_assert_cmpstr (gdata_tasks_task_get_status (task), ==,
                         GDATA_TASKS_STATUS_COMPLETED);
@@ -325,6 +329,8 @@ test_task_properties (void)
                        "\"due\": \"2014-08-30T17:20:00Z\","
                        "\"completed\": \"2014-08-30T17:20:00Z\","
                        "\"deleted\": true,"
+                       "\"position\": \"1\","
+                       "\"parent\": \"parent-uid\","
                        "\"hidden\": false"
                "}");
 
@@ -340,6 +346,8 @@ test_task_properties (void)
                        "\"due\": \"2014-08-30T17:20:00Z\","
                        "\"completed\": \"2014-08-30T17:20:00Z\","
                        "\"deleted\": false,"
+                       "\"position\": \"1\","
+                       "\"parent\": \"parent-uid\","
                        "\"hidden\": false"
                "}");
 


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