added display of tags
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 28 Sep 2014 10:29:26 +0000 (12:29 +0200)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 28 Sep 2014 10:29:26 +0000 (12:29 +0200)
NEWS
src/glade/ptask.glade
src/tw.c
src/tw.h
src/ui_taskpanel.c

diff --git a/NEWS b/NEWS
index 6fba535..a3db306 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ v0.0.7
  * disable the removal of recurrent tasks which is freezing ptask
    because taskwarrior CLI is prompting a confirmation. That's the
    consequence of the taskwarrior bug TW-638.
  * disable the removal of recurrent tasks which is freezing ptask
    because taskwarrior CLI is prompting a confirmation. That's the
    consequence of the taskwarrior bug TW-638.
+ * display the tags of the selected task.
 
 v0.0.6
 ------
 
 v0.0.6
 ------
index e0c72af..1339f60 100644 (file)
                           </object>
                           <packing>
                             <property name="left_attach">0</property>
                           </object>
                           <packing>
                             <property name="left_attach">0</property>
-                            <property name="top_attach">4</property>
+                            <property name="top_attach">5</property>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
                           </object>
                           <packing>
                             <property name="left_attach">1</property>
                           </object>
                           <packing>
                             <property name="left_attach">1</property>
-                            <property name="top_attach">4</property>
+                            <property name="top_attach">5</property>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
                             <property name="height">1</property>
                           </packing>
                         </child>
                             <property name="height">1</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkLabel" id="label10">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="halign">start</property>
+                            <property name="margin_left">4</property>
+                            <property name="margin_right">4</property>
+                            <property name="margin_top">4</property>
+                            <property name="margin_bottom">4</property>
+                            <property name="label" translatable="yes">Tags:</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">4</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="tasktags">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="halign">start</property>
+                            <property name="margin_left">4</property>
+                            <property name="margin_right">4</property>
+                            <property name="margin_top">4</property>
+                            <property name="margin_bottom">4</property>
+                            <property name="label" translatable="yes">label</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">4</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">True</property>
                       </object>
                       <packing>
                         <property name="expand">True</property>
index 3049c0b..d363e45 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
@@ -161,13 +161,109 @@ static struct json_object *task_exec_json(const char *opts)
        return o;
 }
 
        return o;
 }
 
+char **json_to_tags(struct json_object *jtask)
+{
+       struct json_object *jtags, *jtag;
+       char **tags;
+       int n, i;
+
+       jtags = json_object_object_get(jtask, "tags");
+
+       if (!jtags)
+               return NULL;
+
+
+       n = json_object_array_length(jtags);
+
+       tags = malloc((n + 1) * sizeof(char *));
+
+       for (i = 0; i < n; i++) {
+               jtag = json_object_array_get_idx(jtags, i);
+               tags[i] = strdup(json_object_get_string(jtag));
+       }
+
+       tags[n] = NULL;
+
+       return tags;
+}
+
+struct task *json_to_task(struct json_object *jtask)
+{
+       struct task *task;
+       const char *urg;
+       struct json_object *json;
+
+       task = malloc(sizeof(struct task));
+
+       json = json_object_object_get(jtask, "id");
+       task->id = json_object_get_int(json);
+
+       json = json_object_object_get(jtask, "description");
+       task->description = strdup(json_object_get_string(json));
+
+       json = json_object_object_get(jtask, "status");
+       task->status = strdup(json_object_get_string(json));
+
+       json = json_object_object_get(jtask, "project");
+       if (json)
+               task->project
+                       = strdup(json_object_get_string(json));
+       else
+               task->project = strdup("");
+
+       json = json_object_object_get(jtask, "priority");
+       if (json)
+               task->priority
+                       = strdup(json_object_get_string(json));
+       else
+               task->priority = strdup("");
+
+       json = json_object_object_get(jtask, "uuid");
+       task->uuid = strdup(json_object_get_string(json));
+
+       json = json_object_object_get(jtask, "urgency");
+       urg = json_object_get_string(json);
+       if (urg)
+               task->urgency = strdup(urg);
+       else
+               task->urgency = NULL;
+
+       task->note = note_get(task->uuid);
+
+       json = json_object_object_get(jtask, "entry");
+       task->entry = parse_time(json_object_get_string(json));
+
+       json = json_object_object_get(jtask, "due");
+       if (json)
+               task->due
+                       = parse_time(json_object_get_string(json));
+       else
+               task->due = NULL;
+
+       json = json_object_object_get(jtask, "start");
+       if (json)
+               task->start
+                       = parse_time(json_object_get_string(json));
+       else
+               task->start = NULL;
+
+       json = json_object_object_get(jtask, "recur");
+       if (json)
+               task->recur = strdup(json_object_get_string(json));
+       else
+               task->recur = NULL;
+
+       task->tags = json_to_tags(jtask);
+
+       return task;
+}
+
 struct task **tw_get_all_tasks(const char *status)
 {
        int i, n;
 struct task **tw_get_all_tasks(const char *status)
 {
        int i, n;
-       struct json_object *jtasks, *jtask, *json;
+       struct json_object *jtasks, *jtask;
        struct task **tasks;
        char *opts;
        struct task **tasks;
        char *opts;
-       const char *urg;
 
        opts = malloc(strlen("export status:") + strlen(status) + 1);
 
 
        opts = malloc(strlen("export status:") + strlen(status) + 1);
 
@@ -187,65 +283,7 @@ struct task **tw_get_all_tasks(const char *status)
        for (i = 0; i < n; i++) {
                jtask = json_object_array_get_idx(jtasks, i);
 
        for (i = 0; i < n; i++) {
                jtask = json_object_array_get_idx(jtasks, i);
 
-               tasks[i] = malloc(sizeof(struct task));
-
-               json = json_object_object_get(jtask, "id");
-               tasks[i]->id = json_object_get_int(json);
-
-               json = json_object_object_get(jtask, "description");
-               tasks[i]->description = strdup(json_object_get_string(json));
-
-               json = json_object_object_get(jtask, "status");
-               tasks[i]->status = strdup(json_object_get_string(json));
-
-               json = json_object_object_get(jtask, "project");
-               if (json)
-                       tasks[i]->project
-                               = strdup(json_object_get_string(json));
-               else
-                       tasks[i]->project = strdup("");
-
-               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));
-
-               json = json_object_object_get(jtask, "urgency");
-               urg = json_object_get_string(json);
-               if (urg)
-                       tasks[i]->urgency = strdup(urg);
-               else
-                       tasks[i]->urgency = NULL;
-
-               tasks[i]->note = note_get(tasks[i]->uuid);
-
-               json = json_object_object_get(jtask, "entry");
-               tasks[i]->entry = parse_time(json_object_get_string(json));
-
-               json = json_object_object_get(jtask, "due");
-               if (json)
-                       tasks[i]->due
-                               = parse_time(json_object_get_string(json));
-               else
-                       tasks[i]->due = NULL;
-
-               json = json_object_object_get(jtask, "start");
-               if (json)
-                       tasks[i]->start
-                               = parse_time(json_object_get_string(json));
-               else
-                       tasks[i]->start = NULL;
-
-               json = json_object_object_get(jtask, "recur");
-               if (json)
-                       tasks[i]->recur = strdup(json_object_get_string(json));
-               else
-                       tasks[i]->recur = NULL;
+               tasks[i] = json_to_task(jtask);
        }
 
        tasks[n] = NULL;
        }
 
        tasks[n] = NULL;
@@ -454,6 +492,8 @@ void tw_task_remove(const char *uuid)
 
 static void task_free(struct task *task)
 {
 
 static void task_free(struct task *task)
 {
+       char **tags;
+
        if (!task)
                return ;
 
        if (!task)
                return ;
 
@@ -469,6 +509,15 @@ static void task_free(struct task *task)
        free(task->start);
        free(task->recur);
 
        free(task->start);
        free(task->recur);
 
+       tags = task->tags;
+       if (tags) {
+               while (*tags) {
+                       free(*tags);
+                       tags++;
+               }
+               free(tags);
+       }
+
        free(task);
 }
 
        free(task);
 }
 
index 18e3720..684c56f 100644 (file)
--- a/src/tw.h
+++ b/src/tw.h
@@ -30,6 +30,7 @@ struct task {
        char *priority;
        char *urgency;
        char *recur;
        char *priority;
        char *urgency;
        char *recur;
+       char **tags;
        struct tm *entry;
        struct tm *due;
        struct tm *start;
        struct tm *entry;
        struct tm *due;
        struct tm *start;
index 1071f76..9787415 100644 (file)
@@ -32,6 +32,7 @@ static GtkButton *w_tasksave_btn;
 static GtkButton *w_taskremove_btn;
 static GtkButton *w_taskdone_btn;
 static GtkButton *w_taskcancel_btn;
 static GtkButton *w_taskremove_btn;
 static GtkButton *w_taskdone_btn;
 static GtkButton *w_taskcancel_btn;
+static GtkLabel *w_tasktags;
 
 static struct task *current_task;
 
 
 static struct task *current_task;
 
@@ -70,6 +71,9 @@ static void enable(int enable)
        gtk_widget_set_sensitive(GTK_WIDGET(w_project), enable);
 
        if (!enable)
        gtk_widget_set_sensitive(GTK_WIDGET(w_project), enable);
 
        if (!enable)
+               gtk_label_set_label(w_tasktags, "");
+
+       if (!enable)
                gtk_combo_box_set_active(w_priority, 0);
        gtk_widget_set_sensitive(GTK_WIDGET(w_priority), enable);
 }
                gtk_combo_box_set_active(w_priority, 0);
        gtk_widget_set_sensitive(GTK_WIDGET(w_priority), enable);
 }
@@ -138,7 +142,7 @@ void ui_taskpanel_init(GtkBuilder *builder)
        log_fct("ENTER");
 
        w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
        log_fct("ENTER");
 
        w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
-
+       w_tasktags = GTK_LABEL(gtk_builder_get_object(builder, "tasktags"));
        w_description = GTK_ENTRY(gtk_builder_get_object(builder,
                                                         "taskdescription"));
        w_project = GTK_ENTRY(gtk_builder_get_object(builder, "taskproject"));
        w_description = GTK_ENTRY(gtk_builder_get_object(builder,
                                                         "taskdescription"));
        w_project = GTK_ENTRY(gtk_builder_get_object(builder, "taskproject"));
@@ -183,6 +187,8 @@ void ui_taskpanel_update(struct task *task)
 {
        GtkTextBuffer *buf;
        int priority;
 {
        GtkTextBuffer *buf;
        int priority;
+       char **tags;
+       gchar *tmp, *gtags;
 
        if (task) {
                current_task = task;
 
        if (task) {
                current_task = task;
@@ -205,6 +211,27 @@ void ui_taskpanel_update(struct task *task)
                priority = priority_to_int(task->priority);
                gtk_combo_box_set_active(w_priority, priority);
 
                priority = priority_to_int(task->priority);
                gtk_combo_box_set_active(w_priority, priority);
 
+               tags = task->tags;
+               gtags = NULL;
+               if (tags) {
+                       while (*tags) {
+                               if (gtags) {
+                                       tmp = g_strconcat(gtags,
+                                                         " ",
+                                                         *tags,
+                                                         NULL);
+                                       g_free(gtags);
+                                       gtags = tmp;
+                               } else {
+                                       gtags = g_strdup(*tags);
+                               }
+                               tags++;
+                       }
+                       gtk_label_set_label(w_tasktags, gtags);
+               } else {
+                       gtk_label_set_label(w_tasktags, "");
+               }
+
                enable(1);
        } else {
                current_task = NULL;
                enable(1);
        } else {
                current_task = NULL;