From 96356700075cd0d5384e8c821b3d493257ce3734 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Wed, 23 Jun 2021 21:37:57 -0400 Subject: [PATCH] Repurposed UserTitlesTab class into TitlesTab. Also implemented system titles tab view in the process. --- .../{user_titles_tab.hpp => titles_tab.hpp} | 23 ++++---- romfs/i18n/en-US/titles_tab.json | 4 ++ romfs/i18n/en-US/user_titles_tab.json | 4 -- source/root_view.cpp | 7 +-- .../{user_titles_tab.cpp => titles_tab.cpp} | 55 +++++++++++-------- 5 files changed, 53 insertions(+), 40 deletions(-) rename include/{user_titles_tab.hpp => titles_tab.hpp} (72%) create mode 100644 romfs/i18n/en-US/titles_tab.json delete mode 100644 romfs/i18n/en-US/user_titles_tab.json rename source/{user_titles_tab.cpp => titles_tab.cpp} (51%) diff --git a/include/user_titles_tab.hpp b/include/titles_tab.hpp similarity index 72% rename from include/user_titles_tab.hpp rename to include/titles_tab.hpp index b7156fe..d2a55d5 100644 --- a/include/user_titles_tab.hpp +++ b/include/titles_tab.hpp @@ -1,5 +1,5 @@ /* - * user_titles_tab.hpp + * titles_tab.hpp * * Copyright (c) 2020-2021, DarkMatterCore . * @@ -21,8 +21,8 @@ #pragma once -#ifndef __USER_TITLES_TAB_HPP__ -#define __USER_TITLES_TAB_HPP__ +#ifndef __TITLES_TAB_HPP__ +#define __TITLES_TAB_HPP__ #include "tasks.hpp" #include "layered_error_frame.hpp" @@ -30,27 +30,30 @@ namespace nxdt::views { /* Expanded ListItem class to hold a title ID. */ - class UserTitlesItem: public brls::ListItem + class TitlesTabItem: public brls::ListItem { private: u64 title_id = 0; + bool is_system = false; public: - UserTitlesItem(TitleApplicationMetadata *app_metadata); + TitlesTabItem(TitleApplicationMetadata *app_metadata, bool is_system); }; - class UserTitlesTab: public LayeredErrorFrame + class TitlesTab: public LayeredErrorFrame { private: nxdt::tasks::TitleTask *title_task = nullptr; nxdt::tasks::TitleEvent::Subscription title_task_sub; - void PopulateList(const nxdt::tasks::TitleApplicationMetadataVector* user_app_metadata); + bool is_system = false; + + void PopulateList(const nxdt::tasks::TitleApplicationMetadataVector* app_metadata); public: - UserTitlesTab(nxdt::tasks::TitleTask *title_task); - ~UserTitlesTab(void); + TitlesTab(nxdt::tasks::TitleTask *title_task, bool is_system); + ~TitlesTab(void); }; } -#endif /* __USER_TITLES_TAB_HPP__ */ +#endif /* __TITLES_TAB_HPP__ */ diff --git a/romfs/i18n/en-US/titles_tab.json b/romfs/i18n/en-US/titles_tab.json new file mode 100644 index 0000000..98d9a7f --- /dev/null +++ b/romfs/i18n/en-US/titles_tab.json @@ -0,0 +1,4 @@ +{ + "no_titles_available": "No titles available.", + "user_titles_notification": "User titles list updated!" +} diff --git a/romfs/i18n/en-US/user_titles_tab.json b/romfs/i18n/en-US/user_titles_tab.json deleted file mode 100644 index bfa9771..0000000 --- a/romfs/i18n/en-US/user_titles_tab.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "no_titles_available": "No user titles available.", - "notification": "User titles list updated!" -} diff --git a/source/root_view.cpp b/source/root_view.cpp index 6a67418..73dcac2 100644 --- a/source/root_view.cpp +++ b/source/root_view.cpp @@ -22,8 +22,7 @@ #include #include #include -#include -//#include +#include //#include #include @@ -74,8 +73,8 @@ namespace nxdt::views /* Add tabs. */ this->addTab("root_view/tabs/gamecard"_i18n, new GameCardTab(this->gc_status_task)); this->addSeparator(); - this->addTab("root_view/tabs/user_titles"_i18n, new UserTitlesTab(this->title_task)); - this->addTab("root_view/tabs/system_titles"_i18n, new brls::Rectangle(nvgRGB(0, 0, 255))); + this->addTab("root_view/tabs/user_titles"_i18n, new TitlesTab(this->title_task, false)); + this->addTab("root_view/tabs/system_titles"_i18n, new TitlesTab(this->title_task, true)); this->addSeparator(); this->addTab("root_view/tabs/options"_i18n, new brls::Rectangle(nvgRGB(255, 255, 0))); this->addSeparator(); diff --git a/source/user_titles_tab.cpp b/source/titles_tab.cpp similarity index 51% rename from source/user_titles_tab.cpp rename to source/titles_tab.cpp index 9397994..c693cee 100644 --- a/source/user_titles_tab.cpp +++ b/source/titles_tab.cpp @@ -1,5 +1,5 @@ /* - * user_titles_tab.cpp + * titles_tab.cpp * * Copyright (c) 2020-2021, DarkMatterCore . * @@ -20,45 +20,56 @@ */ #include -#include +#include using namespace brls::i18n::literals; /* For _i18n. */ namespace nxdt::views { - UserTitlesItem::UserTitlesItem(TitleApplicationMetadata *app_metadata) : brls::ListItem(std::string(app_metadata->lang_entry.name), "", std::string(app_metadata->lang_entry.author)), \ - title_id(app_metadata->title_id) + TitlesTabItem::TitlesTabItem(TitleApplicationMetadata *app_metadata, bool is_system) : brls::ListItem(std::string(app_metadata->lang_entry.name), "", ""), \ + title_id(app_metadata->title_id), + is_system(is_system) { - if (app_metadata->icon && app_metadata->icon_size) this->setThumbnail(app_metadata->icon, app_metadata->icon_size); + brls::Style* style = brls::Application::getStyle(); + + /* Set sublabel. */ + this->subLabel = (!this->is_system ? std::string(app_metadata->lang_entry.author) : fmt::format("{:016X}", this->title_id)); + this->setHeight(style->List.Item.heightWithSubLabel); + + /* Set thumbnail if we're dealing with user metadata. */ + if (!this->is_system && app_metadata->icon && app_metadata->icon_size) this->setThumbnail(app_metadata->icon, app_metadata->icon_size); } - UserTitlesTab::UserTitlesTab(nxdt::tasks::TitleTask *title_task) : LayeredErrorFrame("user_titles_tab/no_titles_available"_i18n), title_task(title_task) + TitlesTab::TitlesTab(nxdt::tasks::TitleTask *title_task, bool is_system) : LayeredErrorFrame("titles_tab/no_titles_available"_i18n), title_task(title_task), is_system(is_system) { /* Populate list. */ - this->PopulateList(this->title_task->GetApplicationMetadata(false)); + this->PopulateList(this->title_task->GetApplicationMetadata(this->is_system)); - /* Subscribe to title event. */ - this->title_task_sub = this->title_task->RegisterListener([this](const nxdt::tasks::TitleApplicationMetadataVector* user_app_metadata) { - /* Update list. */ - this->PopulateList(user_app_metadata); - brls::Application::notify("user_titles_tab/notification"_i18n); - }); + /* Subscribe to title event if this is the user titles tab. */ + if (!this->is_system) + { + this->title_task_sub = this->title_task->RegisterListener([this](const nxdt::tasks::TitleApplicationMetadataVector* app_metadata) { + /* Update list. */ + this->PopulateList(app_metadata); + brls::Application::notify("titles_tab/user_titles_notification"_i18n); + }); + } } - UserTitlesTab::~UserTitlesTab(void) + TitlesTab::~TitlesTab(void) { - /* Unregister task listener. */ - this->title_task->UnregisterListener(this->title_task_sub); + /* Unregister task listener if this is the user titles tab. */ + if (!this->is_system) this->title_task->UnregisterListener(this->title_task_sub); } - void UserTitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataVector* user_app_metadata) + void TitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataVector* app_metadata) { - if (!user_app_metadata) return; + if (!app_metadata) return; bool refocus = false; - size_t user_app_metadata_count = user_app_metadata->size(); + size_t app_metadata_count = app_metadata->size(); - if (user_app_metadata_count) + if (app_metadata_count) { /* Determine if we need to refocus after updating the list. */ brls::View *cur_view = brls::Application::getCurrentFocus(); @@ -82,10 +93,10 @@ namespace nxdt::views this->list->invalidate(true); /* Immediately return if we have no user application metadata. */ - if (!user_app_metadata_count) return; + if (!app_metadata_count) return; /* Populate list. */ - for(TitleApplicationMetadata *cur_app_metadata : *user_app_metadata) this->list->addView(new UserTitlesItem(cur_app_metadata)); + for(TitleApplicationMetadata *cur_app_metadata : *app_metadata) this->list->addView(new TitlesTabItem(cur_app_metadata, this->is_system)); /* Switch to the list. */ this->list->invalidate(true);