Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
Merge 930605c into e0f9100
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlon1 committed Aug 24, 2017
2 parents e0f9100 + 930605c commit cb058a7
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 26 deletions.
3 changes: 2 additions & 1 deletion include/utils.h
Expand Up @@ -135,7 +135,8 @@ class utils {
static std::string make_title(const std::string& url);

static int run_interactively(
const std::string& command, const std::string& caller);
const std::string& command, const std::string& caller)
__attribute__ ((warn_unused_result));

static std::string getcwd();

Expand Down
4 changes: 2 additions & 2 deletions include/view.h
Expand Up @@ -67,8 +67,8 @@ class view {
std::string select_tag();
std::string select_filter(const std::vector<filter_name_expr_pair>& filters);

bool open_in_browser(const std::string& url);
void open_in_pager(const std::string& filename);
bool open_in_browser(const std::string& url) __attribute__ ((warn_unused_result));;
bool open_in_pager(const std::string& filename) __attribute__ ((warn_unused_result));

std::string get_filename_suggestion(const std::string& s);

Expand Down
14 changes: 12 additions & 2 deletions src/controller.cpp
Expand Up @@ -1317,7 +1317,14 @@ void controller::edit_urls_file() {
v->push_empty_formaction();
stfl::reset();

utils::run_interactively(cmdline, "controller::edit_urls_file");
/* We should not check this particular exit code.
* Editors usually fail when closing+saving (and stay open).
* (tested with vim, nano, gedit, geany)
* (texmaker 5.0.1 and notepadqq 1.0.1 close without neither showing an
* error nor saving but despite return 0)
*/
int unused __attribute__((unused));
unused = utils::run_interactively(cmdline, "controller::edit_urls_file");

v->pop_current_formaction();

Expand Down Expand Up @@ -1356,7 +1363,10 @@ std::string controller::bookmark(
if (is_interactive) {
v->push_empty_formaction();
stfl::reset();
utils::run_interactively(cmdline, "controller::bookmark");
int bookmark_cmd_exit_code = utils::run_interactively(cmdline, "controller::bookmark");
if (bookmark_cmd_exit_code != 0) {
return "The bookmark command failed!";
}
v->pop_current_formaction();
return "";
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/feedlist_formaction.cpp
Expand Up @@ -162,7 +162,10 @@ void feedlist_formaction::process_operation(operation op, bool automatic, std::v
if (feed) {
if (feed->rssurl().substr(0,6) != "query:") {
LOG(level::INFO, "feedlist_formaction: opening feed at position `%s': %s", feedpos, feed->link());
v->open_in_browser(feed->link());
if (!v->open_in_browser(feed->link())) {
v->show_error(_("Browser failed to open the link!"));
}

} else {
v->show_error(_("Cannot open query feeds in the browser!"));
}
Expand Down
8 changes: 4 additions & 4 deletions src/itemlist_formaction.cpp
Expand Up @@ -84,9 +84,7 @@ void itemlist_formaction::process_operation(operation op, bool automatic, std::v
LOG(level::INFO, "itemlist_formaction: opening item at pos `%s'", itemposname);
if (itemposname.length() > 0 && visible_items.size() != 0) {
if (itempos < visible_items.size()) {

bool browser_success = v->open_in_browser(visible_items[itempos].first->link());
if (!browser_success) {
if (!v->open_in_browser(visible_items[itempos].first->link())) {
v->show_error(_("Browser failed to open the link!"));
break;
}
Expand All @@ -112,7 +110,9 @@ void itemlist_formaction::process_operation(operation op, bool automatic, std::v
LOG(level::INFO, "itemlist_formaction: opening item at pos `%s'", itemposname);
if (itemposname.length() > 0 && visible_items.size() != 0) {
if (itempos < visible_items.size()) {
v->open_in_browser(visible_items[itempos].first->link());
if (!v->open_in_browser(visible_items[itempos].first->link())) {
v->show_error(_("Browser failed to open the link!"));
}
invalidate(itempos);
}
} else {
Expand Down
12 changes: 9 additions & 3 deletions src/itemview_formaction.cpp
Expand Up @@ -211,7 +211,9 @@ void itemview_formaction::process_operation(operation op, bool automatic, std::v
case OP_OPENINBROWSER:
LOG(level::INFO, "view::run_itemview: starting browser");
v->set_status(_("Starting browser..."));
v->open_in_browser(item->link());
if (!v->open_in_browser(item->link())) {
v->show_error(_("Browser failed to open the link!"));
}
v->set_status("");
break;
case OP_BOOKMARK:
Expand Down Expand Up @@ -370,7 +372,9 @@ void itemview_formaction::process_operation(operation op, bool automatic, std::v
LOG(level::DEBUG, "itemview::run: OP_1 = %d op = %d idx = %u", OP_1, op, idx);
if (idx < links.size()) {
v->set_status(_("Starting browser..."));
v->open_in_browser(links[idx].first);
if (!v->open_in_browser(links[idx].first)) {
v->show_error(_("Browser failed to open the link!"));
}
v->set_status("");
}
}
Expand Down Expand Up @@ -518,7 +522,9 @@ void itemview_formaction::finished_qna(operation op) {
sscanf(qna_responses[0].c_str(),"%u",&idx);
if (idx && idx-1 < links.size()) {
v->set_status(_("Starting browser..."));
v->open_in_browser(links[idx-1].first);
if (!v->open_in_browser(links[idx-1].first)) {
v->show_error(_("Browser failed to open the link!"));
}
v->set_status("");
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/list_formaction.cpp
Expand Up @@ -12,9 +12,12 @@ void list_formaction::open_unread_items_in_browser(std::shared_ptr<rss_feed> fee
for (auto item : feed->items()) {
if (tabcount < v->get_cfg()->get_configvalue_as_int("max-browser-tabs")) {
if (item->unread()) {
v->open_in_browser(item->link());
tabcount += 1;
item->set_unread(!markread);
if (v->open_in_browser(item->link())) {
tabcount += 1;
item->set_unread(!markread);
} else {
v->show_error(_("Browser failed to open the link!"));
}
}
} else {
break;
Expand Down
4 changes: 3 additions & 1 deletion src/pb_controller.cpp
Expand Up @@ -371,7 +371,9 @@ void pb_controller::play_file(const std::string& file) {
cmdline.append(utils::replace_all(file,"\"", "\\\""));
cmdline.append("\"");
stfl::reset();
utils::run_interactively(cmdline, "pb_controller::play_file");
// Is the following exit code important?
int unused __attribute__((unused));
unused = utils::run_interactively(cmdline, "pb_controller::play_file");
}


Expand Down
8 changes: 6 additions & 2 deletions src/urlview_formaction.cpp
Expand Up @@ -30,7 +30,9 @@ void urlview_formaction::process_operation(operation op, bool /* automatic */, s
if (posstr.length() > 0) {
unsigned int idx = utils::to_u(posstr, 0);
v->set_status(_("Starting browser..."));
v->open_in_browser(links[idx].first);
if (!v->open_in_browser(links[idx].first)) {
v->show_error(_("Browser failed to open the link!"));
}
v->set_status("");
} else {
v->show_error(_("No link selected!"));
Expand Down Expand Up @@ -63,7 +65,9 @@ void urlview_formaction::process_operation(operation op, bool /* automatic */, s

if (idx < links.size()) {
v->set_status(_("Starting browser..."));
v->open_in_browser(links[idx].first);
if (!v->open_in_browser(links[idx].first)) {
v->show_error(_("Browser failed to open the link!"));
}
v->set_status("");
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils.cpp
Expand Up @@ -1102,6 +1102,11 @@ int utils::run_interactively(
} else if (status == 127) {
LOG(level::DEBUG, "%s: couldn't run shell", caller);
}
if (status != 0) {
LOG(level::DEBUG, "utils::run_interactively: "
"%s: cmd = %s, returned %d", caller, command, status);
}


return status;
}
Expand Down
14 changes: 7 additions & 7 deletions src/view.cpp
Expand Up @@ -311,7 +311,7 @@ void view::push_empty_formaction() {
current_formaction = formaction_stack_size() - 1;
}

void view::open_in_pager(const std::string& filename) {
bool view::open_in_pager(const std::string& filename) {
formaction_stack.push_back(std::shared_ptr<formaction>());
current_formaction = formaction_stack_size() - 1;
std::string cmdline;
Expand All @@ -332,8 +332,9 @@ void view::open_in_pager(const std::string& filename) {
cmdline.append(filename);
}
stfl::reset();
utils::run_interactively(cmdline, "view::open_in_pager");
int pager_exit_code = utils::run_interactively(cmdline, "view::open_in_pager");
pop_current_formaction();
return pager_exit_code == 0;
}

bool view::open_in_browser(const std::string& url) {
Expand All @@ -360,10 +361,6 @@ bool view::open_in_browser(const std::string& url) {
}
stfl::reset();
int browser_exit_code = utils::run_interactively(cmdline, "view::open_in_browser");
if (browser_exit_code != 0) {
LOG(level::DEBUG, "utils::run_interactively: "
"Starting the browser failed with error code %d - command was %s", browser_exit_code, cmdline);
}
pop_current_formaction();

return browser_exit_code == 0;
Expand Down Expand Up @@ -480,7 +477,10 @@ void view::push_itemview(std::shared_ptr<rss_feed> f, const std::string& guid, c
} else {
std::shared_ptr<rss_item> item = f->get_item_by_guid(guid);
std::string filename = get_ctrl()->write_temporary_item(item);
open_in_pager(filename);
if (!open_in_pager(filename)) {
show_error(_("Pager failed to show the item!"));
return;
}
try {
bool old_unread = item->unread();
item->set_unread(false);
Expand Down

0 comments on commit cb058a7

Please sign in to comment.