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"
37 #include "translations.h"
40 #include <QProxyStyle>
42 class MyProxyStyle
: public QProxyStyle
45 void polish ( QWidget
* w
) {
46 QMenu
* mn
= dynamic_cast<QMenu
*>(w
);
47 QPushButton
* pb
= dynamic_cast<QPushButton
*>(w
);
48 if(!(mn
|| pb
) && !w
->testAttribute(Qt::WA_MacNormalSize
))
49 w
->setAttribute(Qt::WA_MacSmallSize
);
54 int main(int argc
, char *argv
[])
56 #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
57 /* From doc: This attribute must be set before Q(Gui)Application is constructed. */
58 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling
);
61 QApplication
app(argc
, argv
);
62 app
.setApplicationName(APP_COMPANION
);
63 app
.setOrganizationName(COMPANY
);
64 app
.setOrganizationDomain(COMPANY_DOMAIN
);
65 app
.setAttribute(Qt::AA_DontShowIconsInMenus
, false);
67 Q_INIT_RESOURCE(companion
);
69 if (AppDebugMessageHandler::instance())
70 AppDebugMessageHandler::instance()->installAppMessageHandler();
72 CustomDebug::setFilterRules();
74 if (!g
.hasCurrentSettings()) {
75 QString previousVersion
;
76 if (g
.findPreviousVersionSettings(&previousVersion
)) {
78 msgBox
.setText(QObject::tr("We have found existing settings for Companion version: %1.\nDo you want to import them?").arg(previousVersion
));
79 msgBox
.setIcon(QMessageBox::Information
);
80 msgBox
.setStandardButtons(QMessageBox::Yes
| QMessageBox::No
);
81 msgBox
.setDefaultButton(QMessageBox::Yes
);
82 int ret
= msgBox
.exec();
84 if (ret
== QMessageBox::Yes
)
85 g
.importSettings(previousVersion
);
90 QStringList strl
= QApplication::arguments();
91 if (strl
.contains("--version")) {
92 printf("%s\n", VERSION
);
98 if (AppDebugMessageHandler::instance() && g
.appDebugLog() && !g
.appLogsDir().isEmpty() && QDir().mkpath(g
.appLogsDir())) {
99 QString fn
= g
.appLogsDir() % "/CompanionDebug_" % QDateTime::currentDateTime().toString("yy-MM-dd_HH-mm-ss") % ".log";
100 dbgLog
.setFileName(fn
);
101 if (dbgLog
.open(QIODevice::WriteOnly
| QIODevice::Text
)) {
102 AppDebugMessageHandler::instance()->addOutputDevice(&dbgLog
);
107 app
.setStyle(new MyProxyStyle
);
110 Translations::installTranslators();
112 #if defined(JOYSTICKS) || defined(SIMU_AUDIO)
113 uint32_t sdlFlags
= 0;
115 sdlFlags
|= SDL_INIT_JOYSTICK
;
118 sdlFlags
|= SDL_INIT_AUDIO
;
120 if (SDL_Init(sdlFlags
) < 0) {
121 fprintf(stderr
, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError());
125 registerStorageFactories();
126 registerOpenTxFirmwares();
127 SimulatorLoader::registerSimulators();
129 if (g
.profile
[g
.id()].fwType().isEmpty()){
130 g
.profile
[g
.id()].fwType(Firmware::getDefaultVariant()->getId());
131 g
.profile
[g
.id()].fwName("");
134 QString splashScreen
;
135 splashScreen
= ":/images/splash.png";
137 QPixmap pixmap
= QPixmap(splashScreen
);
138 QSplashScreen
*splash
= new QSplashScreen(pixmap
);
140 Firmware::setCurrentVariant(Firmware::getFirmwareForId(g
.profile
[g
.id()].fwType()));
142 MainWindow
*mainWin
= new MainWindow();
143 if (g
.showSplash()) {
145 QTimer::singleShot(1000*SPLASH_TIME
, splash
, SLOT(close()));
146 QTimer::singleShot(1000*SPLASH_TIME
, mainWin
, SLOT(show()));
152 int result
= app
.exec();
157 SimulatorLoader::unregisterSimulators();
158 unregisterOpenTxFirmwares();
159 unregisterStorageFactories();
161 #if defined(JOYSTICKS) || defined(SIMU_AUDIO)
165 qDebug() << "COMPANION EXIT" << result
;
167 if (dbgLog
.isOpen()) {
168 AppDebugMessageHandler::instance()->removeOutputDevice(&dbgLog
);