diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AsyncImageLoader.cpp | 1 | ||||
-rw-r--r-- | src/FileAnalyzer.cpp | 2 | ||||
-rw-r--r-- | src/ImageViewer.cpp | 25 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 21 | ||||
-rw-r--r-- | src/Storage.cpp | 15 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 42 |
7 files changed, 85 insertions, 23 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index 14cfe6a..a6706f5 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -27,6 +27,7 @@ namespace QuickMedia { bool ffmpeg_convert_image_format(const Path &thumbnail_path, const Path &destination_path) { + // TODO: Dont output as jpg, ffmpeg jpg is very slow const char *args[] = { "ffmpeg", "-y", "-v", "quiet", "-i", thumbnail_path.data.c_str(), "--", destination_path.data.c_str(), nullptr}; return exec_program(args, nullptr, nullptr) == 0; } diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp index 4deb8c3..1d24c5f 100644 --- a/src/FileAnalyzer.cpp +++ b/src/FileAnalyzer.cpp @@ -157,6 +157,7 @@ namespace QuickMedia { char size_arg_str[512]; snprintf(size_arg_str, sizeof(size_arg_str), "scale=%d:%d:force_original_aspect_ratio=decrease", width, height); + // TODO: Dont output as jpg, ffmpeg jpg is very slow const char *program_args[] = { "ffmpeg", "-y", "-v", "quiet", "-ss", seconds_str, "-i", file.get_filepath().c_str(), "-frames:v", "1", "-vf", size_arg_str, "--", destination_path_tmp.data.c_str(), nullptr }; if(exec_program(program_args, nullptr, nullptr, allowed_exit_status, 2) != 0) { fprintf(stderr, "Failed to execute ffmpeg, maybe its not installed?\n"); @@ -168,6 +169,7 @@ namespace QuickMedia { if(fallback_first_frame && get_file_type(destination_path_tmp) == FileType::FILE_NOT_FOUND) return video_get_frame(file, destination_path, width, height, 0, false); } else { + // TODO: Dont output as jpg, ffmpeg jpg is very slow const char *program_args[] = { "ffmpeg", "-y", "-v", "quiet", "-ss", seconds_str, "-i", file.get_filepath().c_str(), "-frames:v", "1", "--", destination_path_tmp.data.c_str(), nullptr }; if(exec_program(program_args, nullptr, nullptr, allowed_exit_status, 2) != 0) { fprintf(stderr, "Failed to execute ffmpeg, maybe its not installed?\n"); diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp index fb9912c..454f34b 100644 --- a/src/ImageViewer.cpp +++ b/src/ImageViewer.cpp @@ -296,6 +296,9 @@ namespace QuickMedia { if(event.key.code == mgl::Keyboard::F) *fit_image_to_window = !*fit_image_to_window; + + if(event.key.code == mgl::Keyboard::B) + show_progress_bar = !show_progress_bar; } else if(event.type == mgl::Event::KeyReleased) { if(is_key_scroll_up(event.key)) up_pressed = false; @@ -426,16 +429,18 @@ namespace QuickMedia { const float font_height = page_text_character_size + 8.0f; const float background_height = font_height + 6.0f; - mgl::Rectangle page_text_background(mgl::vec2f(window_size.x, background_height)); - mgl::Color text_background_color = get_theme().shade_color; - text_background_color.a = 225; - page_text_background.set_color(text_background_color); - page_text_background.set_position(mgl::vec2f(0.0f, window_size.y - background_height)); - window->draw(page_text_background); - - auto page_text_bounds = page_text.get_bounds(); - page_text.set_position(mgl::vec2f(floor(window_size.x * 0.5f - page_text_bounds.size.x * 0.5f), floor(window_size.y - background_height * 0.5f - font_height * 0.55f))); - window->draw(page_text); + if(show_progress_bar) { + mgl::Rectangle page_text_background(mgl::vec2f(window_size.x, background_height)); + mgl::Color text_background_color = get_theme().shade_color; + text_background_color.a = 225; + page_text_background.set_color(text_background_color); + page_text_background.set_position(mgl::vec2f(0.0f, window_size.y - background_height)); + window->draw(page_text_background); + + auto page_text_bounds = page_text.get_bounds(); + page_text.set_position(mgl::vec2f(floor(window_size.x * 0.5f - page_text_bounds.size.x * 0.5f), floor(window_size.y - background_height * 0.5f - font_height * 0.55f))); + window->draw(page_text); + } // Free pages that are not visible on the screen int i = 0; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index f3e21da..0671349 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -953,7 +953,7 @@ namespace QuickMedia { string_split(urls_str, ',', [&arrays](const char *str, size_t size) { std::string url(str, size); url = strip(url); - if(!url.empty() && (arrays.empty() || arrays.back() != url)) + if(url.find(".com") != std::string::npos && (arrays.empty() || arrays.back() != url)) arrays.push_back(std::move(url)); return true; }); @@ -4490,6 +4490,9 @@ namespace QuickMedia { } else if(event.key.code == mgl::Keyboard::F) { fit_image_to_window = !fit_image_to_window; redraw = true; + } else if(event.key.code == mgl::Keyboard::B) { + show_manga_bottom_bar = !show_manga_bottom_bar; + redraw = true; } } } @@ -4514,7 +4517,7 @@ namespace QuickMedia { } const float font_height = chapter_text_character_size + 8.0f; - const float bottom_panel_height = font_height + 6.0f; + const float bottom_panel_height = show_manga_bottom_bar ? font_height + 6.0f : 0.0f; mgl::vec2f content_size; content_size.x = window_size.x; @@ -4553,13 +4556,15 @@ namespace QuickMedia { window.draw(image); } - chapter_text_background.set_size(mgl::vec2f(window_size.x, bottom_panel_height)); - chapter_text_background.set_position(mgl::vec2f(0.0f, std::floor(window_size.y - bottom_panel_height))); - window.draw(chapter_text_background); + if(show_manga_bottom_bar) { + chapter_text_background.set_size(mgl::vec2f(window_size.x, bottom_panel_height)); + chapter_text_background.set_position(mgl::vec2f(0.0f, std::floor(window_size.y - bottom_panel_height))); + window.draw(chapter_text_background); - auto text_bounds = chapter_text.get_bounds(); - chapter_text.set_position(vec2f_floor(window_size.x * 0.5f - text_bounds.size.x * 0.5f, window_size.y - bottom_panel_height * 0.5f - font_height * 0.55f)); - window.draw(chapter_text); + auto text_bounds = chapter_text.get_bounds(); + chapter_text.set_position(vec2f_floor(window_size.x * 0.5f - text_bounds.size.x * 0.5f, window_size.y - bottom_panel_height * 0.5f - font_height * 0.55f)); + window.draw(chapter_text); + } window.display(); } else { diff --git a/src/Storage.cpp b/src/Storage.cpp index 7bb3be6..5c12911 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -244,6 +244,21 @@ namespace QuickMedia { return rename_atomic(tmp_path.data.c_str(), path.data.c_str()); } + bool file_append(const Path &path, const std::string &data) { + FILE *file = fopen_eintr(path.data.c_str(), "ab"); + if(!file) { + perror(path.data.c_str()); + return false; + } + + if(fwrite_eintr(data.data(), data.size(), file) != data.size()) { + fclose(file); + return false; + } + + return fclose(file) == 0; + } + void for_files_in_dir(const Path &path, FileIteratorCallback callback) { try { for(auto &p : std::filesystem::directory_iterator(path.data)) { diff --git a/src/main.cpp b/src/main.cpp index ef0568b..b09cf14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ #include "../include/QuickMedia.hpp" #include <locale.h> +#include <malloc.h> int main(int argc, char **argv) { setlocale(LC_ALL, "C"); // Sigh... stupid C + // mallopt(M_MMAP_THRESHOLD, 65536); QuickMedia::Program program; return program.run(argc, argv); } diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 1b43b2d..7080bf9 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -629,12 +629,15 @@ namespace QuickMedia { rooms_page->add_body_item(body_item); } - void MatrixQuickMedia::leave_room(RoomData *room, LeaveType leave_type, const std::string &reason) { + void MatrixQuickMedia::leave_room(RoomData *room, const std::string &event_id, LeaveType leave_type, const std::string &reason) { room_body_item_by_room.erase(room); rooms_page->remove_body_item_by_room_id(room->id); room_tags_page->remove_body_item_by_room_id(room->id); - if(leave_type != LeaveType::LEAVE) + if(leave_type != LeaveType::LEAVE && (event_id.empty() || !matrix->is_other_notification_read(event_id))) { show_notification("QuickMedia", reason); + if(!event_id.empty()) + matrix->mark_other_notification_as_read(event_id); + } } void MatrixQuickMedia::room_add_tag(RoomData *room, const std::string &tag) { @@ -1674,6 +1677,7 @@ namespace QuickMedia { load_silenced_invites(); load_custom_emoji_from_cache(); + load_other_notifications(); sync_thread = std::thread([this, matrix_cache_dir]() { FILE *sync_cache_file; @@ -1858,8 +1862,8 @@ namespace QuickMedia { fwrite(json_data.data(), 1, json_data.size(), sync_cache_file); file_overwrite(get_cache_dir().join("matrix").join(update_cache_file_name), "1"); // To make sure the cache format is up to date - malloc_trim(0); } + malloc_trim(0); fclose(sync_cache_file); } } @@ -2208,6 +2212,18 @@ namespace QuickMedia { parse_custom_emoji(json_root); } + void Matrix::load_other_notifications() { + std::string result; + if(file_get_content(get_storage_dir().join("matrix").join("other_notifications_read"), result) != 0) + return; + + other_notifications_read.clear(); + string_split_view(result, '\n', [this](const char *str, size_t line) { + other_notifications_read.insert(std::string(str, line)); + return true; + }); + } + PluginResult Matrix::parse_sync_account_data(const rapidjson::Value &account_data_json) { if(!account_data_json.IsObject()) return PluginResult::OK; @@ -3884,6 +3900,10 @@ namespace QuickMedia { if(!type_json.IsString() || strcmp(type_json.GetString(), "m.room.member") != 0) continue; + const rapidjson::Value &event_id_json = GetMember(event_json, "event_id"); + if(!event_id_json.IsString()) + continue; + const rapidjson::Value &sender_json = GetMember(event_json, "sender"); if(!sender_json.IsString()) continue; @@ -3924,7 +3944,10 @@ namespace QuickMedia { if(!reason_str.empty()) desc += ", reason: " + reason_str; - ui_thread_tasks.push([this, room, leave_type, desc{std::move(desc)}]{ delegate->leave_room(room, leave_type, desc); }); + std::string event_id_str = event_id_json.GetString(); + ui_thread_tasks.push([this, room, event_id_str{std::move(event_id_str)}, leave_type, desc{std::move(desc)}]{ + delegate->leave_room(room, event_id_str, leave_type, desc); + }); remove_room(room_id_str); break; } @@ -4213,6 +4236,15 @@ namespace QuickMedia { return delegate; } + void Matrix::mark_other_notification_as_read(const std::string &event_id) { + other_notifications_read.insert(event_id); + file_append(get_storage_dir().join("matrix").join("other_notifications_read"), event_id + "\n"); + } + + bool Matrix::is_other_notification_read(const std::string &event_id) const { + return other_notifications_read.find(event_id) != other_notifications_read.end(); + } + PluginResult Matrix::post_message(RoomData *room, const std::string &body, std::string &event_id_response, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info, const std::string &msgtype, const std::string &custom_transaction_id) { std::string transaction_id = custom_transaction_id; if(transaction_id.empty()) @@ -5629,7 +5661,7 @@ namespace QuickMedia { if(download_result == DownloadResult::OK) { RoomData *room = get_room_by_id(room_id); if(room) { - ui_thread_tasks.push([this, room]{ delegate->leave_room(room, LeaveType::LEAVE, ""); }); + ui_thread_tasks.push([this, room]{ delegate->leave_room(room, "", LeaveType::LEAVE, ""); }); remove_room(room_id); } } |