1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 19:03:44 +02:00

Remove unnecessary file existence check in GMenu2X -> InputManager

Instead of checking which input configuration file exists among 2
choices, then asking InputManager to load that file, InputManager
itself now performs the resolution based on whether ifstream::is_open
returns true for each choice.
This commit is contained in:
Nebuleon Fumika 2014-08-10 23:38:10 +00:00 committed by Maarten ter Huurne
parent d6b2643610
commit ab27096f10
3 changed files with 64 additions and 58 deletions

View File

@ -279,18 +279,10 @@ GMenu2X::GMenu2X()
monitor = new MediaMonitor(CARD_ROOT); monitor = new MediaMonitor(CARD_ROOT);
#endif #endif
/* If a user-specified input.conf file exists, we load it; if (!input.init(this, menu.get())) {
* otherwise, we load the default one. */ exit(EXIT_FAILURE);
string input_file = getHome() + "/input.conf";
if (fileExists(input_file.c_str())) {
DEBUG("Loading user-specific input.conf file: %s.\n", input_file.c_str());
} else {
input_file = GMENU2X_SYSTEM_DIR "/input.conf";
DEBUG("Loading system input.conf file: %s.\n", input_file.c_str());
} }
input.init(this, input_file, menu.get());
if (confInt["backlightTimeout"] > 0) if (confInt["backlightTimeout"] > 0)
PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] ); PowerSaver::getInstance()->setScreenTimeout( confInt["backlightTimeout"] );
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ

View File

@ -30,7 +30,7 @@
using namespace std; using namespace std;
void InputManager::init(GMenu2X *gmenu2x, const string &conffile, Menu *menu) { bool InputManager::init(GMenu2X *gmenu2x, Menu *menu) {
this->gmenu2x = gmenu2x; this->gmenu2x = gmenu2x;
this->menu = menu; this->menu = menu;
@ -40,7 +40,21 @@ void InputManager::init(GMenu2X *gmenu2x, const string &conffile, Menu *menu) {
buttonMap[i].js_mapped = false; buttonMap[i].js_mapped = false;
buttonMap[i].kb_mapped = false; buttonMap[i].kb_mapped = false;
} }
readConfFile(conffile);
/* If a user-specified input.conf file exists, we load it;
* otherwise, we load the default one. */
string input_file = gmenu2x->getHome() + "/input.conf";
DEBUG("Loading user-specific input.conf file: %s.\n", input_file.c_str());
if (!readConfFile(input_file)) {
input_file = GMENU2X_SYSTEM_DIR "/input.conf";
DEBUG("Loading system input.conf file: %s.\n", input_file.c_str());
if (!readConfFile(input_file)) {
ERROR("InputManager: failed to open config file\n");
return false;
}
}
return true;
} }
InputManager::InputManager() InputManager::InputManager()
@ -73,13 +87,9 @@ InputManager::~InputManager()
#endif #endif
} }
void InputManager::readConfFile(const string &conffile) { bool InputManager::readConfFile(const string &conffile) {
ifstream inf(conffile.c_str(), ios_base::in); ifstream inf(conffile.c_str(), ios_base::in);
if (inf.fail()) { if (inf.is_open()) {
ERROR("InputManager: failed to open config file\n");
return;
}
string line; string line;
while (getline(inf, line, '\n')) { while (getline(inf, line, '\n')) {
string::size_type pos = line.find("="); string::size_type pos = line.find("=");
@ -110,11 +120,11 @@ void InputManager::readConfFile(const string &conffile) {
if (sourceStr == "keyboard") { if (sourceStr == "keyboard") {
buttonMap[button].kb_mapped = true; buttonMap[button].kb_mapped = true;
buttonMap[button].kb_code = atoi(line.c_str()); buttonMap[button].kb_code = atoi(line.c_str());
#ifndef SDL_JOYSTICK_DISABLED #ifndef SDL_JOYSTICK_DISABLED
} else if (sourceStr == "joystick") { } else if (sourceStr == "joystick") {
buttonMap[button].js_mapped = true; buttonMap[button].js_mapped = true;
buttonMap[button].js_code = atoi(line.c_str()); buttonMap[button].js_code = atoi(line.c_str());
#endif #endif
} else { } else {
WARNING("InputManager: Ignoring unknown button source \"%s\"\n", WARNING("InputManager: Ignoring unknown button source \"%s\"\n",
sourceStr.c_str()); sourceStr.c_str());
@ -123,6 +133,10 @@ void InputManager::readConfFile(const string &conffile) {
} }
inf.close(); inf.close();
return true;
} else {
return false;
}
} }
InputManager::Button InputManager::waitForPressedButton() { InputManager::Button InputManager::waitForPressedButton() {

View File

@ -64,7 +64,7 @@ public:
InputManager(); InputManager();
~InputManager(); ~InputManager();
void init(GMenu2X *gmenu2x, const std::string &conffile, Menu *menu); bool init(GMenu2X *gmenu2x, Menu *menu);
Button waitForPressedButton(); Button waitForPressedButton();
void repeatRateChanged(); void repeatRateChanged();
Uint32 joystickRepeatCallback(Uint32 timeout, struct Joystick *joystick); Uint32 joystickRepeatCallback(Uint32 timeout, struct Joystick *joystick);
@ -72,7 +72,7 @@ public:
bool getButton(Button *button, bool wait); bool getButton(Button *button, bool wait);
private: private:
void readConfFile(const std::string &conffile); bool readConfFile(const std::string &conffile);
struct ButtonMapEntry { struct ButtonMapEntry {
bool kb_mapped, js_mapped; bool kb_mapped, js_mapped;