From c0a3763148d9b0f719361546d1927763507946eb Mon Sep 17 00:00:00 2001 From: Andreas Krennmair Date: Sat, 18 Nov 2006 10:31:07 +0000 Subject: Andreas Krennmair: implemented OPML export --- include/controller.h | 6 +++++- noos.cpp | 2 +- src/controller.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/include/controller.h b/include/controller.h index 94152d48..ab164d3d 100644 --- a/include/controller.h +++ b/include/controller.h @@ -14,12 +14,16 @@ namespace noos { controller(); ~controller(); void set_view(view * vv); - void run(); + void run(int argc = 0, char * argv[] = NULL); void open_feed(unsigned int pos); void open_item(rss_item& item); void reload(unsigned int pos); void reload_all(); private: + void usage(char * argv0); + void import_opml(char * filename); + void export_opml(); + view * v; configreader cfg; cache * rsscache; diff --git a/noos.cpp b/noos.cpp index 2a2b61f7..7c4b6ba9 100644 --- a/noos.cpp +++ b/noos.cpp @@ -13,7 +13,7 @@ int main(int argc, char * argv[]) { view v(&c); c.set_view(&v); - c.run(); + c.run(argc,argv); return 0; } diff --git a/src/controller.cpp b/src/controller.cpp index 2690cd01..a861e86b 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -12,7 +12,7 @@ controller::controller() : v(0), rsscache(0) { cfg.load_config(cfgfile.str()); if (cfg.get_urls().size() == 0) { - std::cerr << "error: no URLs configured." << std::endl; + std::cout << "error: no URLs configured." << std::endl; ::exit(1); } @@ -24,8 +24,8 @@ controller::controller() : v(0), rsscache(0) { rsscache->internalize_rssfeed(feed); feeds.push_back(feed); } - rsscache->cleanup_cache(feeds); + } controller::~controller() { @@ -37,7 +37,21 @@ void controller::set_view(view * vv) { v = vv; } -void controller::run() { +void controller::run(int argc, char * argv[]) { + if (argc>1) { + if (strcmp(argv[1],"-e")==0) { + export_opml(); + } else if (strcmp(argv[1],"-i")==0) { + if (argc>2) { + import_opml(argv[2]); + } else { + usage(argv[0]); + } + } else + usage(argv[0]); + return; + } + v->set_feedlist(feeds); v->run_feedlist(); } @@ -90,3 +104,26 @@ void controller::reload_all() { this->reload(i); } } + +void controller::usage(char * argv0) { + std::cout << argv0 << ": usage: " << argv0 << " [-i |-e]" << std::endl; + std::cout << "\t-e\texport OPML feed to stdout" << std::endl; + std::cout << "\t-i \timport OPML file" << std::endl; + ::exit(1); +} + +void controller::import_opml(char * filename) { + std::cout << "Error: unimplemented!" << std::endl; +} + +void controller::export_opml() { + std::cout << "" << std::endl; + std::cout << "" << std::endl; + std::cout << "\t" << std::endl << "\t\tnoos - Exported Feeds" << std::endl << "\t" << std::endl; + std::cout << "\t" << std::endl; + for (std::vector::iterator it=feeds.begin(); it != feeds.end(); ++it) { + std::cout << "\t\trssurl() << "\" text=\"" << it->title() << "\" />" << std::endl; + } + std::cout << "\t" << std::endl; + std::cout << "" << std::endl; +} -- cgit v1.2.3