aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Info.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-09-18 18:07:10 +0200
committerdec05eba <dec05eba@protonmail.com>2021-09-18 18:07:16 +0200
commitd74766245facd48805c2576c711d20cafa33aa35 (patch)
tree0be58368480ada332d62af14ef1a300170149871 /src/plugins/Info.cpp
parent63774155016ad581dcf418c94cd2ec84fcf86445 (diff)
Show option to open saucenao result urls
ctrl+c for info should only copy the url
Diffstat (limited to 'src/plugins/Info.cpp')
-rw-r--r--src/plugins/Info.cpp59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/plugins/Info.cpp b/src/plugins/Info.cpp
index b488eba..05efc44 100644
--- a/src/plugins/Info.cpp
+++ b/src/plugins/Info.cpp
@@ -5,39 +5,63 @@
#include "../../include/Program.hpp"
#include "../../include/Notification.hpp"
#include "../../include/Storage.hpp"
+#include <SFML/Window/Clipboard.hpp>
namespace QuickMedia {
static const char *REVERSE_IMAGE_SEARCH_URL = "reverse-image-search://";
+ static const char *GOOGLE_SEARCH_URL = "google-search://";
static bool is_youtube_url(const std::string &url) {
return url.find("youtube.com/") != std::string::npos || url.find("youtu.be/") != std::string::npos;
}
+ static PluginResult open_with_browser(const std::string &url) {
+ 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;
+ }
+
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 if(string_starts_with(url, GOOGLE_SEARCH_URL)) {
+ const std::string search_term = url.substr(strlen(GOOGLE_SEARCH_URL));
+ const std::string search_url = "https://www.google.com/search?q=" + url_param_encode(search_term);
+ return open_with_browser(search_url);
} else if(is_youtube_url(url)) {
result_tabs.push_back(Tab{nullptr, std::make_unique<YoutubeVideoPage>(program, url), 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;
+ return open_with_browser(url);
+ }
+ }
- const char *args[] = { launch_program, url_modified.c_str(), nullptr };
- return exec_program_async(args, nullptr) == 0 ? PluginResult::OK : PluginResult::ERR;
+ void InfoPage::copy_to_clipboard(const BodyItem *body_item) const {
+ std::string url;
+ if(string_starts_with(body_item->url, REVERSE_IMAGE_SEARCH_URL)) {
+ url = body_item->url.substr(strlen(REVERSE_IMAGE_SEARCH_URL));
+ } else if(string_starts_with(body_item->url, GOOGLE_SEARCH_URL)) {
+ url = body_item->url.substr(strlen(GOOGLE_SEARCH_URL));
+ } else {
+ url = body_item->url;
}
+
+ if(!url.empty())
+ sf::Clipboard::setString(sf::String::fromUtf8(url.begin(), url.end()));
}
// static
@@ -58,4 +82,11 @@ namespace QuickMedia {
body_item->url = REVERSE_IMAGE_SEARCH_URL + image_url;
return body_item;
}
+
+ // static
+ std::shared_ptr<BodyItem> InfoPage::add_google_search(const std::string &search_term) {
+ auto body_item = BodyItem::create("Search for \"" + search_term + "\" with google search");
+ body_item->url = GOOGLE_SEARCH_URL + search_term;
+ return body_item;
+ }
} \ No newline at end of file