File: customcorona.cpp

package info (click to toggle)
libplasma 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,796 kB
  • sloc: cpp: 17,769; sh: 286; xml: 95; python: 57; javascript: 29; makefile: 7
file content (76 lines) | stat: -rw-r--r-- 2,584 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/

#include "customcorona.h"
#include <QAction>
#include <QDebug>

#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"));
    // applications that want to load a plasma scene would have to load their own shell.. TODO: have a simple shell in plasma-framework for this purpose?
    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(package.fileUrl("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::Containment::Type::Desktop) {
            desktopFound = true;
            break;
        }
    }

    if (!desktopFound) {
        qDebug() << "Loading default layout";
        Plasma::Containment *c = createContainment(QStringLiteral("org.kde.desktopcontainment"));
        c->createApplet(QStringLiteral("org.kde.plasma.analogclock"));
        saveLayout(QStringLiteral("exampleplasmashell-appletsrc"));
    }

    // don't let containments to be removed
    for (auto c : containments()) {
        if (c->containmentType() == Plasma::Containment::Type::Desktop) {
            // example of a shell without a wallpaper
            c->setWallpaperPlugin(QStringLiteral("null"));
            m_view->setContainment(c);
            if (QAction *removeAction = c->internalAction(QStringLiteral("remove"))) {
                removeAction->deleteLater();
            }
            break;
        }
    }
}

#include "moc_customcorona.cpp"