QGIS API Documentation 3.41.0-Master (af5edcb665c)
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#include "moc_qgsauthconfigurationstorageregistry.cpp"
21#include "qgslogger.h"
22#include "qgsthreadingutils.h"
23
24#include <QMutexLocker>
25
29
33
35{
36
38
39 if ( ! storage )
40 {
41 return false;
42 }
43
44 QMutexLocker locker( &mMutex );
45
46 for ( const auto &s : mStorages )
47 {
48 if ( s.get() == storage )
49 {
50 return false;
51 }
52
53 if ( s->id() == storage->id() )
54 {
55 QgsDebugError( QStringLiteral( "A storage with the same ID (%1) already exists" ).arg( storage->id() ) );
56 return false;
57 }
58 }
59
60 mStorages.emplace_back( storage );
61
62 // Forward storageChanged signal from storage to the registry
64
65 emit storageAdded( storage->id() );
66
67 return true;
68}
69
71{
72
74
75 QMutexLocker locker( &mMutex );
76
77 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
78 {
79 if ( ( *it )->id() == id )
80 {
81 mStorages.erase( it );
82 emit storageRemoved( id );
83 return true;
84 }
85 }
86 return false;
87}
88
89
90QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::storages() const
91{
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
107 QMutexLocker locker( &mMutex );
108
109 QList<QgsAuthConfigurationStorage *> readyStorages;
110 for ( const auto &s : std::as_const( mStorages ) )
111 {
112 if ( s->isReady() && s->isEnabled() )
113 {
114 readyStorages.append( s.get() );
115 }
116 }
117
118 return readyStorages;
119}
120
122{
123
124 QMutexLocker locker( &mMutex );
125
126 QList<QgsAuthConfigurationStorage *> readyStorages;
127 for ( const auto &s : std::as_const( mStorages ) )
128 {
129 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
130 {
131 readyStorages.append( s.get() );
132 }
133 }
134
135 return readyStorages;
136}
137
139{
140
141 QMutexLocker locker( &mMutex );
142
143 for ( const auto &s : std::as_const( mStorages ) )
144 {
145 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
146 {
147 return s.get();
148 }
149 }
150 return nullptr;
151
152}
153
155{
156
157 QMutexLocker locker( &mMutex );
158
159 for ( const auto &s : std::as_const( mStorages ) )
160 {
161 if ( s->id() == id )
162 {
163 return s.get();
164 }
165 }
166 return nullptr;
167}
168
170{
171
173
174 QMutexLocker locker( &mMutex );
175
176 std::vector<std::unique_ptr<QgsAuthConfigurationStorage>> orderedStorages;
177 for ( const auto &id : std::as_const( orderIds ) )
178 {
179 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
180 {
181 if ( ( *it )->id() == id )
182 {
183 orderedStorages.push_back( std::move( *it ) );
184 mStorages.erase( it );
185 break;
186 }
187 }
188 }
189
190 // Append the remaining storages
191 for ( auto it = std::make_move_iterator( mStorages.begin() ); it != std::make_move_iterator( mStorages.end() ); ++it )
192 {
193 orderedStorages.push_back( std::move( *it ) );
194 }
195
196 mStorages = std::move( orderedStorages );
197}
198
AuthConfigurationStorageCapability
Authentication configuration storage capabilities.
Definition qgis.h:100
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.
virtual QString id() const =0
Returns the unique identifier of the storage object.
#define QgsDebugError(str)
Definition qgslogger.h:38
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS