5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <QApplication>
25 #include <QSplashScreen>
26 #if defined(JOYSTICKS) || defined(SIMU_AUDIO)
31 #include "appdebugmessagehandler.h"
32 #include "customdebug.h"
33 #include "mainwindow.h"
36 #include "simulatorinterface.h"
38 #include "translations.h"
41 #include <QProxyStyle>
43 class MyProxyStyle
: public QProxyStyle
46 void polish ( QWidget
* w
) {
47 QMenu
* mn
= dynamic_cast<QMenu
*>(w
);
48 QPushButton
* pb
= dynamic_cast<QPushButton
*>(w
);
49 if(!(mn
|| pb
) && !w
->testAttribute(Qt::WA_MacNormalSize
))
50 w
->setAttribute(Qt::WA_MacSmallSize
);
55 int main(int argc
, char *argv
[])
57 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
58 /* From doc: This attribute must be set before Q(Gui)Application is constructed. */
59 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling
);
62 QApplication
app(argc
, argv
);
63 app
.setApplicationName(APP_COMPANION
);
64 app
.setOrganizationName(COMPANY
);
65 app
.setOrganizationDomain(COMPANY_DOMAIN
);
66 app
.setAttribute(Qt::AA_DontShowIconsInMenus
, false);
68 Q_INIT_RESOURCE(companion
);
70 if (AppDebugMessageHandler::instance())
71 AppDebugMessageHandler::instance()->installAppMessageHandler();
73 CustomDebug::setFilterRules();
75 if (!g
.hasCurrentSettings()) {
76 QString previousVersion
;
77 if (g
.findPreviousVersionSettings(&previousVersion
)) {
79 msgBox
.setText(QCoreApplication::translate("Companion", "We have found existing settings for Companion version: %1.\nDo you want to import them?").arg(previousVersion
));
80 msgBox
.setIcon(QMessageBox::Information
);
81 msgBox
.setStandardButtons(QMessageBox::Yes
| QMessageBox::No
);
82 msgBox
.setDefaultButton(QMessageBox::Yes
);
83 int ret
= msgBox
.exec();
85 if (ret
== QMessageBox::Yes
)
86 g
.importSettings(previousVersion
);
91 QStringList strl
= QApplication::arguments();
92 if (strl
.contains("--version")) {
93 printf("%s\n", VERSION
);
99 if (AppDebugMessageHandler::instance() && g
.appDebugLog() && !g
.appLogsDir().isEmpty() && QDir().mkpath(g
.appLogsDir())) {
100 QString fn
= g
.appLogsDir() % "/CompanionDebug_" % QDateTime::currentDateTime().toString("yy-MM-dd_HH-mm-ss") % ".log";
101 dbgLog
.setFileName(fn
);
102 if (dbgLog
.open(QIODevice::WriteOnly
| QIODevice::Text
)) {
103 AppDebugMessageHandler::instance()->addOutputDevice(&dbgLog
);
108 app
.setStyle(new MyProxyStyle
);
111 Translations::installTranslators();
113 #if defined(JOYSTICKS) || defined(SIMU_AUDIO)
114 uint32_t sdlFlags
= 0;
116 sdlFlags
|= SDL_INIT_JOYSTICK
;
119 sdlFlags
|= SDL_INIT_AUDIO
;
121 if (SDL_Init(sdlFlags
) < 0) {
122 fprintf(stderr
, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError());
126 registerStorageFactories();
127 registerOpenTxFirmwares();
128 SimulatorLoader::registerSimulators();
130 if (g
.profile
[g
.id()].fwType().isEmpty()){
131 g
.profile
[g
.id()].fwType(Firmware::getDefaultVariant()->getId());
132 g
.profile
[g
.id()].fwName("");
135 QString splashScreen
;
136 splashScreen
= ":/images/splash.png";
138 QPixmap pixmap
= QPixmap(splashScreen
);
139 QSplashScreen
*splash
= new QSplashScreen(pixmap
);
141 Firmware::setCurrentVariant(Firmware::getFirmwareForId(g
.profile
[g
.id()].fwType()));
143 MainWindow
*mainWin
= new MainWindow();
144 if (g
.showSplash()) {
146 QTimer::singleShot(1000*SPLASH_TIME
, splash
, SLOT(close()));
147 QTimer::singleShot(1000*SPLASH_TIME
, mainWin
, SLOT(show()));
153 int result
= app
.exec();
158 SimulatorLoader::unregisterSimulators();
159 unregisterOpenTxFirmwares();
160 unregisterStorageFactories();
162 #if defined(JOYSTICKS) || defined(SIMU_AUDIO)
166 qDebug() << "COMPANION EXIT" << result
;
168 if (dbgLog
.isOpen()) {
169 AppDebugMessageHandler::instance()->removeOutputDevice(&dbgLog
);