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_tasktree.h>
26 static GtkTreeView *w_treeview;
27 static struct task **current_tasks;
37 static int priority_to_int(const char *str)
51 static gint priority_cmp(GtkTreeModel *model,
56 GValue v1 = {0,}, v2 = {0,};
57 const char *str1, *str2;
60 gtk_tree_model_get_value(model, a, COL_PRIORITY, &v1);
61 str1 = g_value_get_string(&v1);
62 i1 = priority_to_int(str1);
64 gtk_tree_model_get_value(model, b, COL_PRIORITY, &v2);
65 str2 = g_value_get_string(&v2);
66 i2 = priority_to_int(str2);
76 void ui_tasktree_init(GtkBuilder *builder)
80 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "tasktree"));
82 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
83 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model),
90 void ui_tasktree_load_settings(GSettings *settings)
93 GtkSortType sort_order;
96 sort_col_id = g_settings_get_int(settings, "tasks-sort-col");
97 sort_order = g_settings_get_int(settings, "tasks-sort-order");
98 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
99 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model),
100 sort_col_id, sort_order);
103 void ui_tasktree_save_settings(GSettings *settings)
107 GtkSortType sort_order;
109 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
110 gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(model),
113 log_debug("ui_tasktree_save_settings(): sort_col_id=%d", sort_col_id);
114 log_debug("ui_tasktree_save_settings(): sort_col_order=%d", sort_order);
116 g_settings_set_int(settings, "tasks-sort-col", sort_col_id);
117 g_settings_set_int(settings, "tasks-sort-order", sort_order);
121 struct task *ui_tasktree_get_selected_task()
124 GtkTreeViewColumn *cols;
125 struct task **tasks_cur, *result;
136 gtk_tree_view_get_cursor(w_treeview, &path, &cols);
139 model = gtk_tree_view_get_model(w_treeview);
140 gtk_tree_model_get_iter(model, &iter, path);
141 gtk_tree_model_get_value(model,
146 uuid = g_value_get_string(&value);
148 for (tasks_cur = current_tasks; *tasks_cur; tasks_cur++)
149 if (!strcmp((*tasks_cur)->uuid, uuid))
152 gtk_tree_path_free(path);
161 void ui_tasktree_update(struct task **tasks)
163 current_tasks = tasks;