diff --git a/src/AtomFeed.cpp b/src/AtomFeed.cpp index 76adea8..c034b65 100644 --- a/src/AtomFeed.cpp +++ b/src/AtomFeed.cpp @@ -25,25 +25,19 @@ AtomFeed::AtomFeed ( Config* cfg ) : AtomFeed::AtomFeed( ) void AtomFeed::Parse ( Config* cfg ) { - BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); entries = BList(); tinyxml2::XMLDocument xml; xml.LoadFile( filePath.String() ); - time_t tt_lastDate = 0; - BDateTime attrLastDate = BDateTime(); - feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); - if ( tt_lastDate > 0 && cfg->updateFeeds == true ) { - attrLastDate.SetTime_t( tt_lastDate ); - minDate = attrLastDate; - } + Feed::Parse( cfg ); tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed"); RootParse( cfg, xfeed ); ParseEntries( cfg, xfeed ); - tt_lastDate = lastDate.Time_t(); + BFile* feedFile = new BFile( filePath.String(), B_READ_WRITE ); + time_t tt_lastDate = lastDate.Time_t(); feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); } diff --git a/src/Feed.cpp b/src/Feed.cpp index 9946ad7..a020d71 100644 --- a/src/Feed.cpp +++ b/src/Feed.cpp @@ -24,6 +24,22 @@ Feed::Feed ( ) // ---------------------------------------------------------------------------- +void +Feed::Parse ( Config* cfg ) +{ + BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); + time_t tt_lastDate = 0; + BDateTime attrLastDate = BDateTime(); + + feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); + if ( tt_lastDate > 0 && cfg->updateFeeds == true ) { + attrLastDate.SetTime_t( tt_lastDate ); + minDate = attrLastDate; + } +} + +// ------------------------------------- + BString Feed::GetCachePath ( BString givenPath, Config* cfg ) { diff --git a/src/Feed.h b/src/Feed.h index b310a2e..245085d 100644 --- a/src/Feed.h +++ b/src/Feed.h @@ -27,7 +27,7 @@ public: BList entries; bool updated; - void Parse ( Config* ); + virtual void Parse ( Config* ); bool AddEntry ( Config*, Entry* ); bool SetTitle ( const char* ); diff --git a/src/RssFeed.cpp b/src/RssFeed.cpp index f97168e..c1de441 100644 --- a/src/RssFeed.cpp +++ b/src/RssFeed.cpp @@ -25,18 +25,10 @@ RssFeed::RssFeed ( Config* cfg ) : RssFeed::RssFeed( ) void RssFeed::Parse ( Config* cfg ) { - BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); tinyxml2::XMLDocument xml; entries = BList(); - time_t tt_lastDate = 0; - BDateTime attrLastDate = BDateTime(); - - feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); - if ( tt_lastDate > 0 && cfg->updateFeeds == true ) { - attrLastDate.SetTime_t( tt_lastDate ); - minDate = attrLastDate; - } + Feed::Parse( cfg ); xml.LoadFile( filePath.String() ); tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel"); @@ -44,7 +36,8 @@ RssFeed::Parse ( Config* cfg ) RootParse( cfg, xchan ); ParseEntries( cfg, xchan ); - tt_lastDate = lastDate.Time_t(); + time_t tt_lastDate = lastDate.Time_t(); + BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); }