Skip to content

Commit

Permalink
Load SDL mappings from database
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed Dec 22, 2021
1 parent 68c92de commit f86192c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/sdleventreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void SDLEventReader::initSDL()
SDL_JoystickEventState(SDL_ENABLE);

sdlIsOpen = true;
loadSdlMappingsFromDatabase();
settings->getLock()->lock();
settings->beginGroup("Mappings");
QStringList mappings = settings->allKeys();
Expand Down Expand Up @@ -243,6 +244,31 @@ void SDLEventReader::haltServices()
PadderCommon::unlockInputDevices();
}

/**
* @brief Loading additional gamepad mappings from database
*
*/
void SDLEventReader::loadSdlMappingsFromDatabase()
{
QString database_file;
#if defined(Q_OS_UNIX)
database_file = QApplication::applicationDirPath().append("/../share/antimicrox/gamecontrollerdb.txt");
#elif defined(Q_OS_WIN)
database_file = QApplication::applicationDirPath().append("\\share\\antimicrox\\gamecontrollerdb.txt");
#endif
if (QFile::exists(database_file))
{
int result = SDL_GameControllerAddMappingsFromFile(database_file.toStdString().c_str());
if (result == -1)
qWarning() << "Loading game controller mappings from database: " << database_file << " failed";
else
DEBUG() << "Loaded " << result << " game controller mappings from database";
} else
{
qWarning() << "File with game controller mappings " << database_file << " does not exist";
}
}

QMap<SDL_JoystickID, InputDevice *> *SDLEventReader::getJoysticks() const { return joysticks; }

AntiMicroSettings *SDLEventReader::getSettings() const { return settings; }
Expand Down
2 changes: 2 additions & 0 deletions src/sdleventreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class SDLEventReader : public QObject
AntiMicroSettings *settings;
int pollRate;
QTimer pollRateTimer;

void loadSdlMappingsFromDatabase();
};

#endif // SDLEVENTREADER_H

0 comments on commit f86192c

Please sign in to comment.