Support deleting tasks
authorTravis Reitter <treitter@gmail.com>
Mon, 30 Nov 2009 04:57:13 +0000 (20:57 -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 2331619..37343bf 100644 (file)
@@ -231,6 +231,21 @@ milk_auth_task_complete (MilkAuth  *auth,
         return rtm_glib_tasks_complete (priv->rtm_glib, timeline, task, error);
 }
 
+char*
+milk_auth_task_delete (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_delete (priv->rtm_glib, timeline, task, error);
+}
+
 void
 milk_auth_log_in (MilkAuth *auth)
 {
index 61c49f3..6f5b6c9 100644 (file)
@@ -81,5 +81,9 @@ char*         milk_auth_task_complete   (MilkAuth    *auth,
                                          char        *timeline,
                                          RtmTask     *task,
                                          GError     **error);
+char*         milk_auth_task_delete     (MilkAuth    *auth,
+                                         char        *timeline,
+                                         RtmTask     *task,
+                                         GError     **error);
 
 #endif /* _MILK_AUTH_H */
index ad89faf..b22c24f 100644 (file)
@@ -155,11 +155,56 @@ complete_clicked_cb (GtkButton      *button,
         }
 }
 
+/* XXX: high latency until we have a cache; see the note for
+ * complete_clicked_cb() */
 static void
 delete_clicked_cb (GtkButton      *button,
                    MilkMainWindow *window)
 {
-        g_debug ("FIXME: implement 'delete' 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_delete (priv->auth, timeline, task,
+                                        &error);
+                        if (error != NULL) {
+                                g_warning (G_STRLOC ": failed to delete task "
+                                                "%s: %s",
+                                                rtm_task_get_id (task),
+                                                error->message);
+                                g_clear_error (&error);
+                        }
+
+                        rows = g_list_delete_link (rows, rows);
+                }
+        }
 }
 
 static void