2021-07-23 08:24:00 +01:00
/*
* options_tab . cpp
*
2024-04-12 10:47:36 +01:00
* Copyright ( c ) 2020 - 2024 , DarkMatterCore < pabloacurielz @ gmail . com > .
2021-07-23 08:24:00 +01:00
*
* This file is part of nxdumptool ( https : //github.com/DarkMatterCore/nxdumptool).
*
* nxdumptool is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* nxdumptool is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https : //www.gnu.org/licenses/>.
*/
# include <options_tab.hpp>
2021-08-07 09:42:03 +01:00
# include <focusable_item.hpp>
2021-07-23 08:24:00 +01:00
# include <title.h>
2021-08-07 09:42:03 +01:00
# include <sstream>
2021-07-23 08:24:00 +01:00
2021-08-07 09:42:03 +01:00
namespace i18n = brls : : i18n ; /* For getStr(). */
using namespace i18n : : literals ; /* For _i18n. */
2021-07-23 08:24:00 +01:00
namespace nxdt : : views
{
2021-07-29 08:50:17 +01:00
OptionsTabUpdateFileDialog : : OptionsTabUpdateFileDialog ( std : : string path , std : : string url , bool force_https , std : : string success_str ) : brls : : Dialog ( ) , success_str ( success_str )
{
/* Set content view. */
2024-04-15 00:53:43 +01:00
this - > update_progress = new DataTransferProgressDisplay ( ) ;
this - > setContentView ( this - > update_progress ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Add cancel button. */
2024-04-25 00:49:04 +01:00
this - > addButton ( " generic/cancel " _i18n , [ & ] ( brls : : View * view ) {
2021-08-07 09:42:03 +01:00
/* Cancel download task. */
2024-04-25 00:49:04 +01:00
this - > download_task . Cancel ( ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Close dialog. */
this - > close ( ) ;
2021-07-29 08:50:17 +01:00
} ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Disable cancelling with B button. */
this - > setCancelable ( false ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Subscribe to the download task. */
2024-04-15 00:53:43 +01:00
this - > download_task . RegisterListener ( [ & ] ( const nxdt : : tasks : : DataTransferProgress & progress ) {
2021-07-29 08:50:17 +01:00
/* Update progress. */
2024-04-15 00:53:43 +01:00
this - > update_progress - > setProgress ( progress ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Check if the download task has finished. */
2024-04-15 00:53:43 +01:00
if ( this - > download_task . IsFinished ( ) )
2021-07-29 08:50:17 +01:00
{
/* Stop spinner. */
2024-04-15 00:53:43 +01:00
this - > update_progress - > willDisappear ( ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Update button label. */
2024-04-25 00:49:04 +01:00
this - > setButtonText ( 0 , " generic/close " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Display notification. */
2024-04-25 00:49:04 +01:00
brls : : Application : : notify ( this - > download_task . GetResult ( ) ? this - > success_str : " options_tab/notifications/update_failed " _i18n ) ;
2021-07-29 08:50:17 +01:00
}
} ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
/* Start download task. */
2024-04-25 00:49:04 +01:00
this - > download_task . Execute ( path , url , force_https ) ;
2021-07-29 08:50:17 +01:00
}
2022-07-05 02:04:28 +01:00
2024-04-19 11:08:44 +01:00
OptionsTabUpdateApplicationFrame : : OptionsTabUpdateApplicationFrame ( ) : brls : : StagedAppletFrame ( false )
2021-07-29 08:50:17 +01:00
{
2021-08-07 09:42:03 +01:00
/* Set UI properties. */
this - > setTitle ( " options_tab/update_app/label " _i18n ) ;
this - > setIcon ( BOREALIS_ASSET ( " icon/ " APP_TITLE " .jpg " ) ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Add first stage. */
this - > wait_lbl = new brls : : Label ( brls : : LabelStyle : : DIALOG , " options_tab/update_app/frame/please_wait " _i18n , false ) ;
this - > wait_lbl - > setHorizontalAlign ( NVG_ALIGN_CENTER ) ;
this - > addStage ( this - > wait_lbl ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Add second stage. */
this - > changelog_list = new brls : : List ( ) ;
this - > changelog_list - > setSpacing ( this - > changelog_list - > getSpacing ( ) / 2 ) ;
this - > changelog_list - > setMarginBottom ( 20 ) ;
this - > addStage ( this - > changelog_list ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Add third stage. */
2024-04-15 00:53:43 +01:00
this - > update_progress = new DataTransferProgressDisplay ( ) ;
2021-08-07 09:42:03 +01:00
this - > addStage ( this - > update_progress ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Subscribe to the JSON task. */
2024-04-15 00:53:43 +01:00
this - > json_task . RegisterListener ( [ & ] ( const nxdt : : tasks : : DataTransferProgress & progress ) {
2024-04-25 00:49:04 +01:00
/* Return immediately if the JSON task hasn't finished yet or if it was cancelled. */
if ( ! this - > json_task . IsFinished ( ) | | this - > json_task . IsCancelled ( ) ) return ;
2022-07-05 02:04:28 +01:00
2021-08-07 10:44:36 +01:00
std : : string notification = " " ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Retrieve task result. */
2024-04-25 00:49:04 +01:00
nxdt : : tasks : : DownloadDataResult json_task_result = this - > json_task . GetResult ( ) ;
2021-08-07 09:42:03 +01:00
this - > json_buf = json_task_result . first ;
this - > json_buf_size = json_task_result . second ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Parse downloaded JSON object. */
if ( utilsParseGitHubReleaseJsonData ( this - > json_buf , this - > json_buf_size , & ( this - > json_data ) ) )
{
2021-08-07 10:44:36 +01:00
/* Check if the application can be updated. */
if ( utilsIsApplicationUpdatable ( this - > json_data . version , this - > json_data . commit_hash ) )
{
/* Display changelog. */
this - > DisplayChangelog ( ) ;
} else {
/* Set notification string. */
notification = " options_tab/notifications/up_to_date " _i18n ;
}
2021-08-07 09:42:03 +01:00
} else {
2021-08-07 10:44:36 +01:00
/* Log downloaded data. */
2022-07-12 17:34:49 +01:00
LOG_DATA_ERROR ( this - > json_buf , this - > json_buf_size , " Failed to parse GitHub release JSON. Downloaded data: " ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 10:44:36 +01:00
/* Set notification string. */
notification = " options_tab/notifications/github_json_failed " _i18n ;
}
2022-07-05 02:04:28 +01:00
2021-08-07 10:44:36 +01:00
/* Pop view (if needed). */
2024-04-15 00:53:43 +01:00
if ( ! notification . empty ( ) )
2021-08-07 10:44:36 +01:00
{
2021-08-07 09:42:03 +01:00
/* Display notification. */
2021-08-07 10:44:36 +01:00
brls : : Application : : notify ( notification ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 10:44:36 +01:00
/* Pop view. */
2021-08-07 09:42:03 +01:00
this - > onCancel ( ) ;
}
} ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Start JSON task. */
2024-04-25 00:49:04 +01:00
this - > json_task . Execute ( GITHUB_API_RELEASE_URL , true ) ;
2021-08-07 09:42:03 +01:00
}
2022-07-05 02:04:28 +01:00
2024-04-19 11:08:44 +01:00
OptionsTabUpdateApplicationFrame : : ~ OptionsTabUpdateApplicationFrame ( )
2021-08-07 09:42:03 +01:00
{
/* Free parsed JSON data. */
utilsFreeGitHubReleaseJsonData ( & ( this - > json_data ) ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Free JSON buffer. */
if ( this - > json_buf ) free ( this - > json_buf ) ;
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
void OptionsTabUpdateApplicationFrame : : layout ( NVGcontext * vg , brls : : Style * style , brls : : FontStash * stash )
{
brls : : StagedAppletFrame : : layout ( vg , style , stash ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
if ( this - > getCurrentStage ( ) = = 0 )
{
/* Center wait label. */
this - > wait_lbl - > setBoundaries ( this - > x + ( this - > width / 2 ) , this - > y , this - > width , this - > height ) ;
this - > wait_lbl - > invalidate ( ) ;
}
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
bool OptionsTabUpdateApplicationFrame : : onCancel ( void )
{
/* Cancel NRO task. */
2024-04-25 00:49:04 +01:00
this - > nro_task . Cancel ( ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Cancel JSON task. */
2024-04-25 00:49:04 +01:00
this - > json_task . Cancel ( ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Pop view. */
2021-08-11 08:17:57 +01:00
brls : : Application : : popView ( brls : : ViewAnimation : : SLIDE_RIGHT ) ;
2022-07-05 02:04:28 +01:00
2021-07-29 08:50:17 +01:00
return true ;
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
void OptionsTabUpdateApplicationFrame : : DisplayChangelog ( void )
{
2022-07-31 00:47:40 +01:00
int line = 0 ;
2024-04-25 00:49:04 +01:00
std : : string item { } ;
std : : stringstream ss ( this - > json_data . changelog ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Display version string at the top. */
2024-04-12 22:08:54 +01:00
FocusableLabel * version_lbl = new FocusableLabel ( false , false , brls : : LabelStyle : : CRASH , std : : string ( this - > json_data . version ) , true ) ;
2021-08-07 09:42:03 +01:00
version_lbl - > setHorizontalAlign ( NVG_ALIGN_CENTER ) ;
this - > changelog_list - > addView ( version_lbl ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Display release date and commit hash. */
brls : : Label * release_details_lbl = new brls : : Label ( brls : : LabelStyle : : DESCRIPTION , i18n : : getStr ( " options_tab/update_app/frame/release_details " _i18n , \
this - > json_data . commit_hash , RootView : : GetFormattedDateString ( this - > json_data . date ) ) , true ) ;
release_details_lbl - > setHorizontalAlign ( NVG_ALIGN_CENTER ) ;
this - > changelog_list - > addView ( release_details_lbl ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Add changelog header. */
this - > changelog_list - > addView ( new brls : : Header ( " options_tab/update_app/frame/changelog_header " _i18n ) ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Split changelog string and fill list. */
while ( std : : getline ( ss , item ) )
{
/* Don't proceed if this is an empty line. */
/* Make sure to remove any possible carriage returns. */
size_t item_len = item . length ( ) ;
if ( ! item_len ) continue ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
if ( item . back ( ) = = ' \r ' )
{
if ( item_len > 1 )
{
item . pop_back ( ) ;
} else {
continue ;
}
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Add line to the changelog view. */
2022-07-31 00:47:40 +01:00
if ( ! ( line % 2 ) )
{
2024-04-12 12:40:50 +01:00
this - > changelog_list - > addView ( new FocusableLabel ( false , false , brls : : LabelStyle : : SMALL , item , true ) ) ;
2022-07-31 00:47:40 +01:00
} else {
this - > changelog_list - > addView ( new brls : : Label ( brls : : LabelStyle : : SMALL , item , true ) ) ;
}
line + + ;
2021-08-07 09:42:03 +01:00
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Register update action. */
2021-08-11 08:17:57 +01:00
this - > registerAction ( " options_tab/update_app/frame/update_action " _i18n , brls : : Key : : PLUS , [ this ] ( void ) {
2021-08-07 09:42:03 +01:00
/* Display update progress. */
this - > DisplayUpdateProgress ( ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
return true ;
} ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Go to the next stage. */
this - > nextStage ( ) ;
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
void OptionsTabUpdateApplicationFrame : : DisplayUpdateProgress ( void )
{
2022-07-30 15:25:41 +01:00
/* Unregister update action. */
this - > unregisterAction ( brls : : Key : : PLUS ) ;
2022-07-05 02:04:28 +01:00
2022-07-30 15:25:41 +01:00
/* Update cancel action label. */
2024-04-25 00:49:04 +01:00
this - > updateActionHint ( brls : : Key : : B , " generic/cancel " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Subscribe to the NRO task. */
2024-04-15 00:53:43 +01:00
this - > nro_task . RegisterListener ( [ & ] ( const nxdt : : tasks : : DataTransferProgress & progress ) {
2021-08-07 09:42:03 +01:00
/* Update progress. */
2024-04-12 22:08:54 +01:00
this - > update_progress - > setProgress ( progress ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Check if the download task has finished. */
2024-04-15 00:53:43 +01:00
if ( this - > nro_task . IsFinished ( ) )
2021-08-07 09:42:03 +01:00
{
/* Get NRO task result and immediately set application updated state if the task succeeded. */
2024-04-25 00:49:04 +01:00
bool ret = this - > nro_task . GetResult ( ) ;
2021-08-07 09:42:03 +01:00
if ( ret ) utilsSetApplicationUpdatedState ( ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Display notification. */
brls : : Application : : notify ( ret ? " options_tab/notifications/app_updated " _i18n : " options_tab/notifications/update_failed " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Pop view */
this - > onCancel ( ) ;
}
} ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Start NRO task. */
2024-04-25 00:49:04 +01:00
this - > nro_task . Execute ( NRO_TMP_PATH , std : : string ( this - > json_data . download_url ) , true ) ;
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Go to the next stage. */
this - > nextStage ( ) ;
}
2022-07-05 02:04:28 +01:00
2021-08-11 08:17:57 +01:00
OptionsTab : : OptionsTab ( RootView * root_view ) : brls : : List ( ) , root_view ( root_view )
2021-07-23 08:24:00 +01:00
{
/* Set custom spacing. */
this - > setSpacing ( this - > getSpacing ( ) / 2 ) ;
this - > setMarginBottom ( 20 ) ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
/* Information about actual dump options. */
brls : : Label * dump_options_info = new brls : : Label ( brls : : LabelStyle : : DESCRIPTION , " options_tab/dump_options_info " _i18n , true ) ;
dump_options_info - > setHorizontalAlign ( NVG_ALIGN_CENTER ) ;
this - > addView ( dump_options_info ) ;
2022-07-05 02:04:28 +01:00
2021-07-23 08:24:00 +01:00
/* Overclock. */
brls : : ToggleListItem * overclock = new brls : : ToggleListItem ( " options_tab/overclock/label " _i18n , configGetBoolean ( " overclock " ) , \
2022-09-12 19:19:10 +01:00
" options_tab/overclock/description " _i18n , " generic/value_enabled " _i18n , \
" generic/value_disabled " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-07-23 08:24:00 +01:00
overclock - > getClickEvent ( ) - > subscribe ( [ ] ( brls : : View * view ) {
2021-07-25 06:37:13 +01:00
/* Get current value. */
2022-07-12 01:27:03 +01:00
brls : : ToggleListItem * item = static_cast < brls : : ToggleListItem * > ( view ) ;
2021-07-23 08:24:00 +01:00
bool value = item - > getToggleState ( ) ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
/* Update configuration. */
2021-07-23 08:24:00 +01:00
configSetBoolean ( " overclock " , value ) ;
2022-07-05 02:04:28 +01:00
2022-07-12 02:31:39 +01:00
LOG_MSG_DEBUG ( " Overclock setting changed by user. " ) ;
2021-07-23 08:24:00 +01:00
} ) ;
2022-07-05 02:04:28 +01:00
2021-07-23 08:24:00 +01:00
this - > addView ( overclock ) ;
2022-07-05 02:04:28 +01:00
2021-07-23 08:24:00 +01:00
/* Naming convention. */
brls : : SelectListItem * naming_convention = new brls : : SelectListItem ( " options_tab/naming_convention/label " _i18n , {
" options_tab/naming_convention/value_00 " _i18n ,
" options_tab/naming_convention/value_01 " _i18n
} , static_cast < unsigned > ( configGetInteger ( " naming_convention " ) ) ,
" options_tab/naming_convention/description " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-08-11 08:17:57 +01:00
naming_convention - > getValueSelectedEvent ( ) - > subscribe ( [ ] ( int selected ) {
2021-07-25 06:37:13 +01:00
/* Make sure the current value isn't out of bounds. */
2021-07-23 08:24:00 +01:00
if ( selected < 0 | | selected > static_cast < int > ( TitleNamingConvention_Count ) ) return ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
/* Update configuration. */
2021-07-23 08:24:00 +01:00
configSetInteger ( " naming_convention " , selected ) ;
2022-07-05 02:04:28 +01:00
2022-07-12 02:31:39 +01:00
LOG_MSG_DEBUG ( " Naming convention setting changed by user. " ) ;
2021-07-23 08:24:00 +01:00
} ) ;
2022-07-05 02:04:28 +01:00
2021-07-23 08:24:00 +01:00
this - > addView ( naming_convention ) ;
2022-07-05 02:04:28 +01:00
2024-04-19 11:08:44 +01:00
/* Unmount USB Mass Storage devices. */
2024-04-18 20:58:47 +01:00
/* We will replace its default click event with a new one that will: */
/* 1. Check if any UMS devices are available before displaying the dropdown and display a notification if there are none. */
/* 2. Generate the string vector required by the dropdown. */
/* 3. Initialize the dropdown and pass a custom callback that will take care of unmounting the selected device. */
2024-04-19 11:08:44 +01:00
brls : : SelectListItem * unmount_ums_device = new brls : : SelectListItem ( " options_tab/unmount_ums_device/label " _i18n , { " dummy " } , 0 ,
i18n : : getStr ( " options_tab/unmount_ums_device/description " _i18n , APP_TITLE ) , false ) ;
2024-04-18 20:58:47 +01:00
2024-04-19 11:08:44 +01:00
unmount_ums_device - > getClickEvent ( ) - > unsubscribeAll ( ) ;
2024-04-18 20:58:47 +01:00
2024-04-19 11:08:44 +01:00
unmount_ums_device - > getClickEvent ( ) - > subscribe ( [ this ] ( brls : : View * view ) {
2024-04-18 20:58:47 +01:00
if ( this - > ums_devices . empty ( ) )
{
/* Display a notification if we haven't mounted any UMS devices at all. */
this - > DisplayNotification ( " options_tab/notifications/no_ums_devices " _i18n ) ;
return ;
}
/* Generate values vector for the dropdown. */
std : : vector < std : : string > values { } ;
for ( nxdt : : tasks : : UmsDeviceVectorEntry ums_device_entry : this - > ums_devices ) values . push_back ( ums_device_entry . second ) ;
/* Display dropdown. */
2024-04-19 11:08:44 +01:00
brls : : SelectListItem * unmount_ums_device = static_cast < brls : : SelectListItem * > ( view ) ;
brls : : Dropdown : : open ( unmount_ums_device - > getLabel ( ) , values , [ this ] ( int idx ) {
2024-04-18 20:58:47 +01:00
/* Make sure the current value isn't out of bounds. */
if ( idx < 0 | | idx > = static_cast < int > ( this - > ums_devices . size ( ) ) ) return ;
/* Unmount UMS device. */
if ( umsUnmountDevice ( this - > ums_devices . at ( idx ) . first ) )
{
this - > DisplayNotification ( " options_tab/notifications/ums_device_unmount_success " _i18n ) ;
} else {
2024-04-25 00:49:04 +01:00
this - > DisplayNotification ( " options_tab/notifications/ums_device_unmount_failed " _i18n ) ;
2024-04-18 20:58:47 +01:00
}
} ) ;
} ) ;
/* Update UMS devices vector. */
this - > ums_devices = this - > root_view - > GetUmsDevices ( ) ;
/* Subscribe to the UMS device event. */
2024-04-19 11:08:44 +01:00
this - > ums_task_sub = this - > root_view - > RegisterUmsTaskListener ( [ this , unmount_ums_device ] ( const nxdt : : tasks : : UmsDeviceVector & ums_devices ) {
2024-04-18 20:58:47 +01:00
/* Update UMS devices vector. */
this - > ums_devices = this - > root_view - > GetUmsDevices ( ) ;
/* Generate values vector for the dropdown. */
std : : vector < std : : string > values { } ;
for ( nxdt : : tasks : : UmsDeviceVectorEntry ums_device_entry : this - > ums_devices ) values . push_back ( ums_device_entry . second ) ;
/* Update SelectListItem values. */
/* If the dropdown menu is already being displayed, it'll be reloaded or popped from the view stack, depending on whether the provided vector is empty or not. */
2024-04-19 11:08:44 +01:00
unmount_ums_device - > updateValues ( values ) ;
2024-04-18 20:58:47 +01:00
} ) ;
this - > addView ( unmount_ums_device ) ;
2021-07-25 23:23:44 +01:00
/* Update NSWDB XML. */
brls : : ListItem * update_nswdb_xml = new brls : : ListItem ( " options_tab/update_nswdb_xml/label " _i18n , " options_tab/update_nswdb_xml/description " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-07-25 23:23:44 +01:00
update_nswdb_xml - > getClickEvent ( ) - > subscribe ( [ this ] ( brls : : View * view ) {
2021-08-11 08:17:57 +01:00
if ( ! this - > root_view - > IsInternetConnectionAvailable ( ) )
2021-07-29 20:55:31 +01:00
{
/* Display a notification if no Internet connection is available. */
this - > DisplayNotification ( " options_tab/notifications/no_internet_connection " _i18n ) ;
return ;
}
2022-07-05 02:04:28 +01:00
2021-07-30 22:07:26 +01:00
/* Open update dialog. */
2021-07-29 08:50:17 +01:00
OptionsTabUpdateFileDialog * dialog = new OptionsTabUpdateFileDialog ( NSWDB_XML_PATH , NSWDB_XML_URL , false , " options_tab/notifications/nswdb_xml_updated " _i18n ) ;
2021-07-27 16:00:09 +01:00
dialog - > open ( false ) ;
2021-07-25 23:23:44 +01:00
} ) ;
2022-07-05 02:04:28 +01:00
2021-07-25 23:23:44 +01:00
this - > addView ( update_nswdb_xml ) ;
2022-07-05 02:04:28 +01:00
2021-07-23 08:24:00 +01:00
/* Update application. */
2021-07-25 06:37:13 +01:00
brls : : ListItem * update_app = new brls : : ListItem ( " options_tab/update_app/label " _i18n , " options_tab/update_app/description " _i18n ) ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
update_app - > getClickEvent ( ) - > subscribe ( [ this ] ( brls : : View * view ) {
if ( envIsNso ( ) )
{
/* Display a notification if we're running as a NSO. */
this - > DisplayNotification ( " options_tab/notifications/is_nso " _i18n ) ;
return ;
} else
2021-08-11 08:17:57 +01:00
if ( ! this - > root_view - > IsInternetConnectionAvailable ( ) )
2021-07-29 20:55:31 +01:00
{
/* Display a notification if no Internet connection is available. */
this - > DisplayNotification ( " options_tab/notifications/no_internet_connection " _i18n ) ;
return ;
} else
2021-08-07 09:42:03 +01:00
if ( utilsGetApplicationUpdatedState ( ) )
2021-07-25 06:37:13 +01:00
{
/* Display a notification if the application has already been updated. */
this - > DisplayNotification ( " options_tab/notifications/already_updated " _i18n ) ;
return ;
}
2022-07-05 02:04:28 +01:00
2021-08-07 09:42:03 +01:00
/* Display update frame. */
2021-08-11 08:17:57 +01:00
brls : : Application : : pushView ( new OptionsTabUpdateApplicationFrame ( ) , brls : : ViewAnimation : : SLIDE_LEFT , false ) ;
2021-07-25 06:37:13 +01:00
} ) ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
this - > addView ( update_app ) ;
}
2022-07-05 02:04:28 +01:00
2024-04-19 11:08:44 +01:00
OptionsTab : : ~ OptionsTab ( )
2021-07-25 06:37:13 +01:00
{
2024-04-18 20:58:47 +01:00
this - > root_view - > UnregisterUmsTaskListener ( this - > ums_task_sub ) ;
this - > ums_devices . clear ( ) ;
2021-07-25 06:37:13 +01:00
brls : : menu_timer_kill ( & ( this - > notification_timer ) ) ;
}
2022-07-05 02:04:28 +01:00
2024-04-15 12:47:50 +01:00
void OptionsTab : : DisplayNotification ( const std : : string & str )
2021-07-25 06:37:13 +01:00
{
2024-04-15 12:47:50 +01:00
if ( str . empty ( ) | | ! this - > display_notification ) return ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
brls : : Application : : notify ( str ) ;
this - > display_notification = false ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
this - > notification_timer_ctx . duration = brls : : Application : : getStyle ( ) - > AnimationDuration . notificationTimeout ;
this - > notification_timer_ctx . cb = [ this ] ( void * userdata ) { this - > display_notification = true ; } ;
this - > notification_timer_ctx . tick = [ ] ( void * ) { } ;
this - > notification_timer_ctx . userdata = nullptr ;
2022-07-05 02:04:28 +01:00
2021-07-25 06:37:13 +01:00
brls : : menu_timer_start ( & ( this - > notification_timer ) , & ( this - > notification_timer_ctx ) ) ;
2021-07-23 08:24:00 +01:00
}
}