From 68bef7ba87d8c964590260ba188b63b0377fbd46 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 15 Oct 2012 19:02:33 +0000 Subject: [PATCH] --- src/glade/gtask.glade | 165 ++++++++++++++++++++++++++++++++++++++++---------- src/main.c | 124 ++++++++++++++++++++++++++++++++++--- 2 files changed, 248 insertions(+), 41 deletions(-) diff --git a/src/glade/gtask.glade b/src/glade/gtask.glade index 7d38739..fe9ca9b 100644 --- a/src/glade/gtask.glade +++ b/src/glade/gtask.glade @@ -15,54 +15,157 @@ 640 480 - + True True - in + vertical + 144 + True - + True True - True - liststore1 - False - treeviewcolumn1 - 0 - both - True - 1 - - - + in - - autosize - 10 - Id + + True + True + False + liststore1 + False + treeviewcolumn1 + 0 + both + True + -1 + + + - - - 0 - + + autosize + 10 + Id + + + + 0 + + + + + + + autosize + 10 + 30 + Description + True + + + + 1 + + + + + + False + True + + + + + True + False + vertical - - autosize - 10 - 30 - Description + + True + False + + + True + False + Description: + + + False + True + 0 + + + + + True + True + in + + + True + True + + + + + True + True + 1 + + + + True + True + 0 + + + + + True + False + + + OK + True + True + True + top + + + False + True + 0 + + - - - 1 - + + Cancel + True + True + True + + + False + True + 2 + + + False + True + 2 + + + True + True + diff --git a/src/main.c b/src/main.c index 7fade92..3f95c31 100644 --- a/src/main.c +++ b/src/main.c @@ -24,14 +24,16 @@ #include - struct task { int id; char *description; char *status; + char *uuid; }; static struct task **tasks; +static GtkTextView *w_description; +static GtkTreeView *w_treeview; static char *task_exec(char *opts) { @@ -45,6 +47,8 @@ static char *task_exec(char *opts) strcpy(cmd, "task rc.json.array=on "); strcat(cmd, opts); + printf("execute: %s\n", cmd); + f = popen(cmd, "r"); if (!f) { @@ -120,6 +124,9 @@ 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, "uuid"); + tasks[i]->uuid = strdup(json_object_get_string(json)); } tasks[n] = NULL; @@ -129,13 +136,12 @@ static struct task **get_all_tasks() return tasks; } -static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data) +static struct task *get_selected_task(GtkTreeView *treeview) { GtkTreePath *path; GtkTreeViewColumn *cols; gint *i; - - printf("cursor_changed_cbk\n"); + struct task *task; gtk_tree_view_get_cursor(treeview, &path, &cols); @@ -144,18 +150,109 @@ static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data) if (i) printf("row selected: %d\n", *i); - + task = tasks[*i]; + + gtk_tree_path_free(path); + + return task; } - gtk_tree_path_free(path); + return NULL; +} + +static char *escape(char *txt) +{ + char *result; + char *c; + + result = malloc(2*strlen(txt)+1); + c = result; + + while(*txt) { + switch(*txt) { + case '"': + *c = '\\'; c++; + *c = '"'; + break; + case '$': + *c = '\\'; c++; + *c = '$'; + break; + case '&': + *c = '\\'; c++; + *c = '&'; + break; + default: + *c = *txt; + } + c++; + txt++; + } + + *c = '\0'; + + return result; +} + +static int tasksave_clicked_cbk(GtkButton *btn, gpointer data) +{ + struct task *task; + GtkTextBuffer *buf; + char *txt, *opts; + GtkTextIter sIter, eIter; + + 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); + + 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); + + printf("%s\n", txt); + + opts = malloc(1 + + strlen(task->uuid) + + strlen(" modify description:\"") + + strlen(txt) + + strlen("\"") + + 1); + sprintf(opts, " %s modify \"%s\"", task->uuid, txt); + + task_exec(opts); + + return FALSE; +} + +static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data) +{ + struct task *task; + GtkTextBuffer *buf; + + printf("cursor_changed_cbk\n"); + + 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)); + + } return FALSE; } + int main(int argc, char **argv) { GtkWidget *window; - GtkWidget *treeview; + GtkWidget *btn; GtkBuilder *builder; GtkTreeIter iter; int i; @@ -171,9 +268,12 @@ int main(int argc, char **argv) window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); printf("%p\n", window); - treeview = GTK_WIDGET(gtk_builder_get_object(builder, "treeview")); + w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview")); - model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); + w_description = GTK_TEXT_VIEW(gtk_builder_get_object(builder, + "taskdescription")); + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview)); tasks = get_all_tasks(); @@ -186,9 +286,13 @@ int main(int argc, char **argv) -1); } - g_signal_connect(treeview, + g_signal_connect(w_treeview, "cursor-changed", (GCallback)cursor_changed_cbk, tasks); + btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave")); + g_signal_connect(btn, + "clicked", (GCallback)tasksave_clicked_cbk, tasks); + g_object_unref(G_OBJECT(builder)); gtk_widget_show_all(window); -- 2.7.4