popup error dialog when .taskrc does not exist
authorJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 16 Oct 2013 11:24:04 +0000 (11:24 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 16 Oct 2013 11:24:04 +0000 (11:24 +0000)
NEWS
src/main.c
src/tw.c

diff --git a/NEWS b/NEWS
index fede8c0..54322af 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ v0.0.4
  * fixed i18n support.
  * added --version and --help options.
  * added manpage.
+ * popup error dialog when .taskrc does not exist.
 
 v0.0.3
 ------
index 6f1b7fb..ad3f2af 100644 (file)
@@ -138,6 +138,7 @@ static void clear_task_panel()
 
 static void refresh()
 {
+       GtkWidget *dialog;
        GtkTreeModel *model;
        struct task **tasks_cur;
        struct task *task;
@@ -168,24 +169,41 @@ static void refresh()
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
        gtk_list_store_clear(GTK_LIST_STORE(model));
-       for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
-               task = (*tasks_cur);
 
-               gtk_list_store_append(GTK_LIST_STORE(model), &iter);
-
-               if (task->project)
-                       project = task->project;
-               else
-                       project = "";
-
-               gtk_list_store_set(GTK_LIST_STORE(model),
-                                  &iter,
-                                  COL_ID, (*tasks_cur)->id,
-                                  COL_DESCRIPTION, (*tasks_cur)->description,
-                                  COL_PROJECT, project,
-                                  COL_UUID, (*tasks_cur)->uuid,
-                                  COL_PRIORITY, (*tasks_cur)->priority,
-                                  -1);
+       if (tasks) {
+               for (tasks_cur = tasks, i = 0; *tasks_cur; tasks_cur++, i++) {
+                       task = (*tasks_cur);
+
+                       gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+
+                       if (task->project)
+                               project = task->project;
+                       else
+                               project = "";
+
+                       gtk_list_store_set(GTK_LIST_STORE(model),
+                                          &iter,
+                                          COL_ID, (*tasks_cur)->id,
+                                          COL_DESCRIPTION, 
+                                          (*tasks_cur)->description,
+                                          COL_PROJECT, project,
+                                          COL_UUID, (*tasks_cur)->uuid,
+                                          COL_PRIORITY, (*tasks_cur)->priority,
+                                          -1);
+               }
+       }
+       else {
+               dialog = gtk_message_dialog_new(NULL,
+                                               GTK_DIALOG_DESTROY_WITH_PARENT,
+                                               GTK_MESSAGE_ERROR,
+                                               GTK_BUTTONS_CLOSE,
+                                               _("Error loading tasks, verify "
+                                                 "that taskwarrior is "
+                                                 "correctly installed, and its"
+                                                 " configuration file exist."
+                                                 ));
+               gtk_dialog_run(GTK_DIALOG (dialog));
+               gtk_widget_destroy(dialog);
        }
        printf("refresh done\n");
 }
index 890449f..5a6e4c9 100644 (file)
--- a/src/tw.c
+++ b/src/tw.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include <json/json.h>
 
 #include "note.h"
 #include "tw.h"
 
+static int has_taskrc()
+{
+       char *home, *path;
+       int ret;
+       struct stat st;
+
+       home = getenv("HOME");
+
+       if (!home) {
+               fprintf(stderr, "HOME environment variable not defined\n");
+               return 0;
+       }
+
+       path = malloc(strlen(home) + 1 + strlen(".taskrc") + 1);
+       sprintf(path, "%s/%s", home, ".taskrc");
+
+       ret = lstat(path, &st);
+
+       free(path);
+
+       return ret == 0;
+
+}
+
 static char *task_exec(char *opts)
 {
        FILE *f;
@@ -33,6 +58,9 @@ static char *task_exec(char *opts)
        size_t s;
        char *str, *tmp, *cmd, buf[1024];
 
+       if (!has_taskrc())
+               return NULL;
+
        cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
        strcpy(cmd, "task rc.json.array=on ");
        strcat(cmd, opts);