diff --git a/src/qgisapp.cpp b/src/qgisapp.cpp index bcd8c4e3930..0dc257ee145 100644 --- a/src/qgisapp.cpp +++ b/src/qgisapp.cpp @@ -6,7 +6,7 @@ email : sherman at mrcc.com Romans 3:23=>Romans 6:23=>Romans 10:9,10=>Romans 12 ***************************************************************************/ - +/* $Id$ */ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * @@ -67,14 +67,19 @@ #include "qgslayerproperties.h" #include "qgsabout.h" #include "qgspluginmanager.h" +#include "qgsmaplayerinterface.h" #include "qgis.h" #include "qgisapp.h" +#include "qgspluginitem.h" #include "../plugins/qgisplugin.h" #include "xpm/qgis.xpm" #include +typedef QgsMapLayerInterface* create_it(); +typedef QString name_t(); +typedef QString description_t(); // version -static const char *qgisVersion = "0.0.11 - June 10, 2003"; +static const char *qgisVersion = "0.0.12 pre 1 - July 4, 2003"; static const int qgisVersionInt = 11; // cursors static unsigned char zoom_in_bits[] = { @@ -675,13 +680,96 @@ void QgisApp::actionPluginManager_activated(){ QgsPluginManager *pm = new QgsPluginManager(this); if(pm->exec()){ // load selected plugins + std::vector pi = pm->getSelectedPlugins(); + std::vector::iterator it = pi.begin(); + while(it != pi.end()){ + QgsPluginItem plugin = *it; + loadPlugin(plugin.name(), plugin.description(), plugin.fullPath()); + it++; + } + } +} +void QgisApp::loadPlugin(QString name, QString description, QString fullPath){ + QLibrary *myLib = new QLibrary(fullPath); + std::cout << "Library name is " << myLib->library() << std::endl; + bool loaded = myLib->load(); + if (loaded) { + std::cout << "Loaded test plugin library" << std::endl; + std::cout << "Attempting to resolve the classFactory function" << std::endl; + create_it *cf = (create_it *) myLib->resolve("classFactory"); + + if (cf) { + std::cout << "Getting pointer to a MapLayerInterface object from the library\n"; + QgsMapLayerInterface *pl = cf(); + if(pl){ + std::cout << "Instantiated the maplayer test plugin\n"; + // set the main window pointer for the plugin + pl->setQgisMainWindow(this); + std::cout << "getInt returned " << pl->getInt() << " from map layer plugin\n"; + // set up the gui + pl->initGui(); + }else{ + std::cout << "Unable to instantiate the maplayer test plugin\n"; + } + } + }else{ + std::cout << "Failed to load " << fullPath << "\n"; + } +} +void QgisApp::testMapLayerPlugins(){ + // map layer plugins live in their own directory (somewhere to be determined) + QDir mlpDir("../plugins/maplayer", "*.so.1.0.0", QDir::Name | QDir::IgnoreCase, QDir::Files ); + if(mlpDir.count() == 0){ + QMessageBox::information(this,"No MapLayer Plugins", "No MapLayer plugins in ../plugins/maplayer"); + }else{ + for(unsigned i = 0; i < mlpDir.count(); i++){ + std::cout << "Getting information for plugin: " << mlpDir[i] << std::endl; + std::cout << "Attempting to load the plugin using dlopen\n"; + void *handle = dlopen("../plugins/maplayer/" + mlpDir[i], RTLD_LAZY); + if (!handle) { + std::cout << "Error in dlopen: " << dlerror() << std::endl; + }else{ + std::cout << "dlopen suceeded" << std::endl; + dlclose(handle); + } + + QLibrary *myLib = new QLibrary("../plugins/maplayer/" + mlpDir[i]); + std::cout << "Library name is " << myLib->library() << std::endl; + bool loaded = myLib->load(); + if (loaded) { + std::cout << "Loaded test plugin library" << std::endl; + std::cout << "Attempting to resolve the classFactory function" << std::endl; + create_it *cf = (create_it *) myLib->resolve("classFactory"); + + if (cf) { + std::cout << "Getting pointer to a MapLayerInterface object from the library\n"; + QgsMapLayerInterface *pl = cf(); + if(pl){ + std::cout << "Instantiated the maplayer test plugin\n"; + // set the main window pointer for the plugin + pl->setQgisMainWindow(this); + std::cout << "getInt returned " << pl->getInt() << " from map layer plugin\n"; + // set up the gui + pl->initGui(); + }else{ + std::cout << "Unable to instantiate the maplayer test plugin\n"; + } + } + }else{ + std::cout << "Failed to load " << mlpDir[i] << "\n"; + } + } +} } void QgisApp::testPluginFunctions() { + // test maplayer plugins first + testMapLayerPlugins(); + if(false){ // try to load plugins from the plugin directory and test each one QDir pluginDir("../plugins", "*.so*", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks); @@ -746,6 +834,7 @@ void QgisApp::testPluginFunctions() } } } + } } void QgisApp::saveWindowState() diff --git a/src/qgisapp.h b/src/qgisapp.h index b2cecd59cfb..19e25e73cac 100644 --- a/src/qgisapp.h +++ b/src/qgisapp.h @@ -98,8 +98,12 @@ class QgisApp:public QgisAppBase void zoomToLayerExtent(); //! test plugin functionality void testPluginFunctions(); + //! test maplayer plugins + void testMapLayerPlugins(); //! plugin manager void actionPluginManager_activated(); + //! plugin loader + void loadPlugin(QString name, QString description, QString fullPath); //! Save window state void saveWindowState(); //! Restore the window and toolbar state diff --git a/src/qgsmaplayerinterface.h b/src/qgsmaplayerinterface.h new file mode 100644 index 00000000000..945f086ffba --- /dev/null +++ b/src/qgsmaplayerinterface.h @@ -0,0 +1,34 @@ +/*************************************************************************** + begin : Jul 10 2003 + copyright : (C) 2003 by Gary E.Sherman + email : sherman at mrcc.com + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + /* $Id$ */ +#ifndef QGSMAPLAYERINTERFACE_H +#define QGSMAPLAYERINTERFACE_H +/** +* Interface class for map layer plugins +*/ +#include +#include "qgisapp.h" +class QgsMapLayerInterface: public QObject{ + Q_OBJECT +public: +virtual void setQgisMainWindow(QMainWindow *qgis) = 0; +// a test function to return an int +virtual int getInt()=0; +// setup the plugin's GUI +virtual void initGui()=0; +virtual void unload()=0; + +}; +#endif // QGSMAPLAYERINTERFACE_H diff --git a/src/qgspluginitem.cpp b/src/qgspluginitem.cpp index c52f5a97cb2..51dc273498f 100644 --- a/src/qgspluginitem.cpp +++ b/src/qgspluginitem.cpp @@ -10,16 +10,26 @@ // Copyright: See COPYING file that comes with this distribution // // +/* $Id$ */ #include #include "qgspluginitem.h" QgsPluginItem::QgsPluginItem(QString _name, QString _description, QString _fullPath) : - name(_name), description(_description), fullPath(_fullPath) + m_name(_name), m_description(_description), m_fullPath(_fullPath) { } +QString QgsPluginItem::name(){ + return m_name; +} +QString QgsPluginItem::description(){ + return m_description; +} +QString QgsPluginItem::fullPath(){ + return m_fullPath; +} QgsPluginItem::~QgsPluginItem() { } diff --git a/src/qgspluginitem.h b/src/qgspluginitem.h index 2c5ae0080b2..c9cf0adb2e5 100644 --- a/src/qgspluginitem.h +++ b/src/qgspluginitem.h @@ -10,6 +10,7 @@ // Copyright: See COPYING file that comes with this distribution // // +/* $Id$ */ #ifndef QGSPLUGINITEM_H #define QGSPLUGINITEM_H class QString; @@ -21,12 +22,14 @@ Class to contain information about a loadable plugin, including its name, descri class QgsPluginItem{ public: QgsPluginItem(QString name=0, QString description=0, QString fullPath=0); - + QString name(); + QString description(); + QString fullPath(); ~QgsPluginItem(); private: - QString name; - QString description; - QString fullPath; + QString m_name; + QString m_description; + QString m_fullPath; }; diff --git a/src/qgspluginmanager.cpp b/src/qgspluginmanager.cpp index a238fa957f4..8b7d7d4ad8e 100644 --- a/src/qgspluginmanager.cpp +++ b/src/qgspluginmanager.cpp @@ -10,6 +10,7 @@ // Copyright: See COPYING file that comes with this distribution // // +/* $Id$ */ #include #include #include @@ -60,4 +61,14 @@ QDir pluginDir(txtPluginDir->text(), "*.so*", QDir::Name | QDir::IgnoreCase, QDi } } std::vector QgsPluginManager::getSelectedPlugins(){ + std::vector pis; + QCheckListItem *lvi = (QCheckListItem *)lstPlugins->firstChild(); + while(lvi != 0){ + if(lvi->isOn()){ + + pis.push_back(QgsPluginItem(lvi->text(0), lvi->text(1), txtPluginDir->text() + "/" + lvi->text(2))); + } + lvi = (QCheckListItem *)lvi->nextSibling(); + } + return pis; } diff --git a/src/qgsshapefilelayer.h b/src/qgsshapefilelayer.h index e2a40b93c8b..0c1a4069bfa 100644 --- a/src/qgsshapefilelayer.h +++ b/src/qgsshapefilelayer.h @@ -5,7 +5,7 @@ copyright : (C) 2002 by Gary E.Sherman email : sherman at mrcc.com ***************************************************************************/ - +/* $Id$ */ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * diff --git a/src/src.pro b/src/src.pro index 4e3329f3f50..6fdd9da3c20 100644 --- a/src/src.pro +++ b/src/src.pro @@ -58,7 +58,8 @@ HEADERS += qgisapp.h \ qgsprojectio.h \ qgisiface.h \ qgspluginmanager.h \ - qgspluginitem.h + qgspluginitem.h \ + qgsmaplayerinterface.h FORMS += qgisappbase.ui \ qgslegenditembase.ui \ qgsabout.ui \