aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp141
-rw-r--r--src/QuickMedia.cpp30
-rw-r--r--src/Theme.cpp2
3 files changed, 73 insertions, 100 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index e0f39fd..50cab3c 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -62,6 +62,33 @@ namespace QuickMedia {
return result;
}
+ template <typename T>
+ static void get_json_value(const Json::Value &json_obj, const char *field_name, T &val) {
+ const Json::Value &json_val = json_obj[field_name];
+ if(json_val.isNull())
+ return;
+
+ if(!json_val.is<T>()) {
+ fprintf(stderr, "Warning: config variable \"%s\" is not a %s\n", field_name, typeid(T).name());
+ return;
+ }
+
+ val = json_val.as<T>();
+ }
+
+ static void get_json_value(const Json::Value &json_obj, const char *field_name, float &val) {
+ const Json::Value &json_val = json_obj[field_name];
+ if(json_val.isNull())
+ return;
+
+ if(!json_val.isDouble()) {
+ fprintf(stderr, "Warning: config variable \"%s\" is not a float\n", field_name);
+ return;
+ }
+
+ val = json_val.asDouble();
+ }
+
// No-op if this has already been called before
static void init_config() {
if(config_initialized)
@@ -86,59 +113,30 @@ namespace QuickMedia {
}
const Json::Value &search_json = json_root["search"];
- if(search_json.isObject()) {
- const Json::Value &font_size_json = search_json["font_size"];
- if(font_size_json.isNumeric())
- config->search.font_size = font_size_json.asInt();
- }
+ if(search_json.isObject())
+ get_json_value(search_json, "font_size", config->search.font_size);
const Json::Value &tab_json = json_root["tab"];
- if(tab_json.isObject()) {
- const Json::Value &font_size_json = tab_json["font_size"];
- if(font_size_json.isNumeric())
- config->tab.font_size = font_size_json.asInt();
- }
+ if(tab_json.isObject())
+ get_json_value(tab_json, "font_size", config->tab.font_size);
const Json::Value &body_json = json_root["body"];
if(body_json.isObject()) {
- const Json::Value &title_font_size = body_json["title_font_size"];
- if(title_font_size.isNumeric())
- config->body.title_font_size = title_font_size.asInt();
-
- const Json::Value &author_font_size = body_json["author_font_size"];
- if(author_font_size.isNumeric())
- config->body.author_font_size = author_font_size.asInt();
-
- const Json::Value &description_font_size = body_json["description_font_size"];
- if(description_font_size.isNumeric())
- config->body.description_font_size = description_font_size.asInt();
-
- const Json::Value &timestamp_font_size = body_json["timestamp_font_size"];
- if(timestamp_font_size.isNumeric())
- config->body.timestamp_font_size = timestamp_font_size.asInt();
-
- const Json::Value &reaction_font_size = body_json["reaction_font_size"];
- if(reaction_font_size.isNumeric())
- config->body.reaction_font_size = reaction_font_size.asInt();
-
- const Json::Value &embedded_load_font_size = body_json["embedded_load_font_size"];
- if(embedded_load_font_size.isNumeric())
- config->body.embedded_load_font_size = embedded_load_font_size.asInt();
+ get_json_value(body_json, "title_font_size", config->body.title_font_size);
+ get_json_value(body_json, "author_font_size", config->body.author_font_size);
+ get_json_value(body_json, "description_font_size", config->body.description_font_size);
+ get_json_value(body_json, "timestamp_font_size", config->body.timestamp_font_size);
+ get_json_value(body_json, "reaction_font_size", config->body.reaction_font_size);
+ get_json_value(body_json, "embedded_load_font_size", config->body.embedded_load_font_size);
}
const Json::Value &input_json = json_root["input"];
- if(input_json.isObject()) {
- const Json::Value &font_size_json = input_json["font_size"];
- if(font_size_json.isNumeric())
- config->input.font_size = font_size_json.asInt();
- }
+ if(input_json.isObject())
+ get_json_value(input_json, "font_size", config->input.font_size);
const Json::Value &video_json = json_root["video"];
- if(video_json.isObject()) {
- const Json::Value &max_height_json = video_json["max_height"];
- if(max_height_json.isNumeric())
- config->video.max_height = max_height_json.asInt();
- }
+ if(video_json.isObject())
+ get_json_value(video_json, "max_height", config->video.max_height);
const Json::Value &local_manga_json = json_root["local_manga"];
if(local_manga_json.isObject()) {
@@ -150,13 +148,8 @@ namespace QuickMedia {
}
}
- const Json::Value &sort_by_name_json = local_manga_json["sort_by_name"];
- if(sort_by_name_json.isBool())
- config->local_manga.sort_by_name = sort_by_name_json.asBool();
-
- const Json::Value &sort_chapters_by_name_json = local_manga_json["sort_chapters_by_name"];
- if(sort_chapters_by_name_json.isBool())
- config->local_manga.sort_chapters_by_name = sort_chapters_by_name_json.asBool();
+ get_json_value(local_manga_json, "load_progress", config->local_manga.sort_by_name);
+ get_json_value(local_manga_json, "sort_chapters_by_name", config->local_manga.sort_chapters_by_name);
}
const Json::Value &local_anime_json = json_root["local_anime"];
@@ -169,45 +162,21 @@ namespace QuickMedia {
}
}
- const Json::Value &sort_by_name_json = local_anime_json["sort_by_name"];
- if(sort_by_name_json.isBool())
- config->local_anime.sort_by_name = sort_by_name_json.asBool();
-
- const Json::Value &auto_group_episodes_json = local_anime_json["auto_group_episodes"];
- if(auto_group_episodes_json.isBool())
- config->local_anime.auto_group_episodes = auto_group_episodes_json.asBool();
+ get_json_value(local_anime_json, "sort_by_name", config->local_anime.sort_by_name);
+ get_json_value(local_anime_json, "auto_group_episodes", config->local_anime.auto_group_episodes);
}
const Json::Value &youtube_json = json_root["youtube"];
- if(youtube_json.isObject()) {
- const Json::Value &load_progress_json = youtube_json["load_progress"];
- if(load_progress_json.isBool())
- config->youtube.load_progress = load_progress_json.asBool();
- }
-
- const Json::Value &use_system_fonts_json = json_root["use_system_fonts"];
- if(use_system_fonts_json.isBool())
- config->use_system_fonts = use_system_fonts_json.asBool();
-
- const Json::Value &use_system_mpv_config_json = json_root["use_system_mpv_config"];
- if(use_system_mpv_config_json.isBool())
- config->use_system_mpv_config = use_system_mpv_config_json.asBool();
-
- const Json::Value &theme_json = json_root["theme"];
- if(theme_json.isString())
- config->theme = theme_json.asString();
-
- const Json::Value &scale_json = json_root["scale"];
- if(scale_json.isNumeric())
- config->scale = scale_json.asFloat();
-
- const Json::Value &font_scale = json_root["font_scale"];
- if(font_scale.isNumeric())
- config->font_scale = font_scale.asFloat();
-
- const Json::Value &spacing_scale = json_root["spacing_scale"];
- if(spacing_scale.isNumeric())
- config->spacing_scale = spacing_scale.asFloat();
+ if(youtube_json.isObject())
+ get_json_value(youtube_json, "load_progress", config->youtube.load_progress);
+
+ 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);
+ get_json_value(json_root, "theme", config->theme);
+ get_json_value(json_root, "scale", config->scale);
+ get_json_value(json_root, "font_scale", config->font_scale);
+ get_json_value(json_root, "spacing_scale", config->spacing_scale);
}
const Config& get_config() {
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index e710fb5..ebd6ac4 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -675,28 +675,30 @@ namespace QuickMedia {
set_window_icon(disp, window.get_system_handle(), resources_root + "icons/qm_logo.png");
- if(!is_touch_enabled()) {
- if(!circle_mask_shader.load_from_file((resources_root + "shaders/circle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) {
+ if(!is_touch_enabled() && get_config().enable_shaders) {
+ if(get_theme().circle_mask_enabled && !circle_mask_shader.load_from_file((resources_root + "shaders/circle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) {
show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/circle_mask.glsl", Urgency::CRITICAL);
abort();
}
- if(get_theme().drop_shadow) {
- if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle.glsl").c_str(), mgl::Shader::Type::Fragment)) {
- show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle.glsl", Urgency::CRITICAL);
- abort();
+ if(get_theme().rounded_rectangles) {
+ if(get_theme().drop_shadow) {
+ if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle.glsl").c_str(), mgl::Shader::Type::Fragment)) {
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle.glsl", Urgency::CRITICAL);
+ abort();
+ }
+ } else {
+ if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle_no_shadow.glsl").c_str(), mgl::Shader::Type::Fragment)) {
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_no_shadow.glsl", Urgency::CRITICAL);
+ abort();
+ }
}
- } else {
- if(!rounded_rectangle_shader.load_from_file((resources_root + "shaders/rounded_rectangle_no_shadow.glsl").c_str(), mgl::Shader::Type::Fragment)) {
- show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_no_shadow.glsl", Urgency::CRITICAL);
+
+ if(!rounded_rectangle_mask_shader.load_from_file((resources_root + "shaders/rounded_rectangle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) {
+ show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_mask.glsl", Urgency::CRITICAL);
abort();
}
}
-
- if(!rounded_rectangle_mask_shader.load_from_file((resources_root + "shaders/rounded_rectangle_mask.glsl").c_str(), mgl::Shader::Type::Fragment)) {
- show_notification("QuickMedia", "Failed to load " + resources_root + "/shaders/rounded_rectangle_mask.glsl", Urgency::CRITICAL);
- abort();
- }
}
if(!loading_icon.load_from_file((resources_root + "images/loading_icon.png").c_str())) {
diff --git a/src/Theme.cpp b/src/Theme.cpp
index 9f525d5..2d5bfd4 100644
--- a/src/Theme.cpp
+++ b/src/Theme.cpp
@@ -120,6 +120,8 @@ namespace QuickMedia {
parse_hex_set_color(json_root, "loading_page_color", theme->loading_page_color);
parse_hex_set_color(json_root, "more_items_color", theme->more_items_color);
get_bool_value(json_root, "drop_shadow", theme->drop_shadow);
+ get_bool_value(json_root, "circle_mask_enabled", theme->circle_mask_enabled);
+ get_bool_value(json_root, "rounded_rectangles", theme->rounded_rectangles);
}
const Theme& get_theme() {