Rabbit Remote Control 0.0.31
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 (defined(Q_OS_LINUX) && !defined(Q_OA_ANDROID) \
42 && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
43 /* 修复使用 Qt6 时,最大化时,工具栏位置错误。
44 现在很多 linux 用 wayland 作为桌面显示,这样会出现一个问题,
45 由于没有坐标系统,导致无边框窗体无法拖动和定位(即 QWidge::move 失效)。
46 (Qt6 开始强制默认优先用 wayland ,Qt5 默认有 xcb 则优先用 xcb),
47 所以需要在 main 函数最前面加一行 `qputenv("QT_QPA_PLATFORM", "xcb")`;
48 */
49 qputenv("QT_QPA_PLATFORM", "xcb");
50#endif
51#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
52 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
53#endif
54#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
55 QtAndroid::hideSplashScreen();
56#endif
57
58//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
59// Q_INIT_RESOURCE(translations_RabbitRemoteControlApp);
60//#endif
61
62 QApplication::setApplicationVersion(RabbitRemoteControl_VERSION);
63 QApplication::setApplicationName("RabbitRemoteControl");
64#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
65 QApplication::setDesktopFileName(QLatin1String("RabbitRemoteControl.desktop"));
66#endif
67
68 QApplication a(argc, argv);
69
70 RabbitCommon::CTools::Instance()->Init();
71
72 qInfo(log) << a.applicationName() + " " + a.applicationVersion() + " " + QObject::tr("Start");
73
74 QSharedPointer<QTranslator> tApp =
75 RabbitCommon::CTools::Instance()->InstallTranslator("RabbitRemoteControlApp");
76
77 a.setApplicationDisplayName(QObject::tr("Rabbit Remote Control"));
78 a.setOrganizationName(QObject::tr("Kang Lin Studio"));
79
80#ifdef HAVE_UPDATE
81 // Check update version
82 QSharedPointer<CFrmUpdater> pUpdate(new CFrmUpdater());
83 QIcon icon = QIcon::fromTheme("app");
84 if(!icon.isNull())
85 {
86 auto sizeList = icon.availableSizes();
87 if(!sizeList.isEmpty()){
88 QPixmap p = icon.pixmap(*sizeList.begin());
89 pUpdate->SetTitle(p.toImage());
90 }
91 }
92 if(a.arguments().length() > 1) {
93 pUpdate->GenerateUpdateJson();
94 pUpdate->GenerateUpdateXml();
95 return 0;
96 }
97#endif
98
99 MainWindow* w = new MainWindow();
100 try {
101 //w->setWindowIcon(QIcon::themeName("app"));
102 //w->setWindowTitle(a.applicationDisplayName());
103
104#ifdef BUILD_QUIWidget
105 QSharedPointer<QUIWidget> quiwidget(new QUIWidget(nullptr, true));
106 bool check = quiwidget->connect(w, SIGNAL(sigFullScreen()),
107 SLOT(showFullScreen()));
108 Q_ASSERT(check);
109 check = quiwidget->connect(w, SIGNAL(sigShowNormal()),
110 SLOT(showNormal()));
111 Q_ASSERT(check);
112 //quiwidget.setPixmap(QUIWidget::Lab_Ico, ":/image/App");
113 //quiwidget.setTitle(a.applicationDisplayName());
114 quiwidget->setMainWidget(w);
115 quiwidget->show();
116#else
117 w->show();
118#endif
119
120 nRet = a.exec();
121 } catch (std::exception &e) {
122 qCritical(log) << "exception:" << e.what();
123 } catch(...) {
124 qCritical(log) << "exception:";
125 }
126
127#ifndef BUILD_QUIWidget
128 delete w;
129#endif
130
131 RabbitCommon::CTools::Instance()->Clean();
132 if(tApp)
133 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
134//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
135// Q_CLEANUP_RESOURCE(translations_RabbitRemoteControlApp);
136//#endif
137
138 qInfo(log) << a.applicationName() + " " + a.applicationVersion() + " " + QObject::tr("End");
139 return nRet;
140}
The MainWindow class.
Definition mainwindow.h:32