updated copyright
[ptask.git] / src / main.c
index e692723..95a8054 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 jeanfi@gmail.com
+ * Copyright (C) 2012-2016 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
+#include <locale.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -43,6 +45,7 @@ static struct task **tasks;
 static struct option long_options[] = {
        {"version", no_argument, 0, 'v'},
        {"help", no_argument, 0, 'h'},
+       {"force-unsupported-taskwarrior", no_argument, 0, 'f'},
        {"debug", required_argument, 0, 'd'},
        {0, 0, 0, 0}
 };
@@ -56,7 +59,7 @@ static void print_version()
                 "This is free software: you are free to change and "
                 " redistribute it.\n"
                 "There is NO WARRANTY, to the extent permitted by law.\n"),
-              "2012-2013");
+              "2012-2016");
 }
 
 static void print_help()
@@ -72,7 +75,8 @@ static void print_help()
               "  -v, --version       display version information and exit"));
 
        puts("");
-
+       puts(_("  -f, --force-unsupported-taskwarrior force usage of an"
+              " unsupported version of taskwarrior"));
        puts(_("  -d, --debug=LEVEL   "
               "set the debug level, integer between 0 and 3"));
 
@@ -86,7 +90,7 @@ static void print_help()
 void refresh()
 {
        GtkWidget *dialog;
-       const char *current_prj, *current_uuid;
+       const char *current_uuid;
        struct task **old_tasks;
 
        log_fct_enter();
@@ -94,12 +98,10 @@ void refresh()
 
        if (tasks) {
                old_tasks = tasks;
-               current_prj = ui_projecttree_get_project();
                current_uuid = ui_tasktree_get_task_uuid();
-               ui_tasktree_update(NULL, NULL);
+               ui_tasktree_update(NULL);
        } else {
                old_tasks = NULL;
-               current_prj = NULL;
                current_uuid = NULL;
        }
 
@@ -107,7 +109,7 @@ void refresh()
 
        if (tasks) {
                ui_projecttree_update(tasks);
-               ui_tasktree_update(tasks, current_prj);
+               ui_tasktree_update(tasks);
                if (current_uuid)
                        ui_tasktree_set_selected_task(current_uuid);
        } else {
@@ -117,7 +119,7 @@ void refresh()
                                                GTK_BUTTONS_CLOSE,
                                                _("Error loading tasks, verify "
                                                  "that a supported version of "
-                                                 "taskwarrior is installed "));
+                                                 "taskwarrior is installed."));
                gtk_dialog_run(GTK_DIALOG(dialog));
                gtk_widget_destroy(dialog);
        }
@@ -154,7 +156,10 @@ int main(int argc, char **argv)
 {
        GtkWindow *window;
        GtkBuilder *builder;
-       int optc, cmdok, opti;
+       int optc, cmdok, opti, ret;
+       GError *err;
+       gchar *msg;
+       GtkMessageDialog *diag;
 
        program_name = argv[0];
 
@@ -166,7 +171,7 @@ int main(int argc, char **argv)
 #endif
 
        cmdok = 1;
-       while ((optc = getopt_long(argc, argv, "vhd:", long_options,
+       while ((optc = getopt_long(argc, argv, "vhfd:", long_options,
                                   &opti)) != -1) {
                switch (optc) {
                case 'h':
@@ -179,6 +184,11 @@ int main(int argc, char **argv)
                        log_level = atoi(optarg);
                        log_info(_("Enables debug mode."));
                        break;
+               case 'f':
+                       log_info(_("Force usage of an unsupported version of "
+                                  "taskwarrior."));
+                       tw_enable_check_version(0);
+                       break;
                default:
                        cmdok = 0;
                        break;
@@ -198,10 +208,32 @@ int main(int argc, char **argv)
        settings_init();
 
        builder = gtk_builder_new();
-       gtk_builder_add_from_file
+       err = NULL;
+       ret = gtk_builder_add_from_file
                (builder,
                 PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "ptask.glade",
-                NULL);
+                &err);
+
+       if (!ret) {
+               msg = g_strdup_printf(_("Failed to load UI: %s"),
+                                     err->message);
+               log_err(msg);
+
+               diag = GTK_MESSAGE_DIALOG(gtk_message_dialog_new
+                                         (NULL,
+                                          GTK_DIALOG_DESTROY_WITH_PARENT,
+                                          GTK_MESSAGE_ERROR,
+                                          GTK_BUTTONS_CLOSE,
+                                          msg,
+                                          NULL));
+
+               gtk_dialog_run(GTK_DIALOG(diag));
+
+               g_free(msg);
+
+               exit(EXIT_FAILURE);
+       }
+
        window = create_window(builder);
 
        gtk_builder_connect_signals(builder, NULL);