plugincontroller.cpp 2.65 KB
Newer Older
Sandro Andrade's avatar
Sandro Andrade committed
1
2
3
4
5
6
7
8
9
/****************************************************************************
**
** Copyright (C) 2016 by Sandro S. Andrade <sandroandrade@kde.org>
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License or (at your option) version 3 or any later version
** accepted by the membership of KDE e.V. (or its successor approved
10
** by the membership of KDE e.V.), which shall act as a proxy
Sandro Andrade's avatar
Sandro Andrade committed
11
12
13
14
15
16
17
18
19
20
21
22
** defined in Section 14 of version 3 of the license.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/

23
#include "plugincontroller.h"
24

Sandro Andrade's avatar
Sandro Andrade committed
25
#include "core.h"
26
27

#include <interfaces/iplugin.h>
28
29
#include <interfaces/isoundbackend.h>

Sandro Andrade's avatar
Sandro Andrade committed
30
#include <KPluginLoader>
31
32
33

#include <QDebug>

34
35
namespace Minuet
{
36

37
38
39
PluginController::PluginController(QObject *parent)
    : IPluginController(parent)
{
40
41
42
43
44
45
46
47
    m_plugins = KPluginLoader::findPlugins(QStringLiteral("minuet"), [&](const KPluginMetaData &meta) {
        if (!meta.serviceTypes().contains(QStringLiteral("Minuet/Plugin"))) {
            qDebug() << "Plugin" << meta.fileName() << "is installed into the minuet plugin directory, but does not have"
                " \"Minuet/Plugin\" set as the service type. This plugin will not be loaded.";
            return false;
        }
        return true;
    });
48
}
49

50
51
PluginController::~PluginController()
{
52
53
    qDeleteAll(m_loadedPlugins.values().begin(), m_loadedPlugins.values().end());
    m_loadedPlugins.clear();
54
}
55

56
bool PluginController::initialize(Core *core)
57
58
59
60
61
62
63
64
{
    foreach (const KPluginMetaData &pluginMetaData, m_plugins)
    {
        if (m_loadedPlugins.value(pluginMetaData))
            continue;

        KPluginLoader loader(pluginMetaData.fileName());
        IPlugin *plugin = qobject_cast<IPlugin *>(loader.instance());
65
        if (plugin) {
66
            m_loadedPlugins.insert(pluginMetaData, plugin);
67
68
69
70
71
72
            ISoundBackend *soundBackend = 0;
            if (!core->soundBackend() && (soundBackend = qobject_cast<ISoundBackend *>(plugin))) {
                qDebug() << "Setting soundbackend to" << soundBackend->metaObject()->className();
                core->setSoundBackend(soundBackend);
            }
        }
73
74
75
76
77
    }

    return true;
}

Sandro Andrade's avatar
Sandro Andrade committed
78
}
79