/*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2012-2013 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <getopt.h>
+#include <sys/stat.h>
#include <json/json.h>
+#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <config.h>
+
+#include "log.h"
#include "note.h"
#include "tw.h"
+static const char *program_name;
static struct task **tasks;
static GtkTextView *w_note;
static GtkEntry *w_description;
COL_PRIORITY
};
+static struct option long_options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {"debug", required_argument, 0, 'd'},
+ {0, 0, 0, 0}
+};
+
+static void print_version()
+{
+ printf("ptask %s\n", VERSION);
+ printf(_("Copyright (C) %s jeanfi@gmail.com\n"
+ "License GPLv2: GNU GPL version 2 or later "
+ "<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"
+ "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");
+}
+
+static void print_help()
+{
+ printf(_("Usage: %s [OPTION]...\n"), program_name);
+
+ puts(_("ptask is a task management user interface based on taskwarrior."));
+
+ puts("");
+ puts(_("Options:"));
+ puts(_(" -h, --help display this help and exit\n"
+ " -v, --version display version information and exit"));
+
+ puts("");
+
+ puts(_(" -d, --debug=LEVEL "
+ "set the debug level, integer between 0 and 3"));
+
+ puts("");
+
+ printf(_("Report bugs to: %s\n"), PACKAGE_BUGREPORT);
+ puts("");
+ printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
+}
+
static struct task *get_selected_task(GtkTreeView *treeview)
{
GtkTreePath *path;
GValue value = {0,};
const char *uuid;
- printf("get_selected_task\n");
+ log_debug("get_selected_task");
gtk_tree_view_get_cursor(treeview, &path, &cols);
static void refresh()
{
+ GtkWidget *dialog;
GtkTreeModel *model;
struct task **tasks_cur;
struct task *task;
int status;
const char *project;
- printf("refresh\n");
+ log_debug("refresh");
clear_task_panel();
status = gtk_combo_box_get_active(w_status);
- printf("status: %d\n", status);
+ log_debug("status: %d", status);
if (tasks)
tw_task_list_free(tasks);
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");
+ log_debug("refresh done");
}
int taskdone_clicked_cbk(GtkButton *btn, gpointer data)
task = get_selected_task(GTK_TREE_VIEW(w_treeview));
- printf("tasksave_clicked_cbk %d\n", task->id);
+ log_debug("tasksave_clicked_cbk %d", task->id);
buf = gtk_text_view_get_buffer(w_note);
gtk_text_buffer_get_iter_at_offset(buf, &eIter, -1);
txt = gtk_text_buffer_get_text(buf, &sIter, &eIter, TRUE);
- printf("note=%s\n", txt);
+ log_debug("note=%s", txt);
if (!task->note || strcmp(txt, task->note))
note_put(task->uuid, txt);
tw_modify_project(task->uuid, ctxt);
priority = gtk_combo_box_get_active(w_priority);
- printf("priority: %d\n", priority);
+ log_debug("priority: %d", priority);
switch (priority) {
case 3:
int refresh_clicked_cbk(GtkButton *btn, gpointer data)
{
- printf("refresh_clicked_cbk\n");
+ log_debug("refresh_clicked_cbk");
refresh();
return FALSE;
GtkEntry *entry;
const char *ctxt;
- printf("newtask_clicked_cbk\n");
+ log_debug("newtask_clicked_cbk");
builder = gtk_builder_new();
gtk_builder_add_from_file
result = gtk_dialog_run(diag);
if (result == GTK_RESPONSE_ACCEPT) {
- printf("ok\n");
+ log_debug("ok");
entry = GTK_ENTRY(gtk_builder_get_object
(builder, "diag_tasknew_description"));
ctxt = gtk_entry_get_text(entry);
- printf("%s\n", ctxt);
+ log_debug("%s", ctxt);
tw_add(ctxt);
refresh();
} else {
- printf("cancel\n");
+ log_debug("cancel");
}
g_object_unref(G_OBJECT(builder));
static int status_changed_cbk(GtkComboBox *w, gpointer data)
{
- printf("status_changed_cbk\n");
+ log_debug("status_changed_cbk");
refresh();
return FALSE;
GtkTextBuffer *buf;
int priority;
- printf("cursor_changed_cbk\n");
+ log_debug("cursor_changed_cbk");
task = get_selected_task(treeview);
priority = priority_to_int(task->priority);
gtk_combo_box_set_active(w_priority, priority);
} else {
- printf("clear task widgets\n");
+ log_debug("clear task widgets");
clear_task_panel();
- printf("clear task widgets done\n");
+ log_debug("clear task widgets done");
}
return FALSE;
return 0;
}
+static void log_init()
+{
+ char *home, *path, *dir;
+
+ home = getenv("HOME");
+
+ if (!home)
+ return ;
+
+ dir = malloc(strlen(home)+1+strlen(".ptask")+1);
+ sprintf(dir, "%s/%s", home, ".ptask");
+ mkdir(dir, 0777);
+
+ path = malloc(strlen(dir)+1+strlen("log")+1);
+ sprintf(path, "%s/%s", dir, "log");
+
+ log_open(path);
+
+ free(dir);
+ free(path);
+}
+
int main(int argc, char **argv)
{
- GtkWidget *window;
- GtkWidget *btn;
+ GtkWidget *window, *btn;
GtkBuilder *builder;
GtkTreeModel *model;
+ int optc, cmdok, opti;
+
+ program_name = argv[0];
+
+ setlocale(LC_ALL, "");
+
+#if ENABLE_NLS
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+#endif
+
+ cmdok = 1;
+ while ((optc = getopt_long(argc, argv, "vhd:", long_options,
+ &opti)) != -1) {
+ switch (optc) {
+ case 'h':
+ print_help();
+ exit(EXIT_SUCCESS);
+ case 'v':
+ print_version();
+ exit(EXIT_SUCCESS);
+ case 'd':
+ log_level = atoi(optarg);
+ log_info(_("Enables debug mode."));
+ break;
+ default:
+ cmdok = 0;
+ break;
+ }
+ }
+
+ if (!cmdok || optind != argc) {
+ fprintf(stderr, _("Try `%s --help' for more information.\n"),
+ program_name);
+ exit(EXIT_FAILURE);
+ }
+
+ log_init();
gtk_init(NULL, NULL);
builder = gtk_builder_new();