summaryrefslogtreecommitdiffstats
path: root/kommander/pluginmanager
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commite9ae80694875f869892f13f4fcaf1170a00dea41 (patch)
treeaa2f8d8a217e2d376224c8d46b7397b68d35de2d /kommander/pluginmanager
downloadtdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.tar.gz
tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kommander/pluginmanager')
-rw-r--r--kommander/pluginmanager/Makefile.am18
-rw-r--r--kommander/pluginmanager/main.cpp101
-rw-r--r--kommander/pluginmanager/mainwindow.cpp106
-rw-r--r--kommander/pluginmanager/mainwindow.h56
-rw-r--r--kommander/pluginmanager/pluginmanager.cpp89
-rw-r--r--kommander/pluginmanager/pluginmanager.h53
6 files changed, 423 insertions, 0 deletions
diff --git a/kommander/pluginmanager/Makefile.am b/kommander/pluginmanager/Makefile.am
new file mode 100644
index 00000000..5b3e56c8
--- /dev/null
+++ b/kommander/pluginmanager/Makefile.am
@@ -0,0 +1,18 @@
+bin_PROGRAMS = kmdr-plugins
+
+kmdr_plugins_SOURCES = main.cpp mainwindow.cpp pluginmanager.cpp
+kmdr_plugins_LDADD = $(top_builddir)/kommander/factory/libkommanderfactory.la $(LIB_KIO)
+
+#KDE_ICON = kmdr-plugins
+
+appsdir = $(kde_appsdir)/Applications
+#apps_DATA = kmdr-plugins.desktop
+
+INCLUDES = -I$(top_srcdir)/kommander/factory $(all_includes)
+
+METASOURCES = AUTO
+
+# the library search path.
+kmdr_plugins_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+
+noinst_HEADERS = mainwindow.h pluginmanager.h
diff --git a/kommander/pluginmanager/main.cpp b/kommander/pluginmanager/main.cpp
new file mode 100644
index 00000000..cdbf9cd5
--- /dev/null
+++ b/kommander/pluginmanager/main.cpp
@@ -0,0 +1,101 @@
+/***************************************************************************
+ main.cpp - Kommander plugin manager interface
+ -------------------
+ begin : Tue Aug 13 09:31:50 EST 2002
+ copyright : (C) 2004 Marc Britton <consume@optushome.com.au>
+ (C) 2005 Michal Rudolf <mrudolf@kdewebdev.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. *
+ * *
+ ***************************************************************************/
+
+/* KDE INCLUDES */
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+#include <kurl.h>
+#include <qapplication.h>
+#include <qobject.h>
+#include <kapplication.h>
+
+/* QT INCLUDES */
+#include <qstringlist.h>
+
+/* OTHER INCLUDES */
+#include "pluginmanager.h"
+#include "mainwindow.h"
+#include "kommanderversion.h"
+
+#include <iostream>
+using namespace std;
+
+static const char *description =
+ I18N_NOOP("kmdr-plugins is a component of the Kommander dialog system that manages installed plugins.");
+// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE
+
+
+static KCmdLineOptions options[] =
+{
+ { "a", 0, 0},
+ { "add <file>", I18N_NOOP("Register given library"), 0},
+ { "r", 0, 0},
+ { "remove <file>", I18N_NOOP("Remove given library"), 0},
+ { "c", 0, 0},
+ { "check", I18N_NOOP("Check all installed plugins and remove those missing"), 0},
+ { "l", 0, 0},
+ { "list", I18N_NOOP("List all installed plugins"), 0},
+ KCmdLineLastOption
+};
+
+int main(int argc, char *argv[])
+{
+ KLocale::setMainCatalogue("kommander");
+ KAboutData aboutData( "kmdr-plugins", I18N_NOOP("Kommander Plugin Manager"),
+ KOMMANDER_VERSION, description, KAboutData::License_GPL,
+ "(C) 2004-2005 Kommander authors");
+ aboutData.addAuthor("Marc Britton", "Original author", "consume@optusnet.com.au");
+ aboutData.addAuthor("Eric Laffoon", "Project manager", "eric@kdewebdev.org");
+ aboutData.addAuthor("Michal Rudolf", "Current maintainer", "mrudolf@kdewebdev.org");
+ KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineArgs::addCmdLineOptions(options); // Add our own options.
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ KApplication app;
+
+ if (!args->getOption("add").isNull() || !args->getOption("remove").isNull() || args->isSet("check") || args->isSet("list"))
+ {
+ PluginManager P;
+ if (args->isSet("check"))
+ P.verify();
+
+ QCStringList items = args->getOptionList("add");
+ for (QCStringList::ConstIterator it = items.begin(); it != items.end(); ++it)
+ if (!P.add(*it))
+ cerr << i18n("Error adding plugin '%1'").arg(*it).local8Bit();
+
+ items = args->getOptionList("remove");
+ for (QCStringList::ConstIterator it = items.begin(); it != items.end(); ++it)
+ if (!P.remove(*it))
+ cerr << i18n("Error removing plugin '%1'").arg(*it).local8Bit();
+
+ if (args->isSet("list"))
+ {
+ QStringList plugins = P.items();
+ for (QStringList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
+ cout << (*it).local8Bit() << "\n";
+ }
+ }
+ else
+ {
+ MainWindow *mw = new MainWindow();
+ app.setMainWidget(mw);
+ mw->show();
+ return app.exec();
+ }
+}
diff --git a/kommander/pluginmanager/mainwindow.cpp b/kommander/pluginmanager/mainwindow.cpp
new file mode 100644
index 00000000..4cc67d62
--- /dev/null
+++ b/kommander/pluginmanager/mainwindow.cpp
@@ -0,0 +1,106 @@
+/***************************************************************************
+ mainwindow.cpp - Kommander plugin manager mainwindow class implementation
+ -------------------
+ begin : Tue Aug 13 09:31:50 EST 2002
+ copyright : (C) 2004 by Marc Britton
+ email : consume@optushome.com.au
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 "mainwindow.h"
+#include "pluginmanager.h"
+
+#include <ktoolbar.h>
+#include <klistbox.h>
+#include <kconfig.h>
+#include <kfiledialog.h>
+#include <klibloader.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+
+MainWindow::MainWindow( QWidget* parent, const char *name, WFlags f )
+ : KMainWindow( parent, name, f )
+{
+ KToolBar *toolBar = new KToolBar( this );
+ toolBar->insertButton("fileopen", Add, true, i18n("Add") );
+ toolBar->insertButton("no", Remove, true, i18n("Remove") );
+ toolBar->insertButton("reload", Refresh, true, i18n("Refresh") );
+ connect( toolBar, SIGNAL(clicked(int)), this, SLOT(toolButton(int)) );
+
+ m_list = new KListBox( this );
+ setCentralWidget(m_list);
+
+ m_pluginManager = new PluginManager;
+ m_list->insertStringList(m_pluginManager->items());
+}
+
+MainWindow::~MainWindow()
+{
+ delete m_pluginManager;
+}
+
+void MainWindow::toolButton( int id )
+{
+ switch (id)
+ {
+ case Add:
+ add();
+ break;
+ case Remove:
+ remove();
+ break;
+ case Refresh:
+ verify();
+ break;
+ }
+}
+
+void MainWindow::add()
+{
+ QString libDir = KGlobal::dirs()->findResourceDir("lib", "libkommanderplugin");
+ QString plugin = KFileDialog::getOpenFileName(libDir, "lib*", this,
+ i18n("Add Kommander Plugin"));
+ add(plugin);
+}
+
+void MainWindow::add(const QString &plugin)
+{
+ if (!m_pluginManager->add(plugin))
+ {
+ QString errMsg = i18n("<qt>Unable to load Kommander plugin<br><b>%1</b></qt>").arg(plugin);
+ KMessageBox::error(this, errMsg, i18n("Cannot add plugin"));
+ }
+ else
+ refresh();
+}
+
+void MainWindow::remove()
+{
+ QString plugin = m_list->currentText();
+ if (m_pluginManager->remove(plugin))
+ refresh();
+}
+
+void MainWindow::refresh()
+{
+ m_list->clear();
+ m_list->insertStringList(m_pluginManager->items());
+}
+
+void MainWindow::verify()
+{
+ m_pluginManager->verify();
+ refresh();
+}
+
+#include "mainwindow.moc"
diff --git a/kommander/pluginmanager/mainwindow.h b/kommander/pluginmanager/mainwindow.h
new file mode 100644
index 00000000..addf1a5f
--- /dev/null
+++ b/kommander/pluginmanager/mainwindow.h
@@ -0,0 +1,56 @@
+/***************************************************************************
+ mainwindow.h - Kommander plugin manager mainwindow class definition
+ -------------------
+ begin : Tue Aug 13 09:31:50 EST 2002
+ copyright : (C) 2004 by Marc Britton
+ email : consume@optushome.com.au
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef HAVE_MAINWINDOW_H
+#define HAVE_MAINWINDOW_H
+
+#include <kmainwindow.h>
+
+class KListBox;
+class PluginManager;
+
+class MainWindow : public KMainWindow
+{
+ Q_OBJECT
+public:
+ MainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
+ ~MainWindow();
+
+protected slots:
+ // Call function asigned to tollbutton (0 = add, 1 = remove)
+ void toolButton( int id );
+ // Remove currently selected plugin
+ void remove();
+ // Show dialogbox for selecting plugin, then add it
+ void add();
+ // Add given plugin if is not added yet
+ void add( const QString &plugin );
+ // Check whether installed plugins are valid
+ void verify();
+private:
+ enum {Add, Remove, Refresh};
+
+ // Referesh plugin list
+ void refresh();
+
+ // ListBox of available plugins
+ KListBox *m_list;
+ // plugin manager
+ PluginManager* m_pluginManager;
+};
+
+#endif
diff --git a/kommander/pluginmanager/pluginmanager.cpp b/kommander/pluginmanager/pluginmanager.cpp
new file mode 100644
index 00000000..e9301b26
--- /dev/null
+++ b/kommander/pluginmanager/pluginmanager.cpp
@@ -0,0 +1,89 @@
+/***************************************************************************
+ pluginmanager.cpp - Plugin manager class
+ -------------------
+ copyright : (C) 2005 Michal Rudolf <mrudolf@kdewebdev.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 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);
+}
+
diff --git a/kommander/pluginmanager/pluginmanager.h b/kommander/pluginmanager/pluginmanager.h
new file mode 100644
index 00000000..0c7c79b7
--- /dev/null
+++ b/kommander/pluginmanager/pluginmanager.h
@@ -0,0 +1,53 @@
+/***************************************************************************
+ pluginmanager.h - Plugin manager class
+ -------------------
+ copyright : (C) 2005 Michal Rudolf <mrudolf@kdewebdev.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. *
+ * *
+ ***************************************************************************/
+
+
+#ifndef __HAVE_PLUGINMANAGER_H
+#define __HAVE_PLUGINMANAGER_H
+
+#include <qstringlist.h>
+
+class KConfig;
+
+class PluginManager
+{
+public:
+ PluginManager();
+ ~PluginManager();
+
+ // number of known plugins
+ int count() const;
+ // n-th plugin
+ QString item(int i) const;
+ // adds a plugin if valid;
+ // FIXME: if overwrite is true, plugin with the same base name will be removed
+ bool add(const QString& plugin, bool overwrite = true);
+ // removes given plugin
+ bool remove(const QString& plugin);
+ // remove invalid plugins, returns number of removed plugins
+ int verify();
+ // list of plugins
+ QStringList items() const;
+private:
+ // returns expanded library name or null if it is invalid
+ QString libraryName(const QString& plugin) const;
+
+ QStringList* m_list;
+ KConfig *m_cfg;
+};
+
+
+#endif
+