AntiMicroX
Loading...
Searching...
No Matches
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
37static 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
45static QString findWinLocalConfigPath()
46{
47 QString temp = QCoreApplication::applicationDirPath();
48 return temp;
49}
50
51static 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#endif
64
65namespace PadderCommon {
66inline QString configPath()
67{
68#if defined(Q_OS_WIN) && defined(WIN_PORTABLE_PACKAGE)
69 return findWinLocalConfigPath();
70#elif defined(Q_OS_WIN)
71 return findWinSystemConfigPath();
72#else
73 return (!qgetenv("XDG_CONFIG_HOME").isEmpty()) ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicrox"
74 : QDir::homePath() + "/.config/antimicrox";
75#endif
76}
77
78const QString configFileName = "antimicrox_settings.ini";
79inline QString configFilePath()
80{
81#if defined(Q_OS_WIN) && defined(WIN_PORTABLE_PACKAGE)
82 return QString(configPath()).append("\\").append(configFileName);
83#elif defined(Q_OS_WIN)
84 return QString(configPath()).append("\\").append(configFileName);
85#else
86 return QString(configPath()).append("/").append(configFileName);
87#endif
88}
89
90inline QString configLegacyFilePath()
91{
92#if defined(Q_OS_WIN)
93 return ""; // earlier vesrions of antimicrox was not supported by Windows
94#else
95 QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
96 ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicroX"
97 : QDir::homePath() + "/.config/antimicroX";
98
99 return QString(configPath).append("/").append("antimicroX_settings.ini");
100#endif
101}
102
104{
105#if defined(Q_OS_WIN)
106 QString temp = configFilePath().replace("antimicrox", "antimicro").replace("/", "\\");
107 return temp;
108#else
109 QString configPath = (!qgetenv("XDG_CONFIG_HOME").isEmpty())
110 ? QString::fromUtf8(qgetenv("XDG_CONFIG_HOME")) + "/antimicro"
111 : QDir::homePath() + "/.config/antimicro";
112 return QString(configPath).append("/").append("antimicro_settings.ini");
113#endif
114}
115
117// Specify the last known profile version that requires a migration
118// to be performed in order to be compatible with the latest version.
120const QString localSocketKey = "antimicroxSignalListener";
121const QString unhideCommand = "unhideWindow";
122const QString githubProjectPage = "https://github.com/AntiMicroX/antimicrox/";
123const QString githubIssuesPage = "https://github.com/AntiMicroX/antimicrox/issues";
124const QString wikiPage = QString("%1/wiki").arg(githubProjectPage);
125
126const QString mouseDeviceName("antimicrox Mouse Emulation");
127const QString keyboardDeviceName("antimicrox Keyboard Emulation");
128const QString springMouseDeviceName("antimicrox Abs Mouse Emulation");
129
130const int ANTIMICROX_MAJOR_VERSION = PROJECT_MAJOR_VERSION;
131const int ANTIMICROX_MINOR_VERSION = PROJECT_MINOR_VERSION;
132const int ANTIMICROX_PATCH_VERSION = PROJECT_PATCH_VERSION;
133
134const QString programVersion =
136#ifdef QT_DEBUG
137 + "-d"
138#endif
139 ;
140const QString sdlVersionUsed = ([] {
141 SDL_version linkedver;
142 SDL_GetVersion(&linkedver);
143 return QString("%1.%2.%3").arg(linkedver.major).arg(linkedver.minor).arg(linkedver.patch);
144})();
145
146const QString sdlVersionCompiled = ([] {
147 SDL_version compver;
148 SDL_VERSION(&compver);
149 return QString("%1.%2.%3").arg(compver.major).arg(compver.minor).arg(compver.patch);
150})();
151
152extern QWaitCondition waitThisOut;
153extern QMutex sdlWaitMutex;
154extern QMutex inputDaemonMutex;
155extern bool editingBindings;
157
158QString preferredProfileDir(AntiMicroSettings *settings);
159QStringList arguments(const int &argc, char **argv);
160QStringList parseArgumentsString(QString tempString);
161void reloadTranslations(QTranslator *translator, QTranslator *appTranslator, QString language);
162void lockInputDevices();
163void unlockInputDevices();
164
172QIcon loadIcon(QString name);
173
181QIcon loadIcon(const QString &name, const QString &fallback_location);
182
186inline QString getProfileName(QFileInfo &profile)
187{
188 QString retVal = profile.completeBaseName();
189
190 return retVal;
191}
192
193void log_system_config();
194} // namespace PadderCommon
195
196Q_DECLARE_METATYPE(QThread *)
197
198#endif // COMMON_H
Definition antimicrosettings.h:27
Definition mousehelper.h:26
Definition common.cpp:33
const QString localSocketKey
Definition common.h:120
const QString wikiPage
Definition common.h:124
QMutex inputDaemonMutex
Definition common.cpp:223
bool editingBindings
Definition common.cpp:224
const QString githubProjectPage
Definition common.h:122
QStringList parseArgumentsString(QString tempString)
Definition common.cpp:90
const int ANTIMICROX_MAJOR_VERSION
Definition common.h:130
QMutex sdlWaitMutex
Definition common.cpp:222
QString configAntimicroLegacyFilePath()
Definition common.h:103
QString configPath()
Definition common.h:66
void lockInputDevices()
Definition common.cpp:158
MouseHelper mouseHelperObj
Definition common.cpp:225
const int LATESTCONFIGMIGRATIONVERSION
Definition common.h:119
const int ANTIMICROX_MINOR_VERSION
Definition common.h:131
void unlockInputDevices()
Definition common.cpp:160
const QString programVersion
Definition common.h:134
const QString sdlVersionUsed
Definition common.h:140
QString preferredProfileDir(AntiMicroSettings *settings)
Definition common.cpp:34
QIcon loadIcon(const QString &name, const QString &fallback_location)
Universal method for loading icons.
Definition common.cpp:162
const int ANTIMICROX_PATCH_VERSION
Definition common.h:132
const QString unhideCommand
Definition common.h:121
QWaitCondition waitThisOut
Definition common.cpp:221
QString getProfileName(QFileInfo &profile)
Returns the "human-readable" name of the given profile.
Definition common.h:186
const QString sdlVersionCompiled
Definition common.h:146
QString configLegacyFilePath()
Definition common.h:90
void reloadTranslations(QTranslator *translator, QTranslator *appTranslator, QString language)
Reload main application and base Qt translation files.
Definition common.cpp:125
QString configFilePath()
Definition common.h:79
const QString githubIssuesPage
Definition common.h:123
QStringList arguments(const int &argc, char **argv)
Definition common.cpp:80
void log_system_config()
Definition common.cpp:203
const QString configFileName
Definition common.h:78
const int LATESTCONFIGFILEVERSION
Definition common.h:116
static const QString keyboardDeviceName
Definition uinputeventhandler.cpp:37
static const QString springMouseDeviceName
Definition uinputeventhandler.cpp:38
static const QString mouseDeviceName
Definition uinputeventhandler.cpp:36