added remove task button
[ptask.git] / src / tw.c
index 3e5e55b..43760d4 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -37,6 +37,8 @@ static char *task_exec(char *opts)
        size_t s;
        char *str, *tmp, *cmd, buf[1024];
 
+       log_fct_enter();
+
        cmd = malloc(strlen("task ") + strlen(opts) + 1);
        strcpy(cmd, "task ");
        strcat(cmd, opts);
@@ -67,6 +69,8 @@ static char *task_exec(char *opts)
        if (ret == -1)
                log_err("pclose fails");
 
+       log_fct_exit();
+
        return str;
 }
 
@@ -276,6 +280,8 @@ void tw_modify_priority(const char *uuid, const char *priority)
        char *str;
        char *opts;
 
+       log_fct_enter();
+
        str = escape(priority);
 
        opts = malloc(1
@@ -290,15 +296,19 @@ void tw_modify_priority(const char *uuid, const char *priority)
 
        free(str);
        free(opts);
+
+       log_fct_exit();
 }
 
 void tw_add(const char *newdesc, const char *prj, const char *prio)
 {
        char *opts, *eprj;
 
+       log_fct_enter();
+
        eprj = escape(prj);
 
-       opts = malloc(strlen(" add")
+       opts = malloc(strlen("add")
                      + strlen(" priority:")
                      + 1
                      + strlen(" project:\\\"")
@@ -309,7 +319,7 @@ void tw_add(const char *newdesc, const char *prj, const char *prio)
                      + strlen("\"")
                      + 1);
 
-       strcpy(opts, " add");
+       strcpy(opts, "add");
 
        if (prio && strlen(prio) == 1) {
                strcat(opts, " priority:");
@@ -324,12 +334,14 @@ void tw_add(const char *newdesc, const char *prj, const char *prio)
 
        strcat(opts, " \"");
        strcat(opts, newdesc);
-       strcat(opts, " \"");
+       strcat(opts, "\"");
 
        tw_exec(opts);
 
        free(opts);
        free(eprj);
+
+       log_fct_exit();
 }
 
 void tw_done(const char *uuid)
@@ -347,6 +359,21 @@ void tw_done(const char *uuid)
        free(opts);
 }
 
+void tw_task_remove(const char *uuid)
+{
+       char *opts;
+
+       opts = malloc(1
+                     + strlen(uuid)
+                     + strlen(" delete")
+                     + 1);
+       sprintf(opts, " %s delete", uuid);
+
+       tw_exec(opts);
+
+       free(opts);
+}
+
 static void task_free(struct task *task)
 {
        if (!task)
@@ -426,10 +453,11 @@ struct project **tw_get_projects(struct task **tasks)
        struct project **prjs, **tmp, *prj;
        const char *prj_name;
 
-       log_debug("tw_get_projects()");
+       log_fct_enter();
 
-       prjs = malloc(sizeof(struct project *));
-       *prjs = NULL;
+       prjs = malloc(2 * sizeof(struct project *));
+       prjs[0] = project_new("ALL", 0);
+       prjs[1] = NULL;
 
        for (t_cur = tasks; *t_cur; t_cur++) {
                prj_name = (*t_cur)->project;
@@ -444,7 +472,10 @@ struct project **tw_get_projects(struct task **tasks)
                        free(prjs);
                        prjs = tmp;
                }
+               prjs[0]->count++;
        }
 
+       log_fct_exit();
+
        return prjs;
 }