void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element, QTreeWidget *modulesTreeWidget, QStandardItemModel * modulesListModel, bool direct ) { QDomNode n = element.firstChild(); QTreeWidgetItem *item; QTreeWidgetItem *lastItem = 0; while ( !n.isNull() ) { QDomElement e = n.toElement(); if ( !e.isNull() ) { // QgsDebugMsg(QString("tag = %1").arg(e.tagName())); if ( e.tagName() != "section" && e.tagName() != "grass" ) { QgsDebugMsg( QString( "Unknown tag: %1" ).arg( e.tagName() ) ); continue; } // Check GRASS version QString version_min = e.attribute( "version_min" ); QString version_max = e.attribute( "version_max" ); if ( !QgsGrassModuleOption::checkVersion( e.attribute( "version_min" ), e.attribute( "version_max" ) ) ) { n = n.nextSibling(); continue; } if ( parent ) { item = new QTreeWidgetItem( parent, lastItem ); } else { item = new QTreeWidgetItem( modulesTreeWidget, lastItem ); } if ( e.tagName() == "section" ) { QString label = QApplication::translate( "grasslabel", e.attribute( "label" ).toUtf8() ); QgsDebugMsg( QString( "label = %1" ).arg( label ) ); item->setText( 0, label ); item->setExpanded( false ); addModules( item, e, modulesTreeWidget, modulesListModel, direct ); lastItem = item; } else if ( e.tagName() == "grass" ) { // GRASS module QString name = e.attribute( "name" ); QgsDebugMsg( QString( "name = %1" ).arg( name ) ); QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name; QgsGrassModule::Description description = QgsGrassModule::description( path ); if ( !direct || description.direct ) { QString label = description.label; QPixmap pixmap = QgsGrassModule::pixmap( path, 32 ); item->setText( 0, name + " - " + label ); item->setIcon( 0, QIcon( pixmap ) ); item->setText( 1, name ); lastItem = item; // Add this item to our list model QStandardItem * mypDetailItem = new QStandardItem( name + "\n" + label ); mypDetailItem->setData( name, Qt::UserRole + 1 ); //for calling runModule later QString mySearchText = name + " - " + label; mypDetailItem->setData( mySearchText, Qt::UserRole + 2 ); //for filtering later mypDetailItem->setData( pixmap, Qt::DecorationRole ); mypDetailItem->setCheckable( false ); mypDetailItem->setEditable( false ); // setData in the delegate with a variantised QgsDetailedItemData QgsDetailedItemData myData; myData.setTitle( name ); myData.setDetail( label ); myData.setIcon( pixmap ); myData.setCheckable( false ); myData.setRenderAsWidget( false ); QVariant myVariant = qVariantFromValue( myData ); mypDetailItem->setData( myVariant, Qt::UserRole ); modulesListModel->appendRow( mypDetailItem ); } else { delete item; } } } n = n.nextSibling(); } }
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 QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element ) { QDomNode n = element.firstChild(); QTreeWidgetItem *item; QTreeWidgetItem *lastItem = 0; while ( !n.isNull() ) { QDomElement e = n.toElement(); if ( !e.isNull() ) { // QgsDebugMsg(QString("tag = %1").arg(e.tagName())); if ( e.tagName() == "section" && e.tagName() == "grass" ) { QgsDebugMsg( QString( "Unknown tag: %1" ).arg( e.tagName() ) ); continue; } if ( parent ) { item = new QTreeWidgetItem( parent, lastItem ); } else { item = new QTreeWidgetItem( mModulesTree, lastItem ); } if ( e.tagName() == "section" ) { QString label = e.attribute( "label" ); QgsDebugMsg( QString( "label = %1" ).arg( label ) ); item->setText( 0, label ); item->setExpanded( false ); addModules( item, e ); lastItem = item; } else if ( e.tagName() == "grass" ) { // GRASS module QString name = e.attribute( "name" ); QgsDebugMsg( QString( "name = %1" ).arg( name ) ); QString path = QgsApplication::pkgDataPath() + "/grass/modules/" + name; QString label = QgsGrassModule::label( path ); QPixmap pixmap = QgsGrassModule::pixmap( path, 25 ); item->setText( 0, name + " - " + label ); item->setIcon( 0, QIcon( pixmap ) ); item->setText( 1, name ); lastItem = item; // // Experimental work by Tim - add this item to our list model // QStandardItem * mypDetailItem = new QStandardItem( name ); mypDetailItem->setData( name, Qt::UserRole + 1 ); //for calling runModule later QString mySearchText = name + " - " + label; mypDetailItem->setData( mySearchText, Qt::UserRole + 2 ); //for filtering later mypDetailItem->setData( pixmap, Qt::DecorationRole ); mypDetailItem->setCheckable( false ); mypDetailItem->setEditable( false ); // setData in the delegate with a variantised QgsDetailedItemData QgsDetailedItemData myData; myData.setTitle( name ); myData.setDetail( label ); myData.setIcon( pixmap ); myData.setCheckable( false ); myData.setRenderAsWidget( true ); QVariant myVariant = qVariantFromValue( myData ); mypDetailItem->setData( myVariant, Qt::UserRole ); mModelTools->appendRow( mypDetailItem ); // // End of experimental work by Tim // } } n = n.nextSibling(); } }
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 ); } }