~ubuntu-branches/ubuntu/raring/recorditnow/raring

« back to all changes in this revision

Viewing changes to joschy-snapshot-23-02-10/joschycore/joschycore/pluginmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-09 14:54:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110109145401-gyckb4airz4fio50
Tags: 0.8.1-0ubuntu1
* New upstream release. (LP: #681270)
  - Update debian/copyright.
* Build-depend on recordmydesktop.
* Add a watch file.
* Drop 01_fix_ftbfs_kwarning_call.diff, fixed upstream.
* Add 01_joschy_install_to_usr_lib.diff.
* Add 02_fix_ftbfs_no-add-needed.diff.
* Add 03_dont_install_header_files.diff.
* Replace dependency on libpolkit-qt-1-0 with policykit-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2010  Kai Dombrowe <just89@gmx.de>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Lesser General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2.1 of the License, or (at your option) any later version.
 
8
 
 
9
    This library is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    Lesser General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Lesser General Public
 
15
    License along with this library; if not, write to the Free Software
 
16
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
17
*/
 
18
 
 
19
// own
 
20
#include "pluginmanager_p.h"
 
21
 
 
22
// Qt
 
23
#include <QtCore/QDir>
 
24
#include <QtCore/QPluginLoader>
 
25
 
 
26
 
 
27
namespace Joschy {
 
28
 
 
29
 
 
30
PluginManager::PluginManager(QObject *parent)
 
31
    : QObject(parent)
 
32
{
 
33
 
 
34
    updatePluginList();
 
35
 
 
36
}
 
37
 
 
38
 
 
39
QList<Joschy::PluginInfo> PluginManager::availableProvider() const
 
40
{
 
41
 
 
42
    QList<Joschy::PluginInfo> list;
 
43
    foreach (const PluginInfo &info, m_pluginList) {
 
44
        if (info.type() == Joschy::PluginInfo::ProviderType) {
 
45
            list.append(info);
 
46
        }
 
47
    }
 
48
    return list;
 
49
 
 
50
}
 
51
 
 
52
 
 
53
QList<Joschy::PluginInfo> PluginManager::availableNetworkLayer() const
 
54
{
 
55
 
 
56
    QList<Joschy::PluginInfo> list;
 
57
    foreach (const PluginInfo &info, m_pluginList) {
 
58
        if (info.type() == Joschy::PluginInfo::NetworkLayerType) {
 
59
            list.append(info);
 
60
        }
 
61
    }
 
62
    return list;
 
63
 
 
64
}
 
65
 
 
66
 
 
67
void PluginManager::unloadPlugin(Joschy::Plugin *plugin)
 
68
{
 
69
 
 
70
    if (m_loadedPlugins.contains(plugin)) {
 
71
        m_loadedPlugins.removeAll(plugin);
 
72
        delete plugin;
 
73
    }
 
74
 
 
75
}
 
76
 
 
77
 
 
78
void PluginManager::updatePluginList()
 
79
{
 
80
 
 
81
    m_pluginList.clear();
 
82
 
 
83
    JOSCHY_DEBUG() << "load plugin list...";
 
84
    const QStringList filters = QStringList() << "*.plugin";
 
85
    foreach (const QString &pluginDir, Joschy::PluginInfo::pluginDirs()) {
 
86
        JOSCHY_DEBUG() << "PluginDir:" << pluginDir;
 
87
        QDir dir(pluginDir);
 
88
        foreach (const QString &file, dir.entryList(filters, QDir::Files)) {
 
89
            m_pluginList.append(PluginInfo(dir.absoluteFilePath(file)));
 
90
        }
 
91
    }
 
92
    JOSCHY_DEBUG() << "Done: " << m_pluginList.size();
 
93
 
 
94
}
 
95
 
 
96
 
 
97
Joschy::Plugin *PluginManager::loadPluginInternal(const Joschy::PluginInfo &info)
 
98
{
 
99
 
 
100
    JOSCHY_DEBUG() << "load:" << info.library();
 
101
    QPluginLoader loader(info.library());
 
102
    QObject *instance = loader.instance();
 
103
    if (instance) {
 
104
        JOSCHY_DEBUG() << "success";
 
105
        Joschy::Plugin *plugin = qobject_cast<Joschy::Plugin*>(instance);
 
106
        m_loadedPlugins.append(plugin);
 
107
        plugin->setPluginManager(this);
 
108
        return plugin;
 
109
    } else {
 
110
        JOSCHY_DEBUG() << "error:" << loader.errorString();
 
111
        return 0;
 
112
    }
 
113
 
 
114
}
 
115
 
 
116
 
 
117
} // namespace Joschy
 
118
 
 
119
 
 
120
#include "pluginmanager_p.moc"