Plasma5Support

appsengine.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "appsengine.h"
8#include "appsource.h"
9
10#include <KSycoca>
11
12AppsEngine::AppsEngine(QObject *parent)
13 : Plasma5Support::DataEngine(parent)
14{
15 init();
16}
17
18AppsEngine::~AppsEngine()
19{
20}
21
22void AppsEngine::init()
23{
24 addGroup(KServiceGroup::root());
27 addGroup(KServiceGroup::root());
28 });
29}
30
32{
33 AppSource *source = dynamic_cast<AppSource *>(containerForSource(name));
34 // if source does not exist, return null service
35 if (!source) {
37 }
38
39 // if source represents a group or something, return null service
40 if (!source->isApp()) {
42 }
43 // if source represent a proper app, return real service
44 Plasma5Support::Service *service = source->createService();
45 service->setParent(this);
46 return service;
47}
48
49void AppsEngine::addGroup(KServiceGroup::Ptr group)
50{
51 if (!(group && group->isValid())) {
52 return;
53 }
54 AppSource *appSource = new AppSource(group, this);
55 // TODO listen for changes
56 addSource(appSource);
57 // do children
58 for (const auto groupEntries = group->groupEntries(KServiceGroup::NoOptions); const KServiceGroup::Ptr &subGroup : groupEntries) {
59 addGroup(subGroup);
60 }
61 for (const auto serviceEntries = group->serviceEntries(KServiceGroup::NoOptions); const KService::Ptr &app : serviceEntries) {
62 addApp(app);
63 }
64}
65
66void AppsEngine::addApp(KService::Ptr app)
67{
68 AppSource *appSource = new AppSource(app, this);
69 // TODO listen for changes
70 addSource(appSource);
71}
72
73K_PLUGIN_CLASS_WITH_JSON(AppsEngine, "plasma-dataengine-apps.json")
74
75#include "appsengine.moc"
App Source.
Definition appsource.h:19
Apps Data Engine.
Definition appsengine.h:32
Plasma5Support::Service * serviceForSource(const QString &name) override
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
static Ptr root()
static KSycoca * self()
Q_SIGNAL void databaseChanged()
virtual Q_INVOKABLE Service * serviceForSource(const QString &source)
void addSource(DataContainer *source)
Adds an already constructed data source.
Q_INVOKABLE DataContainer * containerForSource(const QString &source)
Retrieves a pointer to the DataContainer for a given source.
void removeAllSources()
Removes all data sources.
This class provides a generic API for write access to settings or services.
Definition service.h:78
Namespace for everything in libplasma.
Definition datamodel.cpp:15
QCA_EXPORT void init()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setParent(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.