Changeset 2028


Ignore:
Timestamp:
05/18/07 23:59:58 (6 years ago)
Author:
zecke
Message:

2007-05-18 Holger Freyther <zecke@…>

Start caching data

  • src/application-data.h: Hold a MokoCache? object
  • src/callbacks.c: Move the filling of the GtkListStore? into a method to be used by the method loading from a cache. (add_mrss_item): The refactored method (feed_update_thread): Move the code to add_mrss_item and cache the data. (load_data_from_cache): Empty stub
  • src/callbacks.h:
  • src/main.c: (main): Create the MokoCache?
Location:
trunk/src/target/OM-2007/applications/openmoko-rssreader
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/OM-2007/applications/openmoko-rssreader/ChangeLog

    r2027 r2028  
     12007-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 
    1162007-05-18  Holger Freyther  <zecke@selfish.org> 
    217 
  • trunk/src/target/OM-2007/applications/openmoko-rssreader/src/application-data.h

    r1712 r2028  
    3434#include <libmokoui/moko-tool-box.h> 
    3535 
     36#include "moko_cache.h" 
     37 
    3638#include <gtk/gtk.h> 
    3739 
    3840struct RSSReaderData { 
    3941    MokoApplication   *app; 
     42    MokoCache         *cache; 
    4043    GtkMenu           *menu; 
    4144    GtkMenu           *filter; 
  • trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.c

    r1904 r2028  
    3030#include "callbacks.h" 
    3131#include "rfcdate.h" 
     32#include "moko_cache.h" 
    3233 
    3334#include <libmokoui/moko-tool-box.h> 
     
    3637#include <mrss.h> 
    3738#include <string.h> 
     39#include <stdlib.h> 
    3840 
    3941struct FeedEntry { 
     
    9496 
    9597 
     98static 
     99void 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 
    96162/* 
    97163 * asynchronous update thread! 
     
    116182 */ 
    117183static void feed_update_thread( struct RSSReaderData *data ) { 
    118     GtkTreeIter iter; 
    119  
    120184    for ( int i = 0; i < NUMBER_OF_FEEDS; ++i ) { 
    121185        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 ); 
    123188        if ( ret ) { 
    124189            /* TODO use the footer to report error? */ 
     
    127192        } 
    128193 
    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); 
    184206        } 
    185207 
    186         mrss_free( data ); 
     208        free (buffer); 
     209        mrss_free( rss_data ); 
    187210    } 
    188211 
     
    190213    filter_feeds( data ); 
    191214    gdk_threads_leave(); 
     215} 
     216 
     217/** 
     218 * read the feeds from disk 
     219 */ 
     220void load_data_from_cache (struct RSSReaderData *data) 
     221{ 
    192222} 
    193223 
  • trunk/src/target/OM-2007/applications/openmoko-rssreader/src/callbacks.h

    r1491 r2028  
    3939 * toolbox callbacks 
    4040 */ 
     41void load_data_from_cache (struct RSSReaderData *data); 
    4142void cb_subscribe_button_clicked  ( GtkButton *btn, struct RSSReaderData *d); 
    4243void refresh_categories( struct RSSReaderData* ); 
  • trunk/src/target/OM-2007/applications/openmoko-rssreader/src/main.c

    r1853 r2028  
    293293    data->app = MOKO_APPLICATION( moko_application_get_instance() ); 
    294294    g_set_application_name( _("FeedReader") ); 
     295    data->cache = MOKO_CACHE(moko_cache_new ("rss-reader")); 
    295296 
    296297    setup_ui( data ); 
Note: See TracChangeset for help on using the changeset viewer.