From 68bf32c9de206a3f80a615782069425522ddad8d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 16 Oct 2012 20:12:14 +0000 Subject: [PATCH] --- src/Makefile.in | 2 + src/glade/gtask.glade | 199 +++++++++++++++++++++++++++++++++++++++++--------- src/main.c | 80 ++++++++++++++++---- src/tw.c | 20 +++++ src/tw.h | 1 + 5 files changed, 254 insertions(+), 48 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index ff036da..670c384 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -248,6 +248,8 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = glade + +# -export-dynamic is need for defining handlers in the glade file. AM_LDFLAGS = -Wl,--as-needed -export-dynamic AM_CPPFLAGS = -Wall -Werror $(GTK_CFLAGS) $(JSON_CFLAGS) gtask_SOURCES = main.c \ diff --git a/src/glade/gtask.glade b/src/glade/gtask.glade index a569c56..f02c3b3 100644 --- a/src/glade/gtask.glade +++ b/src/glade/gtask.glade @@ -1,17 +1,107 @@ - - - - - - - - - + + False + 5 + New Task + dialog + + + False + vertical + 2 + + + False + end + + + gtk-ok + True + True + True + True + + + False + True + 0 + + + + + gtk-cancel + True + True + True + True + + + False + True + 1 + + + + + False + True + end + 0 + + + + + True + False + + + True + False + 4 + 4 + 4 + 4 + Description: + + + False + True + 0 + + + + + True + True + 4 + 4 + 4 + 4 + • + + + False + True + 1 + + + + + False + True + 1 + + + + + + button1 + button2 + - + @@ -25,6 +115,18 @@ + + + + + + + + + + + + False gtask @@ -34,21 +136,48 @@ True False + 4 + 4 + 4 + 4 vertical True False - - refresh + True - True - True - 4 - 4 - 4 - + False + start + + + Refresh + True + True + True + + + + False + False + 0 + + + + + New Task + True + True + True + + + + False + False + 1 + + False @@ -60,21 +189,17 @@ True False - 4 - 4 - 4 True False 4 4 - 4 Status: False - True + False 0 @@ -82,10 +207,7 @@ True False - 4 - 4 - 4 - liststore2 + statusstore 0 @@ -96,21 +218,21 @@ False - True + False 1 False - True + False 2 False - True + False 0 @@ -135,10 +257,10 @@ 4 4 4 - liststore1 + taskstore False treeviewcolumn1 - 0 + 1 both True @@ -161,6 +283,10 @@ 10 Project + True + True + True + 2 @@ -176,6 +302,10 @@ 30 Description True + True + True + True + 1 @@ -226,6 +356,8 @@ True False + start + center 4 4 4 @@ -284,6 +416,7 @@ True False + start 4 4 4 @@ -330,7 +463,7 @@ 4 - OK + Save True True True diff --git a/src/main.c b/src/main.c index b39f554..0c059ff 100644 --- a/src/main.c +++ b/src/main.c @@ -34,34 +34,42 @@ static GtkTreeView *w_treeview; static GtkWidget *w_tasksave_btn; static GtkComboBox *w_status; +enum { + COL_ID, + COL_DESCRIPTION, + COL_PROJECT, + COL_UUID +}; + static struct task *get_selected_task(GtkTreeView *treeview) { GtkTreePath *path; GtkTreeViewColumn *cols; - gint *i; - struct task *task; + struct task **tasks_cur; + GtkTreeIter iter; + GtkTreeModel *model; + GValue value = {0,}; + const char *uuid; printf("get_selected_task\n"); gtk_tree_view_get_cursor(treeview, &path, &cols); if (path) { - i = gtk_tree_path_get_indices(path); + model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); + gtk_tree_model_get_iter(model, &iter, path); + gtk_tree_model_get_value(model, &iter, COL_UUID, &value); - if (i) { - printf("row selected: %d\n", *i); + uuid = g_value_get_string(&value); - task = tasks[*i]; - } else { - task = NULL; - } + for(tasks_cur = tasks; *tasks_cur; tasks_cur++) + if (!strcmp((*tasks_cur)->uuid, uuid)) + return *tasks_cur; gtk_tree_path_free(path); - } else { - task = NULL; } - return task; + return NULL; } static void clear_task_panel() @@ -116,13 +124,14 @@ static void refresh() if (task->project) gtk_list_store_set(GTK_LIST_STORE(model), &iter, - 2, task->project, + COL_PROJECT, task->project, -1); gtk_list_store_set(GTK_LIST_STORE(model), &iter, - 0, (*tasks_cur)->id, - 1, (*tasks_cur)->description, + COL_ID, (*tasks_cur)->id, + COL_DESCRIPTION, (*tasks_cur)->description, + COL_UUID, (*tasks_cur)->uuid, -1); } } @@ -172,6 +181,47 @@ int refresh_clicked_cbk(GtkButton *btn, gpointer data) return FALSE; } +int newtask_clicked_cbk(GtkButton *btn, gpointer data) +{ + gint result; + static GtkDialog *diag; + GtkBuilder *builder; + GtkEntry *entry; + const char *ctxt; + + printf("newtask_clicked_cbk\n"); + + builder = gtk_builder_new(); + gtk_builder_add_from_file + (builder, + PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade", + NULL); + diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_tasknew")); + gtk_builder_connect_signals(builder, NULL); + + result = gtk_dialog_run(diag); + + if (result == GTK_RESPONSE_ACCEPT) { + printf("ok\n"); + entry = GTK_ENTRY(gtk_builder_get_object + (builder, "diag_tasknew_description")); + ctxt = gtk_entry_get_text(entry); + + printf("%s\n", ctxt); + + tw_add(ctxt); + refresh(); + } else { + printf("cancel\n"); + } + + g_object_unref(G_OBJECT(builder)); + + gtk_widget_destroy(GTK_WIDGET(diag)); + + return FALSE; +} + static int status_changed_cbk(GtkComboBox *w, gpointer data) { printf("status_changed_cbk\n"); diff --git a/src/tw.c b/src/tw.c index ae67094..9a551bc 100644 --- a/src/tw.c +++ b/src/tw.c @@ -215,3 +215,23 @@ void tw_modify_project(const char *uuid, const char *newproject) free(str); free(opts); } + +void tw_add(const char *newdesc) +{ + char *str; + char *opts; + + str = escape(newdesc); + + opts = malloc(1 + + strlen(" add \"") + + strlen(str) + + strlen("\"") + + 1); + sprintf(opts, " add \"%s\"", str); + + task_exec(opts); + + free(str); + free(opts); +} diff --git a/src/tw.h b/src/tw.h index 182e603..9c6f0b2 100644 --- a/src/tw.h +++ b/src/tw.h @@ -32,6 +32,7 @@ struct task { 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); +void tw_add(const char *newdesc); char *task_exec(char *opts); char *escape(const char *txt); -- 2.7.4