void QgsPluginManager::clearAll() { // clear all selection checkboxes for ( int row = 0; row < mModelPlugins->rowCount(); row++ ) { QStandardItem *mypItem = mModelPlugins->item( row, 0 ); QgsDetailedItemData myData = qVariantValue<QgsDetailedItemData>( mypItem->data( PLUGIN_DATA_ROLE ) ); myData.setChecked( false ); QVariant myVariant = qVariantFromValue( myData ); mypItem->setData( myVariant, PLUGIN_DATA_ROLE ); } }
void QgsPluginManager::on_vwPlugins_clicked( const QModelIndex &theIndex ) { if ( theIndex.column() == 0 ) { // // If the model has been filtered, the index row in the proxy wont match // the index row in the underlying model so we need to jump through this // little hoop to get the correct item // QModelIndex realIndex = mModelProxy->mapToSource( theIndex ); QStandardItem* mypItem = mModelPlugins->itemFromIndex( realIndex ); QgsDetailedItemData myData = qVariantValue<QgsDetailedItemData>( mypItem->data( PLUGIN_DATA_ROLE ) ); if ( myData.isEnabled() ) { myData.setChecked( ! myData.isChecked() ); } QVariant myVariant = qVariantFromValue( myData ); mypItem->setData( myVariant, PLUGIN_DATA_ROLE ); } }
void QgsPluginManager::getPluginDescriptions() { QString sharedLibExtension; #ifdef WIN32 sharedLibExtension = "*.dll"; #else sharedLibExtension = "*.so*"; #endif // check all libs in the current ans user plugins directories, and get name and descriptions QSettings settings; QStringList myPathList( lblPluginDir->text() ); QString myPaths = settings.value( "plugins/searchPathsForPlugins", "" ).toString(); if ( !myPaths.isEmpty() ) { myPathList.append( myPaths.split( "|" ) ); } for ( int j = 0; j < myPathList.size(); ++j ) { QString myPluginDir = myPathList.at( j ); QDir pluginDir( myPluginDir, sharedLibExtension, QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::NoSymLinks ); if ( pluginDir.count() == 0 ) { QMessageBox::information( this, tr( "No Plugins" ), tr( "No QGIS plugins found in %1" ).arg( myPluginDir ) ); return; } QgsDebugMsg( "PLUGIN MANAGER:" ); for ( uint i = 0; i < pluginDir.count(); i++ ) { QString lib = QString( "%1/%2" ).arg( myPluginDir ).arg( pluginDir[i] ); #ifdef TESTLIB // This doesn't work on WIN32 and causes problems with plugins // on OS X (the code doesn't cause a problem but including dlfcn.h // renders plugins unloadable) #if !defined(WIN32) && !defined(Q_OS_MACX) // test code to help debug loading problems // This doesn't work on WIN32 and causes problems with plugins // on OS X (the code doesn't cause a problem but including dlfcn.h // renders plugins unloadable) //void *handle = dlopen((const char *) lib, RTLD_LAZY); void *handle = dlopen( lib.toLocal8Bit().data(), RTLD_LAZY | RTLD_GLOBAL ); if ( !handle ) { QgsDebugMsg( "Error in dlopen: " ); QgsDebugMsg( dlerror() ); } else { QgsDebugMsg( "dlopen suceeded for " + lib ); dlclose( handle ); } #endif //#ifndef WIN32 && Q_OS_MACX #endif //#ifdef TESTLIB QgsDebugMsg( "Examining: " + lib ); QLibrary *myLib = new QLibrary( lib ); bool loaded = myLib->load(); if ( !loaded ) { QgsDebugMsg( QString( "Failed to load: %1 (%2)" ).arg( myLib->fileName() ).arg( myLib->errorString() ) ); delete myLib; continue; } QgsDebugMsg( "Loaded library: " + myLib->fileName() ); // Don't bother with libraries that are providers //if(!myLib->resolve("isProvider")) //MH: Replaced to allow for plugins that are linked to providers //type is only used in non-provider plugins if ( !myLib->resolve( "type" ) ) { delete myLib; continue; } // resolve the metadata from plugin name_t *pName = ( name_t * ) cast_to_fptr( myLib->resolve( "name" ) ); description_t *pDesc = ( description_t * ) cast_to_fptr( myLib->resolve( "description" ) ); category_t *pCat = ( category_t * ) cast_to_fptr( myLib->resolve( "category" ) ); version_t *pVersion = ( version_t * ) cast_to_fptr( myLib->resolve( "version" ) ); icon_t* pIcon = ( icon_t * ) cast_to_fptr( myLib->resolve( "icon" ) ); // show the values (or lack of) for each function if ( pName ) { QgsDebugMsg( "Plugin name: " + pName() ); } else { QgsDebugMsg( "Plugin name not returned when queried" ); } if ( pDesc ) { QgsDebugMsg( "Plugin description: " + pDesc() ); } else { QgsDebugMsg( "Plugin description not returned when queried" ); } if ( pCat ) { QgsDebugMsg( "Plugin category: " + pCat() ); } else { QgsDebugMsg( "Plugin category not returned when queried" ); } if ( pVersion ) { QgsDebugMsg( "Plugin version: " + pVersion() ); } else { QgsDebugMsg( "Plugin version not returned when queried" ); } if ( pIcon ) { QgsDebugMsg( "Plugin icon: " + pIcon() ); } if ( !pName || !pDesc || !pVersion ) { QgsDebugMsg( "Failed to get name, description, or type for " + myLib->fileName() ); delete myLib; continue; } QString pluginName = pName(); QString pluginDesc = pDesc(); // if no category defined - use default value QString pluginCat = ( pCat ? pCat() : tr( "Plugins" ) ); QString pluginVersion = pVersion(); QString pluginIconFileName = ( pIcon ? pIcon() : QString() ); QString baseName = QFileInfo( lib ).baseName(); QString myLibraryName = pluginDir[i]; // filtering will be done on the display role so give it name and desription // user wont see this text since we are using a custome delegate QStandardItem * mypDetailItem = new QStandardItem( pluginName + " - " + pluginDesc ); mypDetailItem->setData( myLibraryName, PLUGIN_LIBRARY_ROLE ); mypDetailItem->setData( myPluginDir, PLUGIN_DIRECTORY_ROLE ); mypDetailItem->setData( baseName, PLUGIN_BASE_NAME_ROLE ); //for matching in registry later QgsDetailedItemData myData; myData.setTitle( pluginName ); myData.setDetail( pluginDesc ); myData.setCategory( tr( "Installed in %1 menu/toolbar" ).arg( pluginCat ) ); myData.setRenderAsWidget( false ); myData.setCheckable( true ); myData.setChecked( false ); //start unchecked - we will check it later if needed if ( pluginIconFileName.isEmpty() ) myData.setIcon( QPixmap( QgsApplication::defaultThemePath() + "/plugin.png" ) ); else myData.setIcon( QPixmap( pluginIconFileName ) ); QgsDebugMsg( "Getting an instance of the QgsPluginRegistry" ); // check to see if the plugin is loaded and set the checkbox accordingly QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance(); // get the library using the plugin description if ( !pRegistry->isLoaded( baseName ) ) { QgsDebugMsg( "Couldn't find plugin in the registry" ); } else { QgsDebugMsg( "Found plugin in the registry" ); // TODO: this check shouldn't be necessary, plugin base names must be unique if ( pRegistry->library( baseName ) == myLib->fileName() ) { // set the checkbox myData.setChecked( true ); } } QVariant myVariant = qVariantFromValue( myData ); mypDetailItem->setData( myVariant, PLUGIN_DATA_ROLE ); // Add items to model mModelPlugins->appendRow( mypDetailItem ); delete myLib; } } }
void QgsPluginManager::getPythonPluginDescriptions() { if ( !mPythonUtils || !mPythonUtils->isEnabled() ) return; // look for plugins systemwide QStringList pluginList = mPythonUtils->pluginList(); for ( int i = 0; i < pluginList.size(); i++ ) { QString packageName = pluginList[i]; // import plugin's package - skip loading it if an error occured if ( !mPythonUtils->loadPlugin( packageName ) ) continue; // get information from the plugin QString pluginName = mPythonUtils->getPluginMetadata( packageName, "name" ); QString description = mPythonUtils->getPluginMetadata( packageName, "description" ); QString category = mPythonUtils->getPluginMetadata( packageName, "category" ); QString version = mPythonUtils->getPluginMetadata( packageName, "version" ); QString iconName = mPythonUtils->getPluginMetadata( packageName, "icon" ); if ( pluginName == "__error__" || description == "__error__" || version == "__error__" ) continue; // if there is no category in Python plugin assume default 'Plugins' category if ( category == "__error__" ) { category = tr( "Plugins" ); } bool isCompatible = QgsPluginRegistry::instance()->isPythonPluginCompatible( packageName ); QString compatibleString; // empty by default if ( !isCompatible ) compatibleString = " " + tr( "[ incompatible ]" ); // filtering will be done on the display role so give it name and desription // user wont see this text since we are using a custome delegate QStandardItem * mypDetailItem = new QStandardItem( pluginName + " - " + description ); QString myLibraryName = "python:" + packageName; mypDetailItem->setData( myLibraryName, PLUGIN_LIBRARY_ROLE ); //for loading libs later mypDetailItem->setData( packageName, PLUGIN_BASE_NAME_ROLE ); //for matching in registry later mypDetailItem->setCheckable( false ); mypDetailItem->setEditable( false ); mypDetailItem->setEnabled( isCompatible ); // setData in the delegate with a variantised QgsDetailedItemData QgsDetailedItemData myData; myData.setTitle( pluginName + " (" + version + ")" + compatibleString ); myData.setEnabled( isCompatible ); myData.setDetail( description ); myData.setCategory( tr( "Installed in %1 menu/toolbar" ).arg( category ) ); //myData.setIcon(pixmap); //todo use a python logo here myData.setCheckable( true ); myData.setRenderAsWidget( false ); myData.setChecked( false ); //start off assuming false if ( iconName == "__error__" ) myData.setIcon( QPixmap( QgsApplication::defaultThemePath() + "/plugin.png" ) ); else { bool relative = QFileInfo( iconName ).isRelative(); if ( relative ) { QString pluginDir; mPythonUtils->evalString( QString( "qgis.utils.pluginDirectory('%1')" ).arg( packageName ), pluginDir ); iconName = pluginDir + "/" + iconName; } myData.setIcon( QPixmap( iconName ) ); } // check to see if the plugin is loaded and set the checkbox accordingly QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance(); if ( pRegistry->isLoaded( packageName ) && pRegistry->isPythonPlugin( packageName ) ) { QgsDebugMsg( "Found plugin in the registry" ); // set the checkbox myData.setChecked( true ); } else { QgsDebugMsg( "Couldn't find plugin in the registry: " + packageName ); } QVariant myVariant = qVariantFromValue( myData ); mypDetailItem->setData( myVariant, PLUGIN_DATA_ROLE ); // Add item to model mModelPlugins->appendRow( mypDetailItem ); } }