(no commit message)
[ptask.git] / src / tw.c
index e2a7bca..c92c1ee 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "note.h"
 
 char *task_exec(char *opts)
 {
@@ -86,13 +87,18 @@ static struct json_object *task_exec_json(char *opts)
        return NULL;
 }
 
-struct task **get_all_tasks()
+struct task **tw_get_all_tasks(const char *status)
 {
        int i, n;
        struct json_object *jtasks, *jtask, *json;
        struct task **tasks;
+       char *opts;
 
-       jtasks = task_exec_json("export");
+       opts = malloc(strlen("export status:") + strlen(status) + 1);
+       sprintf(opts, "export status:%s", status);
+
+       jtasks = task_exec_json(opts);
+       free(opts);
 
        if (!jtasks)
                return NULL;
@@ -122,10 +128,17 @@ struct task **get_all_tasks()
                else
                        tasks[i]->project = NULL;
 
+               json = json_object_object_get(jtask, "priority");
+               if (json)
+                       tasks[i]->priority
+                               = strdup(json_object_get_string(json));
+               else
+                       tasks[i]->priority = strdup("");
+
                json = json_object_object_get(jtask, "uuid");
                tasks[i]->uuid = strdup(json_object_get_string(json));
 
-               tasks[i]->note = NULL;
+               tasks[i]->note = note_get(tasks[i]->uuid);
        }
 
        tasks[n] = NULL;
@@ -169,3 +182,100 @@ char *escape(const char *txt)
        return result;
 }
 
+void tw_modify_description(const char *uuid, const char *newdesc)
+{
+       char *str;
+       char *opts;
+
+       str = escape(newdesc);
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" modify :\"")
+                     + strlen(str)
+                     + strlen("\"")
+                     + 1);
+       sprintf(opts, " %s modify \"%s\"", uuid, str);
+
+       task_exec(opts);
+
+       free(str);
+       free(opts);
+}
+
+void tw_modify_project(const char *uuid, const char *newproject)
+{
+       char *str;
+       char *opts;
+
+       str = escape(newproject);
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" modify project:\"")
+                     + strlen(str)
+                     + strlen("\"")
+                     + 1);
+       sprintf(opts, " %s modify project:\"%s\"", uuid, str);
+
+       task_exec(opts);
+
+       free(str);
+       free(opts);
+}
+
+void tw_modify_priority(const char *uuid, const char *priority)
+{
+       char *str;
+       char *opts;
+
+       str = escape(priority);
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" modify priority:\"")
+                     + strlen(str)
+                     + strlen("\"")
+                     + 1);
+       sprintf(opts, " %s modify priority:\"%s\"", uuid, str);
+
+       task_exec(opts);
+
+       free(str);
+       free(opts);
+}
+
+void tw_add(const char *newdesc)
+{
+       char *str;
+       char *opts;
+
+       str = escape(newdesc);
+
+       opts = malloc(1
+                     + strlen(" add \"")
+                     + strlen(str)
+                     + strlen("\"")
+                     + 1);
+       sprintf(opts, " add \"%s\"", str);
+
+       task_exec(opts);
+
+       free(str);
+       free(opts);
+}
+
+void tw_done(const char *uuid)
+{
+       char *opts;
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" done")
+                     + 1);
+       sprintf(opts, " %s done", uuid);
+
+       task_exec(opts);
+
+       free(opts);
+}