玉兔远程控制 0.1.0-bate5
载入中...
搜索中...
未找到
main.cpp
1// Author: Kang Lin <kl222@126.com>
2
14#include <QLoggingCategory>
15#include <QApplication>
16#include <QSettings>
17#include <QDebug>
18#include <QtGlobal>
19#include <QSharedPointer>
20#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
21 #include <QRegularExpression>
22#endif
23#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
24#include <QtAndroid>
25#endif
26
27#include "RabbitCommonTools.h"
28
29#ifdef HAVE_UPDATE
30#include "FrmUpdater.h"
31#endif
32#ifdef BUILD_QUIWidget
33 #include "QUIWidget/QUIWidget.h"
34#endif
35
36#include "StatsAppUsage.h"
37#include "mainwindow.h"
38
39static Q_LOGGING_CATEGORY(log, "App.Main")
40
41int main(int argc, char *argv[])
42{
43 int nRet = 0;
44
45 qDebug(log) << "Version:" << RabbitRemoteControl_VERSION;
46 QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
47
48 // 修复 qtwebengine 沙箱权限问题
49 if(!qEnvironmentVariable("SNAP").isEmpty()) {
50 qputenv("QTWEBENGINE_DISABLE_SANDBOX", "1");
51 }
52
53 //qputenv("QT_MEDIA_BACKEND", "ffmpeg");
54
55#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) \
56 && (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)))
57 /* 修复使用 Qt6 时,最大化时,工具栏位置错误。
58 现在很多 linux 用 wayland 或 wayland-egl 作为桌面显示,这样会出现一个问题,
59 由于没有坐标系统,导致无边框窗体无法拖动和定位(即 QWidge::move 失效)。
60 (Qt6 开始强制默认优先用 wayland ,Qt5 默认有 xcb 则优先用 xcb),
61 所以需要在 main 函数最前面加一行 `qputenv("QT_QPA_PLATFORM", "xcb")`;
62 */
63 QString szPlatform = qEnvironmentVariable("QT_QPA_PLATFORM");
64 if(szPlatform.isEmpty()
65 || -1 != szPlatform.indexOf(QRegularExpression("wayland.*")))
66 qputenv("QT_QPA_PLATFORM", "xcb");
67 qInfo(log) << "QT_QPA_PLATFORM:" << szPlatform << "\nCurrent Qt Platform is:"
68 << qEnvironmentVariable("QT_QPA_PLATFORM")
69 << "; This can be modified with the environment variables QT_QPA_PLATFORM:\n"
70 << "export QT_QPA_PLATFORM=xcb\n Optional: xcb; vnc";
71#endif
72#if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
73 QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
74#endif
75#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
76 QtAndroid::hideSplashScreen();
77#endif
78
79//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
80// Q_INIT_RESOURCE(translations_RabbitRemoteControlApp);
81//#endif
82
83 QApplication::setApplicationVersion(RabbitRemoteControl_VERSION);
84 QApplication::setApplicationName("RabbitRemoteControl");
85#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
86 QApplication::setDesktopFileName(QLatin1String("RabbitRemoteControl.desktop"));
87#endif
88
89 QApplication app(argc, argv);
90
91 RabbitCommon::CTools::Instance()->Init();
92
93 qInfo(log) << app.applicationName() + " " + app.applicationVersion()
94 + " " + QObject::tr("Start") + " ......"
95 << "\n" << app.arguments();
96
97 QSharedPointer<QTranslator> tApp =
98 RabbitCommon::CTools::Instance()->InstallTranslator("RabbitRemoteControlApp");
99
100 app.setApplicationDisplayName(QObject::tr("Rabbit Remote Control"));
101 app.setOrganizationName(QObject::tr("Kang Lin Studio"));
102
103#ifdef HAVE_UPDATE
104 // Check update version
105 if(qEnvironmentVariable("SNAP").isEmpty()
106 && qEnvironmentVariable("FLATPAK_ID").isEmpty()) {
107 QSharedPointer<CFrmUpdater> pUpdate(new CFrmUpdater());
108 if(pUpdate) {
109 QIcon icon = QIcon::fromTheme("app");
110 if(!icon.isNull())
111 {
112 auto sizeList = icon.availableSizes();
113 if(!sizeList.isEmpty()){
114 QPixmap p = icon.pixmap(*sizeList.begin());
115 pUpdate->SetTitle(p.toImage());
116 }
117 }
118 if(app.arguments().length() > 1) {
119 try{
120 pUpdate->GenerateUpdateJson();
121 pUpdate->GenerateUpdateXml();
122 } catch(...) {
123 qCritical(log) << "Generate update fail";
124 }
125 qInfo(log) << app.applicationName() + " " + app.applicationVersion()
126 + " " + QObject::tr("Generate update json file End");
127 return 0;
128 }
129 } else {
130 qCritical(log) << "new CFrmUpdater() fail";
131 }
132 }
133#endif
134
135 CStatsAppUsage* pStats = new CStatsAppUsage("v" + QApplication::applicationVersion());
136 if(pStats) {
137 bool check = QObject::connect(pStats, &CStatsAppUsage::sigFinished, pStats, &CStatsAppUsage::deleteLater);
138 Q_ASSERT(check);
139 }
140 MainWindow* w = new MainWindow();
141 try {
142 //w->setWindowIcon(QIcon::themeName("app"));
143 //w->setWindowTitle(app.applicationDisplayName());
144
145 w->show();
146 nRet = app.exec();
147 } catch (std::exception &e) {
148 qCritical(log) << "exception:" << e.what();
149 } catch(...) {
150 qCritical(log) << "exception:";
151 }
152
153 delete w;
154 if(pStats)
155 pStats->Stop();
156
157 RabbitCommon::CTools::Instance()->Clean();
158 if(tApp)
159 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
160//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
161// Q_CLEANUP_RESOURCE(translations_RabbitRemoteControlApp);
162//#endif
163
164 qInfo(log) << app.applicationName() + " " + app.applicationVersion() + " " + QObject::tr("End");
165 return nRet;
166}
The MainWindow class
Definition mainwindow.h:34