Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
main.cpp
1// Author: Kang Lin <kl222@126.com>
2
14#include "mainwindow.h"
15
16#include <QApplication>
17#include <QSettings>
18#include <QDebug>
19#include <QtGlobal>
20#include <QSharedPointer>
21#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
22#include <QtAndroid>
23#endif
24
25#include "RabbitCommonTools.h"
26
27#ifdef HAVE_UPDATE
28#include "FrmUpdater.h"
29#endif
30#ifdef BUILD_QUIWidget
31 #include "QUIWidget/QUIWidget.h"
32#endif
33
34#include <QLoggingCategory>
35
36static Q_LOGGING_CATEGORY(log, "App.Main")
37
38int main(int argc, char *argv[])
39{
40 int nRet = 0;
41#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
42 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
43#endif
44#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
45 QtAndroid::hideSplashScreen();
46#endif
47
48//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
49// Q_INIT_RESOURCE(translations_RabbitRemoteControlApp);
50//#endif
51
52 QApplication::setApplicationVersion(RabbitRemoteControl_VERSION);
53 QApplication::setApplicationName("RabbitRemoteControl");
54#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
55 QApplication::setDesktopFileName(QLatin1String("RabbitRemoteControl.desktop"));
56#endif
57
58 QApplication a(argc, argv);
59
60 RabbitCommon::CTools::Instance()->Init();
61
62 qInfo(log) << a.applicationName() + " " + a.applicationVersion() + " " + QObject::tr("Start");
63
64 QSharedPointer<QTranslator> tApp =
65 RabbitCommon::CTools::Instance()->InstallTranslator("RabbitRemoteControlApp");
66
67 a.setApplicationDisplayName(QObject::tr("Rabbit Remote Control"));
68 a.setOrganizationName(QObject::tr("Kang Lin Studio"));
69
70#ifdef HAVE_UPDATE
71 // Check update version
72 QSharedPointer<CFrmUpdater> pUpdate(new CFrmUpdater());
73 QIcon icon = QIcon::fromTheme("app");
74 if(!icon.isNull())
75 {
76 auto sizeList = icon.availableSizes();
77 if(!sizeList.isEmpty()){
78 QPixmap p = icon.pixmap(*sizeList.begin());
79 pUpdate->SetTitle(p.toImage());
80 }
81 }
82 if(a.arguments().length() > 1) {
83 pUpdate->GenerateUpdateJson();
84 pUpdate->GenerateUpdateXml();
85 return 0;
86 }
87#endif
88
89 MainWindow* w = new MainWindow();
90 try {
91 //w->setWindowIcon(QIcon::themeName("app"));
92 //w->setWindowTitle(a.applicationDisplayName());
93
94#ifdef BUILD_QUIWidget
95 QSharedPointer<QUIWidget> quiwidget(new QUIWidget(nullptr, true));
96 bool check = quiwidget->connect(w, SIGNAL(sigFullScreen()),
97 SLOT(showFullScreen()));
98 Q_ASSERT(check);
99 check = quiwidget->connect(w, SIGNAL(sigShowNormal()),
100 SLOT(showNormal()));
101 Q_ASSERT(check);
102 //quiwidget.setPixmap(QUIWidget::Lab_Ico, ":/image/App");
103 //quiwidget.setTitle(a.applicationDisplayName());
104 quiwidget->setMainWidget(w);
105 quiwidget->show();
106#else
107 w->show();
108#endif
109
110 nRet = a.exec();
111 } catch (std::exception &e) {
112 qCritical(log) << "exception:" << e.what();
113 } catch(...) {
114 qCritical(log) << "exception:";
115 }
116
117#ifndef BUILD_QUIWidget
118 delete w;
119#endif
120
121 RabbitCommon::CTools::Instance()->Clean();
122 if(tApp)
123 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
124//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
125// Q_CLEANUP_RESOURCE(translations_RabbitRemoteControlApp);
126//#endif
127
128 qInfo(log) << a.applicationName() + " " + a.applicationVersion() + " " + QObject::tr("End");
129 return nRet;
130}
The MainWindow class.
Definition mainwindow.h:32