aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-04-06 06:16:47 +0200
committerdec05eba <dec05eba@protonmail.com>2021-04-06 06:16:47 +0200
commit04e852c45a3f309d5e139b0ca059b32277c250e4 (patch)
treed704413fa0d76bf7f8c92eacce5e96e0a3d4c874
parent797a36228bdb3b77b7314585a31de6f27feab51d (diff)
Create a unified launcher for quickmedia
-rw-r--r--README.md3
-rw-r--r--icons/nyaa_si_launcher.pngbin3091 -> 16211 bytes
-rw-r--r--include/QuickMedia.hpp4
-rw-r--r--include/Text.hpp3
-rw-r--r--launcher/QuickMedia-4chan.desktop9
-rw-r--r--launcher/QuickMedia-mangadex.desktop9
-rw-r--r--launcher/QuickMedia-manganelo.desktop9
-rw-r--r--launcher/QuickMedia-mangatown.desktop9
-rw-r--r--launcher/QuickMedia-matrix.desktop9
-rw-r--r--launcher/QuickMedia-nyaa.si.desktop9
-rw-r--r--launcher/QuickMedia-soundcloud.desktop9
-rw-r--r--launcher/QuickMedia-spotify.desktop9
-rw-r--r--launcher/QuickMedia-youtube-audio.desktop9
-rw-r--r--launcher/QuickMedia-youtube.desktop9
-rw-r--r--launcher/QuickMedia.desktop8
-rw-r--r--plugins/Page.hpp2
-rw-r--r--plugins/Pipe.hpp6
-rw-r--r--src/Body.cpp2
-rw-r--r--src/QuickMedia.cpp182
-rw-r--r--src/Text.cpp19
-rw-r--r--src/plugins/Pipe.cpp6
21 files changed, 149 insertions, 176 deletions
diff --git a/README.md b/README.md
index 4886e78..98569a2 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Cache is stored under `$HOME/.cache/quickmedia`.
```
usage: quickmedia <plugin> [--use-system-mpv-config] [--dir <directory>]
OPTIONS:
- plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, youtube, spotify, soundcloud, nyaa.si, matrix, file-manager or pipe
+ plugin The plugin to use. Should be either launcher, 4chan, manganelo, mangatown, mangadex, youtube, spotify, soundcloud, nyaa.si, matrix, file-manager or stdin
--no-video Only play audio when playing a video. Disabled by default
--use-system-mpv-config Use system mpv config instead of no config. Disabled by default
--upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default
@@ -17,6 +17,7 @@ OPTIONS:
EXAMPLES:
quickmedia manganelo
quickmedia --upscale-images-always manganelo
+ echo -e "hello\nworld" | quickmedia stdin
```
## Installation
If you are running arch linux then you can install QuickMedia from aur (https://aur.archlinux.org/packages/quickmedia-git/), otherwise you will need to use [sibs](https://git.dec05eba.com/sibs/) to build QuickMedia manually.
diff --git a/icons/nyaa_si_launcher.png b/icons/nyaa_si_launcher.png
index c29320a..45790f7 100644
--- a/icons/nyaa_si_launcher.png
+++ b/icons/nyaa_si_launcher.png
Binary files differ
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index 497f202..c6cd7b5 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -87,6 +87,7 @@ namespace QuickMedia {
RoomData* get_current_chat_room();
void set_go_to_previous_page();
+ void set_pipe_selected_text(const std::string &text);
TaskResult run_task_with_loading_screen(std::function<bool()> callback);
@@ -94,6 +95,7 @@ namespace QuickMedia {
void manga_get_watch_history(const char *plugin_name, BodyItems &history_items);
void youtube_get_watch_history(BodyItems &history_items);
private:
+ void load_plugin_by_name(std::vector<Tab> &tabs, const char *start_dir);
void base_event_handler(sf::Event &event, PageType previous_page, Body *body, SearchBar *search_bar, bool handle_key_press = true, bool handle_searchbar = true);
void event_idle_handler(const sf::Event &event);
void idle_active_handler();
@@ -165,6 +167,7 @@ namespace QuickMedia {
std::string resources_root;
sf::Shader circle_mask_shader;
bool no_video = false;
+ bool force_no_video = false;
bool use_system_mpv_config = false;
UpscaleImageAction upscale_image_action = UpscaleImageAction::NO;
// TODO: Save this to config file when switching modes
@@ -184,5 +187,6 @@ namespace QuickMedia {
sf::Clock idle_timer;
bool idle = true;
bool low_cpu_mode = false;
+ std::string pipe_selected_text;
};
} \ No newline at end of file
diff --git a/include/Text.hpp b/include/Text.hpp
index c74607c..60d0db1 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -65,7 +65,7 @@ namespace QuickMedia
{
public:
Text(bool bold_font);
- Text(sf::String str, bool bold_font, unsigned int characterSize, float maxWidth);
+ Text(sf::String str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls = false);
void setString(sf::String str);
const sf::String& getString() const;
@@ -148,6 +148,7 @@ namespace QuickMedia
bool dirtyText;
bool dirtyCaret;
bool editable;
+ bool highlight_urls;
CaretMoveDirection caretMoveDirection;
sf::FloatRect boundingBox;
int num_lines;
diff --git a/launcher/QuickMedia-4chan.desktop b/launcher/QuickMedia-4chan.desktop
deleted file mode 100644
index 112f1bf..0000000
--- a/launcher/QuickMedia-4chan.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia 4chan
-GenericName=4chan client
-Comment=4chan client with autoplay support and quick comment navigation
-Icon=/usr/share/quickmedia/icons/4chan_launcher.png
-Exec=quickmedia 4chan
-Terminal=false
-Keywords=4chan;quickmedia;
diff --git a/launcher/QuickMedia-mangadex.desktop b/launcher/QuickMedia-mangadex.desktop
deleted file mode 100644
index 8003e35..0000000
--- a/launcher/QuickMedia-mangadex.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia MangaDex
-GenericName=MangaDex reader
-Comment=MangaDex reader, keeps track of your progress
-Icon=/usr/share/quickmedia/icons/mangadex_launcher.png
-Exec=quickmedia mangadex
-Terminal=false
-Keywords=manga;comics;reader;quickmedia;automedia;
diff --git a/launcher/QuickMedia-manganelo.desktop b/launcher/QuickMedia-manganelo.desktop
deleted file mode 100644
index 854fd82..0000000
--- a/launcher/QuickMedia-manganelo.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia Manganelo
-GenericName=Manganelo reader
-Comment=Manganelo reader, keeps track of your progress
-Icon=/usr/share/quickmedia/icons/manganelo_launcher.png
-Exec=quickmedia manganelo
-Terminal=false
-Keywords=manga;comics;reader;quickmedia;automedia;
diff --git a/launcher/QuickMedia-mangatown.desktop b/launcher/QuickMedia-mangatown.desktop
deleted file mode 100644
index d2974bf..0000000
--- a/launcher/QuickMedia-mangatown.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia Mangatown
-GenericName=Mangatown reader
-Comment=Mangatown reader, keeps track of your progress
-Icon=/usr/share/quickmedia/icons/mangatown_launcher.png
-Exec=quickmedia mangatown
-Terminal=false
-Keywords=manga;comics;reader;quickmedia;automedia;
diff --git a/launcher/QuickMedia-matrix.desktop b/launcher/QuickMedia-matrix.desktop
deleted file mode 100644
index 91dcfd1..0000000
--- a/launcher/QuickMedia-matrix.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia Matrix
-GenericName=Matrix client
-Comment=Matrix client
-Icon=/usr/share/quickmedia/icons/matrix_launcher.png
-Exec=quickmedia matrix
-Terminal=false
-Keywords=matrix;chat;quickmedia;
diff --git a/launcher/QuickMedia-nyaa.si.desktop b/launcher/QuickMedia-nyaa.si.desktop
deleted file mode 100644
index 1ab35c8..0000000
--- a/launcher/QuickMedia-nyaa.si.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia Nyaa.si
-GenericName=Nyaa.si browser
-Comment=Nyaa.si search and torrent downloading
-Icon=/usr/share/quickmedia/icons/nyaa_si_launcher.png
-Exec=quickmedia nyaa.si
-Terminal=false
-Keywords=nyaa.si;torrent;quickmedia;anime;
diff --git a/launcher/QuickMedia-soundcloud.desktop b/launcher/QuickMedia-soundcloud.desktop
deleted file mode 100644
index df2245b..0000000
--- a/launcher/QuickMedia-soundcloud.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia Soundcloud
-GenericName=Soundcloud player
-Comment=Soundcloud music player
-Icon=/usr/share/quickmedia/icons/soundcloud_launcher.png
-Exec=quickmedia soundcloud --no-video
-Terminal=false
-Keywords=soundcloud;player;quickmedia;music;
diff --git a/launcher/QuickMedia-spotify.desktop b/launcher/QuickMedia-spotify.desktop
deleted file mode 100644
index cf220ce..0000000
--- a/launcher/QuickMedia-spotify.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia Spotify
-GenericName=Spotify podcast player
-Comment=Spotify podcast player
-Icon=/usr/share/quickmedia/icons/spotify_launcher.png
-Exec=quickmedia spotify --no-video
-Terminal=false
-Keywords=spotify;player;quickmedia;podcast;
diff --git a/launcher/QuickMedia-youtube-audio.desktop b/launcher/QuickMedia-youtube-audio.desktop
deleted file mode 100644
index bc946a3..0000000
--- a/launcher/QuickMedia-youtube-audio.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia YouTube Music
-GenericName=YouTube music player
-Comment=YouTube search and audio playing
-Icon=/usr/share/quickmedia/icons/yt_launcher.png
-Exec=quickmedia youtube --no-video
-Terminal=false
-Keywords=youtube;player;quickmedia;audio;music;
diff --git a/launcher/QuickMedia-youtube.desktop b/launcher/QuickMedia-youtube.desktop
deleted file mode 100644
index 521d7b5..0000000
--- a/launcher/QuickMedia-youtube.desktop
+++ /dev/null
@@ -1,9 +0,0 @@
-[Desktop Entry]
-Type=Application
-Name=QuickMedia YouTube
-GenericName=YouTube player
-Comment=YouTube search and video playing
-Icon=/usr/share/quickmedia/icons/yt_launcher.png
-Exec=quickmedia youtube
-Terminal=false
-Keywords=youtube;player;quickmedia;video;multimedia;
diff --git a/launcher/QuickMedia.desktop b/launcher/QuickMedia.desktop
new file mode 100644
index 0000000..2089dc8
--- /dev/null
+++ b/launcher/QuickMedia.desktop
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Type=Application
+Name=QuickMedia
+GenericName=QuickMedia
+Comment=A dmenu-inspired native client for web services. Currently supported web services: youtube, spotify (podcasts), soundcloud, nyaa.si, manganelo, mangatown, mangadex, 4chan, matrix and others
+Exec=quickmedia launcher
+Terminal=false
+Keywords=4chan;manga;matrix;nyaa;torrent;soundcloud;spotify;podcast;youtube;music;quickmedia;
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index 143d9df..5c0a558 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -111,6 +111,6 @@ namespace QuickMedia {
virtual std::unique_ptr<LazyFetchPage> create_channels_page(Program *program, const std::string &channel_url) = 0;
virtual std::string get_url() = 0;
virtual std::string url_get_playable_url(const std::string &url) { return url; }
- virtual bool video_should_be_skipped(const std::string &url) { return false; }
+ virtual bool video_should_be_skipped(const std::string &url) { (void)url; return false; }
};
} \ No newline at end of file
diff --git a/plugins/Pipe.hpp b/plugins/Pipe.hpp
index 0711ee4..46864be 100644
--- a/plugins/Pipe.hpp
+++ b/plugins/Pipe.hpp
@@ -5,11 +5,13 @@
namespace QuickMedia {
class PipePage : public Page {
public:
- PipePage(Program *program) : Page(program) {}
- const char* get_title() const override { return ""; }
+ PipePage(Program *program, const char *title = "") : Page(program), title(title) {}
+ const char* get_title() const override { return title; }
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
bool is_single_page() const override { return true; }
static void load_body_items_from_stdin(BodyItems &items);
+ private:
+ const char *title;
};
} \ No newline at end of file
diff --git a/src/Body.cpp b/src/Body.cpp
index 61d319a..1e45dcb 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -800,7 +800,7 @@ namespace QuickMedia {
if(body_item->description_text)
body_item->description_text->setString(std::move(str));
else
- body_item->description_text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale()), width);
+ body_item->description_text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale()), width, true);
body_item->description_text->setFillColor(body_item->get_description_color());
body_item->description_text->updateGeometry();
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 8a500fe..c7d63d7 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -56,6 +56,32 @@ static int FPS_IDLE = 2;
static const double IDLE_TIMEOUT_SEC = 2.0;
static const sf::Vector2i AVATAR_THUMBNAIL_SIZE(std::floor(32 * QuickMedia::get_ui_scale()), std::floor(32 * QuickMedia::get_ui_scale()));
+static const std::pair<const char*, const char*> valid_plugins[] = {
+ std::make_pair("launcher", nullptr),
+ std::make_pair("manganelo", "manganelo_logo.png"),
+ std::make_pair("mangatown", "mangatown_logo.png"),
+ std::make_pair("mangadex", "mangadex_logo.png"),
+ std::make_pair("youtube", "yt_logo_rgb_dark_small.png"),
+ std::make_pair("spotify", "spotify_logo.png"),
+ std::make_pair("soundcloud", "soundcloud_logo.png"),
+ std::make_pair("pornhub", "pornhub_logo.png"),
+ std::make_pair("4chan", "4chan_logo.png"),
+ std::make_pair("nyaa.si", "nyaa_si_logo.png"),
+ std::make_pair("matrix", "matrix_logo.png"),
+ std::make_pair("mastodon", "pleroma_logo.png"),
+ std::make_pair("pleroma", "pleroma_logo.png"),
+ std::make_pair("file-manager", nullptr),
+ std::make_pair("stdin", nullptr)
+};
+
+static const char* get_plugin_logo_name(const char *plugin_name) {
+ for(const auto &valid_plugin : valid_plugins) {
+ if(strcmp(plugin_name, valid_plugin.first) == 0)
+ return valid_plugin.second;
+ }
+ return nullptr;
+}
+
// Prevent writing to broken pipe from exiting the program
static void sigpipe_handler(int) {
@@ -449,7 +475,7 @@ namespace QuickMedia {
static void usage() {
fprintf(stderr, "usage: quickmedia <plugin> [--no-video] [--use-system-mpv-config] [--dir <directory>]\n");
fprintf(stderr, "OPTIONS:\n");
- fprintf(stderr, " plugin The plugin to use. Should be either 4chan, manganelo, mangatown, mangadex, pornhub, youtube, spotify, soundcloud, nyaa.si, matrix, file-manager or pipe\n");
+ fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manganelo, mangatown, mangadex, pornhub, youtube, spotify, soundcloud, nyaa.si, matrix, file-manager or stdin\n");
fprintf(stderr, " --no-video Only play audio when playing a video. Disabled by default\n");
fprintf(stderr, " --use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n");
fprintf(stderr, " --upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default\n");
@@ -458,70 +484,44 @@ namespace QuickMedia {
fprintf(stderr, "EXAMPLES:\n");
fprintf(stderr, " quickmedia manganelo\n");
fprintf(stderr, " quickmedia --upscale-images-always manganelo\n");
+ fprintf(stderr, " echo -e \"hello\\nworld\" | quickmedia stdin\n");
}
static bool is_manga_plugin(const char *plugin_name) {
return strcmp(plugin_name, "manganelo") == 0 || strcmp(plugin_name, "mangatown") == 0 || strcmp(plugin_name, "mangadex") == 0;
}
+ static std::shared_ptr<BodyItem> create_launcher_body_item(const char *title, const char *plugin_name, const std::string &thumbnail_url) {
+ auto body_item = BodyItem::create(title);
+ body_item->url = plugin_name;
+ body_item->thumbnail_url = thumbnail_url;
+ body_item->thumbnail_is_local = true;
+ body_item->thumbnail_size.x = 32;
+ body_item->thumbnail_size.y = 32;
+ return body_item;
+ }
+
int Program::run(int argc, char **argv) {
if(argc < 2) {
usage();
return -1;
}
- std::string plugin_logo_path;
const char *start_dir = nullptr;
std::vector<Tab> tabs;
for(int i = 1; i < argc; ++i) {
if(!plugin_name) {
- if(strcmp(argv[i], "manganelo") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/manganelo_logo.png";
- } else if(strcmp(argv[i], "mangatown") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/mangatown_logo.png";
- } else if(strcmp(argv[i], "mangadex") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/mangadex_logo.png";
- } else if(strcmp(argv[i], "youtube") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/yt_logo_rgb_dark_small.png";
- } else if(strcmp(argv[i], "spotify") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/spotify_logo.png";
- no_video = true;
- } else if(strcmp(argv[i], "soundcloud") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/soundcloud_logo.png";
- no_video = true;
- } else if(strcmp(argv[i], "pornhub") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/pornhub_logo.png";
- plugin_name = argv[i];
- } else if(strcmp(argv[i], "4chan") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/4chan_logo.png";
- } else if(strcmp(argv[i], "nyaa.si") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/nyaa_si_logo.png";
- } else if(strcmp(argv[i], "matrix") == 0) {
- plugin_name = argv[i];
- matrix = new Matrix();
- plugin_logo_path = resources_root + "images/matrix_logo.png";
- } else if(strcmp(argv[i], "mastodon") == 0 || strcmp(argv[i], "pleroma") == 0) {
- plugin_name = argv[i];
- plugin_logo_path = resources_root + "images/pleroma_logo.png";
- } else if(strcmp(argv[i], "file-manager") == 0) {
- plugin_name = argv[i];
- } else if(strcmp(argv[i], "pipe") == 0) {
- plugin_name = argv[i];
+ for(const auto &valid_plugin : valid_plugins) {
+ if(strcmp(argv[i], valid_plugin.first) == 0) {
+ plugin_name = argv[i];
+ break;
+ }
}
}
if(strcmp(argv[i], "--no-video") == 0) {
- no_video = true;
+ force_no_video = true;
} else if(strcmp(argv[i], "--use-system-mpv-config") == 0) {
use_system_mpv_config = true;
} else if(strcmp(argv[i], "--upscale-images") == 0) {
@@ -605,18 +605,65 @@ namespace QuickMedia {
return -1;
}
+ load_plugin_by_name(tabs, start_dir);
+
+ while(!tabs.empty() || matrix) {
+ if(matrix) {
+ if(matrix->load_cached_session() == PluginResult::OK) {
+ current_page = PageType::CHAT;
+ } else {
+ fprintf(stderr, "Failed to load session cache, redirecting to login page\n");
+ current_page = PageType::CHAT_LOGIN;
+ chat_login_page();
+ }
+ after_matrix_login_page();
+ return exit_code;
+ }
+
+ page_loop(tabs);
+ tabs.clear();
+
+ if(strcmp(plugin_name, "launcher") == 0) {
+ plugin_name = pipe_selected_text.c_str();
+ load_plugin_by_name(tabs, start_dir);
+ }
+ }
+
+ return exit_code;
+ }
+
+ void Program::load_plugin_by_name(std::vector<Tab> &tabs, const char *start_dir) {
+ if(!plugin_name || plugin_name[0] == '\0')
+ return;
+
window.setTitle("QuickMedia - " + std::string(plugin_name));
+ const char *plugin_logo_name = get_plugin_logo_name(plugin_name);
+ std::string plugin_logo_path;
+ if(plugin_logo_name)
+ plugin_logo_path = resources_root + "images/" + plugin_logo_name;
+ no_video = force_no_video;
+ plugin_logo = sf::Texture();
if(!plugin_logo_path.empty()) {
- if(!plugin_logo.loadFromFile(plugin_logo_path)) {
+ if(!plugin_logo.loadFromFile(plugin_logo_path))
fprintf(stderr, "Failed to load plugin logo, path: %s\n", plugin_logo_path.c_str());
- return -2;
- }
plugin_logo.generateMipmap();
plugin_logo.setSmooth(true);
}
- if(strcmp(plugin_name, "manganelo") == 0) {
+ if(strcmp(plugin_name, "launcher") == 0) {
+ auto pipe_body = create_body();
+ pipe_body->items.push_back(create_launcher_body_item("4chan", "4chan", resources_root + "icons/4chan_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Mangadex", "mangadex", resources_root + "icons/mangadex_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Manganelo", "manganelo", resources_root + "icons/manganelo_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Mangatown", "mangatown", resources_root + "icons/mangatown_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Matrix", "matrix", resources_root + "icons/matrix_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Nyaa.si", "nyaa.si", resources_root + "icons/nyaa_si_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Soundcloud", "soundcloud", resources_root + "icons/soundcloud_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Spotify", "spotify", resources_root + "icons/spotify_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("YouTube", "youtube", resources_root + "icons/yt_launcher.png"));
+ tabs.push_back(Tab{std::move(pipe_body), std::make_unique<PipePage>(this, "Select plugin to launch"), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ } else if(strcmp(plugin_name, "manganelo") == 0) {
auto search_body = create_body();
tabs.push_back(Tab{std::move(search_body), std::make_unique<ManganeloSearchPage>(this), create_search_bar("Search...", 200)});
@@ -654,12 +701,13 @@ namespace QuickMedia {
auto file_manager_page = std::make_unique<FileManagerPage>(this);
if(start_dir && !file_manager_page->set_current_directory(start_dir)) {
fprintf(stderr, "Invalid directory provided with --dir: %s\n", start_dir);
- return -3;
+ exit_code = -3;
+ return;
}
auto file_manager_body = create_body();
file_manager_page->get_files_in_directory(file_manager_body->items);
tabs.push_back(Tab{std::move(file_manager_body), std::move(file_manager_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
- } else if(strcmp(plugin_name, "pipe") == 0) {
+ } else if(strcmp(plugin_name, "stdin") == 0) {
auto pipe_body = create_body();
PipePage::load_body_items_from_stdin(pipe_body->items);
tabs.push_back(Tab{std::move(pipe_body), std::make_unique<PipePage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
@@ -681,32 +729,19 @@ namespace QuickMedia {
} else if(strcmp(plugin_name, "spotify") == 0) {
auto search_body = create_body();
tabs.push_back(Tab{std::move(search_body), std::make_unique<SpotifyPodcastSearchPage>(this), create_search_bar("Search...", 250)});
+ no_video = true;
} else if(strcmp(plugin_name, "soundcloud") == 0) {
auto search_body = create_body();
tabs.push_back(Tab{std::move(search_body), std::make_unique<SoundcloudSearchPage>(this), create_search_bar("Search...", 500)});
+ no_video = true;
} else if(strcmp(plugin_name, "mastodon") == 0 || strcmp(plugin_name, "pleroma") == 0) {
auto pleroma = std::make_shared<Pleroma>();
auto search_body = create_body();
tabs.push_back(Tab{std::move(search_body), std::make_unique<PleromaHomePage>(this, pleroma), create_search_bar("Search...", 350)});
+ } else if(strcmp(plugin_name, "matrix") == 0) {
+ assert(!matrix);
+ matrix = new Matrix();
}
-
- if(!tabs.empty()) {
- page_loop(tabs);
- return exit_code;
- }
-
- if(matrix) {
- if(matrix->load_cached_session() == PluginResult::OK) {
- current_page = PageType::CHAT;
- } else {
- fprintf(stderr, "Failed to load session cache, redirecting to login page\n");
- current_page = PageType::CHAT_LOGIN;
- chat_login_page();
- }
- after_matrix_login_page();
- }
-
- return exit_code;
}
void Program::base_event_handler(sf::Event &event, PageType previous_page, Body *body, SearchBar *search_bar, bool handle_keypress, bool handle_searchbar) {
@@ -986,6 +1021,10 @@ namespace QuickMedia {
go_to_previous_page = true;
}
+ void Program::set_pipe_selected_text(const std::string &text) {
+ pipe_selected_text = text;
+ }
+
void Program::page_loop_render(sf::RenderWindow &window, std::vector<Tab> &tabs, int selected_tab, TabAssociatedData &tab_associated_data, const Json::Value *json_chapters) {
if(tabs[selected_tab].search_bar) tabs[selected_tab].search_bar->draw(window, false);
@@ -1101,6 +1140,7 @@ namespace QuickMedia {
return;
std::vector<Tab> new_tabs;
+ auto prev_selected_item = tabs[selected_tab].page->submit_body_item;
tabs[selected_tab].page->submit_body_item = selected_item;
PluginResult submit_result = tabs[selected_tab].page->submit(selected_item ? selected_item->get_title() : search_text, selected_item ? selected_item->url : "", new_tabs);
if(submit_result != PluginResult::OK) {
@@ -1126,12 +1166,12 @@ namespace QuickMedia {
tabs[selected_tab].body = std::move(new_tabs[0].body);
else
loop_running = false;
- tabs[selected_tab].page->submit_body_item = nullptr;
+ tabs[selected_tab].page->submit_body_item = prev_selected_item;
return;
}
if(new_tabs.empty()) {
- tabs[selected_tab].page->submit_body_item = nullptr;
+ tabs[selected_tab].page->submit_body_item = prev_selected_item;
return;
}
@@ -1224,7 +1264,7 @@ namespace QuickMedia {
json_chapters = &chapters_json;
}
- tabs[selected_tab].page->submit_body_item = nullptr;
+ tabs[selected_tab].page->submit_body_item = prev_selected_item;
redraw = true;
hide_virtual_keyboard();
};
diff --git a/src/Text.cpp b/src/Text.cpp
index a9f1147..2abc276 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -29,15 +29,16 @@ namespace QuickMedia
Text::Text(bool bold_font) : Text("", bold_font, 0, 0.0f) {}
- Text::Text(sf::String _str, bool bold_font, unsigned int _characterSize, float _maxWidth) :
+ Text::Text(sf::String _str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls) :
bold_font(bold_font),
- characterSize(_characterSize),
- maxWidth(_maxWidth),
+ characterSize(characterSize),
+ maxWidth(maxWidth),
color(sf::Color::White),
dirty(true),
dirtyText(false),
dirtyCaret(false),
editable(false),
+ highlight_urls(highlight_urls),
caretMoveDirection(CaretMoveDirection::NONE),
num_lines(1),
lineSpacing(0.0f),
@@ -324,10 +325,14 @@ namespace QuickMedia
dirtyText = false;
splitTextByFont();
// TODO: Optimize
- auto u8 = str.toUtf8();
- std::string *u8_str = (std::string*)&u8;
- url_ranges = extract_urls(*u8_str);
- convert_utf8_to_utf32_ranges(*u8_str, url_ranges);
+ if(highlight_urls) {
+ auto u8 = str.toUtf8();
+ std::string *u8_str = (std::string*)&u8;
+ url_ranges = extract_urls(*u8_str);
+ convert_utf8_to_utf32_ranges(*u8_str, url_ranges);
+ } else {
+ url_ranges.clear();
+ }
dirty = true;
}
diff --git a/src/plugins/Pipe.cpp b/src/plugins/Pipe.cpp
index 5d7d269..4fa8cf3 100644
--- a/src/plugins/Pipe.cpp
+++ b/src/plugins/Pipe.cpp
@@ -1,10 +1,12 @@
#include "../../plugins/Pipe.hpp"
+#include "../../include/QuickMedia.hpp"
#include <string>
#include <iostream>
namespace QuickMedia {
- PluginResult PipePage::submit(const std::string &title, const std::string&, std::vector<Tab> &result_tabs) {
- puts(title.c_str());
+ PluginResult PipePage::submit(const std::string &title, const std::string &url, std::vector<Tab>&) {
+ puts(!url.empty() ? url.c_str() : title.c_str());
+ program->set_pipe_selected_text(!url.empty() ? url : title);
return PluginResult::OK;
}