bin_PROGRAMS = gtask
-gtask_SOURCES = main.c
+gtask_SOURCES = main.c \
+ tw.c tw.h
#dist_man_MANS = gtask.1
CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
-am_gtask_OBJECTS = main.$(OBJEXT)
+am_gtask_OBJECTS = main.$(OBJEXT) tw.$(OBJEXT)
gtask_OBJECTS = $(am_gtask_OBJECTS)
gtask_LDADD = $(LDADD)
DEFAULT_INCLUDES = -I.@am__isrc@
SUBDIRS = glade
AM_LDFLAGS = -Wl,--as-needed
AM_CPPFLAGS = -Wall -Werror $(GTK_CFLAGS) $(JSON_CFLAGS)
-gtask_SOURCES = main.c
+gtask_SOURCES = main.c \
+ tw.c tw.h
+
all: all-recursive
.SUFFIXES:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tw.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
#include <gtk/gtk.h>
-struct task {
- int id;
- char *description;
- char *status;
- char *uuid;
- char *note;
- char *project;
-};
+#include "tw.h"
static struct task **tasks;
static GtkTextView *w_note;
static GtkEntry *w_description;
static GtkTreeView *w_treeview;
-static char *task_exec(char *opts)
-{
- FILE *f;
- int ret, s;
- char *str, *tmp, *cmd, buf[1024];
-
- str = NULL;
-
- cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
- strcpy(cmd, "task rc.json.array=on ");
- strcat(cmd, opts);
-
- printf("execute: %s\n", cmd);
-
- f = popen(cmd, "r");
-
- if (!f) {
- perror("popen");
- goto exit_free;
- }
-
- str = malloc(1);
- str[0] = '\0';
- while ((s = fread(buf, 1, 1024, f))) {
- tmp = malloc(strlen(str) + s + 1);
- memcpy(tmp, str, strlen(str));
- memcpy(tmp + strlen(str), buf, s);
- tmp[strlen(str) + s] = '\0';
- free(str);
- str = tmp;
- }
-
- ret = pclose(f);
-
- if (ret == -1) {
- printf("pclose fails\n");
- perror("pclose");
- }
-
- exit_free:
- free(cmd);
-
- return str;
-}
-
-static struct json_object *task_exec_json(char *opts)
-{
- struct json_object *o;
- char *str;
-
- str = task_exec(opts);
-
- if (str) {
- o = json_tokener_parse(str);
- free(str);
- return o;
- }
-
- return NULL;
-}
-
-static struct task **get_all_tasks()
-{
- int i, n;
- struct json_object *jtasks, *jtask, *json;
- struct task **tasks;
-
- jtasks = task_exec_json("export");
-
- if (!jtasks)
- return NULL;
-
- n = json_object_array_length(jtasks);
-
- tasks = malloc((n + 1) * sizeof(struct task *));
-
- for (i = 0; i < n; i++) {
- jtask = json_object_array_get_idx(jtasks, i);
-
- tasks[i] = malloc(sizeof(struct task));
-
- json = json_object_object_get(jtask, "id");
- tasks[i]->id = json_object_get_int(json);
-
- json = json_object_object_get(jtask, "description");
- tasks[i]->description = strdup(json_object_get_string(json));
-
- json = json_object_object_get(jtask, "status");
- tasks[i]->status = strdup(json_object_get_string(json));
-
- json = json_object_object_get(jtask, "project");
- if (json)
- tasks[i]->project
- = strdup(json_object_get_string(json));
- else
- tasks[i]->project = NULL;
-
- json = json_object_object_get(jtask, "uuid");
- tasks[i]->uuid = strdup(json_object_get_string(json));
-
- tasks[i]->note = NULL;
- }
-
- tasks[n] = NULL;
-
- json_object_put(jtasks);
-
- return tasks;
-}
-
static struct task *get_selected_task(GtkTreeView *treeview)
{
GtkTreePath *path;
return NULL;
}
-static char *escape(const char *txt)
-{
- char *result;
- char *c;
-
- result = malloc(2*strlen(txt)+1);
- c = result;
-
- while(*txt) {
- switch(*txt) {
- case '"':
- *c = '\\'; c++;
- *c = '"';
- break;
- case '$':
- *c = '\\'; c++;
- *c = '$';
- break;
- case '&':
- *c = '\\'; c++;
- *c = '&';
- break;
- default:
- *c = *txt;
- }
- c++;
- txt++;
- }
-
- *c = '\0';
-
- return result;
-}
-
static int tasksave_clicked_cbk(GtkButton *btn, gpointer data)
{
struct task *task;
--- /dev/null
+/*
+ * Copyright (C) 2010-2012 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
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <json/json.h>
+
+#include "tw.h"
+
+char *task_exec(char *opts)
+{
+ FILE *f;
+ int ret, s;
+ char *str, *tmp, *cmd, buf[1024];
+
+ str = NULL;
+
+ cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
+ strcpy(cmd, "task rc.json.array=on ");
+ strcat(cmd, opts);
+
+ printf("execute: %s\n", cmd);
+
+ f = popen(cmd, "r");
+
+ if (!f) {
+ perror("popen");
+ goto exit_free;
+ }
+
+ str = malloc(1);
+ str[0] = '\0';
+ while ((s = fread(buf, 1, 1024, f))) {
+ tmp = malloc(strlen(str) + s + 1);
+ memcpy(tmp, str, strlen(str));
+ memcpy(tmp + strlen(str), buf, s);
+ tmp[strlen(str) + s] = '\0';
+ free(str);
+ str = tmp;
+ }
+
+ ret = pclose(f);
+
+ if (ret == -1) {
+ printf("pclose fails\n");
+ perror("pclose");
+ }
+
+ exit_free:
+ free(cmd);
+
+ return str;
+}
+
+static struct json_object *task_exec_json(char *opts)
+{
+ struct json_object *o;
+ char *str;
+
+ str = task_exec(opts);
+
+ if (str) {
+ o = json_tokener_parse(str);
+ free(str);
+ return o;
+ }
+
+ return NULL;
+}
+
+struct task **get_all_tasks()
+{
+ int i, n;
+ struct json_object *jtasks, *jtask, *json;
+ struct task **tasks;
+
+ jtasks = task_exec_json("export");
+
+ if (!jtasks)
+ return NULL;
+
+ n = json_object_array_length(jtasks);
+
+ tasks = malloc((n + 1) * sizeof(struct task *));
+
+ for (i = 0; i < n; i++) {
+ jtask = json_object_array_get_idx(jtasks, i);
+
+ tasks[i] = malloc(sizeof(struct task));
+
+ json = json_object_object_get(jtask, "id");
+ tasks[i]->id = json_object_get_int(json);
+
+ json = json_object_object_get(jtask, "description");
+ tasks[i]->description = strdup(json_object_get_string(json));
+
+ json = json_object_object_get(jtask, "status");
+ tasks[i]->status = strdup(json_object_get_string(json));
+
+ json = json_object_object_get(jtask, "project");
+ if (json)
+ tasks[i]->project
+ = strdup(json_object_get_string(json));
+ else
+ tasks[i]->project = NULL;
+
+ json = json_object_object_get(jtask, "uuid");
+ tasks[i]->uuid = strdup(json_object_get_string(json));
+
+ tasks[i]->note = NULL;
+ }
+
+ tasks[n] = NULL;
+
+ json_object_put(jtasks);
+
+ return tasks;
+}
+
+char *escape(const char *txt)
+{
+ char *result;
+ char *c;
+
+ result = malloc(2*strlen(txt)+1);
+ c = result;
+
+ while(*txt) {
+ switch(*txt) {
+ case '"':
+ *c = '\\'; c++;
+ *c = '"';
+ break;
+ case '$':
+ *c = '\\'; c++;
+ *c = '$';
+ break;
+ case '&':
+ *c = '\\'; c++;
+ *c = '&';
+ break;
+ default:
+ *c = *txt;
+ }
+ c++;
+ txt++;
+ }
+
+ *c = '\0';
+
+ return result;
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2010-2012 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
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _GTASK_TW_H_
+#define _GTASK_TW_H_
+
+struct task {
+ int id;
+ char *description;
+ char *status;
+ char *uuid;
+ char *note;
+ char *project;
+};
+
+struct task **get_all_tasks();
+char *task_exec(char *opts);
+char *escape(const char *txt);
+
+#endif