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
99
100
101
102
103
104
105
106
107
108
109
|
#include <urlview_formaction.h>
#include <formatstring.h>
#include <view.h>
#include <config.h>
#include <sstream>
namespace newsbeuter {
/*
* The urlview_formaction is probably the simplest dialog of all. It
* displays a list of URLs, and makes it possible to open the URLs
* in a browser or to bookmark them.
*/
urlview_formaction::urlview_formaction(view * vv, std::string formstr)
: formaction(vv, formstr), quit(false) { }
urlview_formaction::~urlview_formaction() {
}
void urlview_formaction::process_operation(operation op, bool /* automatic */, std::vector<std::string> * /* args */) {
switch (op) {
case OP_OPEN:
{
std::string posstr = f->get("feedpos");
if (posstr.length() > 0) {
std::istringstream is(posstr);
unsigned int idx;
is >> idx;
v->set_status(_("Starting browser..."));
v->open_in_browser(links[idx].first);
v->set_status("");
} else {
v->show_error(_("No link selected!"));
}
}
break;
case OP_BOOKMARK: {
std::string posstr = f->get("feedpos");
if (posstr.length() > 0) {
std::istringstream is(posstr);
unsigned int idx;
is >> idx;
this->start_bookmark_qna("", links[idx].first, "");
} else {
v->show_error(_("No link selected!"));
}
}
break;
case OP_QUIT:
quit = true;
break;
default: // nothing
break;
}
if (quit) {
v->pop_current_formaction();
}
}
void urlview_formaction::prepare() {
if (do_redraw) {
std::string code = "{list";
unsigned int i=0;
for (std::vector<linkpair>::iterator it = links.begin(); it != links.end(); ++it, ++i) {
std::ostringstream os;
char line[1024];
snprintf(line,sizeof(line),"%2u %s",i+1,it->first.c_str());
os << "{listitem[" << i << "] text:" << stfl::quote(line) << "}";
code.append(os.str());
}
code.append("}");
f->modify("urls","replace_inner",code);
}
}
void urlview_formaction::init() {
v->set_status("");
std::string viewwidth = f->get("urls:w");
std::istringstream is(viewwidth);
unsigned int width;
is >> width;
fmtstr_formatter fmt;
fmt.register_fmt('N', PROGRAM_NAME);
fmt.register_fmt('V', PROGRAM_VERSION);
f->set("head", fmt.do_format(v->get_cfg()->get_configvalue("urlview-title-format"), width));
do_redraw = true;
quit = false;
set_keymap_hints();
}
keymap_hint_entry * urlview_formaction::get_keymap_hint() {
static keymap_hint_entry hints[] = {
{ OP_QUIT, _("Quit") },
{ OP_OPEN, _("Open in Browser") },
{ OP_BOOKMARK, _("Save Bookmark") },
{ OP_NIL, NULL }
};
return hints;
}
}
|