summaryrefslogtreecommitdiff
path: root/gdata
diff options
context:
space:
mode:
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2018-09-16 13:43:09 -0300
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2018-09-18 23:44:24 -0300
commit69a9419e3862cbe3b591ca13115b41a378e7fe3a (patch)
treea291e11b4986fb45600aaaf6ad36954c14507e70 /gdata
parent13ebb9cee8098506f557f23e872554321ddfe5b7 (diff)
downloadlibgdata-69a9419e3862cbe3b591ca13115b41a378e7fe3a.tar.gz
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.
Diffstat (limited to 'gdata')
-rw-r--r--gdata/gdata-core.symbols2
-rw-r--r--gdata/services/tasks/gdata-tasks-task.c64
-rw-r--r--gdata/services/tasks/gdata-tasks-task.h2
-rw-r--r--gdata/tests/tasks.c14
4 files changed, 75 insertions, 7 deletions
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..265dd137 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.10, 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.10, 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:
@@ -417,6 +425,30 @@ gdata_tasks_task_get_parent (GDataTasksTask *self)
}
/**
+ * gdata_tasks_task_set_parent:
+ * @self: a #GDataTasksTask
+ * @parent: (nullable): parent of the task
+ *
+ * Sets the #GDataTasksTask:parent property.
+ *
+ * Since: 0.17.10
+ */
+void
+gdata_tasks_task_set_parent (GDataTasksTask *self, const gchar *parent)
+{
+ gchar *local_parent;
+ g_return_if_fail (GDATA_IS_TASKS_TASK (self));
+
+ if (g_strcmp0 (self->priv->parent, parent) == 0)
+ return;
+
+ 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
*
@@ -434,6 +466,30 @@ gdata_tasks_task_get_position (GDataTasksTask *self)
}
/**
+ * gdata_tasks_task_set_position:
+ * @self: a #GDataTasksTask
+ * @position: position of the task in the list
+ *
+ * Sets the #GDataTasksTask:position property.
+ *
+ * Since: 0.17.10
+ */
+void
+gdata_tasks_task_set_position (GDataTasksTask *self, const gchar *position)
+{
+ gchar *local_position;
+ g_return_if_fail (GDATA_IS_TASKS_TASK (self));
+
+ if (g_strcmp0 (self->priv->position, position) == 0)
+ return;
+
+ 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"
"}");