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;
33 static GtkWidget *w_tasksave_btn;
35 static struct task *get_selected_task(GtkTreeView *treeview)
38 GtkTreeViewColumn *cols;
42 printf("get_selected_task\n");
44 gtk_tree_view_get_cursor(treeview, &path, &cols);
47 i = gtk_tree_path_get_indices(path);
50 printf("row selected: %d\n", *i);
57 gtk_tree_path_free(path);
62 printf("get_selected_task returns NULL\n");
70 struct task **tasks_cur;
75 tasks = get_all_tasks();
77 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
78 gtk_list_store_clear(GTK_LIST_STORE(model));
79 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
82 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
85 gtk_list_store_set(GTK_LIST_STORE(model),
90 gtk_list_store_set(GTK_LIST_STORE(model),
93 1, (*tasks_cur)->description,
98 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
103 GtkTextIter sIter, eIter;
106 task = get_selected_task(GTK_TREE_VIEW(w_treeview));
108 printf("tasksave_clicked_cbk %d\n", task->id);
111 buf = gtk_text_view_get_buffer(w_note);
113 gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
114 gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
115 txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
122 ctxt = gtk_entry_get_text(w_description);
127 + strlen(" modify description:\"")
131 sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
142 static int refresh_clicked_cbk(GtkButton *btn, gpointer data)
144 printf("refresh_clicked_cbk\n");
150 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
155 printf("cursor_changed_cbk\n");
157 task = get_selected_task(treeview);
162 buf = gtk_text_view_get_buffer(w_note);
163 gtk_text_buffer_set_text(buf,
168 gtk_entry_set_text(w_description, task->description);
169 gtk_widget_set_sensitive(w_tasksave_btn, 1);
171 gtk_widget_set_sensitive(w_tasksave_btn, 0);
177 int main(int argc, char **argv)
183 gtk_init(NULL, NULL);
184 builder = gtk_builder_new();
185 gtk_builder_add_from_file
187 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
189 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
191 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
193 w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
195 w_description = GTK_ENTRY(gtk_builder_get_object(builder,
200 g_signal_connect(w_treeview,
201 "cursor-changed", (GCallback)cursor_changed_cbk,
204 btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
205 g_signal_connect(btn,
206 "clicked", (GCallback)tasksave_clicked_cbk, tasks);
207 gtk_widget_set_sensitive(btn, 0);
208 w_tasksave_btn = btn;
210 btn = GTK_WIDGET(gtk_builder_get_object(builder, "refresh"));
211 g_signal_connect(btn,
212 "clicked", (GCallback)refresh_clicked_cbk, tasks);
214 g_object_unref(G_OBJECT(builder));
216 gtk_widget_show_all(window);