From 1ff664c141ac890095ba33d96d28aca87f8b2ff7 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Fri, 29 Nov 2013 08:49:25 +0000 Subject: [PATCH] display project table --- src/Makefile.am | 6 +- src/Makefile.in | 15 +- src/glade/ptask.glade | 563 ++++++++++++++++++++++++++++---------------------- src/list.c | 62 ++++++ src/list.h | 27 +++ src/main.c | 4 + src/tw.c | 54 ++++- src/tw.h | 10 +- src/ui_projecttree.c | 54 +++++ src/ui_projecttree.h | 29 +++ 10 files changed, 563 insertions(+), 261 deletions(-) create mode 100644 src/list.c create mode 100644 src/list.h create mode 100644 src/ui_projecttree.c create mode 100644 src/ui_projecttree.h diff --git a/src/Makefile.am b/src/Makefile.am index e8dae2f..3b096b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,14 +11,16 @@ LIBS = $(JSON_LIBS) $(GTK_LIBS) bin_PROGRAMS = ptask -ptask_SOURCES = main.c \ +ptask_SOURCES = list.c list.h \ log.c log.h \ + main.c \ note.c note.h \ pstr.c pstr.h \ ptime.c ptime.h \ tw.c tw.h \ ui.c ui.h \ - ui_newtask_diag.c ui_newtask_diag.h + ui_newtask_diag.c ui_newtask_diag.h \ + ui_projecttree.c ui_projecttree.h dist_man_MANS = ptask.1 diff --git a/src/Makefile.in b/src/Makefile.in index 3b3042d..2b707ce 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -65,9 +65,10 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) -am_ptask_OBJECTS = main.$(OBJEXT) log.$(OBJEXT) note.$(OBJEXT) \ - pstr.$(OBJEXT) ptime.$(OBJEXT) tw.$(OBJEXT) ui.$(OBJEXT) \ - ui_newtask_diag.$(OBJEXT) +am_ptask_OBJECTS = list.$(OBJEXT) log.$(OBJEXT) main.$(OBJEXT) \ + note.$(OBJEXT) pstr.$(OBJEXT) ptime.$(OBJEXT) tw.$(OBJEXT) \ + ui.$(OBJEXT) ui_newtask_diag.$(OBJEXT) \ + ui_projecttree.$(OBJEXT) ptask_OBJECTS = $(am_ptask_OBJECTS) ptask_LDADD = $(LDADD) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) @@ -289,14 +290,16 @@ SUBDIRS = glade # -export-dynamic is need for defining handlers in the glade file. AM_LDFLAGS = -Wl,--as-needed -export-dynamic AM_CPPFLAGS = -Wall -Werror $(GTK_CFLAGS) $(JSON_CFLAGS) -ptask_SOURCES = main.c \ +ptask_SOURCES = list.c list.h \ log.c log.h \ + main.c \ note.c note.h \ pstr.c pstr.h \ ptime.c ptime.h \ tw.c tw.h \ ui.c ui.h \ - ui_newtask_diag.c ui_newtask_diag.h + ui_newtask_diag.c ui_newtask_diag.h \ + ui_projecttree.c ui_projecttree.h dist_man_MANS = ptask.1 gsettings_SCHEMAS = ptask.gschema.xml @@ -385,6 +388,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/note.Po@am__quote@ @@ -393,6 +397,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tw.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_newtask_diag.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ui_projecttree.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/src/glade/ptask.glade b/src/glade/ptask.glade index c56a143..731c12f 100644 --- a/src/glade/ptask.glade +++ b/src/glade/ptask.glade @@ -1,6 +1,26 @@ + + + + + + + + None + + + Low + + + Medium + + + High + + + False 5 @@ -180,25 +200,13 @@ button2 - + - + + + - - - None - - - Low - - - Medium - - - High - - @@ -234,7 +242,7 @@ 640 480 - + True False 4 @@ -342,72 +350,36 @@ True - True - vertical - 200 - True + False - + True - True - 4 + False in - + True - True - 4 - 4 - 4 - 4 - taskstore - False - 1 - both - True + False + projectstore - - - - - Priority - 4 - - - - 4 - - - + - - 10 + Project - True - True - True - 2 - + - 2 + 0 - - 10 - 30 - Description - True - True - True - True - 1 + + Count - + 1 @@ -423,250 +395,339 @@ - + True - False + True vertical + 200 + True - + True - False - 4 - 4 - 4 + True 4 + in - + True - False + True 4 4 4 4 - Description: + taskstore + False + 1 + both + True + + + + + + Priority + 4 + + + + 4 + + + + + + + 10 + Project + True + True + True + 2 + + + + 2 + + + + + + + 10 + 30 + Description + True + True + True + True + 1 + + + + 1 + + + + - - 0 - 1 - 1 - 1 - + + + False + True + + + + + True + False + vertical - + True False - start - center 4 4 4 - Note: - - - 0 - 4 - 1 - 1 - - - - - True - True - 4 - 4 - 4 - True - True - in + 4 + + + True + False + 4 + 4 + 4 + 4 + Description: + + + 0 + 1 + 1 + 1 + + + + + True + False + start + center + 4 + 4 + 4 + Note: + + + 0 + 4 + 1 + 1 + + - + True True + 4 + 4 + 4 + True + True + in + + + True + True + + + + 1 + 4 + 1 + 1 + + + + + True + True + 4 + 4 + 4 + 4 + • + True + + + 1 + 1 + 1 + 1 + + + + + True + False + start + 4 + 4 + 4 + 4 + Project: + + + 0 + 3 + 1 + 1 + + + + + True + True + 4 + 4 + 4 + • + + + 1 + 3 + 1 + 1 + + + + + True + False + start + 4 + 4 + 4 + 4 + Priority: + + + 0 + 2 + 1 + 1 + + + + + True + False + 4 + 4 + 4 + 4 + prioritystore + 0 + + + + 0 + + + + + 1 + 2 + 1 + 1 + + + + + True + False + start + + + Mark Done + True + True + True + + + + False + True + 0 + + + + + 0 + 0 + 2 + 1 + - 1 - 4 - 1 - 1 - - - - - True - True - 4 - 4 - 4 - 4 - • - True - - - 1 - 1 - 1 - 1 - - - - - True - False - start - 4 - 4 - 4 - 4 - Project: - - - 0 - 3 - 1 - 1 - - - - - True - True - 4 - 4 - 4 - • - - - 1 - 3 - 1 - 1 - - - - - True - False - start - 4 - 4 - 4 - 4 - Priority: - - - 0 - 2 - 1 - 1 + True + True + 1 - + True False 4 4 4 4 - prioritystore - 0 - - - 0 - + + Save + True + True + True + top + + + False + True + 0 + - - - 1 - 2 - 1 - 1 - - - - - True - False - start - - Mark Done + + Cancel True True True - False True - 0 + 2 - 0 - 0 - 2 - 1 - - - - - True - True - 1 - - - - - True - False - 4 - 4 - 4 - 4 - - - Save - True - True - True - top - - False - True - 0 - - - - - Cancel - True - True - True - - - False - True + False 2 - False - False - 2 + True + True - True + False True diff --git a/src/list.c b/src/list.c new file mode 100644 index 0000000..d4c4806 --- /dev/null +++ b/src/list.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010-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 + * 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 +#include + +#include "list.h" + +int list_length(void **list) +{ + int n; + + if (!list) + return 0; + + n = 0; + while (*list) { + n++; + list++; + } + + return n; +} + +void **list_add(void **list, void *item) +{ + int n; + void **result; + + n = list_length(list); + + result = malloc((n + 1 + 1) * sizeof(void *)); + + if (list) + memcpy(result, list, n * sizeof(void *)); + + result[n] = item; + result[n + 1] = NULL; + + return result; +} + +void list_free(void **list) +{ + free(list); +} diff --git a/src/list.h b/src/list.h new file mode 100644 index 0000000..91aa116 --- /dev/null +++ b/src/list.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010-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 + * 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 _P_LIST_H_ +#define _P_LIST_H_ + +int list_length(void **list); +void **list_add(void **list, void *item); +void list_free(void **list); + +#endif diff --git a/src/main.c b/src/main.c index 2171895..1a2509e 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,7 @@ #include "note.h" #include "tw.h" #include +#include static const char *program_name; static struct task **tasks; @@ -203,6 +204,7 @@ void refresh() COL_PRIORITY, (*tasks_cur)->priority, -1); } + ui_projecttree_update(tasks); } else { dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, @@ -463,6 +465,8 @@ int main(int argc, char **argv) NULL); window = create_window(builder, settings); + ui_projecttree_init(builder); + 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), diff --git a/src/tw.c b/src/tw.c index 926a039..6c25697 100644 --- a/src/tw.c +++ b/src/tw.c @@ -24,6 +24,7 @@ #include +#include #include #include "note.h" #include @@ -180,7 +181,7 @@ struct task **tw_get_all_tasks(const char *status) tasks[i]->project = strdup(json_object_get_string(json)); else - tasks[i]->project = NULL; + tasks[i]->project = strdup(""); json = json_object_object_get(jtask, "priority"); if (json) @@ -373,3 +374,54 @@ void tw_task_list_free(struct task **tasks) free(tasks); } + +static struct project *project_list_get(struct project **prj, const char *name) +{ + while (*prj) + if (!strcmp((*prj)->name, name)) + return *prj; + else + prj++; + return NULL; +} + +static struct project *project_new(const char *name, int count) +{ + struct project *prj; + + prj = malloc(sizeof(struct project)); + + prj->name = strdup(name); + prj->count = count; + + return prj; +} + +struct project **tw_get_projects(struct task **tasks) +{ + struct task **t_cur; + struct project **prjs, **tmp, *prj; + const char *prj_name; + + log_debug("tw_get_projects()"); + + prjs = malloc(sizeof(struct project *)); + *prjs = NULL; + + for (t_cur = tasks; *t_cur; t_cur++) { + prj_name = (*t_cur)->project; + prj = project_list_get(prjs, prj_name); + if (prj) { + prj->count++; + } else { + prj = project_new(prj_name, 1); + + tmp = (struct project **)list_add((void **)prjs, prj); + + list_free((void **)prjs); + prjs = tmp; + } + } + + return prjs; +} diff --git a/src/tw.h b/src/tw.h index 41a1789..a8c0791 100644 --- a/src/tw.h +++ b/src/tw.h @@ -17,8 +17,8 @@ * 02110-1301 USA */ -#ifndef _GTASK_TW_H_ -#define _GTASK_TW_H_ +#ifndef _PTASK_TW_H_ +#define _PTASK_TW_H_ struct task { int id; @@ -30,6 +30,11 @@ struct task { char *priority; }; +struct project { + char *name; + int count; +}; + struct task **tw_get_all_tasks(const char *status); void tw_modify_description(const char *uuid, const char *newdesc); void tw_modify_project(const char *uuid, const char *newproj); @@ -37,5 +42,6 @@ void tw_modify_priority(const char *uuid, const char *priority); void tw_done(const char *uuid); void tw_add(const char *newdesc, const char *prj, const char *prio); void tw_task_list_free(struct task **tasks); +struct project **tw_get_projects(struct task **tasks); #endif diff --git a/src/ui_projecttree.c b/src/ui_projecttree.c new file mode 100644 index 0000000..d993a17 --- /dev/null +++ b/src/ui_projecttree.c @@ -0,0 +1,54 @@ +/* + * 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 + * 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 + +#include +#include + +static GtkTreeView *w_treeview; + +void ui_projecttree_init(GtkBuilder *builder) +{ + w_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "projecttree")); +} + +void ui_projecttree_update(struct task **ts) +{ + struct project **prjs; + GtkTreeModel *model; + GtkTreeIter iter; + + log_debug("ui_projecttree_update()"); + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview)); + gtk_list_store_clear(GTK_LIST_STORE(model)); + + prjs = tw_get_projects(ts); + while (*prjs) { + gtk_list_store_append(GTK_LIST_STORE(model), &iter); + + gtk_list_store_set(GTK_LIST_STORE(model), + &iter, + 0, (*prjs)->name, + 1, (*prjs)->count, + -1); + + prjs++; + } +} diff --git a/src/ui_projecttree.h b/src/ui_projecttree.h new file mode 100644 index 0000000..d4848d9 --- /dev/null +++ b/src/ui_projecttree.h @@ -0,0 +1,29 @@ +/* + * 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 + * 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 _PTASK_UI_PROJECTTREE_H_ +#define _PTASK_UI_PROJECTTREE_H_ + +#include + +#include + +void ui_projecttree_init(GtkBuilder *builder); +void ui_projecttree_update(struct task **); + +#endif -- 2.7.4