Skip to content

Commit 2279ebb

Browse files
author
gsherman
committedOct 22, 2007
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

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,14 +1563,13 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
15631563
if (QgsPythonUtils::isEnabled())
15641564
{
15651565

1566-
// check for python plugins
1567-
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
1568-
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
1569-
1570-
for (uint i = 0; i < pluginDir.count(); i++)
1566+
// check for python plugins system-wide
1567+
QStringList pluginList = QgsPythonUtils::pluginList();
1568+
1569+
for (int i = 0; i < pluginList.size(); i++)
15711570
{
1572-
QString packageName = pluginDir[i];
1573-
1571+
QString packageName = pluginList[i];
1572+
15741573
// import plugin's package
15751574
if (!QgsPythonUtils::loadPlugin(packageName))
15761575
continue;
@@ -1596,7 +1595,6 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
15961595
loadPythonPlugin(packageName, pluginName);
15971596
}
15981597
}
1599-
16001598
}
16011599
#endif
16021600
}

‎src/app/qgspluginmanager.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ void QgsPluginManager::getPythonPluginDescriptions()
8383
if (!QgsPythonUtils::isEnabled())
8484
return;
8585

86-
// look for plugins
87-
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
88-
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
89-
90-
for (uint i = 0; i < pluginDir.count(); i++)
86+
// look for plugins systemwide
87+
QStringList pluginList = QgsPythonUtils::pluginList();
88+
89+
for (int i = 0; i < pluginList.size(); i++)
9190
{
92-
QString packageName = pluginDir[i];
93-
91+
QString packageName = pluginList[i];
92+
9493
// import plugin's package
9594
QgsPythonUtils::loadPlugin(packageName);
9695

@@ -125,7 +124,6 @@ void QgsPluginManager::getPythonPluginDescriptions()
125124
pl->setOn(true);
126125
}
127126
}
128-
129127
}
130128
#endif
131129
}

‎src/app/qgspythonutils.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include "qgslogger.h"
2525

2626
#include <QMessageBox>
27-
27+
#include <QStringList>
28+
#include <QDir>
2829

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

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

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

288+
QString QgsPythonUtils::homePluginsPath()
289+
{
290+
return QgsApplication::qgisSettingsDirPath() + "/python/plugins/";
291+
}
292+
293+
QStringList QgsPythonUtils::pluginList()
294+
{
295+
QDir pluginDir(QgsPythonUtils::pluginsPath(), "*",
296+
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
297+
298+
QDir homePluginDir(QgsPythonUtils::homePluginsPath(), "*",
299+
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
300+
301+
QStringList pluginList = pluginDir.entryList();
302+
303+
for (uint i = 0; i < homePluginDir.count(); i++)
304+
{
305+
QString packageName = homePluginDir[i];
306+
if(!pluginList.contains(packageName))
307+
pluginList.append(packageName);
308+
309+
}
310+
311+
return pluginList;
312+
}
313+
287314
QString QgsPythonUtils::getPluginMetadata(QString pluginName, QString function)
288315
{
289316
QString command = pluginName + "." + function + "()";

‎src/app/qgspythonutils.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/* $Id$ */
1616

1717
#include <QString>
18+
#include <QStringList>
1819

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

8586
//! return current path for python plugins
8687
static QString pluginsPath();
87-
88+
89+
//! return current path for home directory python plugins
90+
static QString homePluginsPath();
91+
92+
//! return list of all available python plugins
93+
static QStringList pluginList();
94+
8895
//! load python plugin (import)
8996
static bool loadPlugin(QString packageName);
9097

0 commit comments

Comments
 (0)
Please sign in to comment.