Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Added option to load c++ plugins from user specified direct…
…ories. Requires application restart to activate.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15250 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Feb 23, 2011
1 parent 5b947a1 commit 7aa12fc
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 29 deletions.
11 changes: 10 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -490,6 +490,16 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
QgsPluginRegistry::instance()->restoreSessionPlugins( QgsApplication::pluginPath() );
}

// Also restore plugins from user specified plugin directories - added for 1.7
QSettings settings;
QString myPaths = settings.value( "plugins/searchPathsForPlugins", "" ).toString();
if ( !myPaths.isEmpty() )
{
QStringList myPathList = myPaths.split( "|" );
QgsPluginRegistry::instance()->restoreSessionPlugins( myPathList );
QMessageBox::critical( this, tr( "Plugin paths" ), myPaths );
}

mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();
// now build vector file filter
Expand Down Expand Up @@ -541,7 +551,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mMapCanvas->mapRenderer()->setLabelingEngine( mLBL );

// Show a nice tip of the day
QSettings settings;
if ( settings.value( "/qgis/showTips", 1 ).toBool() )
{
mSplash->hide();
Expand Down
57 changes: 55 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -79,9 +79,23 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
spinBoxIdentifyValue->setMinimum( 0.01 );
spinBoxIdentifyValue->setValue( identifyValue );

//local directories to search when loading c++ plugins
QString myPaths = settings.value( "plugins/searchPathsForPlugins", "" ).toString();
if ( !myPaths.isEmpty() )
{
QStringList myPathList = myPaths.split( "|" );
QStringList::const_iterator pathIt = myPathList.constBegin();
for ( ; pathIt != myPathList.constEnd(); ++pathIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListPluginPaths );
newItem->setText( *pathIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListPluginPaths->addItem( newItem );
}
}

//local directories to search when looking for an SVG with a given basename
QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString();
if ( !myPaths.isEmpty() )
{
QStringList myPathList = myPaths.split( "|" );
Expand Down Expand Up @@ -479,8 +493,20 @@ void QgsOptions::saveOptions()
{
QSettings settings;

//search directories for svgs
//search directories for user plugins
QString myPaths;
for ( int i = 0; i < mListPluginPaths->count(); ++i )
{
if ( i != 0 )
{
myPaths += "|";
}
myPaths += mListPluginPaths->item( i )->text();
}
settings.setValue( "plugins/searchPathsForPlugins", myPaths );

//search directories for svgs
myPaths;
for ( int i = 0; i < mListSVGPaths->count(); ++i )
{
if ( i != 0 )
Expand Down Expand Up @@ -881,6 +907,33 @@ QStringList QgsOptions::i18nList()
return myList;
}

void QgsOptions::on_mBtnAddPluginPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
this,
tr( "Choose a directory" ),
QDir::toNativeSeparators( QDir::homePath() ),
QFileDialog::ShowDirsOnly
);

if ( ! myDir.isEmpty() )
{
QListWidgetItem* newItem = new QListWidgetItem( mListPluginPaths );
newItem->setText( myDir );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListPluginPaths->addItem( newItem );
mListPluginPaths->setCurrentItem( newItem );
}
}

void QgsOptions::on_mBtnRemovePluginPath_clicked()
{
int currentRow = mListPluginPaths->currentRow();
QListWidgetItem* itemToRemove = mListPluginPaths->takeItem( currentRow );
delete itemToRemove;
}


void QgsOptions::on_mBtnAddSVGPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -90,6 +90,18 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
/**Remove an URL to exclude from Proxy*/
void on_mRemoveUrlPushButton_clicked();

/* Let the user add a path to the list of search paths
* used for finding user Plugin libs.
* @note added in QGIS 1.7
*/
void on_mBtnAddPluginPath_clicked();

/* Let the user remove a path to the list of search paths
* used for finding Plugin libs.
* @note added in QGIS 1.7
*/
void on_mBtnRemovePluginPath_clicked();

/* Let the user add a path to the list of search paths
* used for finding SVG files.
* @note added in QGIS 1.4
Expand Down
10 changes: 9 additions & 1 deletion src/app/qgspluginregistry.cpp
Expand Up @@ -356,9 +356,17 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
QgsDebugMsg( "Plugin " + theFullPathName + " did not return a valid type and cannot be loaded" );
break;
}

}

//overloaded version of the next method that will load from multiple directories not just one
void QgsPluginRegistry::restoreSessionPlugins( QStringList thePluginDirList )
{
QStringListIterator myIterator( thePluginDirList );
while ( myIterator.hasNext() )
{
restoreSessionPlugins( myIterator.next() );
}
}

void QgsPluginRegistry::restoreSessionPlugins( QString thePluginDirString )
{
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgspluginregistry.h
Expand Up @@ -30,7 +30,7 @@ class QString;

/**
* \class QgsPluginRegistry
* \brief This class tracks plugins that are currently loaded an provides
* \brief This class tracks plugins that are currently loaded and provides
* a means to fetch a pointer to a plugin and unload it
*
* plugin key is:
Expand Down Expand Up @@ -78,6 +78,8 @@ class QgsPluginRegistry
//! Python plugin loader
void loadPythonPlugin( QString packageName );

//! Overloaded version of the next method that will load from multiple directories not just one
void restoreSessionPlugins( QStringList thePluginDirList );
//! Load any plugins used in the last qgis session
void restoreSessionPlugins( QString thePluginDirString );

Expand Down

0 comments on commit 7aa12fc

Please sign in to comment.