Support marking tasks as complete
authorTravis Reitter <treitter@gmail.com>
Mon, 30 Nov 2009 04:51:28 +0000 (20:51 -0800)
committerTravis Reitter <treitter@gmail.com>
Fri, 4 Dec 2009 06:01:13 +0000 (22:01 -0800)
src/milk-auth.c
src/milk-auth.h
src/milk-main-window.c

index 548e16b..2331619 100644 (file)
@@ -203,6 +203,34 @@ milk_auth_get_tasks (MilkAuth    *auth,
         return rtm_tasks;
 }
 
+char*
+milk_auth_timeline_create (MilkAuth  *auth,
+                           GError   **error)
+{
+        MilkAuthPrivate *priv;
+
+        g_return_val_if_fail (MILK_IS_AUTH (auth), NULL);
+
+        priv = MILK_AUTH_PRIVATE (auth);
+
+        return rtm_glib_timelines_create (priv->rtm_glib, error);
+}
+
+char*
+milk_auth_task_complete (MilkAuth  *auth,
+                         char      *timeline,
+                         RtmTask   *task,
+                         GError   **error)
+{
+        MilkAuthPrivate *priv;
+
+        g_return_val_if_fail (MILK_IS_AUTH (auth), NULL);
+
+        priv = MILK_AUTH_PRIVATE (auth);
+
+        return rtm_glib_tasks_complete (priv->rtm_glib, timeline, task, error);
+}
+
 void
 milk_auth_log_in (MilkAuth *auth)
 {
index 845e854..61c49f3 100644 (file)
@@ -69,11 +69,17 @@ typedef enum {
 GType milk_auth_get_type (void);
 
 
-MilkAuth*     milk_auth_get_default (void);
-void          milk_auth_log_in      (MilkAuth    *auth);
-MilkAuthState milk_auth_get_state   (MilkAuth    *auth);
-GList*        milk_auth_get_tasks   (MilkAuth    *auth,
-                                     const char  *last_sync,
-                                     GError     **error);
+MilkAuth*     milk_auth_get_default     (void);
+void          milk_auth_log_in          (MilkAuth    *auth);
+MilkAuthState milk_auth_get_state       (MilkAuth    *auth);
+GList*        milk_auth_get_tasks       (MilkAuth    *auth,
+                                         const char  *last_sync,
+                                         GError     **error);
+char*         milk_auth_timeline_create (MilkAuth    *auth,
+                                         GError     **error);
+char*         milk_auth_task_complete   (MilkAuth    *auth,
+                                         char        *timeline,
+                                         RtmTask     *task,
+                                         GError     **error);
 
 #endif /* _MILK_AUTH_H */
index 598ba2c..ad89faf 100644 (file)
@@ -101,11 +101,58 @@ new_task_clicked_cb (GtkButton      *button,
         g_debug ("FIXME: implement 'new task' action");
 }
 
+/* XXX: The latency between clicking "complete" and actually removing the task
+ * from the view after polling the server is very long, so there's an obvious
+ * lag -- it will be completely transparent (and look very fast) as soon as
+ * we've got a cache in place */
 static void
 complete_clicked_cb (GtkButton      *button,
                      MilkMainWindow *window)
 {
-        g_debug ("FIXME: implement 'complete' action");
+        MilkMainWindowPrivate *priv;
+        GList *rows;
+        GtkTreeModel *model;
+        char *timeline;
+        GError *error = NULL;
+
+        priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+        rows = hildon_touch_selector_get_selected_rows (
+                        HILDON_TOUCH_SELECTOR (priv->task_view),
+                        TASK_VIEW_COLUMN_TITLE);
+        model = hildon_touch_selector_get_model (
+                        HILDON_TOUCH_SELECTOR (priv->task_view),
+                        TASK_VIEW_COLUMN_TITLE);
+
+        timeline = milk_auth_timeline_create (priv->auth, &error);
+
+        if (error) {
+                g_warning (G_STRLOC ": failed to create a timeline: %s",
+                           error->message);
+                g_clear_error (&error);
+        } else {
+                while (rows) {
+                        GtkTreeIter iter;
+                        RtmTask *task;
+
+                        gtk_tree_model_get_iter (model, &iter, rows->data);
+                        gtk_tree_model_get (model, &iter,
+                                        MILK_TASK_MODEL_COLUMN_TASK, &task,
+                                        -1);
+
+                        milk_auth_task_complete (priv->auth, timeline, task,
+                                        &error);
+                        if (error != NULL) {
+                                g_warning (G_STRLOC ": failed to complete task "
+                                                "%s: %s",
+                                                rtm_task_get_id (task),
+                                                error->message);
+                                g_clear_error (&error);
+                        }
+
+                        rows = g_list_delete_link (rows, rows);
+                }
+        }
 }
 
 static void