diff --git a/src/App.cpp b/src/App.cpp index ba6b177..6e6e0c6 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -20,8 +20,8 @@ main ( int argc, char** argv ) usageMsg.ReplaceAll("%app%", "Pogger"); feedMimeType(); - main_cfg = new Config; - main_cfg->Load(); + app->cfg = new Config; + app->cfg->Load(); if ( argc == 1 ) @@ -30,8 +30,8 @@ main ( int argc, char** argv ) cliStart( argc, argv ); - if ( main_cfg->will_save == true ) - main_cfg->Save(); + if ( app->cfg->will_save == true ) + app->cfg->Save(); return 0; } @@ -41,8 +41,8 @@ main ( int argc, char** argv ) void cliStart ( int argc, char** argv ) { - invocation( argc, argv, &main_cfg ); - main_cfg->targetFeeds.DoForEach( &processFeed ); + invocation( argc, argv ); + ((App*)be_app)->cfg->targetFeeds.DoForEach( &processFeed ); } App::App ( ) @@ -55,8 +55,6 @@ App::App ( ) // ---------------------------------------------------------------------------- - -Config* main_cfg; const char* configPath = "/boot/home/config/settings/Pogger/"; BString usageMsg = "Usage: %app% [-hvDus] [-tT datetime] [-cCO path] \n" diff --git a/src/App.h b/src/App.h index d7720d0..c370d19 100644 --- a/src/App.h +++ b/src/App.h @@ -3,12 +3,14 @@ #include #include +#include "Config.h" class App : public BApplication { public: App(void); + Config* cfg; }; // ---------------------------------------------------------------------------- @@ -18,8 +20,6 @@ void cliStart ( int, char** ); // ---------------------------------------------------------------------------- -extern Config* main_cfg; - extern const char* configPath; extern BString usageMsg; diff --git a/src/AtomFeed.cpp b/src/AtomFeed.cpp index 7e52069..5dc761f 100644 --- a/src/AtomFeed.cpp +++ b/src/AtomFeed.cpp @@ -1,5 +1,6 @@ #include #include "Entry.h" +#include "App.h" #include "Config.h" #include "Util.h" #include "AtomFeed.h" @@ -11,30 +12,27 @@ AtomFeed::AtomFeed ( ) homeUrl = BString(""); xmlUrl = BString(""); filePath = BString(""); + outputDir = ((App*)be_app)->cfg->outDir; } 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 -AtomFeed::Parse ( Config* cfg ) +AtomFeed::Parse ( ) { entries = BList(); tinyxml2::XMLDocument xml; xml.LoadFile( filePath.String() ); - Feed::Parse( cfg ); + Feed::Parse(); tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed"); - RootParse( cfg, xfeed ); - ParseEntries( cfg, xfeed ); + RootParse( xfeed ); + ParseEntries( xfeed ); BFile* feedFile = new BFile( filePath.String(), B_READ_WRITE ); time_t tt_lastDate = lastDate.Time_t(); @@ -42,7 +40,7 @@ AtomFeed::Parse ( Config* cfg ) } void -AtomFeed::RootParse( Config* cfg, tinyxml2::XMLElement* xfeed ) +AtomFeed::RootParse( tinyxml2::XMLElement* xfeed ) { tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author"); tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry"); @@ -63,12 +61,12 @@ AtomFeed::RootParse( Config* cfg, tinyxml2::XMLElement* xfeed ) if ( !set && xauthor ) set = SetHomeUrl( xauthor->FirstChildElement("uri") ); if ( !set && xauthlink ) set = SetHomeUrl( xauthlink->Attribute( "href" ) ); - if ( cfg->verbose ) + if ( ((App*)be_app)->cfg->verbose ) printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String()); } void -AtomFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xentry ) +AtomFeed::EntryParse ( tinyxml2::XMLElement* xentry ) { Entry* newEntry= (Entry*)malloc( sizeof(Entry) ); newEntry = new Entry( outputDir ); @@ -97,11 +95,11 @@ AtomFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xentry ) newEntry->SetContent( xprinter.CStr() ); } - AddEntry( cfg, newEntry ); + AddEntry( newEntry ); } void -AtomFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xfeed ) +AtomFeed::ParseEntries ( tinyxml2::XMLElement* xfeed ) { tinyxml2::XMLElement* xentry; @@ -110,11 +108,11 @@ AtomFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xfeed ) int entryCount = xmlCountSiblings( xentry, "entry" ); entries = BList(entryCount); - if ( cfg->verbose ) + if ( ((App*)be_app)->cfg->verbose ) printf("\t-%i entries-\n", entryCount); while ( xentry ) { - EntryParse( cfg, xentry ); + EntryParse( xentry ); xentry = xentry->NextSiblingElement("entry"); } } diff --git a/src/AtomFeed.h b/src/AtomFeed.h index 5bad971..7e9932b 100644 --- a/src/AtomFeed.h +++ b/src/AtomFeed.h @@ -12,14 +12,12 @@ class AtomFeed: public Feed { public: AtomFeed ( ); - AtomFeed ( Feed*, Config* ); AtomFeed ( Feed* ); - AtomFeed ( Config* ); - void Parse ( Config* ); - void RootParse ( Config*, tinyxml2::XMLElement* ); - void EntryParse ( Config*, tinyxml2::XMLElement* ); - void ParseEntries ( Config*, tinyxml2::XMLElement* ); + void Parse ( ); + void RootParse ( tinyxml2::XMLElement* ); + void EntryParse ( tinyxml2::XMLElement* ); + void ParseEntries ( tinyxml2::XMLElement* ); }; #endif diff --git a/src/Entry.cpp b/src/Entry.cpp index 8dcbf49..3b3494b 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -17,7 +17,7 @@ Entry::Entry ( BString outputPath ) } bool -Entry::Filetize ( Config* cfg, bool onlyIfNew = false ) +Entry::Filetize ( bool onlyIfNew = false ) { BDirectory* dir = new BDirectory( outputDir ); BFile* file = new BFile( title.String(), B_READ_WRITE ); diff --git a/src/Entry.h b/src/Entry.h index 8574499..9270e7d 100644 --- a/src/Entry.h +++ b/src/Entry.h @@ -1,7 +1,6 @@ #ifndef ENTRY_H #define ENTRY_H -#include #include #include #include @@ -20,7 +19,7 @@ public: Entry ( BString ); - bool Filetize ( Config*, bool ); + bool Filetize ( bool ); bool SetTitle ( const char* ); bool SetTitle ( tinyxml2::XMLElement* ); @@ -35,6 +34,4 @@ public: bool SetDate ( tinyxml2::XMLElement* ); }; - - #endif diff --git a/src/Feed.cpp b/src/Feed.cpp index a020d71..c0c7771 100644 --- a/src/Feed.cpp +++ b/src/Feed.cpp @@ -1,17 +1,18 @@ #include +#include "App.h" #include "Entry.h" #include "Config.h" #include "Util.h" #include "Feed.h" -Feed::Feed ( BString path, Config* cfg ) +Feed::Feed ( BString path ) { title = BString( "Untitled Feed" ); description = BString( "Nondescript, N/A." ); homeUrl = BString(""); xmlUrl = BString(""); updated = true; - filePath = GetCachePath( path, cfg ); + filePath = GetCachePath( path ); } Feed::Feed ( ) @@ -25,14 +26,14 @@ Feed::Feed ( ) // ---------------------------------------------------------------------------- void -Feed::Parse ( Config* cfg ) +Feed::Parse ( ) { 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 ) { + if ( tt_lastDate > 0 && ((App*)be_app)->cfg->updateFeeds == true ) { attrLastDate.SetTime_t( tt_lastDate ); minDate = attrLastDate; } @@ -41,7 +42,7 @@ Feed::Parse ( Config* cfg ) // ------------------------------------- BString -Feed::GetCachePath ( BString givenPath, Config* cfg ) +Feed::GetCachePath ( BString givenPath ) { BUrl givenUrl = BUrl( givenPath ); BString protocol = givenUrl.Protocol().String(); @@ -51,11 +52,11 @@ Feed::GetCachePath ( BString givenPath, Config* cfg ) if ( protocol != BString("http") && protocol != BString("https") ) return NULL; - return FetchRemoteFeed( givenPath, cfg ); + return FetchRemoteFeed( givenPath ); } BString -Feed::FetchRemoteFeed ( BString givenPath, Config* cfg ) +Feed::FetchRemoteFeed ( BString givenPath ) { BUrl givenUrl = BUrl( givenPath ); time_t tt_lastDate = 0; @@ -67,13 +68,13 @@ Feed::FetchRemoteFeed ( BString givenPath, Config* cfg ) splitName.Append( givenUrl.Path() ); splitName.ReplaceAll("/", "_"); - BString filename = cfg->cacheDir; + BString filename = ((App*)be_app)->cfg->cacheDir; filename.Append(splitName); BFile* cacheFile = new BFile( filename, B_READ_WRITE | B_CREATE_FILE ); cacheFile->ReadAttr( "LastHash", B_STRING_TYPE, 0, oldHash, 41 ); - if ( cfg->verbose ) + if ( ((App*)be_app)->cfg->verbose ) printf( "Saving %s...\n", givenPath.String() ); webFetch( givenUrl, cacheFile, newHash ); @@ -127,8 +128,9 @@ Feed::xmlCountSiblings ( tinyxml2::XMLElement* xsibling, const char* sibling_nam // ---------------------------------------------------------------------------- bool -Feed::AddEntry ( Config* cfg, Entry* newEntry ) +Feed::AddEntry ( Entry* newEntry ) { + Config* cfg = ((App*)be_app)->cfg; if ( !withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) || !withinDateRange( minDate, newEntry->date, maxDate ) ) return false; diff --git a/src/Feed.h b/src/Feed.h index 245085d..d87ebfe 100644 --- a/src/Feed.h +++ b/src/Feed.h @@ -7,11 +7,10 @@ #include #include #include "Entry.h" -#include "Config.h" class Feed { public: - Feed ( BString, Config* ); + Feed ( BString ); Feed ( ); BString title; @@ -27,9 +26,9 @@ public: BList entries; bool updated; - virtual void Parse ( Config* ); + virtual void Parse ( ); - bool AddEntry ( Config*, Entry* ); + bool AddEntry ( Entry* ); bool SetTitle ( const char* ); bool SetTitle ( tinyxml2::XMLElement* ); bool SetDesc ( const char* ); @@ -43,8 +42,8 @@ public: bool IsAtom ( ); protected: - BString GetCachePath ( BString, Config* ); - BString FetchRemoteFeed ( BString, Config* ); + BString GetCachePath ( BString ); + BString FetchRemoteFeed ( BString ); int xmlCountSiblings ( tinyxml2::XMLElement*, const char* ); }; diff --git a/src/Invocation.cpp b/src/Invocation.cpp index bf2f7fd..09824da 100644 --- a/src/Invocation.cpp +++ b/src/Invocation.cpp @@ -19,9 +19,9 @@ usage ( ) } int -invocation ( int argc, char** argv, Config** cfgPtr ) +invocation ( int argc, char** argv ) { - Config* cfg = *(cfgPtr); + Config* cfg = ((App*)be_app)->cfg; BDateTime maxDate; BDateTime minDate; @@ -44,7 +44,7 @@ invocation ( int argc, char** argv, Config** cfgPtr ) switch (c) { case -1: - freeargInvocation( argc, argv, optind, cfgPtr ); + freeargInvocation( argc, argv, optind ); return 0; case 'h': return usage(); @@ -100,9 +100,9 @@ invocation ( int argc, char** argv, Config** cfgPtr ) // ------------------------------------- void -freeargInvocation ( int argc, char** argv, int optind, Config** cfgPtr ) +freeargInvocation ( int argc, char** argv, int optind ) { - Config* cfg = *(cfgPtr); + Config* cfg = ((App*)be_app)->cfg; if ( optind < argc ) { int freeargc = argc - optind; cfg->targetFeeds = BList( freeargc ); @@ -120,7 +120,7 @@ bool processEntry ( void* entry ) { Entry* entryPtr = (Entry*)entry; - entryPtr->Filetize( main_cfg, false ); + entryPtr->Filetize( false ); return false; } @@ -128,22 +128,22 @@ bool processFeed ( void* feedArg ) { BString* feedStr = (BString*)feedArg; - Feed* testFeed = new Feed( *(feedStr), main_cfg ); + Feed* testFeed = new Feed( *(feedStr) ); BList entries; - if ( testFeed->updated == false && main_cfg->updateFeeds == true ) + if ( testFeed->updated == false && ((App*)be_app)->cfg->updateFeeds == true ) return false; if ( testFeed->IsAtom() ) { AtomFeed* feed = (AtomFeed*)malloc( sizeof(AtomFeed) ); - feed = new AtomFeed( testFeed, main_cfg ); - feed->Parse(main_cfg); + feed = new AtomFeed( testFeed ); + feed->Parse(); entries = feed->entries; } if ( testFeed->IsRss() ) { RssFeed* feed = (RssFeed*)malloc( sizeof(RssFeed) ); - feed = new RssFeed( testFeed, main_cfg ); - feed->Parse(main_cfg); + feed = new RssFeed( testFeed ); + feed->Parse(); entries = feed->entries; } diff --git a/src/Invocation.h b/src/Invocation.h index 9ad2ee4..89c6499 100644 --- a/src/Invocation.h +++ b/src/Invocation.h @@ -4,8 +4,8 @@ #include int usage ( ); -int invocation ( int, char**, Config** ); -void freeargInvocation ( int, char**, int, Config** ); +int invocation ( int, char** ); +void freeargInvocation ( int, char**, int ); bool processItem ( void* ); bool processFeed ( void* ); diff --git a/src/RssFeed.cpp b/src/RssFeed.cpp index 30e793f..6d4f9ed 100644 --- a/src/RssFeed.cpp +++ b/src/RssFeed.cpp @@ -1,5 +1,6 @@ #include #include "Entry.h" +#include "App.h" #include "Config.h" #include "Util.h" #include "RssFeed.h" @@ -10,31 +11,27 @@ RssFeed::RssFeed ( ) description = BString(""); homeUrl = BString(""); xmlUrl = BString(""); + outputDir = ((App*)be_app)->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 -RssFeed::Parse ( Config* cfg ) +RssFeed::Parse ( ) { tinyxml2::XMLDocument xml; entries = BList(); - Feed::Parse( cfg ); + Feed::Parse(); xml.LoadFile( filePath.String() ); tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel"); - RootParse( cfg, xchan ); - ParseEntries( cfg, xchan ); + RootParse( xchan ); + ParseEntries( xchan ); time_t tt_lastDate = lastDate.Time_t(); BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY ); @@ -44,19 +41,19 @@ RssFeed::Parse ( Config* cfg ) // ------------------------------------- void -RssFeed::RootParse ( Config* cfg, tinyxml2::XMLElement* xchan ) +RssFeed::RootParse ( tinyxml2::XMLElement* xchan ) { SetTitle ( xchan->FirstChildElement("title") ); SetDesc ( xchan->FirstChildElement("description") ); SetHomeUrl ( xchan->FirstChildElement("link") ); SetDate ( xchan->FirstChildElement("lastBuildDate") ); - if ( cfg->verbose ) + if ( ((App*)be_app)->cfg->verbose ) printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String()); } void -RssFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xitem ) +RssFeed::EntryParse ( tinyxml2::XMLElement* xitem ) { Entry* newEntry = (Entry*)malloc( sizeof(Entry) ); newEntry = new Entry( outputDir ); @@ -71,11 +68,11 @@ RssFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xitem ) if ( lastDate == NULL || lastDate < newEntry->date ) lastDate = newEntry->date; - AddEntry( cfg, newEntry ); + AddEntry( newEntry ); } void -RssFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xchan ) +RssFeed::ParseEntries ( tinyxml2::XMLElement* xchan ) { tinyxml2::XMLElement* xitem; @@ -84,11 +81,11 @@ RssFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xchan ) int entryCount = xmlCountSiblings( xitem, "item" ); entries = BList(entryCount); - if ( cfg->verbose ) + if ( ((App*)be_app)->cfg->verbose ) printf("\t-%i entries-\n", entryCount); while ( xitem ) { - EntryParse( cfg, xitem ); + EntryParse( xitem ); xitem = xitem->NextSiblingElement("item"); } } diff --git a/src/RssFeed.h b/src/RssFeed.h index 488516c..c0920ae 100644 --- a/src/RssFeed.h +++ b/src/RssFeed.h @@ -6,20 +6,17 @@ #include #include #include -#include "Config.h" #include "Feed.h" class RssFeed: public Feed { public: RssFeed ( ); - RssFeed ( Feed*, Config* ); RssFeed ( Feed* ); - RssFeed ( Config* ); - void Parse ( Config* ); - void RootParse ( Config*, tinyxml2::XMLElement* ); - void EntryParse ( Config*, tinyxml2::XMLElement* ); - void ParseEntries ( Config*, tinyxml2::XMLElement* ); + void Parse ( ); + void RootParse ( tinyxml2::XMLElement* ); + void EntryParse ( tinyxml2::XMLElement* ); + void ParseEntries ( tinyxml2::XMLElement* ); }; #endif