2 * Copyright (C) 2010-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <json/json.h>
29 static struct task **tasks;
30 static GtkTextView *w_note;
31 static GtkEntry *w_description;
32 static GtkTreeView *w_treeview;
34 static struct task *get_selected_task(GtkTreeView *treeview)
37 GtkTreeViewColumn *cols;
41 gtk_tree_view_get_cursor(treeview, &path, &cols);
44 i = gtk_tree_path_get_indices(path);
47 printf("row selected: %d\n", *i);
51 gtk_tree_path_free(path);
59 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
64 GtkTextIter sIter, eIter;
67 task = get_selected_task(GTK_TREE_VIEW(w_treeview));
69 printf("tasksave_clicked_cbk %d\n", task->id);
72 buf = gtk_text_view_get_buffer(w_note);
74 gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
75 gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
76 txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
83 ctxt = gtk_entry_get_text(w_description);
88 + strlen(" modify description:\"")
92 sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
101 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
106 printf("cursor_changed_cbk\n");
108 task = get_selected_task(treeview);
113 buf = gtk_text_view_get_buffer(w_note);
114 gtk_text_buffer_set_text(buf,
119 gtk_entry_set_text(w_description, task->description);
125 int main(int argc, char **argv)
133 struct task **tasks_cur;
136 gtk_init(NULL, NULL);
137 builder = gtk_builder_new();
138 gtk_builder_add_from_file
140 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
142 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
143 printf("%p\n", window);
145 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
147 w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
149 w_description = GTK_ENTRY(gtk_builder_get_object(builder,
152 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
154 tasks = get_all_tasks();
156 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
159 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
162 gtk_list_store_set(GTK_LIST_STORE(model),
167 gtk_list_store_set(GTK_LIST_STORE(model),
170 1, (*tasks_cur)->description,
174 g_signal_connect(w_treeview,
175 "cursor-changed", (GCallback)cursor_changed_cbk, tasks);
177 btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
178 g_signal_connect(btn,
179 "clicked", (GCallback)tasksave_clicked_cbk, tasks);
181 g_object_unref(G_OBJECT(builder));
183 gtk_widget_show_all(window);