AntiMicroX
common.h
Go to the documentation of this file.
1 /* antimicrox Gamepad to KB+M event mapper
2  * Copyright (C) 2015 Travis Nickles <nickles.travis@gmail.com>
3  * Copyright (C) 2020 Jagoda Górska <juliagoda.pl@protonmail>
4  * Copyright (C) 2020 Paweł Kotiuk <kotiuk@zohomail.eu>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15 
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef COMMON_H
21 #define COMMON_H
22 
23 #include "antimicrosettings.h"
24 #include "config.h"
25 #include "mousehelper.h"
26 
27 #include <QDir>
28 #include <QIcon>
29 #include <QThread>
30 #include <QTranslator>
31 #include <QWaitCondition>
32 
33 #include <SDL2/SDL_version.h>
34 
35 #ifdef Q_OS_WIN
36 
37 static QString findWinSystemConfigPath()
38 {
39  QString temp;
40  temp = (!qgetenv("LocalAppData").isEmpty()) ? QString::fromUtf8(qgetenv("LocalAppData")) + "\\antimicrox"
41  : QDir::homePath() + "\\.antimicrox";
42  return temp;
43 }
44 
45 static QString findWinLocalConfigPath()
46 {
47  QString temp = QCoreApplication::applicationDirPath();
48  return temp;
49 }
50 
51 static QString findWinDefaultConfigPath()
52 {
53  QString temp = findWinLocalConfigPath();
54  QFileInfo dirInfo(temp);
55  if (!dirInfo.isWritable())
56  {
57  temp = findWinSystemConfigPath();
58  }
59 
60  return temp;
61 }
62 
63 static QString findWinConfigPath(QString configFileName)
64 {
65  QString temp;
66  QFileInfo localConfigInfo(findWinLocalConfigPath().append("/").append(configFileName));
67  QFileInfo systemConfigInfo(findWinSystemConfigPath().append("/").append(configFileName));
68  if (localConfigInfo.exists() && localConfigInfo.isWritable())
69  {
70  temp = localConfigInfo.absoluteFilePath();
71  } else if (systemConfigInfo.exists() && systemConfigInfo.isWritable())
72  {
73  temp = systemConfigInfo.absoluteFilePath();
74  } else
75  {
76  temp = findWinDefaultConfigPath().append("/").append(configFileName);
77  }
78 
79  return temp;
80 }
81 #endif
82 
83 namespace PadderCommon {
84 inline QString configPath()
85 {
86 #if defined(Q_OS_WIN) && defined(WIN_PORTABLE_PACKAGE)
87  return findWinLocalConfigPath();
88 #elif defined(Q_OS_WIN)
89  return findWinSystemConfigPath();
90 #else
91  return (!qgetenv("XDG_CONFIG_HOME").isEmpty()) ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicrox"
92  : QDir::homePath() + "/.config/antimicrox";
93 #endif
94 }
95 
96 const QString configFileName = "antimicrox_settings.ini";
97 inline QString configFilePath()
98 {
99 #if defined(Q_OS_WIN) && defined(WIN_PORTABLE_PACKAGE)
100  return QString(configPath()).append("\\").append(configFileName);
101 #elif defined(Q_OS_WIN)
102  return QString(configPath()).append("\\").append(configFileName);
103 #else
104  return QString(configPath()).append("/").append(configFileName);
105 #endif
106 }
107 
108 inline QString configLegacyFilePath()
109 {
110 #if defined(Q_OS_WIN)
111  return ""; // earlier vesrions of antimicrox was not supported by Windows
112 #else
113  QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
114  ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicroX"
115  : QDir::homePath() + "/.config/antimicroX";
116 
117  return QString(configPath).append("/").append("antimicroX_settings.ini");
118 #endif
119 }
120 
122 {
123 #if defined(Q_OS_WIN)
124  QString temp = configFilePath().replace("antimicrox", "antimicro").replace("/", "\\");
125  return temp;
126 #else
127  QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
128  ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicro"
129  : QDir::homePath() + "/.config/antimicro";
130  return QString(configPath).append("/").append("antimicro_settings.ini");
131 #endif
132 }
133 
134 const int LATESTCONFIGFILEVERSION = 19;
135 // Specify the last known profile version that requires a migration
136 // to be performed in order to be compatible with the latest version.
138 const QString localSocketKey = "antimicroxSignalListener";
139 const QString unhideCommand = "unhideWindow";
140 const QString githubProjectPage = "https://github.com/AntiMicroX/antimicrox/";
141 const QString githubIssuesPage = "https://github.com/AntiMicroX/antimicrox/issues";
142 const QString wikiPage = QString("%1/wiki").arg(githubProjectPage);
143 
144 const QString mouseDeviceName("antimicrox Mouse Emulation");
145 const QString keyboardDeviceName("antimicrox Keyboard Emulation");
146 const QString springMouseDeviceName("antimicrox Abs Mouse Emulation");
147 
148 const int ANTIMICROX_MAJOR_VERSION = PROJECT_MAJOR_VERSION;
149 const int ANTIMICROX_MINOR_VERSION = PROJECT_MINOR_VERSION;
150 const int ANTIMICROX_PATCH_VERSION = PROJECT_PATCH_VERSION;
151 
152 const QString programVersion =
154 #ifdef QT_DEBUG
155  + "-d"
156 #endif
157  ;
158 const QString sdlVersionUsed = ([] {
159  SDL_version linkedver;
160  SDL_GetVersion(&linkedver);
161  return QString("%1.%2.%3").arg(linkedver.major).arg(linkedver.minor).arg(linkedver.patch);
162 })();
163 
164 const QString sdlVersionCompiled = ([] {
165  SDL_version compver;
166  SDL_VERSION(&compver);
167  return QString("%1.%2.%3").arg(compver.major).arg(compver.minor).arg(compver.patch);
168 })();
169 
170 extern QWaitCondition waitThisOut;
171 extern QMutex sdlWaitMutex;
172 extern QMutex inputDaemonMutex;
173 extern bool editingBindings;
175 
176 QString preferredProfileDir(AntiMicroSettings *settings);
177 QStringList arguments(const int &argc, char **argv);
178 QStringList parseArgumentsString(QString tempString);
179 void reloadTranslations(QTranslator *translator, QTranslator *appTranslator, QString language);
180 void lockInputDevices();
181 void unlockInputDevices();
182 
190 QIcon loadIcon(QString name);
191 
199 QIcon loadIcon(const QString &name, const QString &fallback_location);
200 
204 inline QString getProfileName(QFileInfo &profile)
205 {
206  QString retVal = profile.completeBaseName();
207 
208  return retVal;
209 }
210 
211 void log_system_config();
212 } // namespace PadderCommon
213 
214 Q_DECLARE_METATYPE(QThread *)
215 
216 #endif // COMMON_H
VERBOSE
#define VERBOSE()
Definition: logger.h:42
PadderCommon::sdlVersionUsed
const QString sdlVersionUsed
Definition: common.h:158
PadderCommon::sdlVersionCompiled
const QString sdlVersionCompiled
Definition: common.h:164
PadderCommon::mouseDeviceName
const QString mouseDeviceName("antimicrox Mouse Emulation")
PadderCommon::programVersion
const QString programVersion
Definition: common.h:152
PadderCommon::arguments
QStringList arguments(const int &argc, char **argv)
Definition: common.cpp:80
PadderCommon::preferredProfileDir
QString preferredProfileDir(AntiMicroSettings *settings)
Definition: common.cpp:34
PadderCommon::reloadTranslations
void reloadTranslations(QTranslator *translator, QTranslator *appTranslator, QString language)
Reload main application and base Qt translation files.
Definition: common.cpp:125
PadderCommon::springMouseDeviceName
const QString springMouseDeviceName("antimicrox Abs Mouse Emulation")
mousehelper.h
MouseHelper
Definition: mousehelper.h:25
PadderCommon::keyboardDeviceName
const QString keyboardDeviceName("antimicrox Keyboard Emulation")
PadderCommon::parseArgumentsString
QStringList parseArgumentsString(QString tempString)
Definition: common.cpp:90
PadderCommon::ANTIMICROX_MINOR_VERSION
const int ANTIMICROX_MINOR_VERSION
Definition: common.h:149
PadderCommon::loadIcon
QIcon loadIcon(const QString &name, const QString &fallback_location)
Universal method for loading icons.
Definition: common.cpp:162
PadderCommon::mouseHelperObj
MouseHelper mouseHelperObj
Definition: common.cpp:225
PadderCommon::LATESTCONFIGFILEVERSION
const int LATESTCONFIGFILEVERSION
Definition: common.h:134
AntiMicroSettings
Definition: antimicrosettings.h:26
PadderCommon::configAntimicroLegacyFilePath
QString configAntimicroLegacyFilePath()
Definition: common.h:121
PadderCommon::lockInputDevices
void lockInputDevices()
Definition: common.cpp:158
PadderCommon::ANTIMICROX_PATCH_VERSION
const int ANTIMICROX_PATCH_VERSION
Definition: common.h:150
PadderCommon::githubIssuesPage
const QString githubIssuesPage
Definition: common.h:141
PadderCommon::configFilePath
QString configFilePath()
Definition: common.h:97
PadderCommon::configLegacyFilePath
QString configLegacyFilePath()
Definition: common.h:108
PadderCommon::waitThisOut
QWaitCondition waitThisOut
Definition: common.cpp:221
PadderCommon::wikiPage
const QString wikiPage
Definition: common.h:142
PadderCommon::localSocketKey
const QString localSocketKey
Definition: common.h:138
it
that you receive source code or can get it if you want it
Definition: lgpl-2.1.txt:31
PadderCommon::LATESTCONFIGMIGRATIONVERSION
const int LATESTCONFIGMIGRATIONVERSION
Definition: common.h:137
PadderCommon::log_system_config
void log_system_config()
Definition: common.cpp:203
PadderCommon::configPath
QString configPath()
Definition: common.h:84
common.h
PadderCommon
Definition: common.cpp:33
PadderCommon::editingBindings
bool editingBindings
Definition: common.cpp:224
PadderCommon::unlockInputDevices
void unlockInputDevices()
Definition: common.cpp:160
PadderCommon::githubProjectPage
const QString githubProjectPage
Definition: common.h:140
PadderCommon::inputDaemonMutex
QMutex inputDaemonMutex
Definition: common.cpp:223
PadderCommon::unhideCommand
const QString unhideCommand
Definition: common.h:139
antimicrosettings.h
PadderCommon::configFileName
const QString configFileName
Definition: common.h:96
PadderCommon::getProfileName
QString getProfileName(QFileInfo &profile)
Returns the "human-readable" name of the given profile.
Definition: common.h:204
PadderCommon::sdlWaitMutex
QMutex sdlWaitMutex
Definition: common.cpp:222
PadderCommon::ANTIMICROX_MAJOR_VERSION
const int ANTIMICROX_MAJOR_VERSION
Definition: common.h:148