1
/***************************************************************************
2
qgspluginmanager.cpp - description
5
copyright : (C) 2003 by Gary E.Sherman
6
email : sherman at mrcc.com
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
/* $Id: qgspluginmanager.cpp,v 1.17 2004/11/27 19:19:16 gsherman Exp $ */
19
#include <qapplication.h>
20
#include <qfiledialog.h>
21
#include <qlineedit.h>
22
#include <qlistview.h>
23
#include <qmessagebox.h>
25
#include <qsettings.h>
26
#include "../plugins/qgisplugin.h"
27
#include "qgspluginmanager.h"
28
#include "qgspluginitem.h"
29
#include "qgsproviderregistry.h"
30
#include "qgspluginregistry.h"
39
QgsPluginManager::QgsPluginManager(QWidget * parent, const char *name):QgsPluginManagerBase(parent, name)
41
// set the default lib dir to the qgis install directory/lib (this info is
42
// available from the provider registry so we use it here)
43
QgsProviderRegistry *pr = QgsProviderRegistry::instance();
44
/* char **argv = qApp->argv();
45
QString appDir = argv[0];
46
int bin = appDir.findRev("/bin", -1, false);
47
QString baseDir = appDir.left(bin);
48
QString libDir = baseDir + "/lib"; */
50
txtPluginDir->setText(pr->libDirectory());
51
getPluginDescriptions();
55
QgsPluginManager::~QgsPluginManager()
59
void QgsPluginManager::browseFiles()
61
QString s = QFileDialog::getExistingDirectory(0, this, "get existing directory", tr("Choose a directory"), TRUE);
62
txtPluginDir->setText(s);
63
getPluginDescriptions();
66
void QgsPluginManager::getPluginDescriptions()
68
QString sharedLibExtension;
70
sharedLibExtension = "*.dll";
72
sharedLibExtension = "*.so*";
75
// check all libs in the current plugin directory and get name and descriptions
76
QDir pluginDir(txtPluginDir->text(), sharedLibExtension, QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks);
78
if (pluginDir.count() == 0)
80
QMessageBox::information(this, tr("No Plugins"), tr("No QGIS plugins found in ") + txtPluginDir->text());
83
std::cout << "PLUGIN MANAGER:" << std::endl;
84
for (unsigned i = 0; i < pluginDir.count(); i++)
88
// test code to help debug loading problems
89
QString lib = QString("%1/%2").arg(txtPluginDir->text()).arg(pluginDir[i]);
90
// void *handle = dlopen((const char *) lib, RTLD_LAZY);
91
void *handle = dlopen((const char *) lib, RTLD_LAZY | RTLD_GLOBAL);
94
std::cout << "Error in dlopen: " << dlerror() << std::endl;
98
std::cout << "dlopen suceeded" << std::endl;
101
#endif //#ifndef WIN32
102
#endif //#ifdef TESTLIB
105
std::cout << "Examining " << txtPluginDir->text() << "/" << pluginDir[i] << std::endl;
106
QLibrary *myLib = new QLibrary(txtPluginDir->text() + "/" + pluginDir[i]);
107
bool loaded = myLib->load();
110
std::cout << "Loaded " << myLib->library() << std::endl;
111
name_t *pName = (name_t *) myLib->resolve("name");
112
description_t *pDesc = (description_t *) myLib->resolve("description");
113
version_t *pVersion = (version_t *) myLib->resolve("version");
115
// show the values (or lack of) for each function
117
std::cout << "Plugin name: " << pName() << std::endl;
119
std::cout << "Plugin name not returned when queried\n";
122
std::cout << "Plugin description: " << pDesc() << std::endl;
124
std::cout << "Plugin description not returned when queried\n";
127
std::cout << "Plugin version: " << pVersion() << std::endl;
129
std::cout << "Plugin version not returned when queried\n";
132
if (pName && pDesc && pVersion)
134
QCheckListItem *pl = new QCheckListItem(lstPlugins, pName(), QCheckListItem::CheckBox); //, pDesc(), pluginDir[i])
135
pl->setText(1, pVersion());
136
pl->setText(2, pDesc());
137
pl->setText(3, pluginDir[i]);
140
std::cout << "Getting an instance of the QgsPluginRegistry" << std::endl;
142
// check to see if the plugin is loaded and set the checkbox accordingly
143
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
144
// get the library using the plugin description
146
std::cout << "Getting library name from the registry" << std::endl;
148
QString libName = pRegistry->library(pName());
149
if (libName.length() > 0)
152
std::cout << "Found library name in the registry" << std::endl;
154
if (libName == myLib->library())
162
std::cout << "Failed to get name, description, or type for " << myLib->library() << std::endl;
166
std::cout << "Failed to load " << myLib->library() << std::endl;
171
void QgsPluginManager::apply()
177
void QgsPluginManager::unload()
181
std::cout << "Checking for plugins to unload" << std::endl;
183
QCheckListItem *lvi = (QCheckListItem *) lstPlugins->firstChild();
188
// its off -- see if it is loaded and if so, unload it
189
QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
191
std::cout << "Checking to see if " << lvi->text(0) << " is loaded" << std::endl;
193
QgisPlugin *plugin = pRegistry->plugin(lvi->text(0));
197
// remove the plugin from the registry
198
pRegistry->removePlugin(lvi->text(0));
199
//disable it to the qsettings file [ts]
200
settings.writeEntry("/qgis/Plugins/" + lvi->text(0), false);
203
lvi = (QCheckListItem *) lvi->nextSibling();
207
std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
209
std::vector < QgsPluginItem > pis;
210
QCheckListItem *lvi = (QCheckListItem *) lstPlugins->firstChild();
216
pis.push_back(QgsPluginItem(lvi->text(0), lvi->text(2), txtPluginDir->text() + "/" + lvi->text(3)));
221
lvi = (QCheckListItem *) lvi->nextSibling();
225
void QgsPluginManager::selectAll()
227
// select all plugins
228
QCheckListItem *child = dynamic_cast<QCheckListItem *>(lstPlugins->firstChild());
232
child = dynamic_cast<QCheckListItem *>(child->nextSibling());
237
void QgsPluginManager::clearAll()
239
// clear all selection checkboxes
240
QCheckListItem *child = dynamic_cast<QCheckListItem *>(lstPlugins->firstChild());
244
child = dynamic_cast<QCheckListItem *>(child->nextSibling());