aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp42
-rw-r--r--src/VideoPlayer.cpp2
-rw-r--r--src/plugins/Dmenu.cpp23
-rw-r--r--src/plugins/Pornhub.cpp13
4 files changed, 41 insertions, 39 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 5a13179..8fdedb3 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -4,6 +4,7 @@
#include "../plugins/Youtube.hpp"
#include "../plugins/Pornhub.hpp"
#include "../plugins/Fourchan.hpp"
+#include "../plugins/Dmenu.hpp"
#include "../include/Scale.hpp"
#include "../include/Program.h"
#include "../include/VideoPlayer.hpp"
@@ -21,8 +22,6 @@
#include <assert.h>
#include <cmath>
#include <string.h>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
#include <signal.h>
static const sf::Color back_color(30, 32, 34);
@@ -44,6 +43,7 @@ static int x_io_error_handler(Display *display) {
namespace QuickMedia {
Program::Program() :
+ disp(nullptr),
window(sf::VideoMode(800, 600), "QuickMedia"),
window_size(800, 600),
body(nullptr),
@@ -51,6 +51,10 @@ namespace QuickMedia {
current_page(Page::SEARCH_SUGGESTION),
image_index(0)
{
+ disp = XOpenDisplay(NULL);
+ if (!disp)
+ throw std::runtime_error("Failed to open display to X11 server");
+
window.setVerticalSyncEnabled(true);
if(!font.loadFromFile("../../../fonts/Lato-Regular.ttf")) {
fprintf(stderr, "Failed to load font: Lato-Regular.ttf\n");
@@ -75,6 +79,8 @@ namespace QuickMedia {
Program::~Program() {
delete body;
delete current_plugin;
+ if(disp)
+ XCloseDisplay(disp);
}
static SearchResult search_selected_suggestion(Body *input_body, Body *output_body, Plugin *plugin, std::string &selected_title, std::string &selected_url) {
@@ -93,11 +99,12 @@ namespace QuickMedia {
static void usage() {
fprintf(stderr, "usage: QuickMedia <plugin> [--tor]\n");
fprintf(stderr, "OPTIONS:\n");
- fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangadex, pornhub or youtube\n");
+ fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangadex, pornhub, youtube or dmenu\n");
fprintf(stderr, "--tor Use tor. Disabled by default\n");
fprintf(stderr, "EXAMPLES:\n");
fprintf(stderr, "QuickMedia manganelo\n");
fprintf(stderr, "QuickMedia youtube --tor\n");
+ fprintf(stderr, "echo \"hello\nworld\" | QuickMedia dmenu\n");
}
static bool is_program_executable_by_name(const char *name) {
@@ -146,6 +153,8 @@ namespace QuickMedia {
} else if(strcmp(argv[i], "4chan") == 0) {
current_plugin = new Fourchan();
plugin_logo_path = "../../../images/4chan_logo.png";
+ } else if(strcmp(argv[i], "dmenu") == 0) {
+ current_plugin = new Dmenu();
}
}
@@ -237,7 +246,7 @@ namespace QuickMedia {
}
}
- return 0;
+ return exit_code;
}
void Program::base_event_handler(sf::Event &event, Page previous_page, bool handle_keypress, bool clear_on_escape, bool handle_searchbar) {
@@ -357,7 +366,7 @@ namespace QuickMedia {
}
search_bar->onTextUpdateCallback = [&update_search_text, this, &tabs, &selected_tab](const std::string &text) {
- if(tabs[selected_tab].body == body)
+ if(tabs[selected_tab].body == body && !current_plugin->search_is_filter())
update_search_text = text;
else {
tabs[selected_tab].body->filter_search_fuzzy(text);
@@ -438,6 +447,7 @@ namespace QuickMedia {
tabs[selected_tab].body->select_next_item();
} else if(event.key.code == sf::Keyboard::Escape) {
current_page = Page::EXIT;
+ exit_code = 1;
} else if(event.key.code == sf::Keyboard::Left) {
selected_tab = std::max(0, selected_tab - 1);
search_bar->clear();
@@ -578,19 +588,6 @@ namespace QuickMedia {
#endif
}
- struct XDisplayScope {
- XDisplayScope(Display *_display) : display(_display) {
-
- }
-
- ~XDisplayScope() {
- if(display)
- XCloseDisplay(display);
- }
-
- Display *display;
- };
-
enum class WindowFullscreenState {
UNSET,
SET,
@@ -631,13 +628,8 @@ namespace QuickMedia {
Page previous_page = pop_page_stack();
- Display* disp = XOpenDisplay(NULL);
- if (!disp)
- throw std::runtime_error("Failed to open display to X11 server");
- XDisplayScope display_scope(disp);
-
std::unique_ptr<sf::RenderWindow> video_player_ui_window;
- auto on_window_create = [disp, &video_player_ui_window](sf::WindowHandle video_player_window) {
+ auto on_window_create = [this, &video_player_ui_window](sf::WindowHandle video_player_window) {
int screen = DefaultScreen(disp);
Window ui_window = XCreateWindow(disp, RootWindow(disp, screen),
0, 0, 1, 1, 0,
@@ -705,7 +697,7 @@ namespace QuickMedia {
}, on_window_create);
load_video_error_check();
- auto on_doubleclick = [this, disp]() {
+ auto on_doubleclick = [this]() {
window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::TOGGLE);
};
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index 165e6e7..08ecc7e 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -84,7 +84,7 @@ namespace QuickMedia {
if(exec_program_async(args.data(), &video_process_id) != 0)
return Error::FAIL_TO_LAUNCH_PROCESS;
- printf("mpv input ipc server: %s\n", ipc_server_path);
+ fprintf(stderr, "mpv input ipc server: %s\n", ipc_server_path);
if((ipc_socket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
perror("Failed to create socket for video player");
diff --git a/src/plugins/Dmenu.cpp b/src/plugins/Dmenu.cpp
new file mode 100644
index 0000000..a3b354b
--- /dev/null
+++ b/src/plugins/Dmenu.cpp
@@ -0,0 +1,23 @@
+#include "../../plugins/Dmenu.hpp"
+#include <iostream>
+
+namespace QuickMedia {
+ Dmenu::Dmenu() : Plugin("dmenu") {
+ std::string line;
+ while(std::getline(std::cin, line)) {
+ stdin_data.push_back(std::move(line));
+ }
+ }
+
+ PluginResult Dmenu::get_front_page(BodyItems &result_items) {
+ for(const std::string &line_data : stdin_data) {
+ result_items.push_back(std::make_unique<BodyItem>(line_data));
+ }
+ return PluginResult::OK;
+ }
+
+ SearchResult Dmenu::search(const std::string &text, BodyItems &result_items) {
+ std::cout << text << std::endl;
+ return SearchResult::OK;
+ }
+} \ No newline at end of file
diff --git a/src/plugins/Pornhub.cpp b/src/plugins/Pornhub.cpp
index c94532b..9a7242a 100644
--- a/src/plugins/Pornhub.cpp
+++ b/src/plugins/Pornhub.cpp
@@ -12,19 +12,6 @@ namespace QuickMedia {
return strstr(str, substr);
}
- static void iterate_suggestion_result(const Json::Value &value, BodyItems &result_items, int &iterate_count) {
- ++iterate_count;
- if(value.isArray()) {
- for(const Json::Value &child : value) {
- iterate_suggestion_result(child, result_items, iterate_count);
- }
- } else if(value.isString() && iterate_count > 2) {
- std::string title = value.asString();
- auto item = std::make_unique<BodyItem>(title);
- result_items.push_back(std::move(item));
- }
- }
-
// TODO: Speed this up by using string.find instead of parsing html
SuggestionResult Pornhub::update_search_suggestions(const std::string &text, BodyItems &result_items) {
std::string url = "https://www.pornhub.com/video/search?search=";