(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 24 Apr 2013 15:47:07 +0000 (15:47 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 24 Apr 2013 15:47:07 +0000 (15:47 +0000)
Makefile
config.status
po/Makefile
po/Makefile.in
src/Makefile.am
src/Makefile.in
src/main.c
src/ttrss.c
src/ttrss.h
src/ttrss_model.c [new file with mode: 0644]
src/ttrss_model.h [new file with mode: 0644]

index 58ae108..ebdf257 100644 (file)
--- 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
index f0ce828..870123f 100755 (executable)
@@ -422,7 +422,7 @@ $config_commands
 Report bugs to <jeanfi@gmail.com>.
 prss home page: <http://wpitchoune.net/prss>."
 
-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"
index 8c03836..1aa077a 100644 (file)
@@ -21,7 +21,7 @@ srcdir = .
 top_srcdir = ..
 
 
-prefix = /tmp/p
+prefix = /tmp
 exec_prefix = ${prefix}
 datarootdir = ${prefix}/share
 datadir = ${datarootdir}
index 8693af6..dfc5daa 100644 (file)
@@ -21,7 +21,7 @@ srcdir = .
 top_srcdir = ..
 
 
-prefix = /tmp/p
+prefix = /tmp
 exec_prefix = ${prefix}
 datarootdir = ${prefix}/share
 datadir = ${datarootdir}
index 671429e..e2393da 100644 (file)
@@ -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 \
index fee124c..888be55 100644 (file)
@@ -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@
 
index af2c2f8..934b852 100644 (file)
@@ -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));
index 9228519..99b8bc4 100644 (file)
@@ -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);
+}
index 78427eb..71b3cef 100644 (file)
 #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 (file)
index 0000000..c67ad65
--- /dev/null
@@ -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 <stdlib.h>
+#include <string.h>
+
+#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 (file)
index 0000000..6d651db
--- /dev/null
@@ -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