Skip to content
Permalink
Browse files

Look for and load plugins from the users .qgis directory.

Patch from Matthew Perry, ticket #781


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7282 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
gsherman
gsherman committed Oct 22, 2007
1 parent 809577f commit 2279ebb0c2dd11e2d4d44fb8e25e7cba1b0494a3
Showing with 49 additions and 19 deletions.
  1. +6 −8 src/app/qgisapp.cpp
  2. +6 −8 src/app/qgspluginmanager.cpp
  3. +29 −2 src/app/qgspythonutils.cpp
  4. +8 −1 src/app/qgspythonutils.h
@@ -1563,14 +1563,13 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
if (QgsPythonUtils::isEnabled())
{

// check for python plugins
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

for (uint i = 0; i < pluginDir.count(); i++)
// check for python plugins system-wide
QStringList pluginList = QgsPythonUtils::pluginList();

for (int i = 0; i < pluginList.size(); i++)
{
QString packageName = pluginDir[i];
QString packageName = pluginList[i];

// import plugin's package
if (!QgsPythonUtils::loadPlugin(packageName))
continue;
@@ -1596,7 +1595,6 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
loadPythonPlugin(packageName, pluginName);
}
}

}
#endif
}
@@ -83,14 +83,13 @@ void QgsPluginManager::getPythonPluginDescriptions()
if (!QgsPythonUtils::isEnabled())
return;

// look for plugins
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

for (uint i = 0; i < pluginDir.count(); i++)
// look for plugins systemwide
QStringList pluginList = QgsPythonUtils::pluginList();

for (int i = 0; i < pluginList.size(); i++)
{
QString packageName = pluginDir[i];
QString packageName = pluginList[i];

// import plugin's package
QgsPythonUtils::loadPlugin(packageName);

@@ -125,7 +124,6 @@ void QgsPluginManager::getPythonPluginDescriptions()
pl->setOn(true);
}
}

}
#endif
}
@@ -24,7 +24,8 @@
#include "qgslogger.h"

#include <QMessageBox>

#include <QStringList>
#include <QDir>

QString QgsPythonUtils::mPluginsPath;
PyObject* QgsPythonUtils::mMainModule;
@@ -47,7 +48,7 @@ void QgsPythonUtils::initPython(QgisInterface* interface)

// expect that bindings are installed locally, so add the path to modules
// also add path to plugins
runString("sys.path = [\"" + pythonPath() + "\", \"" + pluginsPath() + "\"] + sys.path");
runString("sys.path = [\"" + homePluginsPath() + "\", \"" + pythonPath() + "\", \"" + pluginsPath() + "\"] + sys.path");

// import SIP
if (!runString("from sip import wrapinstance, unwrapinstance"))
@@ -284,6 +285,32 @@ QString QgsPythonUtils::pluginsPath()
return pythonPath() + "/plugins";
}

QString QgsPythonUtils::homePluginsPath()
{
return QgsApplication::qgisSettingsDirPath() + "/python/plugins/";
}

QStringList QgsPythonUtils::pluginList()
{
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

QDir homePluginDir(QgsPythonUtils::homePluginsPath(), "*",
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);

QStringList pluginList = pluginDir.entryList();

for (uint i = 0; i < homePluginDir.count(); i++)
{
QString packageName = homePluginDir[i];
if(!pluginList.contains(packageName))
pluginList.append(packageName);

}

return pluginList;
}

QString QgsPythonUtils::getPluginMetadata(QString pluginName, QString function)
{
QString command = pluginName + "." + function + "()";
@@ -15,6 +15,7 @@
/* $Id$ */

#include <QString>
#include <QStringList>

// forward declaration for PyObject
#ifndef PyObject_HEAD
@@ -84,7 +85,13 @@ class QgsPythonUtils

//! return current path for python plugins
static QString pluginsPath();


//! return current path for home directory python plugins
static QString homePluginsPath();

//! return list of all available python plugins
static QStringList pluginList();

//! load python plugin (import)
static bool loadPlugin(QString packageName);

0 comments on commit 2279ebb

Please sign in to comment.
You can’t perform that action at this time.