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);
54 gtk_tree_path_free(path);
59 printf("get_selected_task returns NULL\n");
67 struct task **tasks_cur;
72 tasks = get_all_tasks();
74 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
75 gtk_list_store_clear(GTK_LIST_STORE(model));
76 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
79 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
82 gtk_list_store_set(GTK_LIST_STORE(model),
87 gtk_list_store_set(GTK_LIST_STORE(model),
90 1, (*tasks_cur)->description,
95 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
100 GtkTextIter sIter, eIter;
103 task = get_selected_task(GTK_TREE_VIEW(w_treeview));
105 printf("tasksave_clicked_cbk %d\n", task->id);
108 buf = gtk_text_view_get_buffer(w_note);
110 gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
111 gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
112 txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
119 ctxt = gtk_entry_get_text(w_description);
124 + strlen(" modify description:\"")
128 sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
139 static int refresh_clicked_cbk(GtkButton *btn, gpointer data)
141 printf("refresh_clicked_cbk\n");
147 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
152 printf("cursor_changed_cbk\n");
154 task = get_selected_task(treeview);
159 buf = gtk_text_view_get_buffer(w_note);
160 gtk_text_buffer_set_text(buf,
165 gtk_entry_set_text(w_description, task->description);
166 gtk_widget_set_sensitive(w_tasksave_btn, 1);
168 gtk_widget_set_sensitive(w_tasksave_btn, 0);
174 int main(int argc, char **argv)
180 gtk_init(NULL, NULL);
181 builder = gtk_builder_new();
182 gtk_builder_add_from_file
184 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
186 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
187 printf("%p\n", window);
189 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
191 w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
193 w_description = GTK_ENTRY(gtk_builder_get_object(builder,
198 g_signal_connect(w_treeview,
199 "cursor-changed", (GCallback)cursor_changed_cbk, tasks);
201 btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
202 g_signal_connect(btn,
203 "clicked", (GCallback)tasksave_clicked_cbk, tasks);
204 gtk_widget_set_sensitive(btn, 0);
205 w_tasksave_btn = btn;
207 btn = GTK_WIDGET(gtk_builder_get_object(builder, "refresh"));
208 g_signal_connect(btn,
209 "clicked", (GCallback)refresh_clicked_cbk, tasks);
211 g_object_unref(G_OBJECT(builder));
213 gtk_widget_show_all(window);