New constructors; make Feeds' minDate and maxDate local

This commit is contained in:
Jaidyn Ann 2020-08-14 12:34:09 -05:00
parent 956d7786af
commit 69e1a3085c
9 changed files with 51 additions and 17 deletions

View File

@ -4,16 +4,22 @@
#include "Util.h"
#include "AtomFeed.h"
AtomFeed::AtomFeed ( BString path, Config* cfg )
AtomFeed::AtomFeed ( )
{
title = BString("Untitled Feed");
description = BString("");
homeUrl = BString("");
xmlUrl = BString("");
filePath = path;
outputDir = cfg->outDir;
filePath = BString("");
}
AtomFeed::AtomFeed ( Feed* feed ) : AtomFeed::AtomFeed()
{ filePath = feed->filePath; }
AtomFeed::AtomFeed ( Feed* feed, Config* cfg ) : AtomFeed::AtomFeed( feed )
{ outputDir = cfg->outDir; }
AtomFeed::AtomFeed ( Config* cfg ) : AtomFeed::AtomFeed( )
{ outputDir = cfg->outDir; }
// ----------------------------------------------------------------------------
void
@ -27,9 +33,9 @@ AtomFeed::Parse ( Config* cfg )
BDateTime attrLastDate = BDateTime();
feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) );
if ( tt_lastDate > 0 && cfg->minDate == NULL && cfg->updateFeeds == true ) {
if ( tt_lastDate > 0 && cfg->updateFeeds == true ) {
attrLastDate.SetTime_t( tt_lastDate );
cfg->minDate = attrLastDate;
minDate = attrLastDate;
}
tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed");

View File

@ -11,7 +11,10 @@
class AtomFeed: public Feed {
public:
AtomFeed ( BString, Config* );
AtomFeed ( );
AtomFeed ( Feed*, Config* );
AtomFeed ( Feed* );
AtomFeed ( Config* );
void Parse ( Config* );
void RootParse ( Config*, tinyxml2::XMLElement* );

View File

@ -9,6 +9,15 @@ Config::Config () {
updateFeeds = false;
}
Config::Config ( Config* cfg ) {
verbose = cfg->verbose;
daemon = cfg->daemon;
will_save = cfg->will_save;
updateFeeds = cfg->updateFeeds;
minDate = cfg->minDate;
maxDate = cfg->maxDate;
}
// !! handle file status
void
Config::Load ()

View File

@ -7,6 +7,9 @@
class Config {
public:
Config ( );
Config ( Config* );
bool verbose;
bool daemon;
BString outDir;
@ -21,8 +24,6 @@ public:
bool updateFeeds;
Config ( );
void Load ( );
void Save ( );
};

View File

@ -113,7 +113,8 @@ Feed::xmlCountSiblings ( tinyxml2::XMLElement* xsibling, const char* sibling_nam
bool
Feed::AddEntry ( Config* cfg, Entry* newEntry )
{
if ( !withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) )
if ( !withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) ||
!withinDateRange( minDate, newEntry->date, maxDate ) )
return false;
if ( cfg->verbose == true )

View File

@ -18,6 +18,8 @@ public:
BString description;
BDateTime date;
BDateTime lastDate;
BDateTime minDate;
BDateTime maxDate;
BString homeUrl;
BString xmlUrl;
BString filePath;

View File

@ -149,15 +149,18 @@ processFeed ( void* feedArg )
Feed* testFeed = new Feed( *(feedStr), main_cfg );
BList entries;
if ( testFeed->updated == false && main_cfg->updateFeeds == true )
return false;
if ( testFeed->IsAtom() ) {
AtomFeed* feed = (AtomFeed*)malloc( sizeof(AtomFeed) );
feed = new AtomFeed( testFeed->filePath, main_cfg );
feed = new AtomFeed( testFeed, main_cfg );
feed->Parse(main_cfg);
entries = feed->entries;
}
if ( testFeed->IsRss() ) {
RssFeed* feed = (RssFeed*)malloc( sizeof(RssFeed) );
feed = new RssFeed( testFeed->filePath, main_cfg );
feed = new RssFeed( testFeed, main_cfg );
feed->Parse(main_cfg);
entries = feed->entries;
}

View File

@ -4,16 +4,22 @@
#include "Util.h"
#include "RssFeed.h"
RssFeed::RssFeed ( BString path, Config* cfg )
RssFeed::RssFeed ( )
{
title = BString("Untitled Feed");
description = BString("");
homeUrl = BString("");
xmlUrl = BString("");
filePath = path;
outputDir = cfg->outDir;
}
RssFeed::RssFeed ( Feed* feed ) : RssFeed::RssFeed()
{ filePath = feed->filePath; }
RssFeed::RssFeed ( Feed* feed, Config* cfg ) : RssFeed::RssFeed( feed )
{ outputDir = cfg->outDir; }
RssFeed::RssFeed ( Config* cfg ) : RssFeed::RssFeed( )
{ outputDir = cfg->outDir; }
// ----------------------------------------------------------------------------
void
@ -27,9 +33,9 @@ RssFeed::Parse ( Config* cfg )
feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) );
if ( tt_lastDate > 0 && cfg->minDate == NULL && cfg->updateFeeds == true ) {
if ( tt_lastDate > 0 && cfg->updateFeeds == true ) {
attrLastDate.SetTime_t( tt_lastDate );
cfg->minDate = attrLastDate;
minDate = attrLastDate;
}
xml.LoadFile( filePath.String() );

View File

@ -11,7 +11,10 @@
class RssFeed: public Feed {
public:
RssFeed ( BString, Config* );
RssFeed ( );
RssFeed ( Feed*, Config* );
RssFeed ( Feed* );
RssFeed ( Config* );
void Parse ( Config* );
void RootParse ( Config*, tinyxml2::XMLElement* );