~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/fl_sources/ttrss_source_feed.c

  • Committer: Package Import Robot
  • Author(s): Moray Allan, Bojo42, Rodrigo Gallardo, Moray Allan
  • Date: 2012-03-27 21:44:42 UTC
  • mfrom: (1.5.1)
  • mto: (3.3.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 122.
  • Revision ID: package-import@ubuntu.com-20120327214442-g0xfh714cdmsbnts
Tags: 1.8.3-0.1
[ Bojo42 ]
* Non-maintainer upload.
* New upstream release (Closes: #502307, #623619, #631778, #651913) 
* debian/patches:
  - drop libnotify0.7 as in upstream
  - debian-example-feeds: update, move planets from "News" to "Open Source"
  - www-browser: update due to new file location
  - libtool-dont-rearange-as-needed: rebase
* debian/control:
  - update Standards-Version
  - remove obsolete Build-Depends:
    - quilt not needed for "3.0 (quilt)" source format
    - libnm-glib-dev & libdbus-glib-1-dev: upstream switched to GDBus
    - liblua5.1-0-dev: LUA scripting support got dropped
  - new Build-Depends on libunique-dev, libjson-glib-dev & dh_autoreconf
  - update version dependencies
* debian/rules: run dh_autoreconf & update translations
* debian/liferea.install: nothing to ship from /usr/lib/liferea

[ Rodrigo Gallardo ]
* Lintian love:
  - debian/control: switch from Conflicts to Breaks
  - debian/rules: redo build targets

[ Moray Allan ]
* debian/copyright: update to include additional copyright owners.
* debian/patches/www-browser: also set default external browser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file ttrss_source_feed.c  tt-rss feed subscription routines
 
3
 * 
 
4
 * Copyright (C) 2010-2011 Lars Lindner <lars.lindner@gmail.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version. 
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
 
 
21
#include <glib.h>
 
22
#include <string.h>
 
23
 
 
24
#include "common.h"
 
25
#include "db.h"
 
26
#include "debug.h"
 
27
#include "feedlist.h"
 
28
#include "itemlist.h"
 
29
#include "itemset.h"
 
30
#include "json.h"
 
31
#include "metadata.h"
 
32
#include "subscription.h"
 
33
 
 
34
#include "fl_sources/ttrss_source.h"
 
35
 
 
36
static void
 
37
ttrss_feed_subscription_process_update_result (subscriptionPtr subscription, const struct updateResult* const result, updateFlags flags)
 
38
{
 
39
        if (result->data && result->httpstatus == 200) {
 
40
                JsonParser      *parser = json_parser_new ();
 
41
 
 
42
                if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
 
43
                        JsonArray       *array = json_node_get_array (json_get_node (json_parser_get_root (parser), "content"));
 
44
                        GList           *iter = json_array_get_elements (array);
 
45
                        GList           *items = NULL;
 
46
 
 
47
                        /*
 
48
                           We expect to get something like this
 
49
                           
 
50
                           [{"id":118,
 
51
                             "unread":true,
 
52
                             "marked":false,
 
53
                             "updated":1287927675,
 
54
                             "is_updated":false,
 
55
                             "title":"IBM Says New ...",
 
56
                             "link":"http:\/\/rss.slashdot.org\/~r\/Slashdot\/slashdot\/~3\/ALuhNKO3NV4\/story01.htm",
 
57
                             "feed_id":"5",
 
58
                             "content":"coondoggie writes ..."
 
59
                            },
 
60
                            {"id":117,
 
61
                             "unread":true,
 
62
                             "marked":false,
 
63
                             "updated":1287923814,
 
64
                           [...]
 
65
                         */
 
66
                         
 
67
                        while (iter) {
 
68
                                JsonNode *node = (JsonNode *)iter->data;
 
69
                                itemPtr item = item_new ();
 
70
                                
 
71
                                item_set_id (item, g_strdup_printf ("%lld", json_get_int (node, "id")));
 
72
                                item_set_title (item, json_get_string (node, "title"));
 
73
                                item_set_source (item, json_get_string (node, "link"));
 
74
                                item_set_description (item, json_get_string (node, "content"));
 
75
                                item->time = json_get_int (node, "updated");
 
76
                                
 
77
                                if (json_get_bool (node, "unread")) {
 
78
                                        item->readStatus = FALSE;
 
79
                                }
 
80
                                else {
 
81
                                        item->readStatus = TRUE;
 
82
                                }
 
83
                                if (json_get_bool (node, "marked"))
 
84
                                        item->flagStatus = TRUE;
 
85
                                        
 
86
                                items = g_list_append (items, (gpointer)item);
 
87
                                
 
88
                                iter = g_list_next (iter);
 
89
                        }
 
90
                        
 
91
                        /* merge against feed cache */
 
92
                        if (items) {
 
93
                                itemSetPtr itemSet = node_get_itemset (subscription->node);
 
94
                                gint newCount = itemset_merge_items (itemSet, items, TRUE /* feed valid */, FALSE /* markAsRead */);
 
95
                                itemlist_merge_itemset (itemSet);
 
96
                                itemset_free (itemSet);
 
97
 
 
98
                                feedlist_node_was_updated (subscription->node, newCount);
 
99
                        }
 
100
 
 
101
                        subscription->node->available = TRUE;
 
102
                } else {
 
103
                        subscription->node->available = FALSE;
 
104
 
 
105
                        g_string_append (((feedPtr)subscription->node->data)->parseErrors, _("Could not parse JSON returned by tt-rss API!"));
 
106
                }
 
107
        } else {
 
108
                subscription->node->available = FALSE;
 
109
        }
 
110
}
 
111
 
 
112
static gboolean
 
113
ttrss_feed_subscription_prepare_update_request (subscriptionPtr subscription, 
 
114
                                                 struct updateRequest *request)
 
115
{
 
116
        debug0 (DEBUG_UPDATE, "ttrss_feed_subscription_prepare_update_request()");
 
117
        nodePtr root = node_source_root_from_node (subscription->node);
 
118
        ttrssSourcePtr source = (ttrssSourcePtr) root->data;
 
119
        const gchar *feed_id;
 
120
 
 
121
        debug0 (DEBUG_UPDATE, "preparing tt-rss feed subscription for update");
 
122
        
 
123
        g_assert(source); 
 
124
        if (source->loginState == TTRSS_SOURCE_STATE_NONE) { 
 
125
                subscription_update (root->subscription, 0);
 
126
                return FALSE;
 
127
        }
 
128
        
 
129
        feed_id = metadata_list_get (subscription->metadata, "ttrss-feed-id");
 
130
        if (!feed_id) {
 
131
                g_warning ("tt-rss feed without id! (%s)", subscription->node->title);
 
132
                return FALSE;
 
133
        }
 
134
        update_request_set_source (request, g_strdup_printf (TTRSS_HEADLINES_URL, 
 
135
                metadata_list_get (root->subscription->metadata, "ttrss-url"), 
 
136
                source->session_id,
 
137
                feed_id,
 
138
                15 /* items to fetch */));
 
139
 
 
140
        return TRUE;
 
141
}
 
142
 
 
143
struct subscriptionType ttrssSourceFeedSubscriptionType = {
 
144
        ttrss_feed_subscription_prepare_update_request,
 
145
        ttrss_feed_subscription_process_update_result
 
146
};
 
147