QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgsauthconfigurationstorageregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthconfigurationstorageregistry.cpp - QgsAuthConfigurationStorageRegistry
3
4 ---------------------
5 begin : 20.6.2024
6 copyright : (C) 2024 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17
19
21#include "qgslogger.h"
22#include "qgsthreadingutils.h"
23
24#include <QMutexLocker>
25#include <QString>
26
27#include "moc_qgsauthconfigurationstorageregistry.cpp"
28
29using namespace Qt::StringLiterals;
30
33
36
38{
40
41 if ( !storage )
42 {
43 return false;
44 }
45
46 QMutexLocker locker( &mMutex );
47
48 for ( const auto &s : mStorages )
49 {
50 if ( s.get() == storage )
51 {
52 return false;
53 }
54
55 if ( s->id() == storage->id() )
56 {
57 QgsDebugError( u"A storage with the same ID (%1) already exists"_s.arg( storage->id() ) );
58 return false;
59 }
60 }
61
62 mStorages.emplace_back( storage );
63
64 // Forward storageChanged signal from storage to the registry
66
67 emit storageAdded( storage->id() );
68
69 return true;
70}
71
73{
75
76 QMutexLocker locker( &mMutex );
77
78 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
79 {
80 if ( ( *it )->id() == id )
81 {
82 mStorages.erase( it );
83 emit storageRemoved( id );
84 return true;
85 }
86 }
87 return false;
88}
89
90
91QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::storages() const
92{
93 QMutexLocker locker( &mMutex );
94
95 QList<QgsAuthConfigurationStorage *> storageList;
96 for ( const auto &s : mStorages )
97 {
98 storageList.append( s.get() );
99 }
100
101 return storageList;
102}
103
104QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::readyStorages() const
105{
106 QMutexLocker locker( &mMutex );
107
108 QList<QgsAuthConfigurationStorage *> readyStorages;
109 for ( const auto &s : std::as_const( mStorages ) )
110 {
111 if ( s->isReady() && s->isEnabled() )
112 {
113 readyStorages.append( s.get() );
114 }
115 }
116
117 return readyStorages;
118}
119
121{
122 QMutexLocker locker( &mMutex );
123
124 QList<QgsAuthConfigurationStorage *> readyStorages;
125 for ( const auto &s : std::as_const( mStorages ) )
126 {
127 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
128 {
129 readyStorages.append( s.get() );
130 }
131 }
132
133 return readyStorages;
134}
135
137{
138 QMutexLocker locker( &mMutex );
139
140 for ( const auto &s : std::as_const( mStorages ) )
141 {
142 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
143 {
144 return s.get();
145 }
146 }
147 return nullptr;
148}
149
151{
152 QMutexLocker locker( &mMutex );
153
154 for ( const auto &s : std::as_const( mStorages ) )
155 {
156 if ( s->id() == id )
157 {
158 return s.get();
159 }
160 }
161 return nullptr;
162}
163
165{
167
168 QMutexLocker locker( &mMutex );
169
170 std::vector<std::unique_ptr<QgsAuthConfigurationStorage>> orderedStorages;
171 for ( const auto &id : std::as_const( orderIds ) )
172 {
173 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
174 {
175 if ( ( *it )->id() == id )
176 {
177 orderedStorages.push_back( std::move( *it ) );
178 mStorages.erase( it );
179 break;
180 }
181 }
182 }
183
184 // Append the remaining storages
185 for ( auto it = std::make_move_iterator( mStorages.begin() ); it != std::make_move_iterator( mStorages.end() ); ++it )
186 {
187 orderedStorages.push_back( std::move( *it ) );
188 }
189
190 mStorages = std::move( orderedStorages );
191}
AuthConfigurationStorageCapability
Authentication configuration storage capabilities.
Definition qgis.h:107
void storageChanged(const QString &id)
Emitted after a storage was changed.
void setStorageOrder(const QStringList &orderIds)
Order the storages by the specified orderIds.
QgsAuthConfigurationStorage * firstReadyStorageWithCapability(Qgis::AuthConfigurationStorageCapability capability) const
Returns the first ready (and enabled) authentication configuration storage which has the required cap...
bool removeStorage(const QString &id)
Remove the authentication configuration storage identified by id from the registry.
QgsAuthConfigurationStorage * storage(const QString &id) const
Returns the storage with the specified id or nullptr if not found in the registry.
QList< QgsAuthConfigurationStorage * > storages() const
Returns the list of all registered authentication configuration storages.
QgsAuthConfigurationStorageRegistry()
Creates a new QgsAuthConfigurationStorageRegistry instance.
void storageRemoved(const QString &id)
Emitted after a storage was removed.
QList< QgsAuthConfigurationStorage * > readyStoragesWithCapability(Qgis::AuthConfigurationStorageCapability capability) const
Returns the list of all ready (and enabled) authentication configuration storage with the required ca...
void storageAdded(const QString &id)
Emitted after a storage was added.
QList< QgsAuthConfigurationStorage * > readyStorages() const
Returns the list of all ready (and enabled) authentication configuration storage.
bool addStorage(QgsAuthConfigurationStorage *storage)
Add an authentication configuration storage to the registry.
Abstract class that defines the interface for all authentication configuration storage implementation...
void storageChanged(const QString &id)
Emitted when the storage was updated.
#define QgsDebugError(str)
Definition qgslogger.h:59
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS