Esempio n. 1
0
  foreach ( QString key, providersList )
  {
    QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( key );
    if ( !library )
      continue;

    dataCapabilities_t * dataCapabilities = ( dataCapabilities_t * ) cast_to_fptr( library->resolve( "dataCapabilities" ) );
    if ( !dataCapabilities )
    {
      QgsDebugMsg( library->fileName() + " does not have dataCapabilities" );
      continue;
    }

    int capabilities = dataCapabilities();
    if ( capabilities == QgsDataProvider::NoDataCapabilities )
    {
      QgsDebugMsg( library->fileName() + " does not have any dataCapabilities" );
      continue;
    }

    dataItem_t *dataItem = ( dataItem_t * ) cast_to_fptr( library->resolve( "dataItem" ) );
    if ( !dataItem )
    {
      QgsDebugMsg( library->fileName() + " does not have dataItem" );
      continue;
    }

    QgsDataItem *item = dataItem( "", NULL );  // empty path -> top level
    if ( item )
    {
      QgsDebugMsg( "Add new top level item : " + item->name() );
      connectItem( item );
      providerMap.insertMulti( capabilities, item );
    }
  }
//----------------------------------------------------------------------------
void ctkPluginFrameworkContext::init()
{
  log() << "initializing";

  if (firstInit && ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT
      == props[ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN])
  {
    deleteFWDir();
    firstInit = false;
  }

  // Pre-load libraries
  // This may speed up installing new plug-ins if they have dependencies on
  // one of these libraries. It prevents repeated loading and unloading of the
  // pre-loaded libraries during caching of the plug-in meta-data.
  if (props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].isValid())
  {
    QStringList preloadLibs = props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].toStringList();
    QLibrary::LoadHints loadHints;
    QVariant loadHintsVariant = props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS];
    if (loadHintsVariant.isValid())
    {
      loadHints = loadHintsVariant.value<QLibrary::LoadHints>();
    }

    foreach(QString preloadLib, preloadLibs)
    {
      QLibrary lib;
      QStringList nameAndVersion = preloadLib.split(":");

      QString libraryName;
      if (nameAndVersion.count() == 1)
      {
        libraryName = nameAndVersion.front();
        lib.setFileName(nameAndVersion.front());
      }
      else if (nameAndVersion.count() == 2)
      {
        libraryName = nameAndVersion.front() + "." + nameAndVersion.back();
        lib.setFileNameAndVersion(nameAndVersion.front(), nameAndVersion.back());
      }
      else
      {
        qWarning() << "Wrong syntax in" << preloadLib << ". Use <lib-name>[:version]. Skipping.";
        continue;
      }

      lib.setLoadHints(loadHints);
      log() << "Pre-loading library" << lib.fileName() << "with hints [" << static_cast<int>(loadHints) << "]";
      if (!lib.load())
      {
        qWarning() << "Pre-loading library" << lib.fileName() << "failed:" << lib.errorString() << "\nCheck your library search paths.";
      }
    }
Esempio n. 3
0
 void emitSignals () {
   bool openBabelAvailable = openBabelInterface.isLoaded ();
   bool isInchiAvailable = inChIAvailable && inChIAvailable ();
   bool isGen2dAvailable = gen2dAvailable && gen2dAvailable ();
   qDebug() << "OpenBabel available: " << QString::number (openBabelAvailable)
            << "Library location:" << openBabelInterface.fileName();
   qDebug() << "InChI available: " << QString::number (isInchiAvailable)
            << "gen2d available: " << QString::number (isGen2dAvailable);
   emit parent->obabelIfaceAvailable (openBabelAvailable);
   emit parent->inchiAvailable (isInchiAvailable && isGen2dAvailable);
   emit parent->optimizeAvailable(isGen2dAvailable);
   emit parent->obabelIfaceFileNameChanged(openBabelInterface.fileName());
 }
Esempio n. 4
0
bool load(const char* dllname)
{
    if (library(dllname)) {
        DBG("'%s' is already loaded\n", dllname);
        return true;
    }
    std::list<std::string> libnames = sLibNamesMap[dllname];
    if (libnames.empty())
        libnames.push_back(dllname);
    std::list<std::string>::const_iterator it;
    QLibrary *dll = new QLibrary();
    for (it = libnames.begin(); it != libnames.end(); ++it) {
        dll->setFileName((*it).c_str());
        if (dll->load())
            break;
        DBG("%s\n", dll->errorString().toLocal8Bit().constData()); //why qDebug use toUtf8() and printf use toLocal8Bit()?
    }
    if (it == libnames.end()) {
        DBG("No dll loaded\n");
        delete dll;
        return false;
    }
    DBG("'%s' is loaded~~~\n", dll->fileName().toUtf8().constData());
    sDllMap[dllname] = dll; //map.insert will not replace the old one
    return true;
}
QLibrary *QgsProviderRegistry::providerLibrary( QString const & providerKey ) const
{
  QLibrary *myLib = new QLibrary( library( providerKey ) );

  QgsDebugMsg( "Library name is " + myLib->fileName() );

  if ( myLib->load() )
    return myLib;

  QgsDebugMsg( "Cannot load library: " + myLib->errorString() );

  delete myLib;

  return 0;
}
Esempio n. 6
0
QLibrary *QgsAuthMethodRegistry::authMethodLibrary( const QString &authMethodKey ) const
{
  QLibrary *myLib = new QLibrary( library( authMethodKey ) );

  QgsDebugMsg( "Library name is " + myLib->fileName() );

  if ( myLib->load() )
    return myLib;

  QgsDebugMsg( "Cannot load library: " + myLib->errorString() );

  delete myLib;

  return 0;
}
Esempio n. 7
0
		inline const QString fname() { return library.fileName(); };
Esempio n. 8
0
void LocalApp::readSuffixFilter(){
    QFile *suffixFilterFile = 0;
    if ( appName == "home")
        suffixFilterFile = new QFile (home+"/"+QString("home.suffixfilter"));
    else
        suffixFilterFile = new QFile (home+"/"+ appName + "/"+ appName + QString(".suffixfilter"));
    ERR<<"INFO: LocalApp::readSuffixFilter(): "<<suffixFilterFile->fileName()<<endl;
#ifndef USE_QT5
    if ( ! suffixFilterFile->open(QIODevice::ReadOnly) ){
#else
    if ( ! suffixFilterFile->open(QFile::ReadOnly) ){
#endif
        ERR<<"WARN: LocalApp::readSuffixFilter(): Unable to read : "<<suffixFilterFile->fileName()<<endl;
        suffixFilterFile->close();

    }else {
        suffixFilter += suffixFilterFile->readAll();
        suffixFilterFile->close();
    }

    //TODO: convert suffix filter to map of string
    ERR<<"DBUG: LocalApp::readSuffixFilter(): "<<suffixFilter<<endl;
    delete suffixFilterFile;
}

void LocalApp::readLibraryLoadConfig(){
    QFile *llConfigFile = 0;
    if ( appName == "home")
        llConfigFile = new QFile (home+"/"+QString("home.cfg"));
    else
        llConfigFile = new QFile (home+"/"+ appName + "/"+ appName + QString(".cfg"));
#ifndef USE_QT5
    if ( ! llConfigFile->open(QIODevice::ReadOnly) ){
#else
    if ( ! llConfigFile->open(QFile::ReadOnly) ){
#endif
        ERR<<"DBUG: LocalApp::readLibraryLoadConfig(): Unable to open file :"<<llConfigFile->fileName()<<endl;
    } else {
        QByteArray libConfig;
        while ( (libConfig = llConfigFile->readLine() ).length() > 0 ){
            /*
             * Read the config file
             * <scriptname>:<libraryname>
             */
            QString line(libConfig);
            if( line.split(":").length() > 1) {
                QString script = line.split(":")[0];
                QString soFile = line.split(":")[1];
#ifndef WINDOWS
                soFile.replace(QString("\n"), QString(""));
                soFile += QString(".so");
                //soFile.remove(soFile.length()-1,1);
#else
                soFile.replace(QString("\r\n"), QString(""));
                soFile += QString(".dll");
                //soFile.remove(soFile.length()-2,2);
#endif
                if( appName == "home"){
                    QLibrary *lib = new QLibrary( home + "/" + soFile );
                    lib->setLoadHints(QLibrary::ResolveAllSymbolsHint);
                    lib->load();
                    ERR<<"ERRR: LocalApp::readLibraryLoadConfig(): "<< script<<" -> "<<lib->fileName()<<": Loaded ? "<<lib->isLoaded()<<endl;
                    mapScriptToSo[script] = lib;

                } else {
                    QLibrary *lib = new QLibrary( home + "/" + appName + "/" + soFile, this );
                    lib->setLoadHints(QLibrary::ResolveAllSymbolsHint);
                    lib->load();
                    ERR<<"ERRR: LocalApp::readLibraryLoadConfig(): "<<script<<" -> "<<lib->fileName()<<": Loaded ? "<<lib->isLoaded()<<endl;
                    mapScriptToSo[script] = lib;
                }
            }
        }
    }

    delete llConfigFile;
}


QString LocalApp::readAppName( QUrl url ){
    QString app("");
#ifndef USE_QT5
    ERR<<"INFO: LocalApp::readAppName(): Encoded Path: "<<url.encodedPath()<<endl;
    //QStringList
    app = url.encodedPath().split('/')[0];
    //app = list[0];
    if ( app.contains(".py")){
       app = "home";
    }
    ERR<<"INFO: LocalApp::readAppName(): App: "<<app<<endl;
#else
    ERR<<"INFO: LocalApp::readAppName(): Path: "<<url.path()<<endl;
    app = url.path().split('/')[0];
    if ( app.contains(".py") || app.contains(".")){
        app = "home";
    }
    ERR<<"INFO: LocalApp::readAppName(): App: "<<app<<endl;
    ERR<<"INFO: LocalApp::readAppName(): Path: "<<url.path()<<endl;
#endif
    return app;
}
Esempio n. 9
0
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;
    }
  }
}