blob: e9301b2695a881959e1b767e8cb82994e09c8d0a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/***************************************************************************
pluginmanager.cpp - Plugin manager class
-------------------
copyright : (C) 2005 Michal Rudolf <[email protected]>
***************************************************************************/
/***************************************************************************
* *
* 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) any later version. *
* *
***************************************************************************/
#include <kconfig.h>
#include <klibloader.h>
#include "pluginmanager.h"
PluginManager::PluginManager()
{
m_cfg = new KConfig("kommanderrc");
m_list = new QStringList(m_cfg->readListEntry("plugins"));
}
PluginManager::~PluginManager()
{
m_cfg->writeEntry("plugins", *m_list);
delete m_cfg;
delete m_list;
}
int PluginManager::count() const
{
return m_list->count();
}
QString PluginManager::item(int i) const
{
return (*m_list)[i];
}
bool PluginManager::add(const QString& plugin, bool)
{
QString plugName= libraryName(plugin);
if (plugName.isNull())
return false;
if (m_list->contains(plugName))
return false;
m_list->append(plugName);
return true;
}
bool PluginManager::remove(const QString& plugin)
{
if (!m_list->contains(plugin))
return false;
m_list->remove(plugin);
return true;
}
int PluginManager::verify()
{
QStringList verified;
for (QStringList::ConstIterator it = m_list->begin(); it != m_list->end(); ++it)
if (!libraryName(*it).isNull())
verified.append(*it);
int removed = count() - verified.count();
m_list->clear();
(*m_list) += verified;
return removed;
}
QString PluginManager::libraryName(const QString& plugin) const
{
KLibrary *l = KLibLoader::self()->library(plugin.latin1());
QString libname;
if (l && l->hasSymbol("kommander_plugin"))
libname = l->fileName();
return libname;
}
QStringList PluginManager::items() const
{
return (*m_list);
}
|