(no commit message)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 22 Apr 2013 20:47:11 +0000 (20:47 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 22 Apr 2013 20:47:11 +0000 (20:47 +0000)
src/main.c
src/ttrss.c
src/ttrss.h

index 7a50b5c..79b94f7 100644 (file)
@@ -212,13 +212,14 @@ int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
 
 int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
 {
-       printf("headline_cursor_changed_cbk\n");
-
        GtkTreePath *path;
        GtkTreeViewColumn *cols;
        GtkTreeIter iter;
        GtkTreeModel *model;
        struct headline *headline;
+       const char *str;
+
+       printf("headline_cursor_changed_cbk\n");
 
        gtk_tree_view_get_cursor(treeview, &path, &cols);
 
@@ -227,7 +228,12 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data)
                gtk_tree_model_get_iter(model, &iter, path);
                gtk_tree_model_get(model, &iter, 1, &headline, -1);
 
-               web_load(((struct headline *)headline)->content);
+               str = ttrss_get_headline_content((struct headline *)headline);
+
+               if (str)
+                       web_load(str);
+               else
+                       web_load("");
 
                gtk_tree_path_free(path);
        }
index ec67cc8..c22cf34 100644 (file)
@@ -94,6 +94,41 @@ void ttrss_login(const char *url, const char *user, const char *password)
        json_object_put(rp);
 }
 
+const char *ttrss_get_headline_content(struct headline *h)
+{
+       struct json_object *rp, *rq, *content, *array, *item;
+
+       printf("get_headlines %d\n", h->id);
+
+       if (!h->content) {
+               rq = create_op("getArticle");
+               json_object_object_add(rq, "article_id",
+                                      json_object_new_int(h->id));
+               
+               rp = post_json_object(session_url, rq);
+               
+               json_object_put(rq);
+               
+               array = json_object_object_get(rp, "content");
+
+               if (!array)
+                       goto release;
+
+               item = json_object_array_get_idx(array, 0);
+
+               if (!item)
+                       goto release;
+
+               content = json_object_object_get(item, "content");
+
+               h->content = strdup(json_object_get_string(content));
+                       
+       release:
+               json_object_put(rp);
+       }
+       return h->content;
+}
+
 static struct headline **get_headlines(int feed_id)
 {
        struct json_object *rp, *rq, *content, *jheadline, *j;
@@ -104,8 +139,6 @@ static struct headline **get_headlines(int feed_id)
 
        rq = create_op("getHeadlines");
        json_object_object_add(rq, "feed_id", json_object_new_int(feed_id));
-       json_object_object_add(rq, "show_excerpt", json_object_new_boolean(1));
-       json_object_object_add(rq, "show_content", json_object_new_boolean(1));
 
        rp = post_json_object(session_url, rq);
 
@@ -121,14 +154,14 @@ static struct headline **get_headlines(int feed_id)
 
                        h = malloc(sizeof(struct headline));
 
+                       j = json_object_object_get(jheadline, "id");
+                       h->id = json_object_get_int(j);
+
                        j = json_object_object_get(jheadline, "title");
                        h->title = strdup(json_object_get_string(j));
 
-                       j = json_object_object_get(jheadline, "excerpt");
-                       h->excerpt = strdup(json_object_get_string(j));
-
-                       j = json_object_object_get(jheadline, "content");
-                       h->content = strdup(json_object_get_string(j));
+                       h->excerpt = NULL;
+                       h->content = NULL;
 
                        j = json_object_object_get(jheadline, "unread");
                        h->unread = json_object_get_boolean(j);
index 4c7f67e..020d77a 100644 (file)
@@ -21,6 +21,8 @@
 #define _TTRSS_H_
 
 struct headline {
+       int id;
+
        char *title;
        char *excerpt;
        char *content;
@@ -39,5 +41,6 @@ struct feed {
 void ttrss_login(const char *url, const char *user, const char *password);
 struct feed **ttrss_get_feeds();
 struct headline **ttrss_get_headlines(struct feed *);
+const char *ttrss_get_headline_content(struct headline *);
 
 #endif