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 GSettings *settings;
52 static struct option long_options[] = {
53 {"version", no_argument, 0, 'v'},
54 {"help", no_argument, 0, 'h'},
55 {"debug", required_argument, 0, 'd'},
59 static void print_version()
61 printf("ptask %s\n", VERSION);
62 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
63 "License GPLv2: GNU GPL version 2 or later "
64 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
65 "This is free software: you are free to change and "
67 "There is NO WARRANTY, to the extent permitted by law.\n"),
71 static void print_help()
73 printf(_("Usage: %s [OPTION]...\n"), program_name);
75 puts(_("ptask is a task management user interface based"
80 puts(_(" -h, --help display this help and exit\n"
81 " -v, --version display version information and exit"));
85 puts(_(" -d, --debug=LEVEL "
86 "set the debug level, integer between 0 and 3"));
90 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
92 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
98 const char *current_prj, *current_uuid;
99 struct task **old_tasks;
102 ui_taskpanel_update(NULL);
106 current_prj = ui_projecttree_get_project();
107 current_uuid = ui_tasktree_get_task_uuid();
108 ui_tasktree_update(NULL, NULL);
115 tasks = tw_get_all_tasks(ui_get_status_filter());
118 ui_projecttree_update(tasks);
119 ui_tasktree_update(tasks, current_prj);
121 ui_tasktree_set_selected_task(current_uuid);
123 dialog = gtk_message_dialog_new(NULL,
124 GTK_DIALOG_DESTROY_WITH_PARENT,
127 _("Error loading tasks, verify "
128 "that a supported version of "
129 "taskwarrior is installed "));
130 gtk_dialog_run(GTK_DIALOG(dialog));
131 gtk_widget_destroy(dialog);
135 tw_task_list_free(old_tasks);
140 static int cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
144 ui_taskpanel_update(ui_tasktree_get_selected_task());
151 static void log_init()
153 char *home, *path, *dir;
155 home = getenv("HOME");
160 dir = malloc(strlen(home)+1+strlen(".ptask")+1);
161 sprintf(dir, "%s/%s", home, ".ptask");
164 path = malloc(strlen(dir)+1+strlen("log")+1);
165 sprintf(path, "%s/%s", dir, "log");
173 int main(int argc, char **argv)
177 int optc, cmdok, opti;
179 program_name = argv[0];
181 setlocale(LC_ALL, "");
184 bindtextdomain(PACKAGE, LOCALEDIR);
189 while ((optc = getopt_long(argc, argv, "vhd:", long_options,
199 log_level = atoi(optarg);
200 log_info(_("Enables debug mode."));
208 if (!cmdok || optind != argc) {
209 fprintf(stderr, _("Try `%s --help' for more information.\n"),
216 gtk_init(NULL, NULL);
218 settings = g_settings_new("ptask");
220 builder = gtk_builder_new();
221 gtk_builder_add_from_file
223 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
225 window = create_window(builder, settings);
227 ui_taskpanel_init(builder);
228 ui_tasktree_init(builder);
229 ui_projecttree_init(builder);
231 w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "tasktree"));
233 gtk_builder_connect_signals(builder, NULL);
235 g_signal_connect(w_treeview,
236 "cursor-changed", (GCallback)cursor_changed_cbk,
239 g_object_unref(G_OBJECT(builder));
243 gtk_widget_show_all(GTK_WIDGET(window));