9
9
#include <formatstring.h>
11
#include <listformatter.h>
14
18
#define FILTER_UNREAD_FEEDS "unread_count != \"0\""
16
20
namespace newsbeuter {
18
22
feedlist_formaction::feedlist_formaction(view * vv, std::string formstr)
19
23
: formaction(vv,formstr), zero_feedpos(false), feeds_shown(0),
20
auto_open(false), quit(false), apply_filter(false), search_dummy_feed(v->get_ctrl()->get_cache()) {
24
auto_open(false), quit(false), apply_filter(false), search_dummy_feed(v->get_ctrl()->get_cache()),
25
filterpos(0), set_filterpos(false) {
21
26
assert(true==m.parse(FILTER_UNREAD_FEEDS));
286
void feedlist_formaction::update_visible_feeds(std::vector<rss_feed>& feeds) {
287
assert(v->get_cfg() != NULL); // must not happen
289
if (visible_feeds.size() > 0)
290
visible_feeds.erase(visible_feeds.begin(), visible_feeds.end());
294
for (std::vector<rss_feed>::iterator it = feeds.begin(); it != feeds.end(); ++it, ++i) {
295
if ((tag == "" || it->matches_tag(tag)) && (!apply_filter || m.matches(&(*it)))) {
296
visible_feeds.push_back(feedptr_pos_pair(&(*it),i));
300
feeds_shown = visible_feeds.size();
264
303
void feedlist_formaction::set_feedlist(std::vector<rss_feed>& feeds) {
265
std::string code = "{list";
267
304
assert(v->get_cfg() != NULL); // must not happen
269
306
std::string listwidth = f->get("feeds:w");
271
308
unsigned int width;
275
311
unsigned int i = 0;
276
312
unsigned short feedlist_number = 1;
277
313
unsigned int unread_feeds = 0;
279
if (visible_feeds.size() > 0)
280
visible_feeds.erase(visible_feeds.begin(), visible_feeds.end());
282
315
std::string feedlist_format = v->get_cfg()->get_configvalue("feedlist-format");
284
for (std::vector<rss_feed>::iterator it = feeds.begin(); it != feeds.end(); ++it, ++i, ++feedlist_number) {
286
std::string title = it->title();
317
listformatter listfmt;
319
update_visible_feeds(feeds);
321
for (std::vector<feedptr_pos_pair>::iterator it = visible_feeds.begin(); it != visible_feeds.end(); ++it, ++i, ++feedlist_number) {
322
std::string title = it->first->title();
287
323
if (title.length()==0) {
288
title = it->rssurl(); // rssurl must always be present.
324
title = it->first->rssurl(); // rssurl must always be present.
289
325
if (title.length()==0) {
290
326
title = "<no title>"; // shouldn't happen
297
330
unsigned int unread_count = 0;
298
if (it->items().size() > 0) {
299
unread_count = it->unread_item_count();
331
if (it->first->items().size() > 0) {
332
unread_count = it->first->unread_item_count();
301
334
if (unread_count > 0)
305
* we only display an entry in the feedlist if:
306
* - no tag is active, or the entry matches the currently selected tag
307
* - no filter shall be applied, or the entry matches the currently set filter
309
if ((tag == "" || it->matches_tag(tag)) && (!apply_filter || m.matches(&(*it)))) {
310
visible_feeds.push_back(feedptr_pos_pair(&(*it),i));
312
fmtstr_formatter fmt;
314
snprintf(idxbuf, sizeof(idxbuf),"%u", feedlist_number);
315
snprintf(sbuf,sizeof(sbuf),"(%u/%u)",unread_count,static_cast<unsigned int>(it->items().size()));
317
fmt.register_fmt('i', idxbuf);
318
fmt.register_fmt('u', sbuf);
319
fmt.register_fmt('n', unread_count > 0 ? "N" : " ");
320
fmt.register_fmt('t', title);
321
fmt.register_fmt('l', it->link());
322
fmt.register_fmt('L', it->rssurl());
323
fmt.register_fmt('d', it->description());
325
std::string line = "{listitem[";
326
std::ostringstream num;
328
line.append(num.str());
329
line.append("] text:");
330
line.append(stfl::quote(fmt.do_format(feedlist_format, width)));
337
fmtstr_formatter fmt;
339
fmt.register_fmt('i', utils::strprintf("%u", it->second + 1));
340
fmt.register_fmt('u', utils::strprintf("(%u/%u)",unread_count,static_cast<unsigned int>(it->first->items().size())));
341
fmt.register_fmt('n', unread_count > 0 ? "N" : " ");
342
fmt.register_fmt('t', title);
343
fmt.register_fmt('l', it->first->link());
344
fmt.register_fmt('L', it->first->rssurl());
345
fmt.register_fmt('d', it->first->description());
347
std::string format = fmt.do_format(feedlist_format, width);
348
GetLogger().log(LOG_DEBUG, "feedlist_formaction::set_feedlist: format result = %s", format.c_str());
350
listfmt.add_line(format, it->second);
341
f->modify("feeds","replace_inner",code);
353
f->modify("feeds","replace_inner",listfmt.format_list());
343
355
std::string title_format = v->get_cfg()->get_configvalue("feedlist-title-format");
393
403
GetLogger().log(LOG_DEBUG, "feedlist_formaction::jump_to_previous_unread_feed: visible_feeds[%u] unread items: %u", i, visible_feeds[i].first->unread_item_count());
394
404
if (visible_feeds[i].first->unread_item_count() > 0) {
395
405
GetLogger().log(LOG_DEBUG, "feedlist_formaction::jump_to_previous_unread_feed: hit");
396
std::ostringstream os;
398
f->set("feedpos", os.str());
406
f->set("feedpos", utils::to_s(i));
407
feedpos = visible_feeds[i].second;
414
void feedlist_formaction::goto_feed(const std::string& str) {
416
std::istringstream is(f->get("feedpos"));
418
GetLogger().log(LOG_DEBUG, "feedlist_formaction::goto_feed: curpos = %u str = `%s'", curpos, str.c_str());
419
for (unsigned int i=curpos+1;i<visible_feeds.size();++i) {
420
if (strcasestr(visible_feeds[i].first->title().c_str(), str.c_str()) != NULL) {
421
f->set("feedpos", utils::to_s(i));
425
for (unsigned int i=0;i<=curpos;++i) {
426
if (strcasestr(visible_feeds[i].first->title().c_str(), str.c_str()) != NULL) {
427
f->set("feedpos", utils::to_s(i));
405
433
bool feedlist_formaction::jump_to_next_unread_feed(unsigned int& feedpos) {
406
434
unsigned int curpos;
407
435
std::istringstream is(f->get("feedpos"));
512
539
searchhistory.add_line(searchphrase);
513
540
std::vector<rss_item> items;
515
items = v->get_ctrl()->search_for_items(searchphrase, "");
542
std::string utf8searchphrase = utils::convert_text(searchphrase, "utf-8", nl_langinfo(CODESET));
543
items = v->get_ctrl()->search_for_items(utf8searchphrase, "");
516
544
} catch (const dbexception& e) {
518
snprintf(buf, sizeof(buf), _("Error while searching for `%s': %s"), searchphrase.c_str(), e.what());
545
v->show_error(utils::strprintf(_("Error while searching for `%s': %s"), searchphrase.c_str(), e.what()));
522
548
if (items.size() > 0) {
562
void feedlist_formaction::mark_pos_if_visible(unsigned int pos) {
563
scope_measure m1("feedlist_formaction::mark_pos_if_visible");
564
unsigned int vpos = 0;
565
v->get_ctrl()->update_visible_feeds();
566
for (std::vector<feedptr_pos_pair>::iterator it=visible_feeds.begin();it!=visible_feeds.end();++it, ++vpos) {
567
if (it->second == pos) {
568
GetLogger().log(LOG_DEBUG, "feedlist_formaction::mark_pos_if_visible: match, setting position to %u", vpos);
569
f->set("feedpos", utils::to_s(vpos));
575
void feedlist_formaction::save_filterpos() {
576
std::istringstream is(f->get("feedpos"));
579
if (i<visible_feeds.size()) {
580
filterpos = visible_feeds[i].second;
581
set_filterpos = true;