Slight refactoring

This commit is contained in:
Jaidyn Ann 2020-08-14 14:00:07 -05:00
parent 69e1a3085c
commit b5f0d5bab8
4 changed files with 23 additions and 20 deletions

View File

@ -25,25 +25,19 @@ AtomFeed::AtomFeed ( Config* cfg ) : AtomFeed::AtomFeed( )
void void
AtomFeed::Parse ( Config* cfg ) AtomFeed::Parse ( Config* cfg )
{ {
BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY );
entries = BList(); entries = BList();
tinyxml2::XMLDocument xml; tinyxml2::XMLDocument xml;
xml.LoadFile( filePath.String() ); xml.LoadFile( filePath.String() );
time_t tt_lastDate = 0;
BDateTime attrLastDate = BDateTime();
feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); Feed::Parse( cfg );
if ( tt_lastDate > 0 && cfg->updateFeeds == true ) {
attrLastDate.SetTime_t( tt_lastDate );
minDate = attrLastDate;
}
tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed"); tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed");
RootParse( cfg, xfeed ); RootParse( cfg, xfeed );
ParseEntries( 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) ); feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) );
} }

View File

@ -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 BString
Feed::GetCachePath ( BString givenPath, Config* cfg ) Feed::GetCachePath ( BString givenPath, Config* cfg )
{ {

View File

@ -27,7 +27,7 @@ public:
BList entries; BList entries;
bool updated; bool updated;
void Parse ( Config* ); virtual void Parse ( Config* );
bool AddEntry ( Config*, Entry* ); bool AddEntry ( Config*, Entry* );
bool SetTitle ( const char* ); bool SetTitle ( const char* );

View File

@ -25,18 +25,10 @@ RssFeed::RssFeed ( Config* cfg ) : RssFeed::RssFeed( )
void void
RssFeed::Parse ( Config* cfg ) RssFeed::Parse ( Config* cfg )
{ {
BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY );
tinyxml2::XMLDocument xml; tinyxml2::XMLDocument xml;
entries = BList(); entries = BList();
time_t tt_lastDate = 0;
BDateTime attrLastDate = BDateTime();
Feed::Parse( cfg );
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;
}
xml.LoadFile( filePath.String() ); xml.LoadFile( filePath.String() );
tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel"); tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel");
@ -44,7 +36,8 @@ RssFeed::Parse ( Config* cfg )
RootParse( cfg, xchan ); RootParse( cfg, xchan );
ParseEntries( 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) ); feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) );
} }