From 405df0c81a93802aa56c7398c46970c99f8d9522 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Sun, 8 Aug 2021 03:39:21 -0400 Subject: [PATCH] FocusableItem: reestructure class. Other changes include: * Codebase: update all references to FocusableLabel and FocusableTable constructors to match the changes in FocusableItem. * FocusableTable: objects can now be highlighted, but the highlight background won't be drawn. * http: set low speed limit and time values. --- include/about_tab.hpp | 2 +- include/defines.h | 2 ++ include/focusable_item.hpp | 61 ++++++++++++++++++++------------------ libs/borealis | 2 +- source/core/http.c | 2 ++ source/gamecard_tab.cpp | 2 +- source/options_tab.cpp | 4 +-- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/include/about_tab.hpp b/include/about_tab.hpp index 9e569b4..a1ffe3a 100644 --- a/include/about_tab.hpp +++ b/include/about_tab.hpp @@ -33,7 +33,7 @@ namespace nxdt::views class AboutTabLabel: public FocusableLabel { public: - AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center = false) : FocusableLabel(false, labelStyle, text, true) + AboutTabLabel(brls::LabelStyle labelStyle, std::string text, bool center = false) : FocusableLabel(labelStyle, text, true) { if (center) this->setHorizontalAlign(NVG_ALIGN_CENTER); } diff --git a/include/defines.h b/include/defines.h index 505a421..2bf34d5 100644 --- a/include/defines.h +++ b/include/defines.h @@ -104,6 +104,8 @@ #define HTTP_USER_AGENT APP_TITLE "/" APP_VERSION " (Nintendo Switch)" #define HTTP_CONNECT_TIMEOUT 10L /* 10 seconds. */ +#define HTTP_LOW_SPEED_LIMIT 30L /* 30 bytes per second. */ +#define HTTP_LOW_SPEED_TIME HTTP_CONNECT_TIMEOUT #define HTTP_BUFFER_SIZE 131072L /* 128 KiB. */ #define GITHUB_URL "https://github.com" diff --git a/include/focusable_item.hpp b/include/focusable_item.hpp index 0379400..c05565b 100644 --- a/include/focusable_item.hpp +++ b/include/focusable_item.hpp @@ -32,7 +32,7 @@ namespace nxdt::views class FocusableItem: public ViewType { private: - bool highlight_view; + bool highlight, highlight_bg; protected: brls::View* getDefaultFocus(void) override @@ -40,42 +40,45 @@ namespace nxdt::views return this; } - void playClickAnimation(void) override; - void onFocusGained(void) override; + bool isHighlightBackgroundEnabled(void) override + { + return this->highlight_bg; + } + + void onFocusGained(void) override + { + if (this->highlight) + { + /* Focus and highlight view. */ + brls::View::onFocusGained(); + } else { + /* Focus view without highlighting it. */ + this->focused = true; + this->focusEvent.fire(this); + if (this->hasParent()) this->getParent()->onChildFocusGained(this); + } + } public: template - FocusableItem(bool highlight_view, Types... args) : ViewType(args...) - { - this->highlight_view = highlight_view; - } + FocusableItem(bool highlight, bool highlight_bg, Types... args) : ViewType(args...), highlight(highlight), highlight_bg(highlight_bg) { } }; - template - void FocusableItem::playClickAnimation(void) - { - /* Play click animation. */ - if (this->highlight_view) brls::View::playClickAnimation(); - } + /* Define templated classes for the focusable items we're gonna use. */ - template - void FocusableItem::onFocusGained(void) + class FocusableLabel: public FocusableItem { - if (this->highlight_view) - { - /* Focus and highlight view. */ - brls::View::onFocusGained(); - } else { - /* Focus view without highlighting it. */ - this->focused = true; - this->focusEvent.fire(this); - if (this->hasParent()) this->getParent()->onChildFocusGained(this); - } - } + public: + template + FocusableLabel(Types... args) : FocusableItem(false, false, args...) { } + }; - /* Instantiate templates for the focusable item classes we're gonna use. */ - typedef FocusableItem FocusableLabel; - typedef FocusableItem FocusableTable; + class FocusableTable: public FocusableItem + { + public: + template + FocusableTable(Types... args) : FocusableItem(true, false, args...) { } + }; } #endif /* __FOCUSABLE_ITEM_HPP__ */ diff --git a/libs/borealis b/libs/borealis index fb8891e..4642d9f 160000 --- a/libs/borealis +++ b/libs/borealis @@ -1 +1 @@ -Subproject commit fb8891e4d75474d1a1ecbde1c930b0a308b1c3e0 +Subproject commit 4642d9f87b1fb5509ea771f03d6a194d2accaa2d diff --git a/source/core/http.c b/source/core/http.c index 4bd3105..feb9c31 100644 --- a/source/core/http.c +++ b/source/core/http.c @@ -125,6 +125,8 @@ bool httpPerformGetRequest(const char *url, bool force_https, size_t *outsize, H curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, HTTP_LOW_SPEED_LIMIT); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, HTTP_LOW_SPEED_TIME); curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, HTTP_BUFFER_SIZE); curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)(force_https ? CURL_HTTP_VERSION_2TLS : CURL_HTTP_VERSION_1_1)); diff --git a/source/gamecard_tab.cpp b/source/gamecard_tab.cpp index bb68507..2fadc17 100644 --- a/source/gamecard_tab.cpp +++ b/source/gamecard_tab.cpp @@ -50,7 +50,7 @@ namespace nxdt::views /* Gamecard properties table. */ this->list->addView(new brls::Header("gamecard_tab/list/properties_table/header"_i18n)); - this->properties_table = new FocusableTable(false); + this->properties_table = new FocusableTable(); this->capacity = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/capacity"_i18n); this->total_size = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/total_size"_i18n); this->trimmed_size = this->properties_table->addRow(brls::TableRowType::BODY, "gamecard_tab/list/properties_table/trimmed_size"_i18n); diff --git a/source/options_tab.cpp b/source/options_tab.cpp index 571b862..0ae09e5 100644 --- a/source/options_tab.cpp +++ b/source/options_tab.cpp @@ -306,7 +306,7 @@ namespace nxdt::views std::stringstream ss(std::string(this->json_data.changelog)); /* Display version string at the top. */ - FocusableLabel *version_lbl = new FocusableLabel(false, brls::LabelStyle::CRASH, std::string(this->json_data.version), true); + FocusableLabel *version_lbl = new FocusableLabel(brls::LabelStyle::CRASH, std::string(this->json_data.version), true); version_lbl->setHorizontalAlign(NVG_ALIGN_CENTER); this->changelog_list->addView(version_lbl); @@ -338,7 +338,7 @@ namespace nxdt::views } /* Add line to the changelog view. */ - this->changelog_list->addView(new FocusableLabel(false, brls::LabelStyle::SMALL, item, true)); + this->changelog_list->addView(new FocusableLabel(brls::LabelStyle::SMALL, item, true)); } /* Register update action. */