1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00

Repurposed UserTitlesTab class into TitlesTab.

Also implemented system titles tab view in the process.
This commit is contained in:
Pablo Curiel 2021-06-23 21:37:57 -04:00
parent 7a15b4eab8
commit 9635670007
5 changed files with 53 additions and 40 deletions

View file

@ -1,5 +1,5 @@
/* /*
* user_titles_tab.hpp * titles_tab.hpp
* *
* Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>. * Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>.
* *
@ -21,8 +21,8 @@
#pragma once #pragma once
#ifndef __USER_TITLES_TAB_HPP__ #ifndef __TITLES_TAB_HPP__
#define __USER_TITLES_TAB_HPP__ #define __TITLES_TAB_HPP__
#include "tasks.hpp" #include "tasks.hpp"
#include "layered_error_frame.hpp" #include "layered_error_frame.hpp"
@ -30,27 +30,30 @@
namespace nxdt::views namespace nxdt::views
{ {
/* Expanded ListItem class to hold a title ID. */ /* Expanded ListItem class to hold a title ID. */
class UserTitlesItem: public brls::ListItem class TitlesTabItem: public brls::ListItem
{ {
private: private:
u64 title_id = 0; u64 title_id = 0;
bool is_system = false;
public: public:
UserTitlesItem(TitleApplicationMetadata *app_metadata); TitlesTabItem(TitleApplicationMetadata *app_metadata, bool is_system);
}; };
class UserTitlesTab: public LayeredErrorFrame class TitlesTab: public LayeredErrorFrame
{ {
private: private:
nxdt::tasks::TitleTask *title_task = nullptr; nxdt::tasks::TitleTask *title_task = nullptr;
nxdt::tasks::TitleEvent::Subscription title_task_sub; 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: public:
UserTitlesTab(nxdt::tasks::TitleTask *title_task); TitlesTab(nxdt::tasks::TitleTask *title_task, bool is_system);
~UserTitlesTab(void); ~TitlesTab(void);
}; };
} }
#endif /* __USER_TITLES_TAB_HPP__ */ #endif /* __TITLES_TAB_HPP__ */

View file

@ -0,0 +1,4 @@
{
"no_titles_available": "No titles available.",
"user_titles_notification": "User titles list updated!"
}

View file

@ -1,4 +0,0 @@
{
"no_titles_available": "No user titles available.",
"notification": "User titles list updated!"
}

View file

@ -22,8 +22,7 @@
#include <nxdt_utils.h> #include <nxdt_utils.h>
#include <root_view.hpp> #include <root_view.hpp>
#include <gamecard_tab.hpp> #include <gamecard_tab.hpp>
#include <user_titles_tab.hpp> #include <titles_tab.hpp>
//#include <system_titles_tab.hpp>
//#include <options_tab.hpp> //#include <options_tab.hpp>
#include <about_tab.hpp> #include <about_tab.hpp>
@ -74,8 +73,8 @@ namespace nxdt::views
/* Add tabs. */ /* Add tabs. */
this->addTab("root_view/tabs/gamecard"_i18n, new GameCardTab(this->gc_status_task)); this->addTab("root_view/tabs/gamecard"_i18n, new GameCardTab(this->gc_status_task));
this->addSeparator(); this->addSeparator();
this->addTab("root_view/tabs/user_titles"_i18n, new UserTitlesTab(this->title_task)); this->addTab("root_view/tabs/user_titles"_i18n, new TitlesTab(this->title_task, false));
this->addTab("root_view/tabs/system_titles"_i18n, new brls::Rectangle(nvgRGB(0, 0, 255))); this->addTab("root_view/tabs/system_titles"_i18n, new TitlesTab(this->title_task, true));
this->addSeparator(); this->addSeparator();
this->addTab("root_view/tabs/options"_i18n, new brls::Rectangle(nvgRGB(255, 255, 0))); this->addTab("root_view/tabs/options"_i18n, new brls::Rectangle(nvgRGB(255, 255, 0)));
this->addSeparator(); this->addSeparator();

View file

@ -1,5 +1,5 @@
/* /*
* user_titles_tab.cpp * titles_tab.cpp
* *
* Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>. * Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>.
* *
@ -20,45 +20,56 @@
*/ */
#include <nxdt_utils.h> #include <nxdt_utils.h>
#include <user_titles_tab.hpp> #include <titles_tab.hpp>
using namespace brls::i18n::literals; /* For _i18n. */ using namespace brls::i18n::literals; /* For _i18n. */
namespace nxdt::views namespace nxdt::views
{ {
UserTitlesItem::UserTitlesItem(TitleApplicationMetadata *app_metadata) : brls::ListItem(std::string(app_metadata->lang_entry.name), "", std::string(app_metadata->lang_entry.author)), \ TitlesTabItem::TitlesTabItem(TitleApplicationMetadata *app_metadata, bool is_system) : brls::ListItem(std::string(app_metadata->lang_entry.name), "", ""), \
title_id(app_metadata->title_id) 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. */ /* Populate list. */
this->PopulateList(this->title_task->GetApplicationMetadata(false)); this->PopulateList(this->title_task->GetApplicationMetadata(this->is_system));
/* Subscribe to title event. */ /* Subscribe to title event if this is the user titles tab. */
this->title_task_sub = this->title_task->RegisterListener([this](const nxdt::tasks::TitleApplicationMetadataVector* user_app_metadata) { if (!this->is_system)
{
this->title_task_sub = this->title_task->RegisterListener([this](const nxdt::tasks::TitleApplicationMetadataVector* app_metadata) {
/* Update list. */ /* Update list. */
this->PopulateList(user_app_metadata); this->PopulateList(app_metadata);
brls::Application::notify("user_titles_tab/notification"_i18n); brls::Application::notify("titles_tab/user_titles_notification"_i18n);
}); });
} }
UserTitlesTab::~UserTitlesTab(void)
{
/* Unregister task listener. */
this->title_task->UnregisterListener(this->title_task_sub);
} }
void UserTitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataVector* user_app_metadata) TitlesTab::~TitlesTab(void)
{ {
if (!user_app_metadata) return; /* Unregister task listener if this is the user titles tab. */
if (!this->is_system) this->title_task->UnregisterListener(this->title_task_sub);
}
void TitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataVector* app_metadata)
{
if (!app_metadata) return;
bool refocus = false; 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. */ /* Determine if we need to refocus after updating the list. */
brls::View *cur_view = brls::Application::getCurrentFocus(); brls::View *cur_view = brls::Application::getCurrentFocus();
@ -82,10 +93,10 @@ namespace nxdt::views
this->list->invalidate(true); this->list->invalidate(true);
/* Immediately return if we have no user application metadata. */ /* Immediately return if we have no user application metadata. */
if (!user_app_metadata_count) return; if (!app_metadata_count) return;
/* Populate list. */ /* 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. */ /* Switch to the list. */
this->list->invalidate(true); this->list->invalidate(true);