2 * Copyright (C) 2012-2013 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
25 #include <ui_taskpanel.h>
27 static GtkTextView *w_note;
28 static GtkEntry *w_description;
29 static GtkEntry *w_project;
30 static GtkComboBox *w_priority;
31 static GtkButton *w_tasksave_btn;
32 static GtkButton *w_taskdone_btn;
33 static GtkButton *w_taskcancel_btn;
35 static struct task *current_task;
37 static void enable(int enable)
41 gtk_widget_set_sensitive(GTK_WIDGET(w_tasksave_btn), enable);
42 gtk_widget_set_sensitive(GTK_WIDGET(w_taskdone_btn), enable);
43 gtk_widget_set_sensitive(GTK_WIDGET(w_taskcancel_btn), enable);
45 buf = gtk_text_view_get_buffer(w_note);
47 gtk_text_buffer_set_text(buf, "", 0);
48 gtk_widget_set_sensitive(GTK_WIDGET(w_note), enable);
51 gtk_entry_set_text(w_description, "");
52 gtk_widget_set_sensitive(GTK_WIDGET(w_description), enable);
55 gtk_entry_set_text(w_project, "");
56 gtk_widget_set_sensitive(GTK_WIDGET(w_project), enable);
59 gtk_combo_box_set_active(w_priority, 0);
60 gtk_widget_set_sensitive(GTK_WIDGET(w_priority), enable);
63 static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
68 GtkTextIter sIter, eIter;
76 log_fct(__func__, "%d", task->id);
78 buf = gtk_text_view_get_buffer(w_note);
80 gtk_text_buffer_get_iter_at_offset(buf, &sIter, 0);
81 gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
82 txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
84 log_debug("note=%s", txt);
86 if (!task->note || strcmp(txt, task->note))
87 note_put(task->uuid, txt);
89 ctxt = gtk_entry_get_text(w_description);
90 if (!task->description || strcmp(ctxt, task->description))
91 tw_modify_description(task->uuid, ctxt);
93 ctxt = gtk_entry_get_text(w_project);
94 if (!task->project || strcmp(ctxt, task->project))
95 tw_modify_project(task->uuid, ctxt);
97 priority = gtk_combo_box_get_active(w_priority);
98 log_debug("priority: %d", priority);
114 if (strcmp(task->priority, pri))
115 tw_modify_priority(task->uuid, pri);
122 void ui_taskpanel_init(GtkBuilder *builder)
124 log_fct(__func__, "ENTER");
126 w_note = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "tasknote"));
128 w_description = GTK_ENTRY(gtk_builder_get_object(builder,
130 w_project = GTK_ENTRY(gtk_builder_get_object(builder, "taskproject"));
131 w_priority = GTK_COMBO_BOX(gtk_builder_get_object(builder,
134 w_tasksave_btn = GTK_BUTTON(gtk_builder_get_object(builder,
136 g_signal_connect(w_tasksave_btn,
138 (GCallback)tasksave_clicked_cbk,
141 w_taskdone_btn = GTK_BUTTON(gtk_builder_get_object(builder,
143 w_taskcancel_btn = GTK_BUTTON(gtk_builder_get_object(builder,
148 log_fct(__func__, "EXIT");
151 static int priority_to_int(const char *str)
165 void ui_taskpanel_update(struct task *task)
173 buf = gtk_text_view_get_buffer(w_note);
175 gtk_text_buffer_set_text(buf,
179 gtk_text_buffer_set_text(buf, "", 0);
181 gtk_entry_set_text(w_description, task->description);
184 gtk_entry_set_text(w_project, task->project);
186 gtk_entry_set_text(w_project, "");
188 priority = priority_to_int(task->priority);
189 gtk_combo_box_set_active(w_priority, priority);