From 8d43529da6a9a3a469b107ab07f52991e9f18e75 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 8 Dec 2013 00:31:28 +0000 Subject: [PATCH] added creation date, due, and start date in the list of tasks. --- NEWS | 1 + NEWS.html | 7 +++- src/glade/ptask.glade | 106 +++++++++++++++++++++++++++++++++++--------------- src/ptime.c | 20 +++++++++- src/ptime.h | 2 +- src/tw.c | 33 ++++++++++++++++ src/tw.h | 3 ++ src/ui_tasktree.c | 59 +++++++++++++++++++++++++--- 8 files changed, 189 insertions(+), 42 deletions(-) diff --git a/NEWS b/NEWS index d00b15d..3ae37c7 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ v0.0.5 * implemented the cancel button of the task panel. * added menu. * restore position of vertical/horizaton spliters. + * added creation date, due, and start date in the list of tasks. v0.0.4 ------ diff --git a/NEWS.html b/NEWS.html index 89e84e3..5e14a0b 100644 --- a/NEWS.html +++ b/NEWS.html @@ -356,6 +356,11 @@ added menu. restore position of vertical/horizaton spliters.

+
  • +

    +added creation date, due, and start date in the list of tasks. +

    +
  • @@ -501,7 +506,7 @@ Initial release.

    diff --git a/src/glade/ptask.glade b/src/glade/ptask.glade index 1e9db98..4dbc32d 100644 --- a/src/glade/ptask.glade +++ b/src/glade/ptask.glade @@ -1,26 +1,6 @@ - - - - - - - - None - - - Low - - - Medium - - - High - - - False 5 @@ -200,6 +180,26 @@ button2 + + + + + + + + None + + + Low + + + Medium + + + High + + + @@ -239,6 +239,12 @@ + + + + + + @@ -518,6 +524,54 @@ + + Urgency + 5 + + + + 5 + + + + + + + Creation date + 6 + + + + 6 + + + + + + + Due + 7 + + + + 7 + + + + + + + Start date + 8 + + + + 8 + + + + + 10 30 @@ -535,18 +589,6 @@ - - - Urgency - 5 - - - - 5 - - - - diff --git a/src/ptime.c b/src/ptime.c index 34ae92e..2e017fc 100644 --- a/src/ptime.c +++ b/src/ptime.c @@ -18,9 +18,10 @@ */ #include -#include "ptime.h" +#include +#include -char *time_to_str(time_t *t) +static char *time_to_str(time_t *t) { struct tm lt; char *str; @@ -45,3 +46,18 @@ char *get_time_str() t = time(NULL); return time_to_str(&t); } + +char *tm_to_str(const struct tm *tm) +{ + char *str; + size_t s; + + str = malloc(11); + s = strftime(str, 11, "%Y/%m/%d", tm); + + if (s) + return str; + + log_err("Failed to convert time"); + return NULL; +} diff --git a/src/ptime.h b/src/ptime.h index aac8c52..54320a4 100644 --- a/src/ptime.h +++ b/src/ptime.h @@ -22,6 +22,6 @@ #include char *get_time_str(); -char *time_to_str(time_t *t); +char *tm_to_str(const struct tm *); #endif diff --git a/src/tw.c b/src/tw.c index e48ab59..abc9808 100644 --- a/src/tw.c +++ b/src/tw.c @@ -16,11 +16,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA */ +#define _GNU_SOURCE #include #include #include #include +#include #include @@ -30,6 +32,17 @@ #include #include "tw.h" +struct tm *parse_time(const char *t) +{ + struct tm *tm; + + tm = malloc(sizeof(struct tm)); + memset(tm, 0, sizeof(struct tm)); + strptime(t, "%Y%m%dT%H%M%S%Z", tm); + + return tm; +} + static char *task_exec(char *opts) { FILE *f; @@ -206,6 +219,23 @@ struct task **tw_get_all_tasks(const char *status) 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; } tasks[n] = NULL; @@ -394,6 +424,9 @@ static void task_free(struct task *task) free(task->project); free(task->priority); free(task->urgency); + free(task->entry); + free(task->due); + free(task->start); free(task); } diff --git a/src/tw.h b/src/tw.h index a9af11d..6f3c177 100644 --- a/src/tw.h +++ b/src/tw.h @@ -29,6 +29,9 @@ struct task { char *project; char *priority; char *urgency; + struct tm *entry; + struct tm *due; + struct tm *start; }; struct project { diff --git a/src/ui_tasktree.c b/src/ui_tasktree.c index abec583..8e46c25 100644 --- a/src/ui_tasktree.c +++ b/src/ui_tasktree.c @@ -16,11 +16,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA */ +#define _XOPEN_SOURCE +#include + +#include #include #include #include +#include #include #include #include @@ -34,7 +39,10 @@ enum { COL_PROJECT, COL_UUID, COL_PRIORITY, - COL_URGENCY + COL_URGENCY, + COL_CREATION_DATE, + COL_DUE, + COL_START }; static int priority_to_int(const char *str) @@ -231,6 +239,7 @@ void ui_tasktree_update(struct task **tasks, const char *prj_filter) struct task *task; GtkTreeIter iter; const char *prj; + char *s; current_tasks = tasks; @@ -253,14 +262,52 @@ void ui_tasktree_update(struct task **tasks, const char *prj_filter) gtk_list_store_set(GTK_LIST_STORE(model), &iter, - COL_ID, (*tasks_cur)->id, + COL_ID, + (*tasks_cur)->id, COL_DESCRIPTION, (*tasks_cur)->description, - COL_PROJECT, prj, - COL_UUID, (*tasks_cur)->uuid, - COL_PRIORITY, (*tasks_cur)->priority, - COL_URGENCY, (*tasks_cur)->urgency, + COL_PROJECT, + prj, + COL_UUID, + (*tasks_cur)->uuid, + COL_PRIORITY, + (*tasks_cur)->priority, + COL_URGENCY, + (*tasks_cur)->urgency, -1); + + if ((*tasks_cur)->start) { + s = tm_to_str((*tasks_cur)->start); + gtk_list_store_set + (GTK_LIST_STORE(model), + &iter, + COL_START, + s, + -1); + free(s); + } + + if ((*tasks_cur)->due) { + s = tm_to_str((*tasks_cur)->due); + gtk_list_store_set + (GTK_LIST_STORE(model), + &iter, + COL_DUE, + s, + -1); + free(s); + } + + if ((*tasks_cur)->entry) { + s = tm_to_str((*tasks_cur)->entry); + gtk_list_store_set + (GTK_LIST_STORE(model), + &iter, + COL_CREATION_DATE, + s, + -1); + free(s); + } } } -- 2.7.4