56 QgsProviderRegistry::QgsProviderRegistry( QString pluginPath )
64 char **argv = qApp->argv();
65 QString appDir = argv[0];
66 int bin = appDir.findRev(
"/bin", -1,
false );
67 QString baseDir = appDir.left( bin );
68 QString mLibraryDirectory = baseDir +
"/lib";
70 mLibraryDirectory = pluginPath;
71 mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
72 mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
74 #if defined(WIN32) || defined(__CYGWIN__)
75 mLibraryDirectory.setNameFilters( QStringList(
"*.dll" ) );
77 mLibraryDirectory.setNameFilters( QStringList(
"*provider.so" ) );
79 mLibraryDirectory.setNameFilters( QStringList(
"*.so" ) );
82 QgsDebugMsg( QString(
"Checking %1 for provider plugins" ).arg( mLibraryDirectory.path() ) );
84 if ( mLibraryDirectory.count() == 0 )
86 QString msg =
QObject::tr(
"No QGIS data provider plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() );
87 msg +=
QObject::tr(
"No vector layers can be loaded. Check your QGIS installation" );
96 QListIterator<QFileInfo> it( mLibraryDirectory.entryInfoList() );
97 while ( it.hasNext() )
99 QFileInfo fi( it.next() );
101 QLibrary myLib( fi.filePath() );
104 QgsDebugMsg( QString(
"Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName() ).arg( myLib.errorString() ) );
113 QgsDebugMsg( QString(
"Checking %1: ...invalid (has type method)" ).arg( myLib.fileName() ) );
121 QgsDebugMsg( QString(
"Checking %1: ...invalid (no isProvider method)" ).arg( myLib.fileName() ) );
128 QgsDebugMsg( QString(
"Checking %1: ...invalid (not a provider)" ).arg( myLib.fileName() ) );
136 QgsDebugMsg( QString(
"Checking %1: ...invalid (no description method)" ).arg( myLib.fileName() ) );
143 QgsDebugMsg( QString(
"Checking %1: ...invalid (no providerKey method)" ).arg( myLib.fileName() ) );
152 if ( pDatabaseDrivers )
154 mDatabaseDrivers = pDatabaseDrivers();
159 if ( pDirectoryDrivers )
161 mDirectoryDrivers = pDirectoryDrivers();
166 if ( pProtocolDrivers )
168 mProtocolDrivers = pProtocolDrivers();
173 if ( pFileVectorFilters )
177 if ( !fileVectorFilters.isEmpty() )
178 mVectorFileFilters += fileVectorFilters;
180 QgsDebugMsg( QString(
"Checking %1: ...loaded ok (%2 file filters)" ).arg( myLib.fileName() ).arg( fileVectorFilters.split(
";;" ).count() ) );
190 pBuild( fileRasterFilters );
192 QgsDebugMsg(
"raster filters: " + fileRasterFilters );
193 if ( !fileRasterFilters.isEmpty() )
194 mRasterFileFilters += fileRasterFilters;
196 QgsDebugMsg( QString(
"Checking %1: ...loaded ok (%2 file filters)" ).arg( myLib.fileName() ).arg( fileRasterFilters.split(
";;" ).count() ) );
207 Providers::const_iterator it = mProviders.begin();
209 while ( it != mProviders.end() )
211 QgsDebugMsg( QString(
"cleanup: %1" ).arg( it->first ) );
212 QString lib = it->second->library();
213 QLibrary myLib( lib );
214 if ( myLib.isLoaded() )
234 QString
const & providerKey )
236 QgsProviderRegistry::Providers::const_iterator i =
237 metaData.find( providerKey );
239 if ( i != metaData.end() )
264 Providers::const_iterator it = mProviders.begin();
266 if ( mProviders.empty() )
267 return QObject::tr(
"No data provider plugins are available. No vector layers can be loaded" );
274 while ( it != mProviders.end() )
279 list += it->second->description();
298 mLibraryDirectory = path;
304 return mLibraryDirectory;
326 QString lib =
library( providerKey );
328 #ifdef TESTPROVIDERLIB
329 const char *cLib = lib.toUtf8();
333 void *handle = dlopen( cOgrLib, RTLD_LAZY | RTLD_GLOBAL );
346 QLibrary myLib( lib );
348 QgsDebugMsg(
"Library name is " + myLib.fileName() );
358 QgsDebugMsg( QString(
"Failed to load %1: no classFactory method" ).arg( lib ) );
370 QgsDebugMsg( QString(
"Instantiated the data provider plugin: %1" ).arg( dataProvider->
name() ) );
383 if ( !dataCapabilities )
388 return dataCapabilities();
395 QWidget * parent, Qt::WindowFlags fl )
400 if ( !selectFactory )
403 return selectFactory( parent, fl );
406 #if QT_VERSION >= 0x050000
408 QString
const & functionName )
410 QLibrary myLib(
library( providerKey ) );
412 QgsDebugMsg(
"Library name is " + myLib.fileName() );
416 return myLib.resolve( functionName.toAscii().data() );
420 QgsDebugMsg(
"Cannot load library: " + myLib.errorString() );
426 QString
const & functionName )
428 QLibrary myLib(
library( providerKey ) );
430 QgsDebugMsg(
"Library name is " + myLib.fileName() );
434 return myLib.resolve( functionName.toAscii().data() );
438 QgsDebugMsg(
"Cannot load library: " + myLib.errorString() );
446 QLibrary *myLib =
new QLibrary(
library( providerKey ) );
448 QgsDebugMsg(
"Library name is " + myLib->fileName() );
453 QgsDebugMsg(
"Cannot load library: " + myLib->errorString() );
462 typedef void registerGui_function( QWidget * parent );
466 registerGui_function *registerGui = ( registerGui_function * )
cast_to_fptr(
function( provider,
"registerGui" ) );
471 registerGui( parent );
477 return mVectorFileFilters;
482 return mRasterFileFilters;
487 return mDatabaseDrivers;
492 return mDirectoryDrivers;
497 return mProtocolDrivers;
503 for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
505 lst.append( it->first );