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
25 #include <json/json.h>
27 #include <glib/gi18n.h>
35 #include <ui_projecttree.h>
36 #include <ui_taskpanel.h>
37 #include <ui_tasktree.h>
39 static const char *program_name;
40 static struct task **tasks;
41 static GtkTreeView *w_treeview;
42 static GtkComboBox *w_status;
43 static GSettings *settings;
53 static struct option long_options[] = {
54 {"version", no_argument, 0, 'v'},
55 {"help", no_argument, 0, 'h'},
56 {"debug", required_argument, 0, 'd'},
60 static void print_version()
62 printf("ptask %s\n", VERSION);
63 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
64 "License GPLv2: GNU GPL version 2 or later "
65 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
66 "This is free software: you are free to change and "
68 "There is NO WARRANTY, to the extent permitted by law.\n"),
72 static void print_help()
74 printf(_("Usage: %s [OPTION]...\n"), program_name);
76 puts(_("ptask is a task management user interface based"
81 puts(_(" -h, --help display this help and exit\n"
82 " -v, --version display version information and exit"));
86 puts(_(" -d, --debug=LEVEL "
87 "set the debug level, integer between 0 and 3"));
91 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
93 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
96 static struct task *get_selected_task(GtkTreeView *treeview)
99 GtkTreeViewColumn *cols;
100 struct task **tasks_cur;
106 log_debug("get_selected_task");
108 gtk_tree_view_get_cursor(treeview, &path, &cols);
111 model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
112 gtk_tree_model_get_iter(model, &iter, path);
113 gtk_tree_model_get_value(model, &iter, COL_UUID, &value);
115 uuid = g_value_get_string(&value);
117 for (tasks_cur = tasks; *tasks_cur; tasks_cur++)
118 if (!strcmp((*tasks_cur)->uuid, uuid))
121 gtk_tree_path_free(path);
131 struct task **tasks_cur;
139 ui_taskpanel_update(NULL);
141 status = gtk_combo_box_get_active(w_status);
142 log_debug("status: %d", status);
145 tw_task_list_free(tasks);
149 tasks = tw_get_all_tasks("pending");
152 tasks = tw_get_all_tasks("completed");
155 tasks = tw_get_all_tasks("pending");
158 model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
159 gtk_list_store_clear(GTK_LIST_STORE(model));
162 for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
165 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
168 project = task->project;
172 gtk_list_store_set(GTK_LIST_STORE(model),
174 COL_ID, (*tasks_cur)->id,
176 (*tasks_cur)->description,
177 COL_PROJECT, project,
178 COL_UUID, (*tasks_cur)->uuid,
179 COL_PRIORITY, (*tasks_cur)->priority,
182 ui_projecttree_update(tasks);
184 dialog = gtk_message_dialog_new(NULL,
185 GTK_DIALOG_DESTROY_WITH_PARENT,
188 _("Error loading tasks, verify "
189 "that a supported version of "
190 "taskwarrior is installed "));
191 gtk_dialog_run(GTK_DIALOG(dialog));
192 gtk_widget_destroy(dialog);
194 log_fct(__func__, "EXIT");
197 int taskdone_clicked_cbk(GtkButton *btn, gpointer data)
201 task = get_selected_task(GTK_TREE_VIEW(w_treeview));
208 int refresh_clicked_cbk(GtkButton *btn, gpointer data)
210 log_debug("refresh_clicked_cbk");
216 static int status_changed_cbk(GtkComboBox *w, gpointer data)
218 log_debug("status_changed_cbk");
224 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
228 ui_taskpanel_update(get_selected_task(treeview));
235 static void log_init()
237 char *home, *path, *dir;
239 home = getenv("HOME");
244 dir = malloc(strlen(home)+1+strlen(".ptask")+1);
245 sprintf(dir, "%s/%s", home, ".ptask");
248 path = malloc(strlen(dir)+1+strlen("log")+1);
249 sprintf(path, "%s/%s", dir, "log");
257 int main(int argc, char **argv)
261 int optc, cmdok, opti;
263 program_name = argv[0];
265 setlocale(LC_ALL, "");
268 bindtextdomain(PACKAGE, LOCALEDIR);
273 while ((optc = getopt_long(argc, argv, "vhd:", long_options,
283 log_level = atoi(optarg);
284 log_info(_("Enables debug mode."));
292 if (!cmdok || optind != argc) {
293 fprintf(stderr, _("Try `%s --help' for more information.\n"),
300 gtk_init(NULL, NULL);
302 settings = g_settings_new("ptask");
304 builder = gtk_builder_new();
305 gtk_builder_add_from_file
307 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
309 window = create_window(builder, settings);
311 ui_taskpanel_init(builder);
312 ui_tasktree_init(builder);
313 ui_projecttree_init(builder);
315 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "tasktree"));
317 w_status = GTK_COMBO_BOX(gtk_builder_get_object(builder, "status"));
319 gtk_builder_connect_signals(builder, NULL);
321 g_signal_connect(w_treeview,
322 "cursor-changed", (GCallback)cursor_changed_cbk,
324 g_signal_connect(w_status,
325 "changed", (GCallback)status_changed_cbk,
328 g_object_unref(G_OBJECT(builder));
332 gtk_widget_show_all(GTK_WIDGET(window));