From: Jean-Philippe Orsini Date: Wed, 24 Apr 2013 19:54:14 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=commitdiff_plain;h=48e7c0631ee3371b5cf6503417b4ec1c2b733176 --- diff --git a/src/glade/prss.glade b/src/glade/prss.glade index ebab096..e3f14e8 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -10,7 +10,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/src/main.c b/src/main.c index d3f134b..849c112 100644 --- a/src/main.c +++ b/src/main.c @@ -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("%s", - (*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 + ("%s", + (*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, diff --git a/src/ttrss.c b/src/ttrss.c index a9fb0f8..64a0375 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -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); +} diff --git a/src/ttrss.h b/src/ttrss.h index d23c6e2..28370f3 100644 --- a/src/ttrss.h +++ b/src/ttrss.h @@ -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); diff --git a/src/ttrss_model.c b/src/ttrss_model.c index 2c80c9e..a1cdcef 100644 --- a/src/ttrss_model.c +++ b/src/ttrss_model.c @@ -18,6 +18,7 @@ */ #include +#include #include #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; +} diff --git a/src/ttrss_model.h b/src/ttrss_model.h index 338d941..b502010 100644 --- a/src/ttrss_model.h +++ b/src/ttrss_model.h @@ -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);