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);
68 struct task **tasks_cur;
73 tasks = get_all_tasks();
75 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
76 gtk_list_store_clear(GTK_LIST_STORE(model));
77 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
80 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
83 gtk_list_store_set(GTK_LIST_STORE(model),
88 gtk_list_store_set(GTK_LIST_STORE(model),
91 1, (*tasks_cur)->description,
96 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
101 GtkTextIter sIter, eIter;
104 task = get_selected_task(GTK_TREE_VIEW(w_treeview));
106 printf("tasksave_clicked_cbk %d\n", task->id);
109 buf = gtk_text_view_get_buffer(w_note);
111 gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
112 gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
113 txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
120 ctxt = gtk_entry_get_text(w_description);
125 + strlen(" modify description:\"")
129 sprintf(opts, " %s modify \"%s\"", task->uuid, txt);
140 static int refresh_clicked_cbk(GtkButton *btn, gpointer data)
142 printf("refresh_clicked_cbk\n");
148 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
153 printf("cursor_changed_cbk\n");
155 task = get_selected_task(treeview);
160 buf = gtk_text_view_get_buffer(w_note);
161 gtk_text_buffer_set_text(buf,
166 gtk_entry_set_text(w_description, task->description);
167 gtk_widget_set_sensitive(w_tasksave_btn, 1);
169 gtk_widget_set_sensitive(w_tasksave_btn, 0);
175 int main(int argc, char **argv)
181 gtk_init(NULL, NULL);
182 builder = gtk_builder_new();
183 gtk_builder_add_from_file
185 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
187 window = GTK_WIDGET(gtk_builder_get_object(builder, "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,
202 btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
203 g_signal_connect(btn,
204 "clicked", (GCallback)tasksave_clicked_cbk, tasks);
205 gtk_widget_set_sensitive(btn, 0);
206 w_tasksave_btn = btn;
208 btn = GTK_WIDGET(gtk_builder_get_object(builder, "refresh"));
209 g_signal_connect(btn,
210 "clicked", (GCallback)refresh_clicked_cbk, tasks);
212 g_object_unref(G_OBJECT(builder));
214 gtk_widget_show_all(window);