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>
32 static GtkTreeView *w_treeview;
34 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
40 prj = ui_projecttree_get_project();
42 ui_tasktree_update_filter(prj);
49 void ui_projecttree_init(GtkBuilder *builder)
51 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder,
53 g_signal_connect(w_treeview,
54 "cursor-changed", (GCallback)cursor_changed_cbk,
58 const char *ui_projecttree_get_project()
61 GtkTreeViewColumn *cols;
69 gtk_tree_view_get_cursor(w_treeview, &path, &cols);
72 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
73 gtk_tree_model_get_iter(model, &iter, path);
74 gtk_tree_model_get_value(model, &iter, COL_NAME, &value);
76 prj = g_value_get_string(&value);
78 if (!strcmp(prj, "ALL"))
90 void ui_projecttree_update(struct task **ts)
92 struct project **prjs, **cur;
96 const char *current_prj;
100 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
102 current_prj = ui_projecttree_get_project();
104 gtk_list_store_clear(GTK_LIST_STORE(model));
106 prjs = tw_get_projects(ts);
107 for (cur = prjs; *cur; cur++) {
108 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
110 gtk_list_store_set(GTK_LIST_STORE(model),
112 COL_NAME, (*cur)->name,
113 COL_COUNT, (*cur)->count,
117 if (!strcmp((*cur)->name, current_prj)) {
118 p = gtk_tree_model_get_path(model, &iter);
120 gtk_tree_view_set_cursor(w_treeview,
129 tw_project_list_free(prjs);