aboutsummaryrefslogtreecommitdiff
path: root/src/listformaction.cpp
blob: 747f35f4cbcfdbefb606785e872e5280f1ded15d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "listformaction.h"

#include "controller.h"
#include "rssfeed.h"
#include "view.h"

namespace newsboat {

ListFormAction::ListFormAction(View& v,
	const std::string& context,
	std::string formstr,
	std::string list_name,
	ConfigContainer* cfg, RegexManager& r)
	: FormAction(v, formstr, cfg)
	, list(list_name, context, FormAction::f, r, cfg->get_configvalue_as_int("scrolloff"))
{
}

bool ListFormAction::process_operation(Operation op,
	const std::vector<std::string>& /* args */,
	BindingType /*bindingType*/)
{
	switch (op) {
	case OP_CMD_START_1:
		FormAction::start_cmdline("1");
		break;
	case OP_CMD_START_2:
		FormAction::start_cmdline("2");
		break;
	case OP_CMD_START_3:
		FormAction::start_cmdline("3");
		break;
	case OP_CMD_START_4:
		FormAction::start_cmdline("4");
		break;
	case OP_CMD_START_5:
		FormAction::start_cmdline("5");
		break;
	case OP_CMD_START_6:
		FormAction::start_cmdline("6");
		break;
	case OP_CMD_START_7:
		FormAction::start_cmdline("7");
		break;
	case OP_CMD_START_8:
		FormAction::start_cmdline("8");
		break;
	case OP_CMD_START_9:
		FormAction::start_cmdline("9");
		break;

	default:
		if (handle_list_operations(list, op)) {
			break;
		}
		break;
	}
	return true;
}

nonstd::optional<std::uint8_t> ListFormAction::open_unread_items_in_browser(
	std::shared_ptr<RssFeed> feed,
	bool markread)
{
	int tabcount = 0;
	nonstd::optional<std::uint8_t> return_value = 0;
	std::vector<std::string> guids_of_read_articles;
	for (const auto& item : feed->items()) {
		if (tabcount <
			cfg->get_configvalue_as_int("max-browser-tabs")) {
			if (item->unread()) {
				const bool interactive = true;
				const auto exit_code = v.open_in_browser(item->link(), item->feedurl(),
						"article", item->title(), interactive);
				if (!exit_code.has_value() || *exit_code != 0) {
					return_value = exit_code;
					break;
				}

				tabcount += 1;
				if (markread) {
					item->set_unread(false);
					guids_of_read_articles.push_back(item->guid());
				}
			}
		} else {
			break;
		}
	}

	if (guids_of_read_articles.size() > 0) {
		v.get_ctrl()->mark_all_read(guids_of_read_articles);
	}

	return return_value;
}

} // namespace newsboat