diff options
author | 2006-11-12 18:37:58 +0000 | |
---|---|---|
committer | 2006-11-12 18:37:58 +0000 | |
commit | 50366a504f098ca4c0c7e75d1421fb0d3b0255c4 (patch) | |
tree | c7dc13ead994a035be328e1b1d9bf0457f854573 /src | |
parent | 64e626c79f67d62b23fc189032fc0d9804a9216f (diff) | |
download | newsboat-50366a504f098ca4c0c7e75d1421fb0d3b0255c4.tar.gz newsboat-50366a504f098ca4c0c7e75d1421fb0d3b0255c4.tar.zst newsboat-50366a504f098ca4c0c7e75d1421fb0d3b0255c4.zip |
Andreas Krennmair:
added unread flag.
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.cpp | 28 | ||||
-rw-r--r-- | src/controller.cpp | 4 | ||||
-rw-r--r-- | src/rss.cpp | 2 | ||||
-rw-r--r-- | src/view.cpp | 63 |
4 files changed, 71 insertions, 26 deletions
diff --git a/src/cache.cpp b/src/cache.cpp index f4f34cb3..bd90e51b 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -45,7 +45,7 @@ static int rssfeed_callback(void * myfeed, int argc, char ** argv, char ** azCol static int rssitem_callback(void * myfeed, int argc, char ** argv, char ** azColName) { rss_feed * feed = (rss_feed *)myfeed; - assert (argc == 6); + assert (argc == 7); rss_item item; item.guid() = argv[0]; item.title() = argv[1]; @@ -53,6 +53,7 @@ static int rssitem_callback(void * myfeed, int argc, char ** argv, char ** azCol item.link() = argv[3]; item.pubDate() = argv[4]; item.description() = argv[5]; + item.unread() = (std::string("1") == argv[6]); feed->items().push_back(item); return 0; } @@ -100,7 +101,8 @@ void cache::populate_tables() { " url VARCHAR(1024) NOT NULL, " " feedurl VARCHAR(1024) NOT NULL, " " pubDate DATETIME NOT NULL, " - " content VARCHAR(65535) NOT NULL );", NULL, NULL, NULL); + " content VARCHAR(65535) NOT NULL," + " unread INT(1) NOT NULL );", NULL, NULL, NULL); } @@ -131,20 +133,30 @@ void cache::externalize_rssfeed(rss_feed& feed) { assert(rc == SQLITE_OK); free(query); if (count_cbh.count() > 0) { - char * update = sqlite3_mprintf("UPDATE rss_item SET title = '%q', author = '%q', url = '%q', feedurl = '%q', pubDate = '%q', content = '%q' WHERE guid = '%q'", - it->title().c_str(), it->author().c_str(), it->link().c_str(), - feed.rssurl().c_str(), it->pubDate().c_str(), it->description().c_str(), it->guid().c_str()); + char * update; + + if (!it->unread()) { + update = sqlite3_mprintf("UPDATE rss_item SET title = '%q', author = '%q', url = '%q', feedurl = '%q', pubDate = '%q', content = '%q', unread = '0' WHERE guid = '%q'", + it->title().c_str(), it->author().c_str(), it->link().c_str(), + feed.rssurl().c_str(), it->pubDate().c_str(), it->description().c_str(), it->guid().c_str()); + } else { + update = sqlite3_mprintf("UPDATE rss_item SET title = '%q', author = '%q', url = '%q', feedurl = '%q', pubDate = '%q', content = '%q' WHERE guid = '%q'", + it->title().c_str(), it->author().c_str(), it->link().c_str(), + feed.rssurl().c_str(), it->pubDate().c_str(), it->description().c_str(), it->guid().c_str()); + } rc = sqlite3_exec(db,update,NULL,NULL,NULL); assert(rc == SQLITE_OK); + std::cerr << "item update query:" << update << " |" << std::endl; free(update); } else { - char * insert = sqlite3_mprintf("INSERT INTO rss_item (guid,title,author,url,feedurl,pubDate,content) " - "VALUES ('%q','%q','%q','%q','%q','%q','%q')", + char * insert = sqlite3_mprintf("INSERT INTO rss_item (guid,title,author,url,feedurl,pubDate,content,unread) " + "VALUES ('%q','%q','%q','%q','%q','%q','%q',1)", it->guid().c_str(), it->title().c_str(), it->author().c_str(), it->link().c_str(), feed.rssurl().c_str(), it->pubDate().c_str(), it->description().c_str()); rc = sqlite3_exec(db,insert,NULL,NULL,NULL); assert(rc == SQLITE_OK); free(insert); + std::cerr << "item insert" << std::endl; } } } @@ -170,7 +182,7 @@ void cache::internalize_rssfeed(rss_feed& feed) { feed.items().erase(feed.items().begin(),feed.items().end()); } - query = sqlite3_mprintf("SELECT guid,title,author,url,pubDate,content FROM rss_item WHERE feedurl = '%q';",feed.rssurl().c_str()); + query = sqlite3_mprintf("SELECT guid,title,author,url,pubDate,content,unread FROM rss_item WHERE feedurl = '%q';",feed.rssurl().c_str()); rc = sqlite3_exec(db,query,rssitem_callback,&feed,NULL); assert(rc == SQLITE_OK); free(query); diff --git a/src/controller.cpp b/src/controller.cpp index 17e8d779..146228b1 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -42,6 +42,7 @@ void controller::run() { void controller::open_item(rss_item& item) { v->run_itemview(item); + item.unread() = false; // XXX: see TODO list } void controller::open_feed(unsigned int pos) { @@ -56,6 +57,8 @@ void controller::open_feed(unsigned int pos) { v->feedlist_error("Error: feed contains no items!"); } else { v->run_itemlist(feed); + rsscache->externalize_rssfeed(feed); // save possibly changed unread flags + v->set_feedlist(feeds); } } else { v->feedlist_error("Error: invalid feed!"); @@ -72,6 +75,7 @@ void controller::reload(unsigned int pos) { parser.parse(); feeds[pos] = parser.get_feed(); rsscache->externalize_rssfeed(feeds[pos]); + rsscache->internalize_rssfeed(feeds[pos]); v->feedlist_status(""); v->set_feedlist(feeds); } else { diff --git a/src/rss.cpp b/src/rss.cpp index 471ea2e2..18b3eaaf 100644 --- a/src/rss.cpp +++ b/src/rss.cpp @@ -34,7 +34,7 @@ void rss_parser::parse() { if (item->author) x.author() = item->author; if (item->description) x.description() = item->description; if (item->pubDate) x.pubDate() = item->pubDate; - if (item->guid) + if (item->guid) x.guid() = item->guid; else x.guid() = item->link; // XXX hash something to get a better alternative GUID diff --git a/src/view.cpp b/src/view.cpp index dd9f997a..70a62671 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -103,29 +103,40 @@ void view::run_feedlist() { void view::run_itemlist(rss_feed& feed) { bool quit = false; - + bool rebuild_list = true; std::vector<rss_item>& items = feed.items(); - std::string code = "{list"; + do { + if (rebuild_list) { + + std::string code = "{list"; + + unsigned int i=0; + for (std::vector<rss_item>::iterator it = items.begin(); it != items.end(); ++it, ++i) { + std::string line = "{listitem["; + std::ostringstream x; + x << i; + line.append(x.str()); + line.append("] text:"); + std::string title = " "; + if (it->unread()) { + title.append("N "); + } else { + title.append(" "); + } + title.append(it->title()); + line.append(stfl_quote(title.c_str())); + line.append("}"); + code.append(line); + } - unsigned int i=0; - for (std::vector<rss_item>::iterator it = items.begin(); it != items.end(); ++it, ++i) { - std::string line = "{listitem["; - std::ostringstream x; - x << i; - line.append(x.str()); - line.append("] text:"); - std::string title = it->title(); - line.append(stfl_quote(title.c_str())); - line.append("}"); - code.append(line); - } + code.append("}"); - code.append("}"); + stfl_modify(itemlist_form,"items","replace_inner",code.c_str()); - stfl_modify(itemlist_form,"items","replace_inner",code.c_str()); + rebuild_list = false; + } - do { const char * event = stfl_run(itemlist_form,0); if (!event) continue; @@ -136,6 +147,7 @@ void view::run_itemlist(rss_feed& feed) { unsigned int pos = 0; posname >> pos; ctrl->open_item(items[pos]); + rebuild_list = true; } else { itemlist_error("Error: no item selected!"); // should not happen } @@ -233,6 +245,23 @@ void view::set_feedlist(std::vector<rss_feed>& feeds) { if (title == "") { title = it->rssurl(); // rssurl must always be present. } + + // TODO: refactor + char buf[20]; + char buf2[20]; + unsigned int unread_count = 0; + if (it->items().size() > 0) { + for (std::vector<rss_item>::iterator rit = it->items().begin(); rit != it->items().end(); ++rit) { + if (rit->unread()) + ++unread_count; + } + } + snprintf(buf,sizeof(buf),"(%u/%u) ",unread_count,it->items().size()); + snprintf(buf2,sizeof(buf2),"%14s",buf); + std::string newtitle(buf2); + newtitle.append(title); + title = newtitle; + std::string line = "{listitem["; std::ostringstream num; num << i; |