From 9bd5bfe210a022c963a4c49030bf12198c8920b6 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 1 Sep 2018 18:15:22 -0400 Subject: [PATCH] Add 'Exit Message' option to General settings (#363) Allows for an alternate message to exit the front-end, useful in combination with a custom exit command to, say, shut down the system. --- config/language/msg_template.txt | 2 ++ src/fe_config.cpp | 18 +++++++++++++----- src/fe_overlay.cpp | 5 ++++- src/fe_settings.cpp | 27 ++++++++++++++++++++++++++- src/fe_settings.hpp | 5 +++++ src/main.cpp | 2 +- 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/config/language/msg_template.txt b/config/language/msg_template.txt index ac66bf08d..5c6bcfde7 100644 --- a/config/language/msg_template.txt +++ b/config/language/msg_template.txt @@ -107,6 +107,7 @@ Exit Attract-Mode;Exit Attract-Mode Exit Attract-Mode?;Exit Attract-Mode? Exit Command;Exit Command Exit Hotkey;Exit Hotkey +Exit Message;Exit Message Exit to Desktop;Exit to Desktop Extra;Extra Favourite;Favourite @@ -331,6 +332,7 @@ _help_emu_system;The system identifier(s) for this emulator. Multiple values ca _help_emu_workdir;The working directory for this emulator. This is the directory that the frontend runs the emulator from. Also, any relative rom paths, artwork paths, or additional import file paths are treated as being relative to this directory _help_emulators;Configure emulator settings _help_exit_command;Command to execute when exiting the frontend [i.e. "sudo shutdown"] +_help_exit_message;Alternate message to exit the frontend [i.e. "Shut Down System"] _help_filter_add_exception;Add an exception to this filter. If a game matches an exception (and wasn't filtered out by an earlier rule) it will be listed in the filter _help_filter_add_rule;Add a rule to this filter. A game must match all filter rules (or a single exception) to be listed in a filter _help_filter_delete;Delete this filter diff --git a/src/fe_config.cpp b/src/fe_config.cpp index c5dd9f099..454f65768 100755 --- a/src/fe_config.cpp +++ b/src/fe_config.cpp @@ -1949,6 +1949,11 @@ void FeMiscMenu::get_options( FeConfigContext &ctx ) ctx.fe_settings.get_info( FeSettings::ExitCommand ), "_help_exit_command" ); + ctx.add_optl( Opt::EDIT, + "Exit Message", + ctx.fe_settings.get_info( FeSettings::ExitMessage ), + "_help_exit_message" ); + ctx.add_optl( Opt::EDIT, "Default Font", ctx.fe_settings.get_info( FeSettings::DefaultFont ), @@ -2014,18 +2019,21 @@ bool FeMiscMenu::save( FeConfigContext &ctx ) ctx.fe_settings.set_info( FeSettings::ExitCommand, ctx.opt_list[9].get_value() ); - ctx.fe_settings.set_info( FeSettings::DefaultFont, + ctx.fe_settings.set_info( FeSettings::ExitMessage, ctx.opt_list[10].get_value() ); - ctx.fe_settings.set_info( FeSettings::FontPath, + ctx.fe_settings.set_info( FeSettings::DefaultFont, ctx.opt_list[11].get_value() ); - ctx.fe_settings.set_info( FeSettings::VideoDecoder, + ctx.fe_settings.set_info( FeSettings::FontPath, ctx.opt_list[12].get_value() ); -#ifdef SFML_SYSTEM_WINDOWS + ctx.fe_settings.set_info( FeSettings::VideoDecoder, + ctx.opt_list[13].get_value() ); + +#ifdef SFML_SYSTEM_WINDOWS ctx.fe_settings.set_info( FeSettings::HideConsole, - ctx.opt_list[13].get_vindex() == 0 ? FE_CFG_YES_STR : FE_CFG_NO_STR ); + ctx.opt_list[14].get_vindex() == 0 ? FE_CFG_YES_STR : FE_CFG_NO_STR ); #endif return true; diff --git a/src/fe_overlay.cpp b/src/fe_overlay.cpp index 22fd9031b..ec193d643 100644 --- a/src/fe_overlay.cpp +++ b/src/fe_overlay.cpp @@ -1931,7 +1931,10 @@ bool FeOverlay::common_exit() return true; } - int retval = confirm_dialog( "Exit Attract-Mode?", "" ); + std::string exit_msg; + m_feSettings.get_exit_question( exit_msg ); + + int retval = confirm_dialog( exit_msg, "" ); // // retval is 0 if the user confirmed exit. diff --git a/src/fe_settings.cpp b/src/fe_settings.cpp index ebd433ed0..c1278259a 100644 --- a/src/fe_settings.cpp +++ b/src/fe_settings.cpp @@ -394,6 +394,7 @@ const char *FeSettings::configSettingStrings[] = { "language", "exit_command", + "exit_message", "default_font", "font_path", "screen_saver_timeout", @@ -574,7 +575,7 @@ void FeSettings::init_display() if ( m_displays_menu_exit ) { std::string exit_str; - get_resource( "Exit Attract-Mode", exit_str ); + get_exit_message( exit_str ); FeRomInfo rom( exit_str ); rom.set_info( FeRomInfo::Title, exit_str ); @@ -2252,6 +2253,23 @@ int FeSettings::exit_command() const return r; } +void FeSettings::get_exit_message( std::string &exit_message ) const +{ + if ( m_exit_message.empty() ) + get_resource( "Exit Attract-Mode", exit_message ); + else + exit_message = m_exit_message; +} + +void FeSettings::get_exit_question( std::string &exit_question ) const +{ + // Question string is never empty; check message. + if ( m_exit_message.empty() ) + get_resource( "Exit Attract-Mode?", exit_question ); + else + exit_question = m_exit_question; +} + void FeSettings::do_text_substitutions( std::string &str, int filter_offset, int index_offset ) { int filter_index = get_filter_index_from_offset( filter_offset ); @@ -2667,6 +2685,8 @@ const std::string FeSettings::get_info( int index ) const return m_language; case ExitCommand: return m_exit_command; + case ExitMessage: + return m_exit_message; case DefaultFont: return m_default_font; case FontPath: @@ -2792,6 +2812,11 @@ bool FeSettings::set_info( int index, const std::string &value ) m_exit_command = value; break; + case ExitMessage: + m_exit_message = value; + m_exit_question = value + "?"; + break; + case DefaultFont: m_default_font = value; break; diff --git a/src/fe_settings.hpp b/src/fe_settings.hpp index 197924e21..c3702536d 100644 --- a/src/fe_settings.hpp +++ b/src/fe_settings.hpp @@ -104,6 +104,7 @@ class FeSettings : public FeBaseConfigurable { Language=0, ExitCommand, + ExitMessage, DefaultFont, FontPath, ScreenSaverTimeout, @@ -151,6 +152,8 @@ class FeSettings : public FeBaseConfigurable std::string m_config_path; std::string m_default_font; std::string m_exit_command; + std::string m_exit_message; + std::string m_exit_question; std::string m_language; std::string m_current_search_str; @@ -348,6 +351,8 @@ class FeSettings : public FeBaseConfigurable void *launch_opaque ); // run current selection int exit_command() const; // run configured exit command (if any) + void get_exit_message( std::string &exit_message ) const; + void get_exit_question( std::string &exit_question ) const; void toggle_layout(); void set_current_layout_file( const std::string &layout_file ); diff --git a/src/main.cpp b/src/main.cpp index 96b2374f0..8bf72ab33 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -720,7 +720,7 @@ int main(int argc, char *argv[]) // Add an exit option at the end of the lists menu // std::string exit_str; - feSettings.get_resource( "Exit Attract-Mode", exit_str ); + feSettings.get_exit_message( exit_str ); disp_names.push_back( exit_str ); exit_opt = disp_names.size() - 1; }