Skip to content

Commit 1c2c079

Browse files
committed
else cascade cleanups
1 parent 81ff2a3 commit 1c2c079

File tree

3 files changed

+247
-351
lines changed

3 files changed

+247
-351
lines changed

src/app/qgspluginmanager.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,11 @@ void QgsPluginManager::unload()
475475

476476
if ( pRegistry->isPythonPlugin( baseName ) )
477477
{
478-
if ( mPythonUtils && mPythonUtils->isEnabled() )
478+
if ( mPythonUtils && mPythonUtils->isEnabled() && mPythonUtils->canUninstallPlugin( baseName ) )
479479
{
480-
if ( mPythonUtils->canUninstallPlugin( baseName ) )
481-
{
482-
mPythonUtils->unloadPlugin( baseName );
483-
//disable it to the qsettings file
484-
settings.setValue( "/PythonPlugins/" + baseName, false );
485-
}
480+
mPythonUtils->unloadPlugin( baseName );
481+
//disable it to the qsettings file
482+
settings.setValue( "/PythonPlugins/" + baseName, false );
486483
}
487484
}
488485
else // C++ plugin
@@ -537,8 +534,8 @@ std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
537534
// bool python=false);
538535
pis.push_back( QgsPluginItem( pluginName, library, 0, pythonic ) );
539536
}
540-
541537
}
538+
542539
return pis;
543540
}
544541

src/app/qgspluginregistry.cpp

+97-114
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ QgisPlugin *QgsPluginRegistry::plugin( QString key )
100100
{
101101
QMap<QString, QgsPluginMetadata>::iterator it = mPlugins.find( key );
102102
if ( it == mPlugins.end() )
103-
return NULL;
103+
return 0;
104104

105105
// note: not used by python plugins
106106

@@ -109,12 +109,7 @@ QgisPlugin *QgsPluginRegistry::plugin( QString key )
109109

110110
bool QgsPluginRegistry::isPythonPlugin( QString key )
111111
{
112-
if ( mPythonUtils && mPythonUtils->isEnabled() )
113-
{
114-
if ( mPythonUtils->isPluginLoaded( key ) )
115-
return true;
116-
}
117-
return false;
112+
return mPythonUtils && mPythonUtils->isEnabled() && mPythonUtils->isPluginLoaded( key );
118113
}
119114

120115
void QgsPluginRegistry::addPlugin( QString key, QgsPluginMetadata metadata )
@@ -272,30 +267,20 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
272267

273268
void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
274269
{
275-
QSettings settings;
276-
277-
QString baseName = QFileInfo( theFullPathName ).baseName();
278-
279270
// first check to see if its already loaded
271+
QString baseName = QFileInfo( theFullPathName ).baseName();
280272
if ( isLoaded( baseName ) )
281-
{
282-
// plugin is loaded
283-
// QMessageBox::warning(this, "Already Loaded", description + " is already loaded");
284273
return;
285-
}
286274

287275
QLibrary myLib( theFullPathName );
288-
289-
QString myError; //we will only show detailed diagnostics if something went wrong
290-
myError += QObject::tr( "Library name is %1\n" ).arg( myLib.fileName() );
291-
292-
bool loaded = myLib.load();
293-
if ( !loaded )
276+
if ( !myLib.load() )
294277
{
295278
QgsMessageLog::logMessage( QObject::tr( "Failed to load %1 (Reason: %2)" ).arg( myLib.fileName() ).arg( myLib.errorString() ), QObject::tr( "Plugins" ) );
296279
return;
297280
}
298281

282+
QString myError( QObject::tr( "Library name is %1\n" ).arg( myLib.fileName() ) );
283+
299284
myError += QObject::tr( "Attempting to resolve the classFactory function\n" );
300285

301286
type_t *pType = ( type_t * ) cast_to_fptr( myLib.resolve( "type" ) );
@@ -309,59 +294,57 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
309294
{
310295
// UI only -- doesn't use mapcanvas
311296
create_ui *cf = ( create_ui * ) cast_to_fptr( myLib.resolve( "classFactory" ) );
312-
if ( cf )
297+
if ( !cf )
298+
{
299+
QgsMessageLog::logMessage( QObject::tr( "Unable to find the class factory for %1." ).arg( theFullPathName ), QObject::tr( "Plugins" ) );
300+
break;
301+
}
302+
303+
QSettings settings;
304+
QgisPlugin *pl = cf( mQgisInterface );
305+
if ( !pl )
306+
{
307+
// something went wrong
308+
QMessageBox::warning( mQgisInterface->mainWindow(), QObject::tr( "Error Loading Plugin" ),
309+
QObject::tr( "There was an error loading a plugin."
310+
"The following diagnostic information may help the QGIS developers resolve the issue:\n%1." )
311+
.arg( myError ) );
312+
//disable it to the qsettings file [ts]
313+
settings.setValue( "/Plugins/" + baseName, false );
314+
break;
315+
}
316+
317+
pl->initGui();
318+
// add it to the plugin registry
319+
addPlugin( baseName, QgsPluginMetadata( myLib.fileName(), pName(), pl ) );
320+
//add it to the qsettings file [ts]
321+
settings.setValue( "/Plugins/" + baseName, true );
322+
QgsMessageLog::logMessage( QObject::tr( "Loaded %1 (Path: %2)" ).arg( pName() ).arg( myLib.fileName() ), QObject::tr( "Plugins" ), QgsMessageLog::INFO );
323+
324+
QObject *o = dynamic_cast<QObject *>( pl );
325+
if ( !o )
326+
break;
327+
328+
QgsDebugMsg( QString( "plugin object name: %1" ).arg( o->objectName() ) );
329+
if ( o->objectName().isEmpty() )
313330
{
314-
QgisPlugin *pl = cf( mQgisInterface );
315-
if ( pl )
316-
{
317-
pl->initGui();
318-
// add it to the plugin registry
319-
addPlugin( baseName, QgsPluginMetadata( myLib.fileName(), pName(), pl ) );
320-
//add it to the qsettings file [ts]
321-
settings.setValue( "/Plugins/" + baseName, true );
322-
QgsMessageLog::logMessage( QObject::tr( "Loaded %1 (Path: %2)" ).arg( pName() ).arg( myLib.fileName() ), QObject::tr( "Plugins" ), QgsMessageLog::INFO );
323-
324-
QObject *o = dynamic_cast<QObject *>( pl );
325-
if ( o )
326-
{
327-
QgsDebugMsg( QString( "plugin object name: %1" ).arg( o->objectName() ) );
328-
if ( o->objectName().isEmpty() )
329-
{
330331
#ifndef WIN32
331-
baseName = baseName.mid( 3 );
332+
baseName = baseName.mid( 3 );
332333
#endif
333-
QgsDebugMsg( QString( "object name to %1" ).arg( baseName ) );
334-
o->setObjectName( QString( "qgis_plugin_%1" ).arg( baseName ) );
335-
QgsDebugMsg( QString( "plugin object name now: %1" ).arg( o->objectName() ) );
336-
}
337-
338-
if ( !o->parent() )
339-
{
340-
QgsDebugMsg( QString( "setting plugin parent" ) );
341-
o->setParent( QgisApp::instance() );
342-
}
343-
else
344-
{
345-
QgsDebugMsg( QString( "plugin parent already set" ) );
346-
}
347-
}
348-
}
349-
else
350-
{
351-
// something went wrong
352-
QMessageBox::warning( mQgisInterface->mainWindow(), QObject::tr( "Error Loading Plugin" ),
353-
QObject::tr( "There was an error loading a plugin."
354-
"The following diagnostic information may help the QGIS developers resolve the issue:\n%1." )
355-
.arg( myError ) );
356-
//disable it to the qsettings file [ts]
357-
settings.setValue( "/Plugins/" + baseName, false );
358-
}
334+
QgsDebugMsg( QString( "object name to %1" ).arg( baseName ) );
335+
o->setObjectName( QString( "qgis_plugin_%1" ).arg( baseName ) );
336+
QgsDebugMsg( QString( "plugin object name now: %1" ).arg( o->objectName() ) );
337+
}
338+
339+
if ( !o->parent() )
340+
{
341+
QgsDebugMsg( QString( "setting plugin parent" ) );
342+
o->setParent( QgisApp::instance() );
359343
}
360344
else
361345
{
362-
QgsMessageLog::logMessage( QObject::tr( "Unable to find the class factory for %1." ).arg( theFullPathName ), QObject::tr( "Plugins" ) );
346+
QgsDebugMsg( QString( "plugin parent already set" ) );
363347
}
364-
365348
}
366349
break;
367350
default:
@@ -411,73 +394,73 @@ void QgsPluginRegistry::restoreSessionPlugins( QString thePluginDirString )
411394
}
412395
}
413396

414-
if ( mPythonUtils && mPythonUtils->isEnabled() )
397+
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
398+
return;
399+
400+
// check for python plugins system-wide
401+
QStringList pluginList = mPythonUtils->pluginList();
402+
QgsDebugMsg( "Loading python plugins" );
403+
404+
QStringList corePlugins = QStringList();
405+
corePlugins << "plugin_installer";
406+
corePlugins << "fTools";
407+
corePlugins << "GdalTools";
408+
corePlugins << "db_manager";
409+
410+
// make the required core plugins enabled by default:
411+
for ( int i = 0; i < corePlugins.size(); i++ )
415412
{
416-
// check for python plugins system-wide
417-
QStringList pluginList = mPythonUtils->pluginList();
418-
QgsDebugMsg( "Loading python plugins" );
419-
420-
QStringList corePlugins = QStringList();
421-
corePlugins << "plugin_installer";
422-
corePlugins << "fTools";
423-
corePlugins << "GdalTools";
424-
corePlugins << "db_manager";
425-
426-
// make the required core plugins enabled by default:
427-
for ( int i = 0; i < corePlugins.size(); i++ )
413+
if ( !mySettings.contains( "/PythonPlugins/" + corePlugins[i] ) )
428414
{
429-
if ( !mySettings.contains( "/PythonPlugins/" + corePlugins[i] ) )
430-
{
431-
mySettings.setValue( "/PythonPlugins/" + corePlugins[i], true );
432-
}
415+
mySettings.setValue( "/PythonPlugins/" + corePlugins[i], true );
433416
}
417+
}
434418

435-
for ( int i = 0; i < pluginList.size(); i++ )
436-
{
437-
QString packageName = pluginList[i];
419+
for ( int i = 0; i < pluginList.size(); i++ )
420+
{
421+
QString packageName = pluginList[i];
438422

439-
// TODO: apply better solution for #5879
440-
// start - temporary fix for issue #5879
441-
if ( QgsApplication::isRunningFromBuildDir() )
423+
// TODO: apply better solution for #5879
424+
// start - temporary fix for issue #5879
425+
if ( QgsApplication::isRunningFromBuildDir() )
426+
{
427+
if ( corePlugins.contains( packageName ) )
442428
{
443-
if ( corePlugins.contains( packageName ) )
444-
{
445-
QgsApplication::setPkgDataPath( QString( "" ) );
446-
}
447-
else
448-
{
449-
QgsApplication::setPkgDataPath( QgsApplication::buildSourcePath() );
450-
}
429+
QgsApplication::setPkgDataPath( QString( "" ) );
451430
}
452-
// end - temporary fix for issue #5879, more below
453-
454-
if ( checkPythonPlugin( packageName ) )
431+
else
455432
{
456-
// check if the plugin was active on last session
457-
458-
if ( mySettings.value( "/PythonPlugins/" + packageName ).toBool() )
459-
{
460-
loadPythonPlugin( packageName );
461-
}
433+
QgsApplication::setPkgDataPath( QgsApplication::buildSourcePath() );
462434
}
463435
}
464-
// start - temporary fix for issue #5879, more above
465-
if ( QgsApplication::isRunningFromBuildDir() )
436+
// end - temporary fix for issue #5879, more below
437+
438+
if ( checkPythonPlugin( packageName ) )
466439
{
467-
QgsApplication::setPkgDataPath( QgsApplication::buildSourcePath() );
440+
// check if the plugin was active on last session
441+
442+
if ( mySettings.value( "/PythonPlugins/" + packageName ).toBool() )
443+
{
444+
loadPythonPlugin( packageName );
445+
}
468446
}
469-
// end - temporary fix for issue #5879
470447
}
471448

449+
// start - temporary fix for issue #5879, more above
450+
if ( QgsApplication::isRunningFromBuildDir() )
451+
{
452+
QgsApplication::setPkgDataPath( QgsApplication::buildSourcePath() );
453+
}
454+
// end - temporary fix for issue #5879
455+
472456
QgsDebugMsg( "Plugin loading completed" );
473457
}
474458

475459

476460
bool QgsPluginRegistry::checkCppPlugin( QString pluginFullPath )
477461
{
478462
QLibrary myLib( pluginFullPath );
479-
bool loaded = myLib.load();
480-
if ( ! loaded )
463+
if ( !myLib.load() )
481464
{
482465
QgsMessageLog::logMessage( QObject::tr( "Failed to load %1 (Reason: %2)" ).arg( myLib.fileName() ).arg( myLib.errorString() ), QObject::tr( "Plugins" ) );
483466
return false;
@@ -488,7 +471,7 @@ bool QgsPluginRegistry::checkCppPlugin( QString pluginFullPath )
488471
category_t * myCategory = ( category_t * ) cast_to_fptr( myLib.resolve( "category" ) );
489472
version_t * myVersion = ( version_t * ) cast_to_fptr( myLib.resolve( "version" ) );
490473

491-
if ( myName && myDescription && myVersion && myCategory )
474+
if ( myName && myDescription && myVersion && myCategory )
492475
return true;
493476

494477
QgsDebugMsg( "Failed to get name, description, category or type for " + myLib.fileName() );

0 commit comments

Comments
 (0)