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
29 #include <glib/gi18n.h>
38 #include <ui_projecttree.h>
39 #include <ui_taskpanel.h>
40 #include <ui_tasktree.h>
42 static const char *program_name;
43 static struct task **tasks;
45 static struct option long_options[] = {
46 {"version", no_argument, 0, 'v'},
47 {"help", no_argument, 0, 'h'},
48 {"force-unsupported-taskwarrior", no_argument, 0, 'f'},
49 {"debug", required_argument, 0, 'd'},
53 static void print_version()
55 printf("ptask %s\n", VERSION);
56 printf(_("Copyright (C) %s jeanfi@gmail.com\n"
57 "License GPLv2: GNU GPL version 2 or later "
58 "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
59 "This is free software: you are free to change and "
61 "There is NO WARRANTY, to the extent permitted by law.\n"),
65 static void print_help()
67 printf(_("Usage: %s [OPTION]...\n"), program_name);
69 puts(_("ptask is a task management user interface based"
74 puts(_(" -h, --help display this help and exit\n"
75 " -v, --version display version information and exit"));
78 puts(_(" -f, --force-unsupported-taskwarrior force usage of an"
79 " unsupported version of taskwarrior"));
80 puts(_(" -d, --debug=LEVEL "
81 "set the debug level, integer between 0 and 3"));
85 printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
87 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
93 const char *current_uuid;
94 struct task **old_tasks;
97 ui_taskpanel_update(NULL);
101 current_uuid = ui_tasktree_get_task_uuid();
102 ui_tasktree_update(NULL);
108 tasks = tw_get_all_tasks(ui_get_status_filter());
111 ui_projecttree_update(tasks);
112 ui_tasktree_update(tasks);
114 ui_tasktree_set_selected_task(current_uuid);
116 dialog = gtk_message_dialog_new(NULL,
117 GTK_DIALOG_DESTROY_WITH_PARENT,
120 _("Error loading tasks, verify "
121 "that a supported version of "
122 "taskwarrior is installed."));
123 gtk_dialog_run(GTK_DIALOG(dialog));
124 gtk_widget_destroy(dialog);
128 tw_task_list_free(old_tasks);
133 static void log_init()
135 char *home, *path, *dir;
137 home = getenv("HOME");
142 dir = malloc(strlen(home)+1+strlen(".ptask")+1);
143 sprintf(dir, "%s/%s", home, ".ptask");
146 path = malloc(strlen(dir)+1+strlen("log")+1);
147 sprintf(path, "%s/%s", dir, "log");
155 int main(int argc, char **argv)
159 int optc, cmdok, opti, ret;
162 GtkMessageDialog *diag;
164 program_name = argv[0];
166 setlocale(LC_ALL, "");
169 bindtextdomain(PACKAGE, LOCALEDIR);
174 while ((optc = getopt_long(argc, argv, "vhfd:", long_options,
184 log_level = atoi(optarg);
185 log_info(_("Enables debug mode."));
188 log_info(_("Force usage of an unsupported version of "
190 tw_enable_check_version(0);
198 if (!cmdok || optind != argc) {
199 fprintf(stderr, _("Try `%s --help' for more information.\n"),
206 gtk_init(NULL, NULL);
210 builder = gtk_builder_new();
212 ret = gtk_builder_add_from_file
214 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
218 msg = g_strdup_printf(_("Failed to load UI: %s"),
222 diag = GTK_MESSAGE_DIALOG(gtk_message_dialog_new
224 GTK_DIALOG_DESTROY_WITH_PARENT,
230 gtk_dialog_run(GTK_DIALOG(diag));
237 window = create_window(builder);
239 gtk_builder_connect_signals(builder, NULL);
241 g_object_unref(G_OBJECT(builder));
245 gtk_widget_show_all(GTK_WIDGET(window));