From 150347d61ee08df85b377c5af0c5c2d7b3cc8716 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 16 Oct 2012 07:33:57 +0000 Subject: [PATCH] --- src/glade/gtask.glade | 304 ++++++++++++++++++++++++++++++++++---------------- src/main.c | 66 ++++++++--- 2 files changed, 257 insertions(+), 113 deletions(-) diff --git a/src/glade/gtask.glade b/src/glade/gtask.glade index fe9ca9b..9e15293 100644 --- a/src/glade/gtask.glade +++ b/src/glade/gtask.glade @@ -3,9 +3,11 @@ - + - + + + @@ -15,156 +17,262 @@ 640 480 - + True - True + False vertical - 144 - True - + True - True - in + False - + + refresh True True - False - liststore1 - False - treeviewcolumn1 - 0 - both - True - -1 - - - - - - autosize - 10 - Id - - - - 0 - - - - - - - autosize - 10 - 30 - Description - True - - - - 1 - - - - + True + + False + True + 0 + + + + + + + - False - True + False + True + 0 - + True - False + True vertical + 144 + True - + True - False - - - True - False - Description: - - - False - True - 0 - - + True + 4 + in - + True True - in + 4 + 4 + 4 + 4 + liststore1 + False + treeviewcolumn1 + 0 + both + True + + + - - True - True + + autosize + 10 + Id + + + + 0 + + + + + + + 10 + Project + + + + 2 + + + + + + + autosize + 10 + 30 + Description + True + + + + 1 + + - - True - True - 1 - - True - True - 0 + False + True - + True False + vertical - - OK + True - True - True - top + False + 4 + 4 + 4 + 4 + + + True + False + 4 + 4 + 4 + 4 + Description: + + + 0 + 0 + 1 + 1 + + + + + True + False + 4 + 4 + 4 + Note: + + + 0 + 1 + 1 + 1 + + + + + True + True + 4 + 4 + 4 + True + True + in + + + True + True + + + + + 1 + 1 + 1 + 1 + + + + + True + True + • + True + + + 1 + 0 + 1 + 1 + + - False + True True - 0 + 1 - - Cancel + True - True - True + False + 4 + 4 + 4 + 4 + + + OK + True + True + True + top + + + False + True + 0 + + + + + Cancel + True + True + True + + + False + True + 2 + + False - True + False 2 - False - True - 2 + True + True - True - True + True + True + 1 diff --git a/src/main.c b/src/main.c index 3f95c31..62fa99c 100644 --- a/src/main.c +++ b/src/main.c @@ -29,10 +29,13 @@ struct task { char *description; char *status; char *uuid; + char *note; + char *project; }; static struct task **tasks; -static GtkTextView *w_description; +static GtkTextView *w_note; +static GtkEntry *w_description; static GtkTreeView *w_treeview; static char *task_exec(char *opts) @@ -125,8 +128,17 @@ static struct task **get_all_tasks() 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 = NULL; + json = json_object_object_get(jtask, "uuid"); tasks[i]->uuid = strdup(json_object_get_string(json)); + + tasks[i]->note = NULL; } tasks[n] = NULL; @@ -161,7 +173,7 @@ static struct task *get_selected_task(GtkTreeView *treeview) return NULL; } -static char *escape(char *txt) +static char *escape(const char *txt) { char *result; char *c; @@ -201,20 +213,26 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data) GtkTextBuffer *buf; char *txt, *opts; GtkTextIter sIter, eIter; + const char *ctxt; task = get_selected_task(GTK_TREE_VIEW(w_treeview)); printf("tasksave_clicked_cbk %d\n", task->id); - buf = gtk_text_view_get_buffer(w_description); + if (task->note) { + buf = gtk_text_view_get_buffer(w_note); - gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0); - gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1); - txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE); + gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0); + gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1); + txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE); - txt = escape(txt); + txt = escape(txt); + + printf("%s\n", txt); + } - printf("%s\n", txt); + ctxt = gtk_entry_get_text(w_description); + txt = escape(ctxt); opts = malloc(1 + strlen(task->uuid) @@ -223,8 +241,10 @@ static int tasksave_clicked_cbk(GtkButton *btn, gpointer data) + strlen("\"") + 1); sprintf(opts, " %s modify \"%s\"", task->uuid, txt); - + task_exec(opts); + + free(txt); return FALSE; } @@ -239,11 +259,15 @@ static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data) task = get_selected_task(treeview); if (task) { - buf = gtk_text_view_get_buffer(w_description); - gtk_text_buffer_set_text(buf, - task->description, - strlen(task->description)); + if (task->note) { + buf = gtk_text_view_get_buffer(w_note); + gtk_text_buffer_set_text(buf, + task->note, + strlen(task->note)); + } + + gtk_entry_set_text(w_description, task->description); } return FALSE; @@ -258,6 +282,7 @@ int main(int argc, char **argv) int i; GtkTreeModel *model; struct task **tasks_cur; + struct task *task; gtk_init(NULL, NULL); builder = gtk_builder_new(); @@ -270,15 +295,26 @@ int main(int argc, char **argv) w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview")); - w_description = GTK_TEXT_VIEW(gtk_builder_get_object(builder, - "taskdescription")); + w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote")); + + w_description = GTK_ENTRY(gtk_builder_get_object(builder, + "taskdescription")); model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview)); tasks = get_all_tasks(); for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) { + task = (*tasks_cur); + gtk_list_store_append(GTK_LIST_STORE(model), &iter); + + if (task->project) + gtk_list_store_set(GTK_LIST_STORE(model), + &iter, + 2, task->project, + -1); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, (*tasks_cur)->id, -- 2.7.4