Make priority sorting work
[milk] / src / milk-cache.c
index af0c7cb..24eebff 100644 (file)
@@ -247,8 +247,9 @@ db_get_tasks_active (sqlite3 *db)
         char *statement;
         GList *tasks = NULL;
 
+        /* FIXME: get the priority */
         statement = g_strdup_printf ("SELECT "
-                        "task_id, name, due_date FROM tasks "
+                        "task_id, name, priority, due_date FROM tasks "
                         "WHERE "
                                 "delete_date IS NULL AND "
                                 "complete_date IS NULL"
@@ -277,8 +278,10 @@ db_get_tasks_active (sqlite3 *db)
 
                 rtm_task_set_id   (task, (char*)sqlite3_column_text (query, 0));
                 rtm_task_set_name (task, (char*)sqlite3_column_text (query, 1));
+                rtm_task_set_priority (task,
+                                (char*)sqlite3_column_text (query, 2));
 
-                if (db_date_column_to_timeval (query, 2, &timeval))
+                if (db_date_column_to_timeval (query, 3, &timeval))
                         rtm_task_set_due_date (task, &timeval);
 
                 tasks = g_list_prepend (tasks, task);
@@ -384,6 +387,7 @@ db_update_schema_0_to_1 (sqlite3 *db)
                         "       ON DELETE CASCADE,"
                         "name TEXT NOT NULL,"
                         "local_changes BOOLEAN DEFAULT 0,"
+                        "priority TEXT,"
                         "due_date TEXT,"
                         "delete_date TEXT,"
                         "complete_date TEXT,"
@@ -542,6 +546,7 @@ db_insert_or_update_local_task (sqlite3    *db,
         GTimeVal *due, *deleted, *completed;
         char *name_str, *due_str, *deleted_str, *completed_str;
         const char *task_id;
+        const char *priority;
         const char *list_id;
         const char *taskseries_id;
         gint status;
@@ -591,6 +596,9 @@ db_insert_or_update_local_task (sqlite3    *db,
         task_id = rtm_task_get_id (task);
         task_id = task_id ? task_id : "NULL";
 
+        priority = rtm_task_get_priority (task);
+        priority = priority ? priority : "N";
+
         list_id = rtm_task_get_list_id (task);
         list_id = list_id ? list_id : "NULL";
 
@@ -610,14 +618,15 @@ db_insert_or_update_local_task (sqlite3    *db,
 
         /* all but the name fields are already quoted or NULL */
         statement = g_strdup_printf ("INSERT OR REPLACE INTO tasks "
-                        "('local_id','task_id','name','due_date','delete_date',"
-                        "'complete_date','list_id','taskseries_id',"
-                        "'local_changes') "
-                        "VALUES (%s, %s, '%s', %s, %s, %s, %s, %s, %d)"
+                        "('local_id','task_id','name','priority','due_date',"
+                        "'delete_date','complete_date','list_id',"
+                        "'taskseries_id','local_changes') "
+                        "VALUES (%s, %s, '%s', '%s', %s, %s, %s, %s, %s, %d)"
                         ";",
                         local_id,
                         task_id,
                         name_str,
+                        priority,
                         due_str,
                         deleted_str,
                         completed_str,
@@ -800,6 +809,7 @@ db_insert_or_update_task (sqlite3  *db,
 
         success &= db_insert_or_update_local_task (db, task,
                         local_id_formatted, local_changes);
+
         g_free (local_id_formatted);
 
         return success;
@@ -1212,7 +1222,10 @@ cache_receive_changes_ERROR:
 static gboolean
 cache_send_receive_changes (MilkCache *cache)
 {
-        return cache_send_changes (cache) && cache_receive_changes (cache);
+        cache_send_changes (cache);
+        cache_receive_changes (cache);
+
+        return TRUE;
 }
 
 static void
@@ -1223,9 +1236,6 @@ restart_send_receive_poll (MilkCache *cache,
 
         priv = MILK_CACHE_PRIVATE (cache);
 
-        /* FIXME: cut this */
-        g_debug ("restarting the send/receive poll");
-
         if (priv->update_id)
                 g_source_remove (priv->update_id);