2 * Copyright (C) 2010-2012 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
23 #include <json/json.h>
33 static char *task_exec(char *opts)
37 char *str, *tmp, *cmd, buf[1024];
41 cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
42 strcpy(cmd, "task rc.json.array=on ");
54 while ((s = fread(buf, 1, 1024, f))) {
55 tmp = malloc(strlen(str) + s + 1);
56 memcpy(tmp, str, strlen(str));
57 memcpy(tmp + strlen(str), buf, s);
58 tmp[strlen(str) + s] = '\0';
66 printf("pclose fails\n");
76 static struct json_object *task_exec_json(char *opts)
78 struct json_object *o;
81 str = task_exec(opts);
84 o = json_tokener_parse(str);
92 static struct task **get_all_tasks()
95 struct json_object *jtasks, *jtask, *json;
98 jtasks = task_exec_json("export");
103 n = json_object_array_length(jtasks);
105 tasks = malloc((n + 1) * sizeof(struct task *));
107 for (i = 0; i < n; i++) {
108 jtask = json_object_array_get_idx(jtasks, i);
110 tasks[i] = malloc(sizeof(struct task));
112 json = json_object_object_get(jtask, "id");
113 tasks[i]->id = json_object_get_int(json);
115 json = json_object_object_get(jtask, "description");
116 tasks[i]->description = strdup(json_object_get_string(json));
118 json = json_object_object_get(jtask, "status");
119 tasks[i]->status = strdup(json_object_get_string(json));
124 json_object_put(jtasks);
129 int main(int argc, char **argv)
137 struct task **tasks, **tasks_cur;
139 gtk_init(NULL, NULL);
140 builder = gtk_builder_new();
141 gtk_builder_add_from_file
143 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "gtask.glade",
145 window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
146 printf("%p\n", window);
148 treeview = GTK_WIDGET(gtk_builder_get_object(builder, "treeview"));
150 model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
152 tasks = get_all_tasks();
154 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
155 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
156 gtk_list_store_set(GTK_LIST_STORE(model),
159 1, (*tasks_cur)->description,
163 g_object_unref(G_OBJECT(builder));
165 gtk_widget_show_all(window);