c8e30ae1e867daa4854aab5569ca60eb67f21d04
[ptask.git] / src / ui_projecttree.c
1 /*
2  * Copyright (C) 2012-2013 jeanfi@gmail.com
3  *
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.
8  *
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.
13  *
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
17  * 02110-1301 USA
18  */
19 #include <stdio.h>
20 #include <string.h>
21
22 #include <log.h>
23 #include <ui_projecttree.h>
24
25 enum {
26         COL_NAME,
27         COL_COUNT
28 };
29
30 static GtkTreeView *w_treeview;
31
32 void ui_projecttree_init(GtkBuilder *builder)
33 {
34         w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder,
35                                                           "projecttree"));
36 }
37
38 const char *ui_projecttree_get_project()
39 {
40         GtkTreePath *path;
41         GtkTreeViewColumn *cols;
42         GtkTreeIter iter;
43         GtkTreeModel *model;
44         GValue value = {0,};
45         const char *prj;
46
47         log_fct_enter();
48
49         gtk_tree_view_get_cursor(w_treeview, &path, &cols);
50
51         if (path) {
52                 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
53                 gtk_tree_model_get_iter(model, &iter, path);
54                 gtk_tree_model_get_value(model, &iter, COL_NAME, &value);
55
56                 prj = g_value_get_string(&value);
57         } else {
58                 prj = NULL;
59         }
60
61         log_fct_exit();
62
63         return prj;
64 }
65
66
67 void ui_projecttree_update(struct task **ts)
68 {
69         struct project **prjs, **cur;
70         GtkTreeModel *model;
71         GtkTreeIter iter;
72
73         log_fct_enter();
74
75         model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
76         gtk_list_store_clear(GTK_LIST_STORE(model));
77
78         prjs = tw_get_projects(ts);
79         for (cur = prjs; *cur; cur++) {
80                 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
81
82                 gtk_list_store_set(GTK_LIST_STORE(model),
83                                    &iter,
84                                    COL_NAME, (*cur)->name,
85                                    COL_COUNT, (*cur)->count,
86                                    -1);
87         }
88
89         tw_project_list_free(prjs);
90
91         log_fct_exit();
92 }
93