Implement the priority +/- buttons
[milk] / src / milk-main-window.c
index 9754c45..c4d7bb2 100644 (file)
@@ -194,14 +194,104 @@ static void
 priority_plus_clicked_cb (GtkButton      *button,
                           MilkMainWindow *window)
 {
-        g_debug ("FIXME: implement 'priority plus' action");
+        MilkMainWindowPrivate *priv;
+        GList *tasks;
+        char *timeline;
+        GError *error = NULL;
+
+        priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+        tasks = get_selected_tasks (window);
+        timeline = milk_cache_timeline_create (priv->cache, &error);
+
+        if (error) {
+                g_warning (G_STRLOC ": failed to create a timeline: %s",
+                           error->message);
+                g_clear_error (&error);
+        } else {
+                while (tasks) {
+                        const char *priority;
+                        const char *priority_new;
+
+                        priority = rtm_task_get_priority (tasks->data);
+
+                        if (FALSE) {
+                        } else if (!g_strcmp0 (priority, "1")) {
+                                priority_new = "1";
+                        } else if (!g_strcmp0 (priority, "2")) {
+                                priority_new = "1";
+                        } else if (!g_strcmp0 (priority, "3")) {
+                                priority_new = "2";
+                        } else if (!g_strcmp0 (priority, "N")) {
+                                priority_new = "3";
+                        } else {
+                                g_warning ("unknown priority '%s'; setting to "
+                                                "unprioritized", priority);
+                                priority_new = "N";
+                        }
+
+                        milk_cache_task_set_priority (priv->cache, timeline,
+                                        tasks->data, priority_new, NULL);
+                        tasks = g_list_delete_link (tasks, tasks);
+                }
+        }
+
+        /* XXX: it would be nicer to select the tasks in their new positions */
+        hildon_touch_selector_unselect_all (
+                        HILDON_TOUCH_SELECTOR (priv->task_view),
+                        TASK_VIEW_COLUMN_TITLE);
 }
 
 static void
 priority_minus_clicked_cb (GtkButton      *button,
                            MilkMainWindow *window)
 {
-        g_debug ("FIXME: implement 'priority minus' action");
+        MilkMainWindowPrivate *priv;
+        GList *tasks;
+        char *timeline;
+        GError *error = NULL;
+
+        priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+        tasks = get_selected_tasks (window);
+        timeline = milk_cache_timeline_create (priv->cache, &error);
+
+        if (error) {
+                g_warning (G_STRLOC ": failed to create a timeline: %s",
+                           error->message);
+                g_clear_error (&error);
+        } else {
+                while (tasks) {
+                        const char *priority;
+                        const char *priority_new;
+
+                        priority = rtm_task_get_priority (tasks->data);
+
+                        if (FALSE) {
+                        } else if (!g_strcmp0 (priority, "1")) {
+                                priority_new = "2";
+                        } else if (!g_strcmp0 (priority, "2")) {
+                                priority_new = "3";
+                        } else if (!g_strcmp0 (priority, "3")) {
+                                priority_new = "N";
+                        } else if (!g_strcmp0 (priority, "N")) {
+                                priority_new = "N";
+                        } else {
+                                g_warning ("unknown priority '%s'; setting to "
+                                                "unprioritized", priority);
+                                priority_new = "N";
+                        }
+
+                        milk_cache_task_set_priority (priv->cache, timeline,
+                                        tasks->data, priority_new, NULL);
+                        tasks = g_list_delete_link (tasks, tasks);
+                }
+        }
+
+        /* XXX: it would be nicer to select the tasks in their new positions */
+        hildon_touch_selector_unselect_all (
+                        HILDON_TOUCH_SELECTOR (priv->task_view),
+                        TASK_VIEW_COLUMN_TITLE);
 }
 
 static void