-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.cpp
120 lines (103 loc) · 4.56 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
openSUSE Welcome - A welcome utility
Copyright (C) 2019 Carson Black
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtWebEngine/QtWebEngine>
#include <QtWebEngine/QQuickWebEngineProfile>
#include <QTranslator>
#include <QLocale>
#include <QDir>
#include "sysinfo.h"
#include "launcher.h"
#include "enabler.h"
#include "panellayouter.h"
/// a workaround since QMimeDatabase detects .html as "application/x-extension-html" (chromium doesn't like this)
/// instead of "text/html" as it used to.
///
/// cf QTBUG-106688.
class WorkaroundSchemeHandler : public QWebEngineUrlSchemeHandler
{
public:
WorkaroundSchemeHandler(QObject *parent = nullptr) : QWebEngineUrlSchemeHandler(parent)
{
}
void requestStarted(QWebEngineUrlRequestJob *job) override
{
QByteArray requestMethod = job->requestMethod();
if (requestMethod != "GET") {
job->fail(QWebEngineUrlRequestJob::RequestDenied);
return;
}
QUrl requestUrl = job->requestUrl();
QString requestPath = requestUrl.path();
QScopedPointer<QFile> file(new QFile(':' + requestPath, job));
if (!file->exists() || file->size() == 0) {
job->fail(QWebEngineUrlRequestJob::UrlNotFound);
return;
}
QFileInfo fileInfo(*file);
QMimeDatabase mimeDatabase;
QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo);
if (mimeType.name() == "application/x-extension-html") {
mimeType = mimeDatabase.mimeTypeForName("text/html");
}
job->reply(mimeType.name().toUtf8(), file.take());
}
};
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QWebEngineUrlScheme qrcScheme(QByteArrayLiteral("qrc"));
qrcScheme.setFlags(QWebEngineUrlScheme::SecureScheme
| QWebEngineUrlScheme::LocalAccessAllowed
| QWebEngineUrlScheme::CorsEnabled
| QWebEngineUrlScheme::ViewSourceAllowed);
QWebEngineUrlScheme::registerScheme(qrcScheme);
QWebEngineUrlScheme aqrcScheme(QByteArrayLiteral("aqrc"));
aqrcScheme.setFlags(QWebEngineUrlScheme::SecureScheme
| QWebEngineUrlScheme::LocalAccessAllowed
| QWebEngineUrlScheme::CorsEnabled
| QWebEngineUrlScheme::ViewSourceAllowed);
QWebEngineUrlScheme::registerScheme(qrcScheme);
QWebEngineUrlScheme::registerScheme(aqrcScheme);
QtWebEngine::initialize();
QGuiApplication app(argc, argv);
WorkaroundSchemeHandler *handler = new WorkaroundSchemeHandler(&app);
QQuickWebEngineProfile::defaultProfile()->installUrlSchemeHandler("aqrc", handler);
app.setDesktopFileName("org.opensuse.opensuse_welcome.desktop");
app.setOrganizationName("openSUSE");
app.setOrganizationDomain("opensuse.org");
app.setApplicationName("org.opensuse.opensuse_welcome");
qmlRegisterType<SysInfo>("org.openSUSE.Welcome", 1, 0, "SysInfo");
qmlRegisterType<Launcher>("org.openSUSE.Welcome", 1, 0, "Launcher");
qmlRegisterType<Enabler>("org.openSUSE.Welcome", 1, 0, "Enabler");
qmlRegisterType<PanelLayouter>("org.openSUSE.Welcome", 1, 0, "XfceLayouter");
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator welcomeTranslator;
welcomeTranslator.load("qml_" + QLocale::system().name(), "/usr/share/openSUSE-Welcome/i18n");
app.installTranslator(&welcomeTranslator);
QDir autostartFolder(QDir::homePath() + "/.config/autostart/");
if (!autostartFolder.exists()) {
autostartFolder.mkdir(QDir::homePath() + "/.config/autostart/");
}
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}