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 GSettings *settings;
51 static struct option long_options[] = {
52 {"version", no_argument, 0, 'v'},
53 {"help", no_argument, 0, 'h'},
54 {"debug", required_argument, 0, 'd'},
58 static void print_version()
60 printf("ptask %s\n", VERSION);
61 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
62 "License GPLv2: GNU GPL version 2 or later "
63 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
64 "This is free software: you are free to change and "
66 "There is NO WARRANTY, to the extent permitted by law.\n"),
70 static void print_help()
72 printf(_("Usage: %s [OPTION]...\n"), program_name);
74 puts(_("ptask is a task management user interface based"
79 puts(_(" -h, --help display this help and exit\n"
80 " -v, --version display version information and exit"));
84 puts(_(" -d, --debug=LEVEL "
85 "set the debug level, integer between 0 and 3"));
89 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
91 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
97 const char *current_prj, *current_uuid;
98 struct task **old_tasks;
101 ui_taskpanel_update(NULL);
105 current_prj = ui_projecttree_get_project();
106 current_uuid = ui_tasktree_get_task_uuid();
107 ui_tasktree_update(NULL, NULL);
114 tasks = tw_get_all_tasks(ui_get_status_filter());
117 ui_projecttree_update(tasks);
118 ui_tasktree_update(tasks, current_prj);
120 ui_tasktree_set_selected_task(current_uuid);
122 dialog = gtk_message_dialog_new(NULL,
123 GTK_DIALOG_DESTROY_WITH_PARENT,
126 _("Error loading tasks, verify "
127 "that a supported version of "
128 "taskwarrior is installed "));
129 gtk_dialog_run(GTK_DIALOG(dialog));
130 gtk_widget_destroy(dialog);
134 tw_task_list_free(old_tasks);
139 static void log_init()
141 char *home, *path, *dir;
143 home = getenv("HOME");
148 dir = malloc(strlen(home)+1+strlen(".ptask")+1);
149 sprintf(dir, "%s/%s", home, ".ptask");
152 path = malloc(strlen(dir)+1+strlen("log")+1);
153 sprintf(path, "%s/%s", dir, "log");
161 int main(int argc, char **argv)
165 int optc, cmdok, opti;
167 program_name = argv[0];
169 setlocale(LC_ALL, "");
172 bindtextdomain(PACKAGE, LOCALEDIR);
177 while ((optc = getopt_long(argc, argv, "vhd:", long_options,
187 log_level = atoi(optarg);
188 log_info(_("Enables debug mode."));
196 if (!cmdok || optind != argc) {
197 fprintf(stderr, _("Try `%s --help' for more information.\n"),
204 gtk_init(NULL, NULL);
206 settings = g_settings_new("ptask");
208 builder = gtk_builder_new();
209 gtk_builder_add_from_file
211 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
213 window = create_window(builder, settings);
215 ui_taskpanel_init(builder);
216 ui_tasktree_init(builder);
217 ui_projecttree_init(builder);
219 gtk_builder_connect_signals(builder, NULL);
221 g_object_unref(G_OBJECT(builder));
225 gtk_widget_show_all(GTK_WIDGET(window));