Changeset View
Changeset View
Standalone View
Standalone View
shell/shellmanager.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "shellmanager.h" | 20 | #include "shellmanager.h" | ||
21 | 21 | | |||
22 | #include <algorithm> | 22 | #include <algorithm> | ||
23 | 23 | | |||
24 | #include <QCoreApplication> | 24 | #include <QCoreApplication> | ||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QDir> | 26 | #include <QDir> | ||
27 | #include <QFileInfo> | ||||
27 | #include <QList> | 28 | #include <QList> | ||
28 | #include <QTimer> | 29 | #include <QTimer> | ||
29 | 30 | | |||
30 | #include <qplatformdefs.h> | 31 | #include <qplatformdefs.h> | ||
31 | #include <QQmlEngine> | 32 | #include <QQmlEngine> | ||
32 | #include <QQmlComponent> | 33 | #include <QQmlComponent> | ||
33 | 34 | | |||
34 | //#include <config-prefix.h> | 35 | //#include <config-prefix.h> | ||
35 | #include "shellcorona.h" | 36 | #include "shellcorona.h" | ||
36 | #include "config-workspace.h" | 37 | #include "config-workspace.h" | ||
37 | 38 | | |||
38 | #include <KMessageBox> | 39 | #include <KMessageBox> | ||
39 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
40 | 41 | | |||
42 | #include <KDeclarative/QmlObjectSharedEngine> | ||||
43 | | ||||
41 | static const QStringList s_shellsDirs(QStandardPaths::locateAll(QStandardPaths::QStandardPaths::GenericDataLocation, | 44 | static const QStringList s_shellsDirs(QStandardPaths::locateAll(QStandardPaths::QStandardPaths::GenericDataLocation, | ||
42 | PLASMA_RELATIVE_DATA_INSTALL_DIR "/shells/", | 45 | PLASMA_RELATIVE_DATA_INSTALL_DIR "/shells/", | ||
43 | QStandardPaths::LocateDirectory)); | 46 | QStandardPaths::LocateDirectory)); | ||
44 | static const QString s_shellLoaderPath = QStringLiteral("/contents/loader.qml"); | 47 | static const QString s_shellLoaderPath = QStringLiteral("/contents/loader.qml"); | ||
45 | 48 | | |||
46 | bool ShellManager::s_standaloneOption = false; | 49 | bool ShellManager::s_standaloneOption = false; | ||
47 | QString ShellManager::s_fixedShell; | 50 | QString ShellManager::s_fixedShell; | ||
48 | QString ShellManager::s_testModeLayout; | 51 | QString ShellManager::s_testModeLayout; | ||
Show All 38 Lines | 87 | { | |||
87 | 90 | | |||
88 | d->corona = new ShellCorona(this); | 91 | d->corona = new ShellCorona(this); | ||
89 | 92 | | |||
90 | connect( | 93 | connect( | ||
91 | this, &ShellManager::shellChanged, | 94 | this, &ShellManager::shellChanged, | ||
92 | d->corona, &ShellCorona::setShell | 95 | d->corona, &ShellCorona::setShell | ||
93 | ); | 96 | ); | ||
94 | 97 | | |||
95 | // TODO: Use corona's qml engine when it switches from QScriptEngine | 98 | for (const QString &shellsDir : qAsConst(s_shellsDirs)) { | ||
96 | static QQmlEngine * engine = new QQmlEngine(this); | 99 | const auto dirs = QDir(shellsDir).entryList(QDir::Dirs | QDir::NoDotAndDotDot); | ||
97 | 100 | for (const auto &dir : dirs) { | |||
98 | for (const QString &shellsDir: s_shellsDirs) { | | |||
99 | for (const auto & dir: QDir(shellsDir).entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { | | |||
100 | const QString qmlFile = shellsDir + dir + s_shellLoaderPath; | 101 | const QString qmlFile = shellsDir + dir + s_shellLoaderPath; | ||
101 | // qDebug() << "Making a new instance of " << qmlFile; | 102 | qDebug() << "Making a new instance of " << qmlFile; | ||
102 | 103 | | |||
103 | //this shell is not valid, ignore it | 104 | //this shell is not valid, ignore it | ||
104 | if (!QFile::exists(qmlFile)) { | 105 | if (!QFileInfo::exists(qmlFile)) { | ||
105 | continue; | 106 | continue; | ||
106 | } | 107 | } | ||
107 | 108 | | |||
108 | QQmlComponent handlerComponent(engine, | 109 | auto *handlerContainer = new KDeclarative::QmlObjectSharedEngine(this); | ||
109 | QUrl::fromLocalFile(qmlFile) | 110 | handlerContainer->setSource(QUrl::fromLocalFile(qmlFile)); | ||
110 | ); | | |||
111 | auto handler = handlerComponent.create(); | | |||
112 | 111 | | |||
113 | // Writing out the errors | 112 | QObject *handler = handlerContainer->rootObject(); | ||
114 | for (const auto & error: handlerComponent.errors()) { | | |||
115 | qWarning() << "Error: " << error; | | |||
116 | } | | |||
117 | 113 | | |||
118 | if (handler) { | 114 | if (handler) { | ||
119 | handler->setProperty("pluginName", dir); | 115 | handler->setProperty("pluginName", dir); | ||
120 | // This property is useful for shells to launch themselves in some specific sessions | 116 | // This property is useful for shells to launch themselves in some specific sessions | ||
121 | // For example mediacenter shell can be launched when in plasma-mediacenter session | 117 | // For example mediacenter shell can be launched when in plasma-mediacenter session | ||
122 | handler->setProperty("currentSession", QString::fromUtf8(qgetenv("DESKTOP_SESSION"))); | 118 | handler->setProperty("currentSession", QString::fromUtf8(qgetenv("DESKTOP_SESSION"))); | ||
123 | registerHandler(handler); | 119 | registerHandler(handler); | ||
124 | } | 120 | } | ||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |