Skip to content

Commit

Permalink
Add 'Exit Message' option to General settings
Browse files Browse the repository at this point in the history
Allows for an alternate message to exit the front-end, useful in
combination with a custom exit command to, say, shut down the system.
  • Loading branch information
mbarnes committed Jul 1, 2017
1 parent 7a7afa5 commit b40aeeb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/language/msg_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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
Expand Down Expand Up @@ -315,6 +316,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
Expand Down
16 changes: 12 additions & 4 deletions src/fe_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,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 ),
Expand Down Expand Up @@ -1917,18 +1922,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() );

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;
Expand Down
5 changes: 4 additions & 1 deletion src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,10 @@ bool FeOverlay::common_exit()
return true;
}

int retval = confirm_dialog( "Exit Attract-Mode?", "", FeInputMap::Exit );
std::string exit_msg;
m_feSettings.get_exit_question( exit_msg );

int retval = confirm_dialog( exit_msg, "", FeInputMap::Exit );

//
// retval is 0 if the user confirmed exit.
Expand Down
27 changes: 26 additions & 1 deletion src/fe_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ const char *FeSettings::configSettingStrings[] =
{
"language",
"exit_command",
"exit_message",
"default_font",
"font_path",
"screen_saver_timeout",
Expand Down Expand Up @@ -588,7 +589,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 );
Expand Down Expand Up @@ -2082,6 +2083,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 );
Expand Down Expand Up @@ -2507,6 +2525,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:
Expand Down Expand Up @@ -2630,6 +2650,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;
Expand Down
5 changes: 5 additions & 0 deletions src/fe_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class FeSettings : public FeBaseConfigurable
{
Language=0,
ExitCommand,
ExitMessage,
DefaultFont,
FontPath,
ScreenSaverTimeout,
Expand Down Expand Up @@ -150,6 +151,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;

Expand Down Expand Up @@ -316,6 +319,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 );
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,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;
}
Expand Down

0 comments on commit b40aeeb

Please sign in to comment.