File indexing completed on 2024-05-05 04:47:44

0001 /****************************************************************************************
0002  * Copyright (c) 2017 Malte Veerman <malte.veerman@gmail.com>                           *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #define DEBUG_PREFIX "AppletLoader"
0018 
0019 #include "AppletLoader.h"
0020 
0021 #include "AmarokContextPackageStructure.h"
0022 #include "core/support/Amarok.h"
0023 #include "core/support/Debug.h"
0024 
0025 #include <KPackage/PackageLoader>
0026 
0027 using namespace Context;
0028 
0029 AppletLoader::AppletLoader(QObject *parent) : QObject(parent)
0030 {
0031     findApplets();
0032 }
0033 
0034 AppletLoader::~AppletLoader()
0035 {
0036 }
0037 
0038 QList<KPluginMetaData> AppletLoader::applets() const
0039 {
0040     return m_applets;
0041 }
0042 
0043 QList<KPluginMetaData> Context::AppletLoader::enabledApplets() const
0044 {
0045     QList<KPluginMetaData> list;
0046     QStringList enabledApplets = Amarok::config(QStringLiteral("Context")).readEntry("enabledApplets", QStringList());
0047 
0048     for (const auto &applet : m_applets)
0049     {
0050         if (enabledApplets.contains(applet.pluginId()))
0051             list << applet;
0052     }
0053     return list;
0054 }
0055 
0056 void AppletLoader::findApplets()
0057 {
0058     DEBUG_BLOCK
0059 
0060     auto loader = KPackage::PackageLoader::self();
0061     auto structure = new AmarokContextPackageStructure;
0062     loader->addKnownPackageStructure(QStringLiteral("Amarok/ContextApplet"), structure);
0063     m_applets = loader->findPackages(QStringLiteral("Amarok/ContextApplet"),
0064                                      QString(),
0065                                      [] (const KPluginMetaData &data)
0066                                      { return data.serviceTypes().contains(QStringLiteral("Amarok/ContextApplet")); });
0067     Q_EMIT finished(m_applets);
0068 
0069     for (const auto &applet : m_applets)
0070     {
0071         debug() << "Applet found:" << applet.name();
0072     }
0073     debug() << "Number of applets found:" << m_applets.size();
0074 
0075     if( m_applets.isEmpty() )
0076         warning() << "No applets found";
0077 }