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 GtkEntry *w_project;
33 static GtkTreeView *w_treeview;
34 static GtkWidget *w_tasksave_btn;
35 static GtkComboBox *w_status;
36 static GtkComboBox *w_priority;
46 static struct task *get_selected_task(GtkTreeView *treeview)
49 GtkTreeViewColumn *cols;
50 struct task **tasks_cur;
56 printf("get_selected_task\n");
58 gtk_tree_view_get_cursor(treeview, &path, &cols);
61 model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
62 gtk_tree_model_get_iter(model, &iter, path);
63 gtk_tree_model_get_value(model, &iter, COL_UUID, &value);
65 uuid = g_value_get_string(&value);
67 for (tasks_cur = tasks; *tasks_cur; tasks_cur++)
68 if (!strcmp((*tasks_cur)->uuid, uuid))
71 gtk_tree_path_free(path);
77 static void clear_task_panel()
81 gtk_widget_set_sensitive(w_tasksave_btn, 0);
83 buf = gtk_text_view_get_buffer(w_note);
84 gtk_text_buffer_set_text(buf, "", 0);
85 gtk_widget_set_sensitive(GTK_WIDGET(w_note), 0);
87 gtk_entry_set_text(w_description, "");
88 gtk_widget_set_sensitive(GTK_WIDGET(w_description), 0);
90 gtk_entry_set_text(w_project, "");
91 gtk_widget_set_sensitive(GTK_WIDGET(w_project), 0);
93 gtk_combo_box_set_active(w_priority, 0);
94 gtk_widget_set_sensitive(GTK_WIDGET(w_priority), 0);
100 struct task **tasks_cur;
108 status = gtk_combo_box_get_active(w_status);
109 printf("status: %d\n", status);
113 tasks = tw_get_all_tasks("pending");
116 tasks = tw_get_all_tasks("completed");
119 tasks = tw_get_all_tasks("pending");
122 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
123 gtk_list_store_clear(GTK_LIST_STORE(model));
124 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
127 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
130 gtk_list_store_set(GTK_LIST_STORE(model),
132 COL_PROJECT, task->project,
135 gtk_list_store_set(GTK_LIST_STORE(model),
137 COL_ID, (*tasks_cur)->id,
138 COL_DESCRIPTION, (*tasks_cur)->description,
139 COL_UUID, (*tasks_cur)->uuid,
140 COL_PRIORITY, (*tasks_cur)->priority,
145 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
150 GtkTextIter sIter, eIter;
154 task = get_selected_task(GTK_TREE_VIEW(w_treeview));
156 printf("tasksave_clicked_cbk %d\n", task->id);
159 buf = gtk_text_view_get_buffer(w_note);
161 gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
162 gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
163 txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
170 ctxt = gtk_entry_get_text(w_description);
171 if (!task->description || strcmp(ctxt, task->description))
172 tw_modify_description(task->uuid, ctxt);
174 ctxt = gtk_entry_get_text(w_project);
175 if (!task->project || strcmp(ctxt, task->project))
176 tw_modify_project(task->uuid, ctxt);
178 priority = gtk_combo_box_get_active(w_priority);
179 printf("priority: %d\n", priority);
195 if (strcmp(task->priority, pri))
196 tw_modify_priority(task->uuid, pri);
203 int refresh_clicked_cbk(GtkButton *btn, gpointer data)
205 printf("refresh_clicked_cbk\n");
211 int newtask_clicked_cbk(GtkButton *btn, gpointer data)
214 static GtkDialog *diag;
219 printf("newtask_clicked_cbk\n");
221 builder = gtk_builder_new();
222 gtk_builder_add_from_file
224 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
226 diag = GTK_DIALOG(gtk_builder_get_object(builder, "diag_tasknew"));
227 gtk_builder_connect_signals(builder, NULL);
229 result = gtk_dialog_run(diag);
231 if (result == GTK_RESPONSE_ACCEPT) {
233 entry = GTK_ENTRY(gtk_builder_get_object
234 (builder, "diag_tasknew_description"));
235 ctxt = gtk_entry_get_text(entry);
237 printf("%s\n", ctxt);
245 g_object_unref(G_OBJECT(builder));
247 gtk_widget_destroy(GTK_WIDGET(diag));
252 static int status_changed_cbk(GtkComboBox *w, gpointer data)
254 printf("status_changed_cbk\n");
260 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
266 printf("cursor_changed_cbk\n");
268 task = get_selected_task(treeview);
272 buf = gtk_text_view_get_buffer(w_note);
274 gtk_text_buffer_set_text(buf,
278 gtk_text_buffer_set_text(buf, "", 0);
279 gtk_widget_set_sensitive(GTK_WIDGET(w_note), 1);
281 gtk_entry_set_text(w_description, task->description);
282 gtk_widget_set_sensitive(GTK_WIDGET(w_description), 1);
285 gtk_entry_set_text(w_project, task->project);
287 gtk_entry_set_text(w_project, "");
288 gtk_widget_set_sensitive(GTK_WIDGET(w_project), 1);
290 gtk_widget_set_sensitive(w_tasksave_btn, 1);
292 gtk_widget_set_sensitive(GTK_WIDGET(w_priority), 1);
293 if (!strcmp(task->priority, "H"))
295 else if (!strcmp(task->priority, "M"))
297 else if (!strcmp(task->priority, "L"))
302 gtk_combo_box_set_active(w_priority, priority);
304 printf("clear task widgets\n");
311 int main(int argc, char **argv)
317 gtk_init(NULL, NULL);
318 builder = gtk_builder_new();
319 gtk_builder_add_from_file
321 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
323 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
325 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
327 w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
329 w_description = GTK_ENTRY(gtk_builder_get_object(builder,
331 w_project = GTK_ENTRY(gtk_builder_get_object(builder, "taskproject"));
332 w_status = GTK_COMBO_BOX(gtk_builder_get_object(builder, "status"));
333 w_priority = GTK_COMBO_BOX(gtk_builder_get_object(builder,
338 gtk_builder_connect_signals(builder, NULL);
340 g_signal_connect(w_treeview,
341 "cursor-changed", (GCallback)cursor_changed_cbk,
343 g_signal_connect(w_status,
344 "changed", (GCallback)status_changed_cbk,
346 btn = GTK_WIDGET(gtk_builder_get_object(builder, "tasksave"));
347 g_signal_connect(btn,
348 "clicked", (GCallback)tasksave_clicked_cbk, tasks);
349 gtk_widget_set_sensitive(btn, 0);
350 w_tasksave_btn = btn;
352 /*btn = GTK_WIDGET(gtk_builder_get_object(builder, "refresh"));
353 g_signal_connect(btn,
354 "clicked", (GCallback)refresh_clicked_cbk, tasks);*/
356 g_object_unref(G_OBJECT(builder));
358 gtk_widget_show_all(window);