Plasma5Support

appsource.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-only
5*/
6
7#include "appsource.h"
8#include "appsengine.h"
9#include "appservice.h"
10
11#include <QDebug>
12
13AppSource::AppSource(const KServiceGroup::Ptr &group, QObject *parent)
14 : Plasma5Support::DataContainer(parent)
15 , m_group(group)
16 , m_app()
17 , m_isApp(false)
18{
19 setObjectName(m_group->entryPath());
20 setData(QStringLiteral("isApp"), false);
21 updateGroup();
22}
23
24AppSource::AppSource(const KService::Ptr &app, QObject *parent)
25 : Plasma5Support::DataContainer(parent)
26 , m_group()
27 , m_app(app)
28 , m_isApp(true)
29{
30 setObjectName(m_app->storageId());
31 setData(QStringLiteral("isApp"), true);
32 updateApp();
33}
34
35AppSource::~AppSource()
36{
37}
38
39Plasma5Support::Service *AppSource::createService()
40{
41 return new AppService(this);
42}
43
44KService::Ptr AppSource::getApp()
45{
46 return m_app;
47}
48
49bool AppSource::isApp() const
50{
51 return m_isApp;
52}
53
54void AppSource::updateGroup()
55{
56 setData(QStringLiteral("iconName"), m_group->icon());
57 setData(QStringLiteral("name"), m_group->caption());
58 setData(QStringLiteral("comment"), m_group->comment());
59 setData(QStringLiteral("display"), !m_group->noDisplay());
60
61 QStringList entries;
62 const auto groupEntries = m_group->entries(true, false, true);
63 for (const KSycocaEntry::Ptr &p : groupEntries) {
64 if (p->isType(KST_KService)) {
65 const KService::Ptr service(static_cast<KService *>(p.data()));
66 entries << service->storageId();
67 } else if (p->isType(KST_KServiceGroup)) {
68 const KServiceGroup::Ptr serviceGroup(static_cast<KServiceGroup *>(p.data()));
69 entries << serviceGroup->entryPath();
70 } else if (p->isType(KST_KServiceSeparator)) {
71 entries << QStringLiteral("---");
72 } else {
73 qDebug() << "unexpected object in entry list";
74 }
75 }
76 setData(QStringLiteral("entries"), entries);
77
79}
80
81void AppSource::updateApp()
82{
83 setData(QStringLiteral("iconName"), m_app->icon());
84 setData(QStringLiteral("name"), m_app->name());
85 setData(QStringLiteral("genericName"), m_app->genericName());
86 setData(QStringLiteral("menuId"), m_app->menuId());
87 setData(QStringLiteral("entryPath"), m_app->entryPath());
88 setData(QStringLiteral("comment"), m_app->comment());
89 setData(QStringLiteral("keywords"), m_app->keywords());
90 setData(QStringLiteral("categories"), m_app->categories());
91 setData(QStringLiteral("display"), !m_app->noDisplay());
93}
App Service.
Definition appservice.h:20
void setData(const QString &key, const QVariant &value)
Set a value for a key.
void checkForUpdate()
Checks whether any data has changed and, if so, emits dataUpdated().
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
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.