QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
34
38
40{
41
43
44 if ( ! storage )
45 {
46 return false;
47 }
48
49 QMutexLocker locker( &mMutex );
50
51 for ( const auto &s : mStorages )
52 {
53 if ( s.get() == storage )
54 {
55 return false;
56 }
57
58 if ( s->id() == storage->id() )
59 {
60 QgsDebugError( u"A storage with the same ID (%1) already exists"_s.arg( storage->id() ) );
61 return false;
62 }
63 }
64
65 mStorages.emplace_back( storage );
66
67 // Forward storageChanged signal from storage to the registry
69
70 emit storageAdded( storage->id() );
71
72 return true;
73}
74
76{
77
79
80 QMutexLocker locker( &mMutex );
81
82 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
83 {
84 if ( ( *it )->id() == id )
85 {
86 mStorages.erase( it );
87 emit storageRemoved( id );
88 return true;
89 }
90 }
91 return false;
92}
93
94
95QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::storages() const
96{
97
98 QMutexLocker locker( &mMutex );
99
100 QList<QgsAuthConfigurationStorage *> storageList;
101 for ( const auto &s : mStorages )
102 {
103 storageList.append( s.get() );
104 }
105
106 return storageList;
107}
108
109QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::readyStorages() const
110{
111
112 QMutexLocker locker( &mMutex );
113
114 QList<QgsAuthConfigurationStorage *> readyStorages;
115 for ( const auto &s : std::as_const( mStorages ) )
116 {
117 if ( s->isReady() && s->isEnabled() )
118 {
119 readyStorages.append( s.get() );
120 }
121 }
122
123 return readyStorages;
124}
125
127{
128
129 QMutexLocker locker( &mMutex );
130
131 QList<QgsAuthConfigurationStorage *> readyStorages;
132 for ( const auto &s : std::as_const( mStorages ) )
133 {
134 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
135 {
136 readyStorages.append( s.get() );
137 }
138 }
139
140 return readyStorages;
141}
142
144{
145
146 QMutexLocker locker( &mMutex );
147
148 for ( const auto &s : std::as_const( mStorages ) )
149 {
150 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
151 {
152 return s.get();
153 }
154 }
155 return nullptr;
156
157}
158
160{
161
162 QMutexLocker locker( &mMutex );
163
164 for ( const auto &s : std::as_const( mStorages ) )
165 {
166 if ( s->id() == id )
167 {
168 return s.get();
169 }
170 }
171 return nullptr;
172}
173
175{
176
178
179 QMutexLocker locker( &mMutex );
180
181 std::vector<std::unique_ptr<QgsAuthConfigurationStorage>> orderedStorages;
182 for ( const auto &id : std::as_const( orderIds ) )
183 {
184 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
185 {
186 if ( ( *it )->id() == id )
187 {
188 orderedStorages.push_back( std::move( *it ) );
189 mStorages.erase( it );
190 break;
191 }
192 }
193 }
194
195 // Append the remaining storages
196 for ( auto it = std::make_move_iterator( mStorages.begin() ); it != std::make_move_iterator( mStorages.end() ); ++it )
197 {
198 orderedStorages.push_back( std::move( *it ) );
199 }
200
201 mStorages = std::move( orderedStorages );
202}
203
AuthConfigurationStorageCapability
Authentication configuration storage capabilities.
Definition qgis.h:105
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