Changeset 2028
- Timestamp:
- 05/18/07 23:59:58 (6 years ago)
- Location:
- trunk/src/target/OM-2007/applications/openmoko-rssreader
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
src/application-data.h (modified) (1 diff)
-
src/callbacks.c (modified) (6 diffs)
-
src/callbacks.h (modified) (1 diff)
-
src/main.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog
r2027 r2028 1 2007-05-18 Holger Freyther <zecke@selfish.org> 2 3 Start caching data 4 5 * src/application-data.h: Hold a MokoCache object 6 * src/callbacks.c: Move the filling of the GtkListStore into a method 7 to be used by the method loading from a cache. 8 (add_mrss_item): The refactored method 9 (feed_update_thread): Move the code to add_mrss_item and cache the 10 data. 11 (load_data_from_cache): Empty stub 12 * src/callbacks.h: 13 * src/main.c: 14 (main): Create the MokoCache 15 1 16 2007-05-18 Holger Freyther <zecke@selfish.org> 2 17 -
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h
r1712 r2028 34 34 #include <libmokoui/moko-tool-box.h> 35 35 36 #include "moko_cache.h" 37 36 38 #include <gtk/gtk.h> 37 39 38 40 struct RSSReaderData { 39 41 MokoApplication *app; 42 MokoCache *cache; 40 43 GtkMenu *menu; 41 44 GtkMenu *filter; -
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c
r1904 r2028 30 30 #include "callbacks.h" 31 31 #include "rfcdate.h" 32 #include "moko_cache.h" 32 33 33 34 #include <libmokoui/moko-tool-box.h> … … 36 37 #include <mrss.h> 37 38 #include <string.h> 39 #include <stdlib.h> 38 40 39 41 struct FeedEntry { … … 94 96 95 97 98 static 99 void add_mrss_item ( struct RSSReaderData *data, const mrss_t *rss_data, const gchar *url, const gchar *category) 100 { 101 GtkTreeIter iter; 102 mrss_item_t *item = rss_data->item; 103 104 while ( item ) { 105 gint content_type = RSS_READER_TEXT_TYPE_NONE; 106 gchar *description = item->description; 107 108 /* 109 * let us try to find the 'content' tag 110 * and then extract the type 111 */ 112 if ( !description && rss_data->version == MRSS_VERSION_ATOM_1_0 && item->other_tags ) { 113 for ( mrss_tag_t *tag = item->other_tags; tag; tag = tag->next ) { 114 if ( strcmp( tag->name, "content" ) == 0 ) { 115 description = tag->value; 116 117 for ( mrss_attribute_t *attribute = tag->attributes; attribute; attribute = attribute->next ) { 118 /* 119 * Detect the type of the content. Currently we know about text/plain and html 120 */ 121 if ( strcmp( attribute->name, "type" ) == 0 ) { 122 if ( strcmp( attribute->value, "plain" ) == 0 ) { 123 content_type = RSS_READER_TEXT_TYPE_PLAIN; 124 } else if ( strcmp( attribute->name, "html" ) == 0 ) { 125 content_type = RSS_READER_TEXT_TYPE_HTML; 126 } else { 127 content_type = RSS_READER_TEXT_TYPE_UNKNOWN; 128 } 129 } 130 } 131 132 /* we are done */ 133 break; 134 } 135 } 136 } 137 138 /* 139 * update the model here. The order in gtk_list_store_set must match 140 * with the order in application-data.h 141 */ 142 RSSRFCDate *date = RSS_RFC_DATE(rss_rfc_date_new ()); 143 rss_rfc_date_set (date, item->pubDate); 144 gdk_threads_enter(); 145 gtk_list_store_append( data->feed_data, &iter ); 146 gtk_list_store_set ( data->feed_data, &iter, 147 RSS_READER_COLUMN_AUTHOR, g_strdup( item->author ), 148 RSS_READER_COLUMN_SUBJECT,g_strdup( item->title ), 149 RSS_READER_COLUMN_DATE, date, 150 RSS_READER_COLUMN_LINK, g_strdup( item->link ), 151 RSS_READER_COLUMN_TEXT, g_strdup( description ), 152 RSS_READER_COLUMN_TEXT_TYPE, content_type , 153 RSS_READER_COLUMN_CATEGORY, g_strdup( category ), 154 RSS_READER_COLUMN_SOURCE, g_strdup( url ), 155 -1 ); 156 gdk_threads_leave(); 157 item = item->next; 158 } 159 160 } 161 96 162 /* 97 163 * asynchronous update thread! … … 116 182 */ 117 183 static void feed_update_thread( struct RSSReaderData *data ) { 118 GtkTreeIter iter;119 120 184 for ( int i = 0; i < NUMBER_OF_FEEDS; ++i ) { 121 185 mrss_t *rss_data; 122 int ret = mrss_parse_url( s_feeds[i].url, &rss_data ); 186 gchar *url = s_feeds[i].url; 187 int ret = mrss_parse_url( url, &rss_data ); 123 188 if ( ret ) { 124 189 /* TODO use the footer to report error? */ … … 127 192 } 128 193 129 mrss_item_t *item = rss_data->item; 130 while ( item ) { 131 gint content_type = RSS_READER_TEXT_TYPE_NONE; 132 gchar *description = item->description; 133 134 /* 135 * let us try to find the 'content' tag 136 * and then extract the type 137 */ 138 if ( !description && rss_data->version == MRSS_VERSION_ATOM_1_0 && item->other_tags ) { 139 for ( mrss_tag_t *tag = item->other_tags; tag; tag = tag->next ) { 140 if ( strcmp( tag->name, "content" ) == 0 ) { 141 description = tag->value; 142 143 for ( mrss_attribute_t *attribute = tag->attributes; attribute; attribute = attribute->next ) { 144 /* 145 * Detect the type of the content. Currently we know about text/plain and html 146 */ 147 if ( strcmp( attribute->name, "type" ) == 0 ) { 148 if ( strcmp( attribute->value, "plain" ) == 0 ) { 149 content_type = RSS_READER_TEXT_TYPE_PLAIN; 150 } else if ( strcmp( attribute->name, "html" ) == 0 ) { 151 content_type = RSS_READER_TEXT_TYPE_HTML; 152 } else { 153 content_type = RSS_READER_TEXT_TYPE_UNKNOWN; 154 } 155 } 156 } 157 158 /* we are done */ 159 break; 160 } 161 } 162 } 163 164 /* 165 * update the model here. The order in gtk_list_store_set must match 166 * with the order in application-data.h 167 */ 168 RSSRFCDate *date = RSS_RFC_DATE(rss_rfc_date_new ()); 169 rss_rfc_date_set (date, item->pubDate); 170 gdk_threads_enter(); 171 gtk_list_store_append( data->feed_data, &iter ); 172 gtk_list_store_set ( data->feed_data, &iter, 173 RSS_READER_COLUMN_AUTHOR, g_strdup( item->author ), 174 RSS_READER_COLUMN_SUBJECT,g_strdup( item->title ), 175 RSS_READER_COLUMN_DATE, date, 176 RSS_READER_COLUMN_LINK, g_strdup( item->link ), 177 RSS_READER_COLUMN_TEXT, g_strdup( description ), 178 RSS_READER_COLUMN_TEXT_TYPE, content_type , 179 RSS_READER_COLUMN_CATEGORY, g_strdup( s_feeds[i].category ), 180 RSS_READER_COLUMN_SOURCE, g_strdup( s_feeds[i].url ), 181 -1 ); 182 gdk_threads_leave(); 183 item = item->next; 194 /* 195 * create the new item(s) 196 */ 197 add_mrss_item (data, rss_data, url, s_feeds[i].category); 198 199 /* 200 * now cache the feed, a bit inefficient as we do not write to a file directly 201 */ 202 char *buffer = NULL; 203 mrss_write_buffer (rss_data, &buffer); 204 if (buffer) { 205 moko_cache_write_object (data->cache, url, buffer, -1, NULL); 184 206 } 185 207 186 mrss_free( data ); 208 free (buffer); 209 mrss_free( rss_data ); 187 210 } 188 211 … … 190 213 filter_feeds( data ); 191 214 gdk_threads_leave(); 215 } 216 217 /** 218 * read the feeds from disk 219 */ 220 void load_data_from_cache (struct RSSReaderData *data) 221 { 192 222 } 193 223 -
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h
r1491 r2028 39 39 * toolbox callbacks 40 40 */ 41 void load_data_from_cache (struct RSSReaderData *data); 41 42 void cb_subscribe_button_clicked ( GtkButton *btn, struct RSSReaderData *d); 42 43 void refresh_categories( struct RSSReaderData* ); -
trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c
r1853 r2028 293 293 data->app = MOKO_APPLICATION( moko_application_get_instance() ); 294 294 g_set_application_name( _("FeedReader") ); 295 data->cache = MOKO_CACHE(moko_cache_new ("rss-reader")); 295 296 296 297 setup_ui( data );
Note: See TracChangeset
for help on using the changeset viewer.
