(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 16 Oct 2012 12:22:10 +0000 (12:22 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Tue, 16 Oct 2012 12:22:10 +0000 (12:22 +0000)
src/main.c
src/tw.c
src/tw.h

index 78beb8f..df27275 100644 (file)
@@ -97,13 +97,13 @@ static void refresh()
        
        switch (status) {
        case 0:
-               tasks = get_all_tasks("pending");
+               tasks = tw_get_all_tasks("pending");
                break;
        case 1:
-               tasks = get_all_tasks("completed");
+               tasks = tw_get_all_tasks("completed");
                break;
        default:
-               tasks = get_all_tasks("pending");
+               tasks = tw_get_all_tasks("pending");
        }
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
@@ -131,7 +131,7 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
 {
        struct task *task;
        GtkTextBuffer *buf;
-       char *txt, *opts;
+       char *txt;
        GtkTextIter sIter, eIter;
        const char *ctxt;
 
@@ -152,19 +152,12 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
        }
 
        ctxt = gtk_entry_get_text(w_description);
-       txt = escape(ctxt);
+       if (!task->description || strcmp(ctxt, task->description))
+           tw_modify_description(task->uuid, ctxt);
 
-       opts = malloc(1
-                     + strlen(task->uuid)
-                     + strlen(" modify description:\"")
-                     + strlen(txt)
-                     + strlen("\"")
-                     + 1);
-       sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
-
-       task_exec(opts);
-
-       free(txt);
+       ctxt = gtk_entry_get_text(w_project);
+       if (!task->project || strcmp(ctxt, task->project))
+           tw_modify_project(task->uuid, ctxt);
 
        refresh();
 
index 7ed0ae1..ae67094 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -86,7 +86,7 @@ static struct json_object *task_exec_json(char *opts)
        return NULL;
 }
 
-struct task **get_all_tasks(const char *status)
+struct task **tw_get_all_tasks(const char *status)
 {
        int i, n;
        struct json_object *jtasks, *jtask, *json;
@@ -174,3 +174,44 @@ 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);
+}
index 4bf2324..182e603 100644 (file)
--- a/src/tw.h
+++ b/src/tw.h
@@ -29,7 +29,10 @@ struct task {
        char *project;
 };
 
-struct task **get_all_tasks(const char *status);
+struct task **tw_get_all_tasks(const char *status);
+void tw_modify_description(const char *uuid, const char *newdesc);
+void tw_modify_project(const char *uuid, const char *newproj);
+
 char *task_exec(char *opts);
 char *escape(const char *txt);