Rabbit Remote Control 0.1.0-bate4
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 QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
22 #include <QRegularExpression>
23#endif
24#if defined(Q_OS_ANDROID) && (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
25#include <QtAndroid>
26#endif
27
28#include "RabbitCommonTools.h"
29
30#ifdef HAVE_UPDATE
31#include "FrmUpdater.h"
32#endif
33#ifdef BUILD_QUIWidget
34 #include "QUIWidget/QUIWidget.h"
35#endif
36
37#include <QLoggingCategory>
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 MainWindow* w = new MainWindow();
136 try {
137 //w->setWindowIcon(QIcon::themeName("app"));
138 //w->setWindowTitle(app.applicationDisplayName());
139
140 w->show();
141
142 nRet = app.exec();
143 } catch (std::exception &e) {
144 qCritical(log) << "exception:" << e.what();
145 } catch(...) {
146 qCritical(log) << "exception:";
147 }
148
149 delete w;
150
151 RabbitCommon::CTools::Instance()->Clean();
152 if(tApp)
153 RabbitCommon::CTools::Instance()->RemoveTranslator(tApp);
154//#if defined (_DEBUG) || !defined(BUILD_SHARED_LIBS)
155// Q_CLEANUP_RESOURCE(translations_RabbitRemoteControlApp);
156//#endif
157
158 qInfo(log) << app.applicationName() + " " + app.applicationVersion() + " " + QObject::tr("End");
159 return nRet;
160}
The MainWindow class.
Definition mainwindow.h:34