Support deleting tasks
[milk] / src / milk-main-window.c
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