From: Jean-Philippe Orsini Date: Sat, 19 Oct 2013 09:52:09 +0000 (+0000) Subject: added version check X-Git-Tag: v0.0.6~105 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=ptask.git;a=commitdiff_plain;h=82cf3f9476fae353dbbe4330da49293fc41f500d added version check --- diff --git a/config.status b/config.status index 25fb07d..7a9ef8b 100755 --- a/config.status +++ b/config.status @@ -635,8 +635,8 @@ S["CPPCHECK_FALSE"]="#" S["CPPCHECK_TRUE"]="" S["HAVE_CPPCHECK"]="yes" S["HELP2MAN"]="help2man" -S["JSON_LIBS"]="-ljson " -S["JSON_CFLAGS"]="-I/usr/include/json " +S["JSON_LIBS"]="-ljson-c " +S["JSON_CFLAGS"]="-I/usr/include/json-c " S["GTK_LIBS"]="-lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 " S["GTK_CFLAGS"]="-pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/i"\ "nclude/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/inclu"\ diff --git a/po/fr.gmo b/po/fr.gmo index 525bf4c..0bb79bb 100644 Binary files a/po/fr.gmo and b/po/fr.gmo differ diff --git a/po/fr.po b/po/fr.po index 8f2c538..6fb558c 100644 --- a/po/fr.po +++ b/po/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: ptask\n" "Report-Msgid-Bugs-To: jeanfi@gmail.com\n" -"POT-Creation-Date: 2013-03-24 13:22+0100\n" +"POT-Creation-Date: 2013-10-19 11:51+0200\n" "PO-Revision-Date: 2012-05-13 18:15+0000\n" "Last-Translator: jeanfi \n" "Language-Team: French <>\n" @@ -19,7 +19,7 @@ msgstr "" "X-Launchpad-Export-Date: 2012-07-02 08:28+0000\n" "X-Generator: Launchpad (build 15520)\n" -#: src/main.c:60 +#: src/main.c:65 #, c-format msgid "" "Copyright (C) %s jeanfi@gmail.com\n" @@ -29,37 +29,51 @@ msgid "" "There is NO WARRANTY, to the extent permitted by law.\n" msgstr "" -#: src/main.c:71 +#: src/main.c:76 #, c-format msgid "Usage: %s [OPTION]...\n" msgstr "" -#: src/main.c:73 -msgid "Ptask is a task management UI based on taskwarrior." +#: src/main.c:78 +msgid "ptask is a task management user interface based on taskwarrior." msgstr "" -#: src/main.c:76 +#: src/main.c:82 #, fuzzy msgid "Options:" msgstr "Description:" -#: src/main.c:77 +#: src/main.c:83 msgid "" " -h, --help display this help and exit\n" " -v, --version display version information and exit" msgstr "" -#: src/main.c:82 +#: src/main.c:88 +msgid " -d, --debug=LEVEL set the debug level, integer between 0 and 3" +msgstr "" + +#: src/main.c:93 #, c-format msgid "Report bugs to: %s\n" msgstr "" -#: src/main.c:84 +#: src/main.c:95 #, c-format msgid "%s home page: <%s>\n" msgstr "" -#: src/main.c:444 +#: src/main.c:210 +msgid "" +"Error loading tasks, verify that a supported version of taskwarrior is " +"installed and its configuration file exist." +msgstr "" + +#: src/main.c:490 +msgid "Enables debug mode." +msgstr "" + +#: src/main.c:499 #, c-format msgid "Try `%s --help' for more information.\n" msgstr "" diff --git a/po/ptask.pot b/po/ptask.pot index cd91085..e0c5434 100644 --- a/po/ptask.pot +++ b/po/ptask.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: jeanfi@gmail.com\n" -"POT-Creation-Date: 2013-03-24 13:22+0100\n" +"POT-Creation-Date: 2013-10-19 11:51+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,7 +17,7 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: src/main.c:60 +#: src/main.c:65 #, c-format msgid "" "Copyright (C) %s jeanfi@gmail.com\n" @@ -27,36 +27,50 @@ msgid "" "There is NO WARRANTY, to the extent permitted by law.\n" msgstr "" -#: src/main.c:71 +#: src/main.c:76 #, c-format msgid "Usage: %s [OPTION]...\n" msgstr "" -#: src/main.c:73 -msgid "Ptask is a task management UI based on taskwarrior." +#: src/main.c:78 +msgid "ptask is a task management user interface based on taskwarrior." msgstr "" -#: src/main.c:76 +#: src/main.c:82 msgid "Options:" msgstr "" -#: src/main.c:77 +#: src/main.c:83 msgid "" " -h, --help display this help and exit\n" " -v, --version display version information and exit" msgstr "" -#: src/main.c:82 +#: src/main.c:88 +msgid " -d, --debug=LEVEL set the debug level, integer between 0 and 3" +msgstr "" + +#: src/main.c:93 #, c-format msgid "Report bugs to: %s\n" msgstr "" -#: src/main.c:84 +#: src/main.c:95 #, c-format msgid "%s home page: <%s>\n" msgstr "" -#: src/main.c:444 +#: src/main.c:210 +msgid "" +"Error loading tasks, verify that a supported version of taskwarrior is " +"installed and its configuration file exist." +msgstr "" + +#: src/main.c:490 +msgid "Enables debug mode." +msgstr "" + +#: src/main.c:499 #, c-format msgid "Try `%s --help' for more information.\n" msgstr "" diff --git a/src/Makefile.am b/src/Makefile.am index db90364..27a5ad9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,7 @@ bin_PROGRAMS = ptask ptask_SOURCES = main.c \ log.c log.h \ note.c note.h \ + pstr.c pstr.h \ ptime.c ptime.h \ tw.c tw.h diff --git a/src/Makefile.in b/src/Makefile.in index bb54ec0..64d74c8 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -66,7 +66,7 @@ CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) am_ptask_OBJECTS = main.$(OBJEXT) log.$(OBJEXT) note.$(OBJEXT) \ - ptime.$(OBJEXT) tw.$(OBJEXT) + pstr.$(OBJEXT) ptime.$(OBJEXT) tw.$(OBJEXT) ptask_OBJECTS = $(am_ptask_OBJECTS) ptask_LDADD = $(LDADD) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) @@ -288,6 +288,7 @@ AM_CPPFLAGS = -Wall -Werror $(GTK_CFLAGS) $(JSON_CFLAGS) ptask_SOURCES = main.c \ log.c log.h \ note.c note.h \ + pstr.c pstr.h \ ptime.c ptime.h \ tw.c tw.h @@ -379,6 +380,7 @@ distclean-compile: @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@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pstr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptime.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tw.Po@am__quote@ diff --git a/src/main.c b/src/main.c index 225f570..6a98b1c 100644 --- a/src/main.c +++ b/src/main.c @@ -75,7 +75,8 @@ static void print_help() { printf(_("Usage: %s [OPTION]...\n"), program_name); - puts(_("ptask is a task management user interface based on taskwarrior.")); + puts(_("ptask is a task management user interface based" + " on taskwarrior.")); puts(""); puts(_("Options:")); @@ -207,9 +208,10 @@ static void refresh() GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error loading tasks, verify " - "that taskwarrior is " - "correctly installed, and its" - " configuration file exist." + "that a supported version of " + "taskwarrior is installed " + "and its configuration file " + "exist." )); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); diff --git a/src/pstr.c b/src/pstr.c new file mode 100644 index 0000000..92a7258 --- /dev/null +++ b/src/pstr.c @@ -0,0 +1,40 @@ +/* + * 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 + +void trim(char *str) +{ + char *p; + int l; + + p = str; + + l = strlen(str) - 1; + while (l && isspace(*(p+l))) { + *(p+l) = '\0'; + l--; + } + + while (*p && isspace(*p)) + p++; + + memmove(str, p, strlen(p)); +} diff --git a/src/pstr.h b/src/pstr.h new file mode 100644 index 0000000..b6e5978 --- /dev/null +++ b/src/pstr.h @@ -0,0 +1,25 @@ +/* + * 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_PSTR_H_ +#define _PTASK_PSTR_H_ + +void trim(char *str); + +#endif diff --git a/src/tw.c b/src/tw.c index 1868d46..2b82693 100644 --- a/src/tw.c +++ b/src/tw.c @@ -26,8 +26,10 @@ #include #include "note.h" +#include #include "tw.h" + static int has_taskrc() { char *home, *path; @@ -58,21 +60,19 @@ 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 "); + cmd = malloc(strlen("task ") + strlen(opts) + 1); + strcpy(cmd, "task "); strcat(cmd, opts); log_debug("execute: %s", cmd); f = popen(cmd, "r"); + free(cmd); + if (!f) { perror("popen"); - str = NULL; - goto exit_free; + return NULL; } str = strdup(""); @@ -90,26 +90,72 @@ static char *task_exec(char *opts) if (ret == -1) log_err("pclose fails"); - exit_free: - free(cmd); - return str; } +static char *task_get_version() +{ + char *out; + + out = task_exec("--version"); + + trim(out); + + return out; +} + +static int task_check_version() +{ + char *ver; + + ver = task_get_version(); + + if (!ver) + return 0; + + log_debug("task version: %s", ver); + + if (!strcmp(ver, "2.2.0")) + return 1; + else + return 0; +} + +static char *tw_exec(char *opts) +{ + if (!has_taskrc()) + return NULL; + + if (!task_check_version()) { + log_err("ptask is not compatible with the installed version of" + " taskwarrior."); + return NULL; + } + + return task_exec(opts); +} + static struct json_object *task_exec_json(char *opts) { struct json_object *o; - char *str; + char *str, *cmd; - str = task_exec(opts); + cmd = malloc(strlen("rc.json.array=on ") + strlen(opts) + 1); + strcpy(cmd, "rc.json.array=on "); + strcat(cmd, opts); + + str = tw_exec(cmd); if (str) { o = json_tokener_parse(str); free(str); - return o; + } else { + o = NULL; } - return NULL; + free(cmd); + + return o; } struct task **tw_get_all_tasks(const char *status) @@ -222,7 +268,7 @@ void tw_modify_description(const char *uuid, const char *newdesc) + 1); sprintf(opts, " %s modify \"%s\"", uuid, str); - task_exec(opts); + tw_exec(opts); free(str); free(opts); @@ -243,7 +289,7 @@ void tw_modify_project(const char *uuid, const char *newproject) + 1); sprintf(opts, " %s modify project:\"%s\"", uuid, str); - task_exec(opts); + tw_exec(opts); free(str); free(opts); @@ -264,7 +310,7 @@ void tw_modify_priority(const char *uuid, const char *priority) + 1); sprintf(opts, " %s modify priority:\"%s\"", uuid, str); - task_exec(opts); + tw_exec(opts); free(str); free(opts); @@ -284,7 +330,7 @@ void tw_add(const char *newdesc) + 1); sprintf(opts, " add \"%s\"", str); - task_exec(opts); + tw_exec(opts); free(str); free(opts); @@ -300,7 +346,7 @@ void tw_done(const char *uuid) + 1); sprintf(opts, " %s done", uuid); - task_exec(opts); + tw_exec(opts); free(opts); }