aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Info.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-17 19:28:51 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-17 19:28:51 +0200
commit177eade2d2c09e8a9ef4c320a0f0426d2480e07b (patch)
treed4c9220ce6016fe82dbe40009d944d0d4cda5bed /src/plugins/Info.cpp
parent42de171702b8a52a01661a25db56dde44f3754d6 (diff)
Add ctrl+i to either open urls in browser or reverse image search. Also fix ctrl+c copy with missing title
Diffstat (limited to 'src/plugins/Info.cpp')
-rw-r--r--src/plugins/Info.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/plugins/Info.cpp b/src/plugins/Info.cpp
new file mode 100644
index 0000000..b1943b3
--- /dev/null
+++ b/src/plugins/Info.cpp
@@ -0,0 +1,47 @@
+#include "../../plugins/Info.hpp"
+#include "../../plugins/Saucenao.hpp"
+#include "../../include/StringUtils.hpp"
+#include "../../include/Program.hpp"
+#include "../../include/Notification.hpp"
+
+namespace QuickMedia {
+ static const char *REVERSE_IMAGE_SEARCH_URL = "reverse-image-search://";
+
+ PluginResult InfoPage::submit(const std::string&, const std::string &url, std::vector<Tab> &result_tabs) {
+ if(string_starts_with(url, REVERSE_IMAGE_SEARCH_URL)) {
+ std::string image_url = url.substr(strlen(REVERSE_IMAGE_SEARCH_URL));
+ result_tabs.push_back(Tab{create_body(), std::make_unique<SaucenaoPage>(program, image_url, false), nullptr});
+ return PluginResult::OK;
+ } else {
+ const char *launch_program = "xdg-open";
+ if(!is_program_executable_by_name("xdg-open")) {
+ launch_program = getenv("BROWSER");
+ if(!launch_program) {
+ show_notification("QuickMedia", "xdg-utils which provides xdg-open needs to be installed to open urls. Alternatively set the $BROWSER environment variable to a browser", Urgency::CRITICAL);
+ return PluginResult::ERR;
+ }
+ }
+
+ std::string url_modified = url;
+ if(strncmp(url.c_str(), "http://", 7) != 0 && strncmp(url.c_str(), "https://", 8) != 0)
+ url_modified = "https://" + url;
+
+ const char *args[] = { launch_program, url_modified.c_str(), nullptr };
+ return exec_program_async(args, nullptr) == 0 ? PluginResult::OK : PluginResult::ERR;
+ }
+ }
+
+ // static
+ std::shared_ptr<BodyItem> InfoPage::add_url(const std::string &url) {
+ auto body_item = BodyItem::create("Open " + url + " in a browser");
+ body_item->url = url;
+ return body_item;
+ }
+
+ // static
+ std::shared_ptr<BodyItem> InfoPage::add_reverse_image_search(const std::string &image_url) {
+ auto body_item = BodyItem::create("Reverse search the image with SauceNAO");
+ body_item->url = REVERSE_IMAGE_SEARCH_URL + image_url;
+ return body_item;
+ }
+} \ No newline at end of file