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
24 #include <ui_projecttree.h>
25 #include <ui_tasktree.h>
27 static GtkTreeView *w_treeview;
28 static struct task **current_tasks;
38 static int priority_to_int(const char *str)
52 static gint priority_cmp(GtkTreeModel *model,
57 GValue v1 = {0,}, v2 = {0,};
58 const char *str1, *str2;
61 gtk_tree_model_get_value(model, a, COL_PRIORITY, &v1);
62 str1 = g_value_get_string(&v1);
63 i1 = priority_to_int(str1);
65 gtk_tree_model_get_value(model, b, COL_PRIORITY, &v2);
66 str2 = g_value_get_string(&v2);
67 i2 = priority_to_int(str2);
77 void ui_tasktree_init(GtkBuilder *builder)
81 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "tasktree"));
83 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
84 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model),
91 void ui_tasktree_load_settings(GSettings *settings)
94 GtkSortType sort_order;
97 sort_col_id = g_settings_get_int(settings, "tasks-sort-col");
98 sort_order = g_settings_get_int(settings, "tasks-sort-order");
99 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
100 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model),
101 sort_col_id, sort_order);
104 void ui_tasktree_save_settings(GSettings *settings)
108 GtkSortType sort_order;
110 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
111 gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(model),
114 log_debug("ui_tasktree_save_settings(): sort_col_id=%d", sort_col_id);
115 log_debug("ui_tasktree_save_settings(): sort_col_order=%d", sort_order);
117 g_settings_set_int(settings, "tasks-sort-col", sort_col_id);
118 g_settings_set_int(settings, "tasks-sort-order", sort_order);
122 struct task *ui_tasktree_get_selected_task()
125 GtkTreeViewColumn *cols;
126 struct task **tasks_cur, *result;
137 gtk_tree_view_get_cursor(w_treeview, &path, &cols);
140 model = gtk_tree_view_get_model(w_treeview);
141 gtk_tree_model_get_iter(model, &iter, path);
142 gtk_tree_model_get_value(model,
147 uuid = g_value_get_string(&value);
149 for (tasks_cur = current_tasks; *tasks_cur; tasks_cur++)
150 if (!strcmp((*tasks_cur)->uuid, uuid))
153 gtk_tree_path_free(path);
162 void ui_tasktree_update(struct task **tasks, const char *prj_filter)
165 struct task **tasks_cur;
170 current_tasks = tasks;
172 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
173 gtk_list_store_clear(GTK_LIST_STORE(model));
176 for (tasks_cur = current_tasks; *tasks_cur; tasks_cur++) {
184 if (prj_filter && strcmp(prj, prj_filter))
187 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
190 gtk_list_store_set(GTK_LIST_STORE(model),
192 COL_ID, (*tasks_cur)->id,
194 (*tasks_cur)->description,
196 COL_UUID, (*tasks_cur)->uuid,
197 COL_PRIORITY, (*tasks_cur)->priority,
204 void ui_tasktree_update_filter(const char *prj_filter)
206 ui_tasktree_update(current_tasks, prj_filter);