44 QgsAuthMethodRegistry::QgsAuthMethodRegistry(
const QString &pluginPath )
50 char **argv = qApp->argv();
51 QString appDir = argv[0];
52 int bin = appDir.findRev(
"/bin", -1,
false );
53 QString baseDir = appDir.left( bin );
54 QString mLibraryDirectory = baseDir +
"/lib";
56 mLibraryDirectory = pluginPath;
57 mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
58 mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
60 #if defined(Q_OS_WIN) || defined(__CYGWIN__) 61 mLibraryDirectory.setNameFilters( QStringList(
"*authmethod.dll" ) );
63 mLibraryDirectory.setNameFilters( QStringList( QStringLiteral(
"*authmethod.so" ) ) );
66 QgsDebugMsg( QString(
"Checking for auth method plugins in: %1" ).arg( mLibraryDirectory.path() ) );
68 if ( mLibraryDirectory.count() == 0 )
70 QString msg = QObject::tr(
"No QGIS auth method plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() );
71 msg += QObject::tr(
"No authentication methods can be used. Check your QGIS installation" );
74 output->
setTitle( QObject::tr(
"No Authentication Methods" ) );
81 QString filePattern = getenv(
"QGIS_AUTHMETHOD_FILE" );
83 if ( !filePattern.isEmpty() )
85 fileRegexp.setPattern( filePattern );
88 QListIterator<QFileInfo> it( mLibraryDirectory.entryInfoList() );
89 while ( it.hasNext() )
91 QFileInfo fi( it.next() );
93 if ( !fileRegexp.isEmpty() )
95 if ( fileRegexp.indexIn( fi.fileName() ) == -1 )
97 QgsDebugMsg(
"auth method " + fi.fileName() +
" skipped because doesn't match pattern " + filePattern );
102 QLibrary myLib( fi.filePath() );
105 QgsDebugMsg( QString(
"Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName(), myLib.errorString() ) );
113 QgsDebugMsg( QString(
"Checking %1: ...invalid (no isAuthMethod method)" ).arg( myLib.fileName() ) );
118 if ( !isAuthMethod() )
120 QgsDebugMsg( QString(
"Checking %1: ...invalid (not an auth method)" ).arg( myLib.fileName() ) );
128 QgsDebugMsg( QString(
"Checking %1: ...invalid (no description method)" ).arg( myLib.fileName() ) );
135 QgsDebugMsg( QString(
"Checking %1: ...invalid (no authMethodKey method)" ).arg( myLib.fileName() ) );
150 AuthMethods::const_iterator it = mAuthMethods.begin();
152 while ( it != mAuthMethods.end() )
155 QString lib = it->second->library();
156 QLibrary myLib( lib );
157 if ( myLib.isLoaded() )
179 QString
const &authMethodKey )
181 QgsAuthMethodRegistry::AuthMethods::const_iterator i =
182 metaData.find( authMethodKey );
184 if ( i != metaData.end() )
207 AuthMethods::const_iterator it = mAuthMethods.begin();
209 if ( mAuthMethods.empty() )
211 return QObject::tr(
"No authentication method plugins are available." );
218 list += QLatin1String(
"<ol>" );
221 while ( it != mAuthMethods.end() )
225 list += QLatin1String(
"<li>" );
228 list += it->second->description();
232 list += QLatin1String(
"<br></li>" );
244 list += QLatin1String(
"</ol>" );
252 return mLibraryDirectory;
257 mLibraryDirectory = path;
267 QString lib =
library( authMethodKey );
269 #ifdef TESTAUTHMETHODLIB 270 const char *cLib = lib.toUtf8();
274 void *handle = dlopen( cOgrLib, RTLD_LAZY | RTLD_GLOBAL );
287 QLibrary myLib( lib );
289 QgsDebugMsg(
"Auth method library name is " + myLib.fileName() );
299 QgsDebugMsg( QString(
"Failed to load %1: no classFactory method" ).arg( lib ) );
303 std::unique_ptr< QgsAuthMethod >
authMethod( classFactory() );
311 QgsDebugMsg( QString(
"Instantiated the auth method plugin: %1" ).arg( authMethod->key() ) );
325 return editFactory( parent );
329 QString
const &functionName )
331 QLibrary myLib(
library( authMethodKey ) );
333 QgsDebugMsg(
"Library name is " + myLib.fileName() );
337 return myLib.resolve( functionName.toLatin1().data() );
341 QgsDebugMsg(
"Cannot load library: " + myLib.errorString() );
348 std::unique_ptr< QLibrary > myLib(
new QLibrary(
library( authMethodKey ) ) );
350 QgsDebugMsg(
"Library name is " + myLib->fileName() );
355 QgsDebugMsg(
"Cannot load library: " + myLib->errorString() );
362 for ( AuthMethods::const_iterator it = mAuthMethods.begin(); it != mAuthMethods.end(); ++it )
364 lst.append( it->first );
371 return findMetadata_( mAuthMethods, authMethodKey );
virtual void setTitle(const QString &title)=0
set title for the messages
QStringList authMethodList() const
Return list of available auth methods by their keys.
static void warning(const QString &msg)
Goes to qWarning.
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then if show...
std::unique_ptr< QgsAuthMethod > authMethod(const QString &authMethodKey)
Create an instance of the auth method.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning)
add a message to the instance (and create it if necessary)
A registry / canonical manager of authentication methods.
QFunctionPointer function(const QString &authMethodKey, const QString &functionName)
Get pointer to auth method function.
QWidget * editWidget(const QString &authMethodKey, QWidget *parent=nullptr)
Return the auth method capabilities.
#define QgsDebugMsgLevel(str, level)
QString pluginList(bool asHtml=false) const
Return list of auth method plugins found.
virtual void setMessage(const QString &message, MessageType msgType)=0
set message, it won't be displayed until
std::map< QString, QgsAuthMethodMetadata * > AuthMethods
Type for auth method metadata associative container.
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
void cleanupAuthMethod_t()
Abstract base class for authentication method plugins.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey) const
Return metadata of the auth method or nullptr if not found.
void setLibraryDirectory(const QDir &path)
Set library directory where to search for plugins.
QString library(const QString &authMethodKey) const
Return path for the library of the auth method.
QgsAuthMethod * classFactoryFunction_t()
QWidget * editFactoryFunction_t(QWidget *parent)
Interface for showing messages from QGIS in GUI independent way.
static QgsAuthMethodRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
virtual ~QgsAuthMethodRegistry()
Virtual dectructor.
QDir libraryDirectory() const
Return library directory where plugins are found.
std::unique_ptr< QLibrary > authMethodLibrary(const QString &authMethodKey) const
Return the library object associated with an auth method key.