/
main.cpp
167 lines (130 loc) · 6.47 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright 2012 Marco Martin <mart@kde.org>
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
* Copyright 2015 David Edmundson <davidedmundson@kde.org>
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QApplication>
#include <QCommandLineParser>
#include <QQuickWindow>
#include <QSessionManager>
#include <QDebug>
#include <QMessageBox>
#include <KAboutData>
#include <KQuickAddons/QtQuickSettings>
#include <kdbusservice.h>
#include <klocalizedstring.h>
#include <kcrash.h>
#include "shellcorona.h"
#include "standaloneappcorona.h"
#include "shellmanager.h"
#include "coronatesthelper.h"
#include <QDir>
int main(int argc, char *argv[])
{
// Devive pixel ratio has some problems in plasmashell currently.
// - dialog continually expands (347951)
// - Text element text is screwed (QTBUG-42606)
// - Panel struts (350614)
// This variable should possibly be removed when all are fixed
qunsetenv("QT_DEVICE_PIXEL_RATIO");
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
QQuickWindow::setDefaultAlphaBuffer(true);
KLocalizedString::setApplicationDomain("plasmashell");
QApplication app(argc, argv);
KQuickAddons::QtQuickSettings::init();
KAboutData aboutData(QStringLiteral("plasmashell"),
i18n("Plasma"),
QStringLiteral(PROJECT_VERSION),
i18n("Plasma Shell"),
KAboutLicense::GPL);
KAboutData::setApplicationData(aboutData);
app.setQuitOnLastWindowClosed(false);
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("plasma")));
{
QCommandLineParser cliOptions;
QCommandLineOption dbgOption(QStringList() << QStringLiteral("d") <<
QStringLiteral("qmljsdebugger"),
i18n("Enable QML Javascript debugger"));
QCommandLineOption winOption(QStringList() << QStringLiteral("w") <<
QStringLiteral("windowed"),
i18n("Force a windowed view for testing purposes"));
QCommandLineOption noRespawnOption(QStringList() << QStringLiteral("n") <<
QStringLiteral("no-respawn"),
i18n("Do not restart plasma-shell automatically after a crash"));
QCommandLineOption shutupOption(QStringList() << QStringLiteral("s") << QStringLiteral("shut-up"),
i18n("Deprecated, does nothing"));
QCommandLineOption shellPluginOption(QStringList() << QStringLiteral("p") << QStringLiteral("shell-plugin"),
i18n("Force loading the given shell plugin"),
QStringLiteral("plugin"));
QCommandLineOption standaloneOption(QStringList() << QStringLiteral("a") << QStringLiteral("standalone"),
i18n("Load plasmashell as a standalone application, needs the shell-plugin option to be specified"));
QCommandLineOption testOption(QStringList() << QStringLiteral("test"),
i18n("Enables test mode and specifies the layout javascript file to set up the testing environment"), i18n("file"), QStringLiteral("layout.js"));
cliOptions.addOption(dbgOption);
cliOptions.addOption(winOption);
cliOptions.addOption(noRespawnOption);
cliOptions.addOption(shutupOption);
cliOptions.addOption(shellPluginOption);
cliOptions.addOption(standaloneOption);
cliOptions.addOption(testOption);
aboutData.setupCommandLine(&cliOptions);
cliOptions.process(app);
aboutData.processCommandLine(&cliOptions);
QGuiApplication::setFallbackSessionManagementEnabled(false);
auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement);
QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement);
ShellManager::s_fixedShell = cliOptions.value(shellPluginOption);
if (!cliOptions.isSet(noRespawnOption)) {
KCrash::setFlags(KCrash::AutoRestart);
}
if (cliOptions.isSet(testOption)) {
const QUrl layoutUrl = QUrl::fromUserInput(cliOptions.value(testOption), {}, QUrl::AssumeLocalFile);
if (!layoutUrl.isLocalFile()) {
qWarning() << "ensure the layout file is local" << layoutUrl;
cliOptions.showHelp(1);
}
QStandardPaths::setTestModeEnabled(true);
QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).removeRecursively();
ShellManager::s_testModeLayout = layoutUrl.toLocalFile();
QObject::connect(ShellManager::instance(), &ShellManager::shellChanged,
ShellManager::instance(),
[layoutUrl]() {
new CoronaTestHelper(ShellManager::instance()->corona());
}
);
}
if (cliOptions.isSet(standaloneOption)) {
if (cliOptions.isSet(shellPluginOption)) {
ShellManager::s_standaloneOption = true;
app.setApplicationName("plasmashell_"+cliOptions.value(shellPluginOption));
app.setQuitOnLastWindowClosed(true);
KDBusService service(KDBusService::Unique);
//This will not leak, because corona deletes itself on window close
new StandaloneAppCorona(cliOptions.value(shellPluginOption));
return app.exec();
} else {
cliOptions.showHelp(1);
}
}
}
KDBusService service(KDBusService::Unique);
QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, ShellManager::instance(), &QObject::deleteLater);
return app.exec();
}