summaryrefslogtreecommitdiffstats
path: root/kommander/pluginmanager/pluginmanager.cpp
blob: e5de0841174675d5351af473d82848d35a979095 (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 <mrudolf@tdewebdev.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) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include <kconfig.h>
#include <klibloader.h>
 
#include "pluginmanager.h"

PluginManager::PluginManager()
{
  m_cfg = new TDEConfig("kommanderrc");
  m_list = new TQStringList(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();
}

TQString PluginManager::item(int i) const
{
  return (*m_list)[i];
}

bool PluginManager::add(const TQString& plugin, bool)
{
  TQString 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 TQString& plugin)
{
  if (!m_list->contains(plugin))
    return false;
  m_list->remove(plugin);
  return true;
}

int PluginManager::verify()
{
  TQStringList verified;
  for (TQStringList::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;
}

TQString PluginManager::libraryName(const TQString& plugin) const
{
  KLibrary *l = KLibLoader::self()->library(plugin.latin1());
  TQString libname;
  if (l && l->hasSymbol("kommander_plugin"))
    libname = l->fileName();
  return libname;
}

TQStringList PluginManager::items() const
{
  return (*m_list);
}