Implement the priority +/- buttons
authorTravis Reitter <treitter@gmail.com>
Thu, 25 Mar 2010 05:30:25 +0000 (22:30 -0700)
committerTravis Reitter <treitter@gmail.com>
Sun, 28 Mar 2010 17:08:24 +0000 (10:08 -0700)
src/milk-auth.h
src/milk-cache.c
src/milk-cache.h
src/milk-main-window.c

index 5e98254..55c5b79 100644 (file)
@@ -95,5 +95,10 @@ char*         milk_auth_task_delete     (MilkAuth    *auth,
                                          char        *timeline,
                                          RtmTask     *task,
                                          GError     **error);
+char*         milk_auth_task_set_priority (MilkAuth    *auth,
+                                           char        *timeline,
+                                           RtmTask     *task,
+                                           const char  *priority,
+                                           GError     **error);
 
 #endif /* _MILK_AUTH_H */
index 0f65230..891d3ff 100644 (file)
@@ -1434,6 +1434,27 @@ milk_cache_task_delete (MilkCache  *cache,
         return milk_auth_task_delete (priv->auth, timeline, task, error);
 }
 
+char*
+milk_cache_task_set_priority (MilkCache  *cache,
+                              char       *timeline,
+                              RtmTask    *task,
+                              const char *priority,
+                              GError    **error)
+{
+        MilkCachePrivate *priv;
+
+        g_return_val_if_fail (MILK_IS_CACHE (cache), NULL);
+
+        priv = MILK_CACHE_PRIVATE (cache);
+
+        /* FIXME: update the task in the database and mark it as having local
+         * changes; then immediately emit the "task-changed" signal, so the
+         * model will immediately reflect that */
+
+        return milk_auth_task_set_priority (priv->auth, timeline, task,
+                        priority, error);
+}
+
 /* XXX: this won't be necessary when the auth handles this transparently; or at
  * least this will merely be a signal to the auth that we're ready to
  * authenticate when it is */
index d774fe0..cc66b19 100644 (file)
@@ -86,4 +86,10 @@ char*           milk_cache_task_delete (MilkCache  *cache,
                                         RtmTask    *task,
                                         GError    **error);
 
+char*           milk_cache_task_set_priority (MilkCache   *cache,
+                                              char        *timeline,
+                                              RtmTask     *task,
+                                              const char  *priority,
+                                              GError     **error);
+
 #endif /* _MILK_CACHE_H */
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