From 215ac920166087ffcf917c293caf6497adf50c3d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 8 Sep 2022 20:08:42 +0200 Subject: Add matrix known servers to config file instead of hardcoded, copy example config and readme to /usr/share/quickmedia --- src/Config.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/QuickMedia.cpp | 20 ++++++-------------- src/plugins/Saucenao.cpp | 1 + 3 files changed, 51 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index 50cab3c..c6c2a29 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -89,6 +89,29 @@ namespace QuickMedia { val = json_val.asDouble(); } + static void matrix_known_homeservers_fallback() { + config->matrix.known_homeservers.insert(config->matrix.known_homeservers.end(), { + "midov.pl", + "matrix.org", + "kde.org", + "librem.one", + "maunium.net", + "halogen.city", + "gnome.org", + "shivering-isles.com", + "nerdsin.space", + "glowers.club", + "privacytools.io", + "linuxdelta.com", + "tchncs.de", + "jupiterbroadcasting.com" + }); + } + + static void config_load_fail_fallback() { + matrix_known_homeservers_fallback(); + } + // No-op if this has already been called before static void init_config() { if(config_initialized) @@ -103,12 +126,14 @@ namespace QuickMedia { Path config_path = get_storage_dir().join("config.json"); if(get_file_type(config_path) != FileType::REGULAR) { + config_load_fail_fallback(); return; } Json::Value json_root; if(!read_file_as_json(config_path, json_root) || !json_root.isObject()) { fprintf(stderr, "Warning: failed to parse config file: %s\n", config_path.data.c_str()); + config_load_fail_fallback(); return; } @@ -170,6 +195,25 @@ namespace QuickMedia { if(youtube_json.isObject()) get_json_value(youtube_json, "load_progress", config->youtube.load_progress); + bool has_known_homeservers_config = false; + const Json::Value &matrix_json = json_root["matrix"]; + if(matrix_json.isObject()) { + const Json::Value &known_homeservers_json = matrix_json["known_homeservers"]; + if(known_homeservers_json.isArray()) { + has_known_homeservers_config = true; + for(const Json::Value &known_homeserver : known_homeservers_json) { + if(!known_homeserver.isString()) { + fprintf(stderr, "Warning: matrix.known_homeservers config contains non string value\n"); + continue; + } + config->matrix.known_homeservers.push_back(known_homeserver.asString()); + } + } + } + + if(!has_known_homeservers_config) + matrix_known_homeservers_fallback(); + get_json_value(json_root, "use_system_fonts", config->use_system_fonts); get_json_value(json_root, "use_system_mpv_config", config->use_system_mpv_config); get_json_value(json_root, "enable_shaders", config->enable_shaders); diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 2ac6f90..7cbe2c4 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1843,6 +1843,7 @@ namespace QuickMedia { } auto body = create_body(); + body->title_mark_urls = true; if(include_reverse_image_search && !body_item->url.empty() && !body_item->thumbnail_url.empty()) { std::string image_url = body_item->url; @@ -7536,21 +7537,12 @@ namespace QuickMedia { auto matrix_invites_page = std::make_unique(this, matrix, invites_body.get()); BodyItems room_dir_body_items; + add_body_item_unique_title(room_dir_body_items, matrix->get_homeserver_domain()); - add_body_item_unique_title(room_dir_body_items, "midov.pl"); - add_body_item_unique_title(room_dir_body_items, "matrix.org"); - add_body_item_unique_title(room_dir_body_items, "kde.org"); - add_body_item_unique_title(room_dir_body_items, "librem.one"); - add_body_item_unique_title(room_dir_body_items, "maunium.net"); - add_body_item_unique_title(room_dir_body_items, "halogen.city"); - add_body_item_unique_title(room_dir_body_items, "gnome.org"); - add_body_item_unique_title(room_dir_body_items, "shivering-isles.com"); - add_body_item_unique_title(room_dir_body_items, "nerdsin.space"); - add_body_item_unique_title(room_dir_body_items, "glowers.club"); - add_body_item_unique_title(room_dir_body_items, "privacytools.io"); - add_body_item_unique_title(room_dir_body_items, "linuxdelta.com"); - add_body_item_unique_title(room_dir_body_items, "tchncs.de"); - add_body_item_unique_title(room_dir_body_items, "jupiterbroadcasting.com"); + for(const std::string &known_homeserver : get_config().matrix.known_homeservers) { + add_body_item_unique_title(room_dir_body_items, known_homeserver); + } + auto room_directory_body = create_body(); room_directory_body->set_items(std::move(room_dir_body_items)); auto matrix_room_directory_page = std::make_unique(this, matrix); diff --git a/src/plugins/Saucenao.cpp b/src/plugins/Saucenao.cpp index ac2b622..1c841b1 100644 --- a/src/plugins/Saucenao.cpp +++ b/src/plugins/Saucenao.cpp @@ -60,6 +60,7 @@ namespace QuickMedia { body_items.push_back(InfoPage::add_google_search(args.title)); auto body = create_body(); + body->title_mark_urls = true; body->set_items(std::move(body_items)); result_tabs.push_back(Tab{ std::move(body), std::make_unique(program), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); return PluginResult::OK; -- cgit v1.2.3