QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
26#include "moc_qgsauthconfigurationstorageregistry.cpp"
27
31
35
37{
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( QStringLiteral( "A storage with the same ID (%1) already exists" ).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{
74
76
77 QMutexLocker locker( &mMutex );
78
79 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
80 {
81 if ( ( *it )->id() == id )
82 {
83 mStorages.erase( it );
84 emit storageRemoved( id );
85 return true;
86 }
87 }
88 return false;
89}
90
91
92QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::storages() const
93{
94
95 QMutexLocker locker( &mMutex );
96
97 QList<QgsAuthConfigurationStorage *> storageList;
98 for ( const auto &s : mStorages )
99 {
100 storageList.append( s.get() );
101 }
102
103 return storageList;
104}
105
106QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::readyStorages() const
107{
108
109 QMutexLocker locker( &mMutex );
110
111 QList<QgsAuthConfigurationStorage *> readyStorages;
112 for ( const auto &s : std::as_const( mStorages ) )
113 {
114 if ( s->isReady() && s->isEnabled() )
115 {
116 readyStorages.append( s.get() );
117 }
118 }
119
120 return readyStorages;
121}
122
124{
125
126 QMutexLocker locker( &mMutex );
127
128 QList<QgsAuthConfigurationStorage *> readyStorages;
129 for ( const auto &s : std::as_const( mStorages ) )
130 {
131 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
132 {
133 readyStorages.append( s.get() );
134 }
135 }
136
137 return readyStorages;
138}
139
141{
142
143 QMutexLocker locker( &mMutex );
144
145 for ( const auto &s : std::as_const( mStorages ) )
146 {
147 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
148 {
149 return s.get();
150 }
151 }
152 return nullptr;
153
154}
155
157{
158
159 QMutexLocker locker( &mMutex );
160
161 for ( const auto &s : std::as_const( mStorages ) )
162 {
163 if ( s->id() == id )
164 {
165 return s.get();
166 }
167 }
168 return nullptr;
169}
170
172{
173
175
176 QMutexLocker locker( &mMutex );
177
178 std::vector<std::unique_ptr<QgsAuthConfigurationStorage>> orderedStorages;
179 for ( const auto &id : std::as_const( orderIds ) )
180 {
181 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
182 {
183 if ( ( *it )->id() == id )
184 {
185 orderedStorages.push_back( std::move( *it ) );
186 mStorages.erase( it );
187 break;
188 }
189 }
190 }
191
192 // Append the remaining storages
193 for ( auto it = std::make_move_iterator( mStorages.begin() ); it != std::make_move_iterator( mStorages.end() ); ++it )
194 {
195 orderedStorages.push_back( std::move( *it ) );
196 }
197
198 mStorages = std::move( orderedStorages );
199}
200
AuthConfigurationStorageCapability
Authentication configuration storage capabilities.
Definition qgis.h:102
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:57
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS