/*
- * 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 <json/json.h>
+#include <glib/gi18n.h>
#include <gtk/gtk.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'},
+ {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 UI based on taskwarrior."));
+
+ puts("");
+ puts(_("Options:"));
+ puts(_(" -h, --help display this help and exit\n"
+ " -v, --version display version information and exit"));
+
+ 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;
static void refresh()
{
+ GtkWidget *dialog;
GtkTreeModel *model;
struct task **tasks_cur;
struct task *task;
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");
}
return FALSE;
}
+static gboolean delete_event_cbk(GtkWidget *w, GdkEvent *evt, gpointer data)
+{
+ gtk_widget_destroy(w);
+ gtk_main_quit();
+
+ return FALSE;
+}
+
+
int newtask_clicked_cbk(GtkButton *btn, gpointer data)
{
gint result;
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, "vh", long_options,
+ &opti)) != -1) {
+ switch (optc) {
+ case 'h':
+ print_help();
+ exit(EXIT_SUCCESS);
+ case 'v':
+ print_version();
+ exit(EXIT_SUCCESS);
+ default:
+ cmdok = 0;
+ break;
+ }
+ }
+
+ if (!cmdok || optind != argc) {
+ fprintf(stderr, _("Try `%s --help' for more information.\n"),
+ program_name);
+ exit(EXIT_FAILURE);
+ }
gtk_init(NULL, NULL);
builder = gtk_builder_new();
NULL);
window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
+ g_signal_connect(window, "delete_event",
+ G_CALLBACK(delete_event_cbk), NULL);
+
w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview));
gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model),