File indexing completed on 2024-05-12 05:37:17
0001 /* 0002 SPDX-FileCopyrightText: 2009 Chani Armitage <chani@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "appsource.h" 0008 #include "appsengine.h" 0009 #include "appservice.h" 0010 0011 #include <QDebug> 0012 0013 AppSource::AppSource(const KServiceGroup::Ptr &group, QObject *parent) 0014 : Plasma5Support::DataContainer(parent) 0015 , m_group(group) 0016 , m_app() 0017 , m_isApp(false) 0018 { 0019 setObjectName(m_group->entryPath()); 0020 setData(QStringLiteral("isApp"), false); 0021 updateGroup(); 0022 } 0023 0024 AppSource::AppSource(const KService::Ptr &app, QObject *parent) 0025 : Plasma5Support::DataContainer(parent) 0026 , m_group() 0027 , m_app(app) 0028 , m_isApp(true) 0029 { 0030 setObjectName(m_app->storageId()); 0031 setData(QStringLiteral("isApp"), true); 0032 updateApp(); 0033 } 0034 0035 AppSource::~AppSource() 0036 { 0037 } 0038 0039 Plasma5Support::Service *AppSource::createService() 0040 { 0041 return new AppService(this); 0042 } 0043 0044 KService::Ptr AppSource::getApp() 0045 { 0046 return m_app; 0047 } 0048 0049 bool AppSource::isApp() const 0050 { 0051 return m_isApp; 0052 } 0053 0054 void AppSource::updateGroup() 0055 { 0056 setData(QStringLiteral("iconName"), m_group->icon()); 0057 setData(QStringLiteral("name"), m_group->caption()); 0058 setData(QStringLiteral("comment"), m_group->comment()); 0059 setData(QStringLiteral("display"), !m_group->noDisplay()); 0060 0061 QStringList entries; 0062 const auto groupEntries = m_group->entries(true, false, true); 0063 for (const KSycocaEntry::Ptr &p : groupEntries) { 0064 if (p->isType(KST_KService)) { 0065 const KService::Ptr service(static_cast<KService *>(p.data())); 0066 entries << service->storageId(); 0067 } else if (p->isType(KST_KServiceGroup)) { 0068 const KServiceGroup::Ptr serviceGroup(static_cast<KServiceGroup *>(p.data())); 0069 entries << serviceGroup->entryPath(); 0070 } else if (p->isType(KST_KServiceSeparator)) { 0071 entries << QStringLiteral("---"); 0072 } else { 0073 qDebug() << "unexpected object in entry list"; 0074 } 0075 } 0076 setData(QStringLiteral("entries"), entries); 0077 0078 checkForUpdate(); 0079 } 0080 0081 void AppSource::updateApp() 0082 { 0083 setData(QStringLiteral("iconName"), m_app->icon()); 0084 setData(QStringLiteral("name"), m_app->name()); 0085 setData(QStringLiteral("genericName"), m_app->genericName()); 0086 setData(QStringLiteral("menuId"), m_app->menuId()); 0087 setData(QStringLiteral("entryPath"), m_app->entryPath()); 0088 setData(QStringLiteral("comment"), m_app->comment()); 0089 setData(QStringLiteral("keywords"), m_app->keywords()); 0090 setData(QStringLiteral("categories"), m_app->categories()); 0091 setData(QStringLiteral("display"), !m_app->noDisplay()); 0092 checkForUpdate(); 0093 }