From 3b14915e76fc7a05512e0523afd39556c0a14567 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Wed, 24 Apr 2013 15:47:07 +0000 Subject: [PATCH] --- Makefile | 2 +- config.status | 6 +-- po/Makefile | 2 +- po/Makefile.in | 2 +- src/Makefile.am | 2 + src/Makefile.in | 5 ++- src/main.c | 6 +-- src/ttrss.c | 64 +++++-------------------------- src/ttrss.h | 23 ++--------- src/ttrss_model.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ttrss_model.h | 49 ++++++++++++++++++++++++ 11 files changed, 188 insertions(+), 85 deletions(-) create mode 100644 src/ttrss_model.c create mode 100644 src/ttrss_model.h diff --git a/Makefile b/Makefile index 58ae108..ebdf257 100644 --- a/Makefile +++ b/Makefile @@ -278,7 +278,7 @@ mandir = ${datarootdir}/man mkdir_p = /bin/mkdir -p oldincludedir = /usr/include pdfdir = ${docdir} -prefix = /tmp/p +prefix = /tmp program_transform_name = s,x,x, psdir = ${docdir} sbindir = ${exec_prefix}/sbin diff --git a/config.status b/config.status index f0ce828..870123f 100755 --- a/config.status +++ b/config.status @@ -422,7 +422,7 @@ $config_commands Report bugs to . prss home page: ." -ac_cs_config="'--prefix=/tmp/p'" +ac_cs_config="'--prefix=/tmp'" ac_cs_version="\ prss config.status 0.0.x configured by ./configure, generated by GNU Autoconf 2.69, @@ -503,7 +503,7 @@ if $ac_cs_silent; then fi if $ac_cs_recheck; then - set X /bin/bash './configure' '--prefix=/tmp/p' $ac_configure_extra_args --no-create --no-recursion + set X /bin/bash './configure' '--prefix=/tmp' $ac_configure_extra_args --no-create --no-recursion shift $as_echo "running CONFIG_SHELL=/bin/bash $*" >&6 CONFIG_SHELL='/bin/bash' @@ -780,7 +780,7 @@ S["libexecdir"]="${exec_prefix}/libexec" S["sbindir"]="${exec_prefix}/sbin" S["bindir"]="${exec_prefix}/bin" S["program_transform_name"]="s,x,x," -S["prefix"]="/tmp/p" +S["prefix"]="/tmp" S["exec_prefix"]="${prefix}" S["PACKAGE_URL"]="http://wpitchoune.net/prss" S["PACKAGE_BUGREPORT"]="jeanfi@gmail.com" diff --git a/po/Makefile b/po/Makefile index 8c03836..1aa077a 100644 --- a/po/Makefile +++ b/po/Makefile @@ -21,7 +21,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp/p +prefix = /tmp exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/po/Makefile.in b/po/Makefile.in index 8693af6..dfc5daa 100644 --- a/po/Makefile.in +++ b/po/Makefile.in @@ -21,7 +21,7 @@ srcdir = . top_srcdir = .. -prefix = /tmp/p +prefix = /tmp exec_prefix = ${prefix} datarootdir = ${prefix}/share datadir = ${datarootdir} diff --git a/src/Makefile.am b/src/Makefile.am index 671429e..e2393da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,6 +16,8 @@ prss_SOURCES = main.c \ http.h \ ttrss.c \ ttrss.h \ + ttrss_model.c \ + ttrss_model.h \ url.c \ url.h \ webbrowser.c \ diff --git a/src/Makefile.in b/src/Makefile.in index fee124c..888be55 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -65,7 +65,7 @@ CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) am_prss_OBJECTS = main.$(OBJEXT) http.$(OBJEXT) ttrss.$(OBJEXT) \ - url.$(OBJEXT) webbrowser.$(OBJEXT) + ttrss_model.$(OBJEXT) url.$(OBJEXT) webbrowser.$(OBJEXT) prss_OBJECTS = $(am_prss_OBJECTS) prss_LDADD = $(LDADD) DEFAULT_INCLUDES = -I.@am__isrc@ @@ -296,6 +296,8 @@ prss_SOURCES = main.c \ http.h \ ttrss.c \ ttrss.h \ + ttrss_model.c \ + ttrss_model.h \ url.c \ url.h \ webbrowser.c \ @@ -390,6 +392,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/http.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_model.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/url.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/webbrowser.Po@am__quote@ diff --git a/src/main.c b/src/main.c index af2c2f8..934b852 100644 --- a/src/main.c +++ b/src/main.c @@ -81,9 +81,9 @@ void update() GtkTreeIter iter; char *title; - ws_init(g_settings_get_string(settings, "url"), - g_settings_get_string(settings, "user"), - g_settings_get_string(settings, "password")); + ttrss_set_config(g_settings_get_string(settings, "url"), + g_settings_get_string(settings, "user"), + g_settings_get_string(settings, "password")); ws_open_session(); model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_treeview)); diff --git a/src/ttrss.c b/src/ttrss.c index 9228519..99b8bc4 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -31,60 +31,7 @@ static char *session_url; static char *session_user; static char *session_pwd; -static int list_length(void **list) -{ - int n; - - if (!list) - return 0; - - n = 0; - while (*list) { - n++; - list++; - } - - return n; -} - -static 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; -} - -struct headline ** -headlines_add(struct headline **list, struct headline *h) -{ - return (struct headline **)list_add((void **)list, (void *)h); -} - -struct headline *feed_get_headline(struct feed *feed, int id) -{ - struct headline **headlines; - - headlines = feed->headlines; - if (headlines) - while (*headlines) { - if ((*headlines)->id == id) - return *headlines; - headlines++; - } - - return NULL; -} +static struct feed **data; void ws_request_add_att_str(json_object *rq, const char *k, const char *str) { @@ -366,7 +313,7 @@ struct feed **ttrss_get_feeds() feed->headlines = NULL; - tmp = (struct feed **)list_add((void **)feeds, feed); + tmp = feeds_add(feeds, feed); free(feeds); feeds = tmp; } @@ -405,3 +352,10 @@ void ttrss_set_article_unread(int id, int unread) json_object_put(rq); json_object_put(rp); } + +void ttrss_set_config(const char *url, const char *user, const char *pwd) +{ + feeds_free(data); + data = NULL; + ws_init(url, user, pwd); +} diff --git a/src/ttrss.h b/src/ttrss.h index 78427eb..71b3cef 100644 --- a/src/ttrss.h +++ b/src/ttrss.h @@ -20,32 +20,15 @@ #ifndef _TTRSS_H_ #define _TTRSS_H_ -struct headline { - int id; - - char *url; - char *title; - char *excerpt; - char *content; - int unread; -}; - -struct feed { - char *title; - char *url; - int id; - int unread; - - struct headline **headlines; -}; +#include "ttrss_model.h" +void ttrss_set_config(const char *url, const char *user, const char *pwd); struct feed **ttrss_get_feeds(); struct headline **ttrss_get_headlines(struct feed *); const char *ttrss_get_headline_content(struct headline *); void ttrss_set_article_unread(int id, int unread); -void ws_init(const char *url, const char *user, const char *pwd); +void ttrs_set_config(const char *url, const char *user, const char *pwd); int ws_open_session(); - #endif diff --git a/src/ttrss_model.c b/src/ttrss_model.c new file mode 100644 index 0000000..c67ad65 --- /dev/null +++ b/src/ttrss_model.c @@ -0,0 +1,112 @@ +/* + * 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 "ttrss_model.h" + +static int list_length(void **list) +{ + int n; + + if (!list) + return 0; + + n = 0; + while (*list) { + n++; + list++; + } + + return n; +} + +static 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; +} + +struct headline **headlines_add(struct headline **list, struct headline *h) +{ + return (struct headline **)list_add((void **)list, (void *)h); +} + +struct feed **feeds_add(struct feed **list, struct feed *f) +{ + return (struct feed **)list_add((void **)list, (void *)f); +} + +struct headline *feed_get_headline(struct feed *feed, int id) +{ + struct headline **headlines; + + headlines = feed->headlines; + if (headlines) + while (*headlines) { + if ((*headlines)->id == id) + return *headlines; + headlines++; + } + + return NULL; +} + +void headlines_free(struct headline **headlines) +{ +} + +void feed_free(struct feed *feed) +{ + if (feed) { + if (feed->title) + free(feed->title); + if (feed->url) + free(feed->url); + headlines_free(feed->headlines); + free(feed); + } +} + +void feeds_free(struct feed **feeds) +{ + struct feed **cur; + + if (feeds) { + cur = feeds; + while (*cur) { + feed_free(*cur); + cur++; + } + free(feeds); + } +} diff --git a/src/ttrss_model.h b/src/ttrss_model.h new file mode 100644 index 0000000..6d651db --- /dev/null +++ b/src/ttrss_model.h @@ -0,0 +1,49 @@ +/* + * 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 _TTRSS_MODEL_H_ +#define _TTRSS_MODEL_H_ + +struct headline { + int id; + + char *url; + char *title; + char *excerpt; + char *content; + int unread; +}; + +struct feed { + char *title; + char *url; + int id; + int unread; + + struct headline **headlines; +}; + +void feed_free(struct feed *feed); +void feeds_free(struct feed **feed); +struct headline **headlines_add(struct headline **list, struct headline *h); + +struct feed **feeds_add(struct feed **list, struct feed *f); +struct headline *feed_get_headline(struct feed *feed, int id); + +#endif -- 2.7.4