(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 24 Apr 2013 19:54:14 +0000 (19:54 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Wed, 24 Apr 2013 19:54:14 +0000 (19:54 +0000)
src/glade/prss.glade
src/main.c
src/ttrss.c
src/ttrss.h
src/ttrss_model.c
src/ttrss_model.h

index ebab096..e3f14e8 100644 (file)
@@ -10,7 +10,7 @@
       <!-- column-name gchararray1 -->
       <column type="gchararray"/>
       <!-- column-name gpointer1 -->
-      <column type="gpointer"/>
+      <column type="gint"/>
     </columns>
   </object>
   <object class="GtkListStore" id="headline_store">
@@ -18,7 +18,7 @@
       <!-- column-name gchararray1 -->
       <column type="gchararray"/>
       <!-- column-name gpointer1 -->
-      <column type="gpointer"/>
+      <column type="gint"/>
     </columns>
   </object>
   <object class="GtkDialog" id="settings_dialog">
index d3f134b..849c112 100644 (file)
@@ -81,11 +81,6 @@ void update()
        GtkTreeIter iter;
        char *title;
 
-       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));
 
        printf("update(): clear feed tree\n");
@@ -108,7 +103,7 @@ void update()
                gtk_list_store_set(GTK_LIST_STORE(model),
                                   &iter,
                                   0, title,
-                                  1, (*feeds),
+                                  1, (*feeds)->id,
                                   -1);
                free(title);
                feeds++;
@@ -179,6 +174,7 @@ int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
        struct feed *feed;
        struct headline **headlines;
        char *title;
+       int feed_id;
 
        if (model_state)
                return TRUE;
@@ -190,32 +186,37 @@ int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
        if (path) {
                model = gtk_tree_view_get_model(treeview);
                gtk_tree_model_get_iter(model, &iter, path);
-               gtk_tree_model_get(model, &iter, 1, &feed, -1);
+               gtk_tree_model_get(model, &iter, 1, &feed_id, -1);
+
+               feed = ttrss_get_feed(feed_id);
 
                headline_model = gtk_tree_view_get_model(w_headlineview);
                headline_store = GTK_LIST_STORE(headline_model);
                model_state = 1;
                gtk_list_store_clear(headline_store);
 
-               headlines = ttrss_feed_get_headlines(feed);
-               while (headlines && *headlines) {
-                       gtk_list_store_append(headline_store, &iter);
-
-                       if ((*headlines)->unread)
-                               title = g_strdup_printf("<b>%s</b>",
-                                                       (*headlines)->title);
-                       else
-                               title = strdup((*headlines)->title);
-
-                       gtk_list_store_set(headline_store,
-                                          &iter,
-                                          0, title,
-                                          1, (*headlines),
-                                          -1);
-
-                       free(title);
-
-                       headlines++;
+               if (feed) {
+                       headlines = ttrss_feed_get_headlines(feed);
+                       while (headlines && *headlines) {
+                               gtk_list_store_append(headline_store, &iter);
+                               
+                               if ((*headlines)->unread)
+                                       title = g_strdup_printf
+                                               ("<b>%s</b>",
+                                                (*headlines)->title);
+                               else
+                                       title = strdup((*headlines)->title);
+                               
+                               gtk_list_store_set(headline_store,
+                                                  &iter,
+                                                  0, title,
+                                                  1, (*headlines),
+                                                  -1);
+                               
+                               free(title);
+                               
+                               headlines++;
+                       }
                }
 
                model_state = 0;
@@ -352,6 +353,11 @@ int main(int argc, char **argv)
        gtk_init(NULL, NULL);
        settings = g_settings_new("prss");
 
+       ttrss_set_config(g_settings_get_string(settings, "url"),
+                        g_settings_get_string(settings, "user"),
+                        g_settings_get_string(settings, "password"));
+       ws_open_session();
+
        builder = gtk_builder_new();
        gtk_builder_add_from_file
                (builder,
index a9fb0f8..64a0375 100644 (file)
@@ -38,11 +38,7 @@ const char *ttrss_get_headline_content(struct headline *h)
 
 struct feed **ttrss_get_feeds()
 {
-       struct feed **tmp;
-
-       tmp = ws_update_feeds(data);
-       feeds_free(data);
-       data = tmp;
+       data = ws_update_feeds(data);
 
        return data;
 }
@@ -56,7 +52,7 @@ struct headline **ttrss_feed_get_headlines(struct feed *f)
 }
 
 void ttrss_set_article_unread(int id, int unread)
-{
+{      
        struct json_object *rp, *rq;
 
        printf("ttrss_set_article_unread %d %d\n", id, unread);
@@ -78,3 +74,8 @@ void ttrss_set_config(const char *url, const char *user, const char *pwd)
        data = NULL;
        ws_init(url, user, pwd);
 }
+
+struct feed *ttrss_get_feed(int id)
+{
+       return feeds_get_feed(data, id);
+}
index d23c6e2..28370f3 100644 (file)
@@ -24,6 +24,7 @@
 
 void ttrss_set_config(const char *url, const char *user, const char *pwd);
 struct feed **ttrss_get_feeds();
+struct feed *ttrss_get_feed(int id);
 struct headline **ttrss_feed_get_headlines(struct feed *);
 const char *ttrss_get_headline_content(struct headline *);
 void ttrss_set_article_unread(int id, int unread);
index 2c80c9e..a1cdcef 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 
 #include "ttrss_model.h"
@@ -161,3 +162,19 @@ void feeds_free(struct feed **feeds)
                free(feeds);
        }
 }
+
+struct feed *feeds_get_feed(struct feed **feeds, int id)
+{
+       struct feed **cur;
+
+       printf("%p\n", feeds);
+
+       if (feeds)
+               for (cur = feeds; *cur; cur++)
+                       if ((*cur)->id == id) {
+                               printf("match!\n");
+                               return *cur;
+                       }
+
+       return NULL;
+}
index 338d941..b502010 100644 (file)
@@ -42,6 +42,7 @@ struct feed {
 struct feed *feed_new(int id, const char *url, const char *title);
 void feed_free(struct feed *feed);
 void feeds_free(struct feed **feed);
+struct feed *feeds_get_feed(struct feed **feed, int i);
 
 struct headline **headlines_add(struct headline **list, struct headline *h);
 struct headline *headline_new(int id, const char *url, const char *title);