From bc5b505b6dfc1103b226e5449c90ff5e9048d4ef Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 28 Apr 2013 08:41:57 +0000 Subject: [PATCH 01/16] --- src/main.c | 5 ++--- src/ttrss_ws.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index b0d6852..bb67679 100644 --- a/src/main.c +++ b/src/main.c @@ -344,14 +344,13 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) headline->title, tmp); free(tmp); - + web_load(str); - free(str); + g_free(str); } else { web_load(""); } - if (headline->unread) { ttrss_set_article_unread(headline->id, 0); headline->unread = 0; diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 98b7f37..654374f 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -221,7 +221,7 @@ int ws_open_session() if (session_id) { version = ws_get_api_version(); log_debug("API version= %d", version); - + if (version > 0) { result = 1; } else { -- 2.7.4 From e731474845fb94c8607a1510b3537c916827f0cc Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 28 Apr 2013 11:41:27 +0000 Subject: [PATCH 02/16] --- src/glade/prss.glade | 63 +++++++++++++++++++++++++++++++++++++++++++++++----- src/log.c | 2 +- src/main.c | 19 ++++++++-------- 3 files changed, 67 insertions(+), 17 deletions(-) diff --git a/src/glade/prss.glade b/src/glade/prss.glade index 6bbbd31..525ffdc 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -5,7 +5,7 @@ Refresh gtk-refresh - + @@ -13,7 +13,7 @@ - + @@ -465,12 +465,63 @@ - + True - True - in + False + vertical - + + True + False + + + True + False + 0 + BBBBBBBB + True + + + + + + + 0 + 0 + 1 + 1 + + + + + + + + + + + + + + False + True + 0 + + + + + True + True + in + + + + + + True + True + 1 + diff --git a/src/log.c b/src/log.c index f5185d3..b4cd3c2 100644 --- a/src/log.c +++ b/src/log.c @@ -48,7 +48,7 @@ void log_close() } -#define LOG_BUFFER 128 +#define LOG_BUFFER 512 static void vlogf(int lvl, const char *fmt, va_list ap) { struct timeval tv; diff --git a/src/main.c b/src/main.c index bb67679..67ea46b 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ static const char *program_name; static GSettings *settings; static GtkPaned *w_panel; +static GtkLabel *w_headline_title; static int model_state; @@ -326,7 +327,7 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) GtkTreeIter iter; GtkTreeModel *model; struct headline *headline; - char *str, *tmp; + char *str; log_debug("headline_cursor_changed_cbk()"); @@ -336,17 +337,13 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) headline = get_selected_headline(&iter); if (headline) { - tmp = ttrss_get_headline_content(headline); + gtk_label_set_text(w_headline_title, headline->title); - if (tmp) { - str = g_strdup_printf("

%s

%s", - headline->url, - headline->title, - tmp); - free(tmp); + str = ttrss_get_headline_content(headline); + if (str) { web_load(str); - g_free(str); + free(str); } else { web_load(""); } @@ -359,7 +356,7 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) model = gtk_tree_view_get_model(w_headlinetree); gtk_list_store_set(GTK_LIST_STORE(model), &iter, - 0, headline->title, + COL_HEADLINE_TITLE, headline->title, -1); } else { log_debug("headline not found"); @@ -527,6 +524,8 @@ int main(int argc, char **argv) "headline_tree")); w_panel = GTK_PANED(gtk_builder_get_object(builder, "paned2")); + w_headline_title + = GTK_LABEL(gtk_builder_get_object(builder, "headline_title")); gtk_builder_connect_signals(builder, NULL); -- 2.7.4 From 0348d77b4a6f6787c415e82f4616a0964e0d39ea Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 28 Apr 2013 11:43:10 +0000 Subject: [PATCH 03/16] --- src/glade/prss.glade | 1 - 1 file changed, 1 deletion(-) diff --git a/src/glade/prss.glade b/src/glade/prss.glade index 525ffdc..f11713e 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -478,7 +478,6 @@ True False 0 - BBBBBBBB True -- 2.7.4 From b2274ef4407e7794c89ef821944f5a16bb2de2df Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 28 Apr 2013 19:44:03 +0000 Subject: [PATCH 04/16] --- src/glade/prss.glade | 93 +++++++++++++++++++++++++++++++++++++++------------- src/main.c | 7 +++- src/ttrss_model.h | 1 + src/ttrss_ws.c | 4 +++ 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/src/glade/prss.glade b/src/glade/prss.glade index f11713e..374106b 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -5,6 +5,11 @@ Refresh gtk-refresh
+ + Preferences + gtk-preferences + + @@ -290,11 +295,12 @@ gtk-preferences + False + preferences_action True False True True - @@ -366,6 +372,19 @@ True + + + preferences_action + True + False + toolbutton1 + True + + + False + True + + False @@ -470,34 +489,64 @@ False vertical - + True False + 0 + in - + True False - 0 - True - - - - + + + True + False + 0 + True + + + + + + + 0 + 0 + 1 + 1 + + + + + + + + + + + + + + + + + True + False + 0 + + + + + + 0 + 1 + 1 + 1 + + - - 0 - 0 - 1 - 1 - - - - - - - - + diff --git a/src/main.c b/src/main.c index 67ea46b..13411c9 100644 --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,7 @@ static GSettings *settings; static GtkPaned *w_panel; static GtkLabel *w_headline_title; +static GtkLabel *w_headline_date; static int model_state; @@ -161,7 +162,7 @@ void refresh_clicked_cbk(GtkWidget *btn, gpointer data) log_debug("refresh_clicked_cbk() done"); } -void settings_activate_cbk(GtkWidget *menu_item, gpointer data) +void preferences_action_activate_cbk(GtkAction *action, gpointer data) { GtkDialog *diag; GtkBuilder *builder; @@ -338,6 +339,8 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) if (headline) { gtk_label_set_text(w_headline_title, headline->title); + gtk_label_set_text(w_headline_date, ctime(&headline->date)); + str = ttrss_get_headline_content(headline); @@ -526,6 +529,8 @@ int main(int argc, char **argv) w_panel = GTK_PANED(gtk_builder_get_object(builder, "paned2")); w_headline_title = GTK_LABEL(gtk_builder_get_object(builder, "headline_title")); + w_headline_date + = GTK_LABEL(gtk_builder_get_object(builder, "headline_date")); gtk_builder_connect_signals(builder, NULL); diff --git a/src/ttrss_model.h b/src/ttrss_model.h index e2ac2d8..81f75c2 100644 --- a/src/ttrss_model.h +++ b/src/ttrss_model.h @@ -28,6 +28,7 @@ struct headline { char *excerpt; char *content; int unread; + time_t date; }; struct feed { diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 654374f..4fc64e2 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -302,6 +302,10 @@ int ws_update_headlines(struct feed *feed) "excerpt"); h->excerpt = strdup(json_object_get_string(j)); + j = json_object_object_get(jheadline, + "updated"); + h->date = json_object_get_int(j); + tmp = headlines_add(feed->headlines, h); if (feed->headlines) free(feed->headlines); -- 2.7.4 From 0053e138f6512ecedf1889ae60a7ff6cba5ed5a0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 28 Apr 2013 20:06:11 +0000 Subject: [PATCH 05/16] --- src/glade/prss.glade | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/glade/prss.glade b/src/glade/prss.glade index 374106b..6f583aa 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -396,6 +396,8 @@ True True + 4 + 4 200 True @@ -498,6 +500,7 @@ True False + 4 True @@ -517,22 +520,11 @@ - - - - - - - - - - - - True False 0 + 0 -- 2.7.4 From 5bb795e97e53ef92cb7b28ee3598ad2aa4ec65d3 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 08:31:39 +0000 Subject: [PATCH 06/16] --- src/http.c | 51 +++++++++++++++++++++++++++++++-------------------- src/http.h | 11 ++++++++--- src/main.c | 1 - src/ttrss_ws.c | 11 +++++++---- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/http.c b/src/http.c index 12f8b72..0689a84 100644 --- a/src/http.c +++ b/src/http.c @@ -30,14 +30,16 @@ #include "http.h" #include "log.h" +struct http_session { + CURL *curl; + pthread_mutex_t lock; +}; + struct ucontent { char *data; size_t len; }; -static CURL *curl; -static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; - static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp) { size_t realsize; @@ -55,18 +57,26 @@ static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp) return realsize; } -void http_init() +struct http_session *http_session_new() { - if (!curl) - curl = curl_easy_init(); + struct http_session *sess; + + sess = malloc(sizeof(struct http_session)); + sess->curl = curl_easy_init(); + pthread_mutex_init(&sess->lock, NULL); + + return sess; } -void http_cleanup() +void http_session_free(struct http_session *sess) { - curl_easy_cleanup(curl); + curl_easy_cleanup(sess->curl); + pthread_mutex_destroy(&sess->lock); + free(sess); } -static char *http_get(const char *url, const char *content) +static char * +http_get(struct http_session *sess, const char *url, const char *content) { struct ucontent chunk; int result; @@ -74,22 +84,22 @@ static char *http_get(const char *url, const char *content) chunk.data = malloc(1); chunk.len = 0; - pthread_mutex_lock(&lock); + pthread_mutex_lock(&sess->lock); - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); + curl_easy_setopt(sess->curl, CURLOPT_URL, url); + curl_easy_setopt(sess->curl, CURLOPT_VERBOSE, 1); if (content) { - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, content); - curl_easy_setopt(curl, + curl_easy_setopt(sess->curl, CURLOPT_POSTFIELDS, content); + curl_easy_setopt(sess->curl, CURLOPT_POSTFIELDSIZE, (long)strlen(content)); } - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(sess->curl, CURLOPT_WRITEFUNCTION, cbk_curl); + curl_easy_setopt(sess->curl, CURLOPT_WRITEDATA, (void *)&chunk); - result = curl_easy_perform(curl); + result = curl_easy_perform(sess->curl); - pthread_mutex_unlock(&lock); + pthread_mutex_unlock(&sess->lock); if (result == CURLE_OK) return chunk.data; @@ -100,7 +110,8 @@ static char *http_get(const char *url, const char *content) return NULL; } -json_object *http_json_get(const char *url, struct json_object *j) +json_object * +http_json_get(struct http_session *sess, const char *url, struct json_object *j) { const char *in; char *out; @@ -111,7 +122,7 @@ json_object *http_json_get(const char *url, struct json_object *j) json_object_to_json_string(j)); in = json_object_to_json_string(j); - out = http_get(url, in); + out = http_get(sess, url, in); if (out) { result = json_tokener_parse(out); diff --git a/src/http.h b/src/http.h index dd78640..985187d 100644 --- a/src/http.h +++ b/src/http.h @@ -20,10 +20,15 @@ #ifndef _PRSS_HTTP_H_ #define _PRSS_HTTP_H_ +#include #include -void http_init(); -void http_cleanup(); -json_object *http_json_get(const char *url, struct json_object *); +struct http_session; + +struct http_session *http_session_new(); +void http_session_free(struct http_session *); + +json_object * +http_json_get(struct http_session *, const char *, struct json_object *); #endif diff --git a/src/main.c b/src/main.c index 13411c9..6d9aead 100644 --- a/src/main.c +++ b/src/main.c @@ -504,7 +504,6 @@ int main(int argc, char **argv) log_init(); - http_init(); ws_init(); gtk_init(NULL, NULL); diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 4fc64e2..51eee15 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -30,13 +30,14 @@ #include "ttrss_ws.h" #include "url.h" -static pthread_mutex_t lock; - static char *session_id; static char *session_url; static char *session_user; static char *session_pwd; +static pthread_mutex_t lock; +static struct http_session *http_session; + void ws_request_add_att_str(json_object *rq, const char *k, const char *str) { json_object_object_add(rq, k, json_object_new_string(str)); @@ -102,7 +103,7 @@ static struct json_object *execute(struct json_object *rq, char **err) struct json_object *rp, *content, *jerror; const char *str; - rp = http_json_get(session_url, rq); + rp = http_json_get(http_session, session_url, rq); content = NULL; @@ -407,7 +408,9 @@ void ws_set_article_unread(int id, int unread) void ws_init() { - pthread_mutexattr_t attr; + pthread_mutexattr_t attr; pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&lock, &attr); + + http_session = http_session_new(); } -- 2.7.4 From 05d4d920a38f57f2afc0ef349d8f4c96a5852878 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 09:14:32 +0000 Subject: [PATCH 07/16] --- src/http.c | 2 +- src/main.c | 4 ++++ src/ttrss.c | 15 +++++++++++++++ src/ttrss.h | 2 ++ src/ttrss_ws.c | 15 +++++++++------ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/http.c b/src/http.c index 0689a84..cd46515 100644 --- a/src/http.c +++ b/src/http.c @@ -87,7 +87,7 @@ http_get(struct http_session *sess, const char *url, const char *content) pthread_mutex_lock(&sess->lock); curl_easy_setopt(sess->curl, CURLOPT_URL, url); - curl_easy_setopt(sess->curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(sess->curl, CURLOPT_VERBOSE, 0); if (content) { curl_easy_setopt(sess->curl, CURLOPT_POSTFIELDS, content); curl_easy_setopt(sess->curl, diff --git a/src/main.c b/src/main.c index 6d9aead..39ad7c3 100644 --- a/src/main.c +++ b/src/main.c @@ -134,6 +134,10 @@ void update() } model_state = 0; + feeds = ttrss_get_feeds(); + if (feeds) + ttrs_download_headline_content(feeds); + log_debug("update() done"); } diff --git a/src/ttrss.c b/src/ttrss.c index 9833040..9b76295 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -125,3 +125,18 @@ struct headline *ttrss_get_headline(int id) { return feeds_get_headline(data, id); } + +void ttrs_download_headline_content(struct feed **feeds) +{ + struct feed **fcur; + struct headline **hcur; + + for (fcur = feeds; *fcur; fcur++) { + hcur = ttrss_feed_get_headlines(*fcur); + + while (hcur && *hcur) { + free(ttrss_get_headline_content(*hcur)); + hcur++; + } + } +} diff --git a/src/ttrss.h b/src/ttrss.h index b426a50..4e9f3a5 100644 --- a/src/ttrss.h +++ b/src/ttrss.h @@ -33,4 +33,6 @@ struct headline *ttrss_get_headline(int id); void ttrs_set_config(const char *url, const char *user, const char *pwd); +void ttrs_download_headline_content(struct feed **); + #endif diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 51eee15..582f9fb 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -36,7 +36,7 @@ static char *session_user; static char *session_pwd; static pthread_mutex_t lock; -static struct http_session *http_session; +static struct http_session *session; void ws_request_add_att_str(json_object *rq, const char *k, const char *str) { @@ -98,12 +98,13 @@ struct json_object *ws_reply_get_content(struct json_object *rp) return json_object_object_get(rp, "content"); } -static struct json_object *execute(struct json_object *rq, char **err) +static struct json_object * +execute(struct http_session *sess, struct json_object *rq, char **err) { struct json_object *rp, *content, *jerror; const char *str; - rp = http_json_get(http_session, session_url, rq); + rp = http_json_get(sess, session_url, rq); content = NULL; @@ -139,14 +140,14 @@ struct json_object *ws_execute(struct json_object *rq) log_debug("ws_execute() lock"); err = NULL; - result = execute(rq, &err); + result = execute(session, rq, &err); if (err) { log_debug("ws_execute(): error=%s\n", err); if (!strcmp(err, "NOT_LOGGED_IN")) { ws_open_session(); - result = execute(rq, NULL); + result = execute(session, rq, NULL); } free(err); @@ -364,6 +365,8 @@ struct feed **ws_update_feeds(struct feed **feeds) j = json_object_object_get(jfeed, "unread"); feed->unread = json_object_get_int(j); + + ws_update_headlines(feed); } json_object_put(rp); } else { @@ -412,5 +415,5 @@ void ws_init() pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&lock, &attr); - http_session = http_session_new(); + session = http_session_new(); } -- 2.7.4 From 17f3f4683056dda89b906f252435a4c2e2799aca Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 09:36:15 +0000 Subject: [PATCH 08/16] --- src/ttrss.c | 58 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/src/ttrss.c b/src/ttrss.c index 9b76295..b3b555e 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -20,6 +20,10 @@ #include #include #include +#include +#include +#include + #include #include @@ -54,6 +58,8 @@ static void file_set_content(const char *path, const char *content) { FILE *fp; + log_debug("file_set_content(): path=%s", path); + fp = fopen(path, "w"); if (fp) { fwrite(content, 1, strlen(content), fp); @@ -61,28 +67,53 @@ static void file_set_content(const char *path, const char *content) } } -char *ttrss_get_headline_content(struct headline *h) +static char *content_get_path(const struct headline *h) { const char *cache_dir; - char *path, *content; cache_dir = get_cache_dir(); - if (cache_dir) { - path = g_strdup_printf("%s/%d", cache_dir, h->id); + if (cache_dir) + return g_strdup_printf("%s/%d", cache_dir, h->id); - content = file_get_content(path); + return NULL; +} - if (!content) { - content = ws_get_article_content(h->id); - file_set_content(path, content); - } +static int is_content_cached(const struct headline *h) +{ + struct stat s; + char *path; + int result; + + path = content_get_path(h); + + if (stat(path, &s) == -1) + result = 0; + else + result = 1; - g_free(path); + free(path); - return content; + return result; +} + +char *ttrss_get_headline_content(struct headline *h) +{ + char *path, *content; + + path = content_get_path(h); + if (path) + content = file_get_content(path); + else + content = NULL; + + if (!content) { + content = ws_get_article_content(h->id); + file_set_content(path, content); } - return NULL; + free(path); + + return content; } struct feed **ttrss_get_feeds() @@ -135,7 +166,8 @@ void ttrs_download_headline_content(struct feed **feeds) hcur = ttrss_feed_get_headlines(*fcur); while (hcur && *hcur) { - free(ttrss_get_headline_content(*hcur)); + if (!is_content_cached(*hcur)) + free(ttrss_get_headline_content(*hcur)); hcur++; } } -- 2.7.4 From 111ccdc319c9f80ef4350b4b07408144a5684229 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 15:00:15 +0000 Subject: [PATCH 09/16] --- src/ttrss_ws.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 582f9fb..c4c2c4f 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -95,13 +95,29 @@ void ws_set_config(const char *url, const char *user, const char *pwd) struct json_object *ws_reply_get_content(struct json_object *rp) { + log_debug("ws_reply_get_content"); return json_object_object_get(rp, "content"); } +static const char *ws_reply_get_error(struct json_object *content) +{ + struct json_object *jerror; + + if (json_object_get_type(content) != json_type_object) + return NULL; + + jerror = json_object_object_get(content, "error"); + + if (!jerror) + return NULL; + + return json_object_get_string(jerror); +} + static struct json_object * execute(struct http_session *sess, struct json_object *rq, char **err) { - struct json_object *rp, *content, *jerror; + struct json_object *rp, *content; const char *str; rp = http_json_get(sess, session_url, rq); @@ -112,15 +128,13 @@ execute(struct http_session *sess, struct json_object *rq, char **err) content = ws_reply_get_content(rp); if (content) { - jerror = json_object_object_get(content, "error"); - if (jerror) { - if (err) { - str = json_object_get_string(jerror); - *err = strdup(str); - } + str = ws_reply_get_error(content); + + if (str) { + *err = strdup(str); content = NULL; } else { - json_object_get(content); + json_object_get(content); } } @@ -143,7 +157,7 @@ struct json_object *ws_execute(struct json_object *rq) result = execute(session, rq, &err); if (err) { - log_debug("ws_execute(): error=%s\n", err); + log_debug("ws_execute(): error=%s", err); if (!strcmp(err, "NOT_LOGGED_IN")) { ws_open_session(); @@ -336,6 +350,7 @@ struct feed **ws_update_feeds(struct feed **feeds) rq = ws_request_new("getFeeds"); rp = ws_execute(rq); + json_object_put(rq); if (rp) { @@ -346,7 +361,7 @@ struct feed **ws_update_feeds(struct feed **feeds) j = json_object_object_get(jfeed, "id"); id = json_object_get_int(j); - + feed = feeds_get_feed(feeds, id); if (!feed) { -- 2.7.4 From 3ef3a6b2acadc5546328a4d96e584dc4f7215af5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 17:06:39 +0000 Subject: [PATCH 10/16] --- src/ttrss.c | 6 ++--- src/ttrss_ws.c | 77 +++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/ttrss.c b/src/ttrss.c index b3b555e..ad78c0b 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -67,7 +67,7 @@ static void file_set_content(const char *path, const char *content) } } -static char *content_get_path(const struct headline *h) +static gchar *content_get_path(const struct headline *h) { const char *cache_dir; @@ -91,7 +91,7 @@ static int is_content_cached(const struct headline *h) else result = 1; - free(path); + g_free(path); return result; } @@ -111,7 +111,7 @@ char *ttrss_get_headline_content(struct headline *h) file_set_content(path, content); } - free(path); + g_free(path); return content; } diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index c4c2c4f..4b9c040 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -95,23 +95,23 @@ void ws_set_config(const char *url, const char *user, const char *pwd) struct json_object *ws_reply_get_content(struct json_object *rp) { - log_debug("ws_reply_get_content"); + log_debug("ws_reply_get_content"); return json_object_object_get(rp, "content"); } static const char *ws_reply_get_error(struct json_object *content) { - struct json_object *jerror; + struct json_object *jerror; - if (json_object_get_type(content) != json_type_object) - return NULL; + if (json_object_get_type(content) != json_type_object) + return NULL; - jerror = json_object_object_get(content, "error"); - - if (!jerror) - return NULL; + jerror = json_object_object_get(content, "error"); - return json_object_get_string(jerror); + if (!jerror) + return NULL; + + return json_object_get_string(jerror); } static struct json_object * @@ -128,13 +128,13 @@ execute(struct http_session *sess, struct json_object *rq, char **err) content = ws_reply_get_content(rp); if (content) { - str = ws_reply_get_error(content); + str = ws_reply_get_error(content); if (str) { - *err = strdup(str); + *err = strdup(str); content = NULL; } else { - json_object_get(content); + json_object_get(content); } } @@ -338,30 +338,23 @@ int ws_update_headlines(struct feed *feed) } } -struct feed **ws_update_feeds(struct feed **feeds) +static struct feed ** +feeds_update(struct feed **feeds, struct json_object *jarray) { - struct json_object *rp, *rq, *jfeed, *j; int i, n, id; + struct json_object *jfeed, *j; + const char *url, *title; struct feed *feed, **tmp; - const char *title, *url; - - log_debug("ws_update_feeds()"); - rq = ws_request_new("getFeeds"); - - rp = ws_execute(rq); - - json_object_put(rq); - - if (rp) { - n = json_object_array_length(rp); + if (jarray) { + n = json_object_array_length(jarray); for (i = 0; i < n; i++) { - jfeed = json_object_array_get_idx(rp, i); + jfeed = json_object_array_get_idx(jarray, i); j = json_object_object_get(jfeed, "id"); id = json_object_get_int(j); - + feed = feeds_get_feed(feeds, id); if (!feed) { @@ -383,10 +376,34 @@ struct feed **ws_update_feeds(struct feed **feeds) ws_update_headlines(feed); } + } + + return feeds; +} + +struct feed **ws_update_feeds(struct feed **feeds) +{ + struct json_object *rp, *rq; + + log_debug("ws_update_feeds()"); + + rq = ws_request_new("getFeeds"); + ws_request_add_att_int(rq, "cat_id", 0); + + rp = ws_execute(rq); + + if (rp) { + feeds = feeds_update(feeds, rp); + json_object_put(rp); + } + + ws_request_add_att_int(rq, "cat_id", -3); + rp = ws_execute(rq); + json_object_put(rq); + + if (rp) { + feeds = feeds_update(feeds, rp); json_object_put(rp); - } else { - feeds_free(feeds); - feeds = NULL; } log_debug("ws_update_feeds() done"); -- 2.7.4 From c6e1efc5d14895adeddd08dca19a954efa6fabdc Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 21:53:51 +0000 Subject: [PATCH 11/16] --- src/main.c | 7 +++---- src/ttrss_ws.c | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 39ad7c3..132aec1 100644 --- a/src/main.c +++ b/src/main.c @@ -130,14 +130,13 @@ void update() COL_FEED_ID, (*feeds)->id, -1); free(title); + + ttrs_download_headline_content(feeds); + feeds++; } model_state = 0; - feeds = ttrss_get_feeds(); - if (feeds) - ttrs_download_headline_content(feeds); - log_debug("update() done"); } diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 4b9c040..0aed58d 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -245,7 +245,6 @@ int ws_open_session() session_id = NULL; result = 0; } - result = 1; } else { result = 0; } @@ -331,6 +330,12 @@ int ws_update_headlines(struct feed *feed) j = json_object_object_get(jheadline, "unread"); h->unread = json_object_get_boolean(j); } + + if (!feed->headlines) { + feed->headlines = malloc(sizeof(struct headline *)); + *(feed->headlines) = NULL; + } + json_object_put(rp); return 1; } else { -- 2.7.4 From 4e47217ca7b179bf07e58ba965d03c2265d09def Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 30 Apr 2013 09:03:16 +0000 Subject: [PATCH 12/16] --- src/main.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 132aec1..2661e4a 100644 --- a/src/main.c +++ b/src/main.c @@ -97,30 +97,34 @@ static void print_help() GtkTreeView *w_feedtree; GtkTreeView *w_headlinetree; +static char *feed_get_formated_title(struct feed *f) +{ + if (f->unread) + return g_strdup_printf("%s (%d)", + f->title, + f->unread); + else + return strdup(f->title); +} + void update() { struct feed **feeds; - GtkTreeModel *model, *headlinemodel; + GtkTreeModel *model, *headline_model; GtkTreeIter iter; char *title; model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_feedtree)); + headline_model = gtk_tree_view_get_model(GTK_TREE_VIEW(w_headlinetree)); log_debug("update(): clear feed tree."); model_state = 1; gtk_list_store_clear(GTK_LIST_STORE(model)); - headlinemodel = gtk_tree_view_get_model(w_headlinetree); - gtk_list_store_clear(GTK_LIST_STORE(headlinemodel)); + gtk_list_store_clear(GTK_LIST_STORE(headline_model)); log_debug("update(): clear feed tree done."); feeds = ttrss_get_feeds(); while (feeds && *feeds) { - if ((*feeds)->unread) - title = g_strdup_printf("%s (%d)", - (*feeds)->title, - (*feeds)->unread); - else - title = strdup((*feeds)->title); - + title = feed_get_formated_title(*feeds); gtk_list_store_append(GTK_LIST_STORE(model), &iter); @@ -129,12 +133,12 @@ void update() COL_FEED_TITLE, title, COL_FEED_ID, (*feeds)->id, -1); - free(title); - - ttrs_download_headline_content(feeds); - + g_free(title); feeds++; } + + ttrs_download_headline_content(feeds); + model_state = 0; log_debug("update() done"); -- 2.7.4 From c15a1b330bc1435c92221214108e398fd9dc1271 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 30 Apr 2013 10:01:36 +0000 Subject: [PATCH 13/16] --- src/glade/prss.glade | 39 +++++++++++++++++++++++++++++---------- src/main.c | 47 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/glade/prss.glade b/src/glade/prss.glade index 6f583aa..ad392ef 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -5,11 +5,6 @@ Refresh gtk-refresh - - Preferences - gtk-preferences - - @@ -20,10 +15,12 @@ - + - + + + @@ -40,6 +37,11 @@ + + Preferences + gtk-preferences + + False 5 @@ -465,9 +467,11 @@ - - 3 - 0 + + True + fixed + 300 + 300 Headline @@ -477,6 +481,21 @@ + + + True + fixed + 50 + 50 + Date + + + + 2 + + + + diff --git a/src/main.c b/src/main.c index 2661e4a..59f3999 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,8 @@ enum { enum { COL_HEADLINE_TITLE, - COL_HEADLINE_ID + COL_HEADLINE_ID, + COL_HEADLINE_DATE }; static struct option long_options[] = { @@ -276,14 +277,37 @@ static struct headline *get_selected_headline(GtkTreeIter *iter) return NULL; } +static char *headline_get_formated_headline(struct headline *h) +{ + if (h->unread) + return g_strdup_printf("%s", h->title); + else + return strdup(h->title); +} + +static char *headline_get_date(struct headline *h) +{ + struct tm *tmp; + char date[200]; + + tmp = localtime(&h->date); + + if (h->unread) + strftime(date, sizeof(date), "%D", tmp); + else + strftime(date, sizeof(date), "%D", tmp); + + return strdup(date); +} + int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) { GtkTreeIter iter; GtkTreeModel *headline_model; GtkListStore *headline_store; struct feed *feed; - struct headline **headlines; - char *title; + struct headline **headlines, *h; + char *title, *date; if (model_state) return TRUE; @@ -303,22 +327,23 @@ int feed_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) 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); + h = *headlines; + + title = headline_get_formated_headline(h); + date = headline_get_date(h); gtk_list_store_set(headline_store, &iter, COL_HEADLINE_TITLE, title, COL_HEADLINE_ID, - (*headlines)->id, + h->id, + COL_HEADLINE_DATE, + date, -1); - free(title); + g_free(title); + free(date); headlines++; } -- 2.7.4 From 4e797ddad1e3df3bfdb4fbe8266e6961562fab23 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 30 Apr 2013 12:35:03 +0000 Subject: [PATCH 14/16] --- src/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.c b/src/main.c index 59f3999..a38238d 100644 --- a/src/main.c +++ b/src/main.c @@ -373,7 +373,6 @@ int headline_cursor_changed_cbk(GtkTreeView *treeview, gpointer data) gtk_label_set_text(w_headline_title, headline->title); gtk_label_set_text(w_headline_date, ctime(&headline->date)); - str = ttrss_get_headline_content(headline); if (str) { -- 2.7.4 From f5e23b613e0e3d6c0f0533abfa3a976221317095 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 30 Apr 2013 12:35:16 +0000 Subject: [PATCH 15/16] --- src/glade/prss.glade | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/glade/prss.glade b/src/glade/prss.glade index ad392ef..31908ba 100644 --- a/src/glade/prss.glade +++ b/src/glade/prss.glade @@ -471,7 +471,6 @@ True fixed 300 - 300 Headline @@ -486,7 +485,6 @@ True fixed 50 - 50 Date -- 2.7.4 From a9b5dea94a9c5219be46b54428531b195c90dd90 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 30 Apr 2013 12:35:26 +0000 Subject: [PATCH 16/16] --- src/ttrss_ws.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 0aed58d..e62fa18 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -103,6 +103,8 @@ static const char *ws_reply_get_error(struct json_object *content) { struct json_object *jerror; + log_debug("ws_reply_get_error"); + if (json_object_get_type(content) != json_type_object) return NULL; -- 2.7.4