summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Andreas Krennmair <ak@synflood.at> 2006-11-18 10:31:07 +0000
committerGravatar Andreas Krennmair <ak@synflood.at> 2006-11-18 10:31:07 +0000
commitc0a3763148d9b0f719361546d1927763507946eb (patch)
tree8029b495fc9ee701520c6eb4a4f39d8e512d741a
parent5829a787ef76afd9dbc88c4e92e0fdc622db7b14 (diff)
downloadnewsboat-c0a3763148d9b0f719361546d1927763507946eb.tar.gz
newsboat-c0a3763148d9b0f719361546d1927763507946eb.tar.zst
newsboat-c0a3763148d9b0f719361546d1927763507946eb.zip
Andreas Krennmair:
implemented OPML export
-rw-r--r--include/controller.h6
-rw-r--r--noos.cpp2
-rw-r--r--src/controller.cpp43
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 <file>|-e]" << std::endl;
+ std::cout << "\t-e\texport OPML feed to stdout" << std::endl;
+ std::cout << "\t-i <file>\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 << "<?xml version=\"1.0\"?>" << std::endl;
+ std::cout << "<opml version=\"1.0\">" << std::endl;
+ std::cout << "\t<head>" << std::endl << "\t\t<title>noos - Exported Feeds</title>" << std::endl << "\t</head>" << std::endl;
+ std::cout << "\t<body>" << std::endl;
+ for (std::vector<rss_feed>::iterator it=feeds.begin(); it != feeds.end(); ++it) {
+ std::cout << "\t\t<outline type=\"rss\" xmlUrl=\"" << it->rssurl() << "\" text=\"" << it->title() << "\" />" << std::endl;
+ }
+ std::cout << "\t</body>" << std::endl;
+ std::cout << "</opml>" << std::endl;
+}