a minimal example of a custom shell
This commit is contained in:
parent
1a804c33e2
commit
2750155af4
@ -9,3 +9,4 @@ add_subdirectory(containments)
|
||||
add_subdirectory(wallpapers)
|
||||
add_subdirectory(dataengines)
|
||||
add_subdirectory(testcontainmentactionsplugin)
|
||||
add_subdirectory(shell)
|
||||
|
21
examples/shell/CMakeLists.txt
Normal file
21
examples/shell/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
set(exampleplasmashell-app_SRCS
|
||||
customcorona.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(exampleplasmashell ${exampleplasmashell-app_SRCS})
|
||||
|
||||
target_link_libraries(
|
||||
exampleplasmashell
|
||||
Qt5::Widgets
|
||||
Qt5::Quick
|
||||
Qt5::Qml
|
||||
KF5::I18n
|
||||
KF5::XmlGui
|
||||
KF5::PlasmaQuick
|
||||
KF5::Plasma
|
||||
KF5::DBusAddons
|
||||
KF5::Notifications
|
||||
KF5::QuickAddons
|
||||
)
|
||||
|
88
examples/shell/customcorona.cpp
Normal file
88
examples/shell/customcorona.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2015 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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 desktopFoundation; either version 2 of
|
||||
* the License or (at your option) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "customcorona.h"
|
||||
#include <QDebug>
|
||||
#include <QAction>
|
||||
#include <KActionCollection>
|
||||
|
||||
#include <KPackage/Package>
|
||||
#include <KPackage/PackageLoader>
|
||||
#include <Plasma/PluginLoader>
|
||||
|
||||
CustomCorona::CustomCorona(QObject *parent)
|
||||
: Plasma::Corona(parent)
|
||||
{
|
||||
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Shell"));
|
||||
package.setPath(QStringLiteral("org.kde.plasma.desktop"));
|
||||
setKPackage(package);
|
||||
|
||||
qmlRegisterUncreatableType<PlasmaQuick::ContainmentView>("org.kde.plasma.shell", 2, 0, "Desktop", QStringLiteral("It is not possible to create objects of type Desktop"));
|
||||
|
||||
m_view = new PlasmaQuick::ContainmentView(this);
|
||||
m_view->setSource(QUrl::fromLocalFile(package.filePath("views", QStringLiteral("Desktop.qml"))));
|
||||
m_view->show();
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QRect CustomCorona::screenGeometry(int id) const
|
||||
{
|
||||
Q_UNUSED(id);
|
||||
//TODO?
|
||||
return QRect();
|
||||
}
|
||||
|
||||
void CustomCorona::load()
|
||||
{
|
||||
loadLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
||||
|
||||
|
||||
bool desktopFound = false;
|
||||
for (auto c : containments()) {
|
||||
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
||||
desktopFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!desktopFound) {
|
||||
qDebug() << "Loading default layout";
|
||||
Plasma::Containment *c = createContainment(QStringLiteral("org.kde.desktopcontainment"));
|
||||
c->createApplet("org.kde.plasma.analogclock");
|
||||
saveLayout(QStringLiteral("exampleplasmashell-appletsrc"));
|
||||
}
|
||||
|
||||
//don't let containments to be removed
|
||||
for (auto c : containments()) {
|
||||
if (c->containmentType() == Plasma::Types::DesktopContainment) {
|
||||
m_view->setContainment(c);
|
||||
QAction *removeAction = c->actions()->action(QStringLiteral("remove"));
|
||||
if(removeAction) {
|
||||
removeAction->deleteLater();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_customcorona.cpp"
|
42
examples/shell/customcorona.h
Normal file
42
examples/shell/customcorona.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2015 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMCORONA_H
|
||||
#define CUSTOMCORONA_H
|
||||
|
||||
#include <plasma/corona.h>
|
||||
#include "plasmaquick/containmentview.h"
|
||||
|
||||
class CustomCorona : public Plasma::Corona
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomCorona(QObject * parent = 0);
|
||||
QRect screenGeometry(int id) const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void load();
|
||||
|
||||
private:
|
||||
PlasmaQuick::ContainmentView *m_view;
|
||||
};
|
||||
|
||||
#endif
|
53
examples/shell/main.cpp
Normal file
53
examples/shell/main.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2015 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* 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) version 3 or any later version
|
||||
* accepted by the membership of KDE e.V. (or its successor approved
|
||||
* by the membership of KDE e.V.), which shall act as a proxy
|
||||
* defined in Section 14 of version 3 of the license.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <qcommandlineparser.h>
|
||||
#include <qcommandlineoption.h>
|
||||
|
||||
#include <KDBusService>
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include "customcorona.h"
|
||||
|
||||
static const char version[] = "1.0";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QQuickWindow::setDefaultAlphaBuffer(true);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setApplicationVersion(version);
|
||||
app.setOrganizationDomain(QStringLiteral("kde.org"));
|
||||
|
||||
KDBusService service(KDBusService::Unique);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(i18n("Plasma Example shell"));
|
||||
parser.addVersionOption();
|
||||
parser.addHelpOption();
|
||||
parser.process(app);
|
||||
|
||||
CustomCorona *corona = new CustomCorona();
|
||||
|
||||
const int ret = app.exec();
|
||||
delete corona;
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user