QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
20#include "qgslogger.h"
21#include "qgsthreadingutils.h"
22
23#include <QMutexLocker>
24
28
32
34{
35
37
38 if ( ! storage )
39 {
40 return false;
41 }
42
43 QMutexLocker locker( &mMutex );
44
45 for ( const auto &s : mStorages )
46 {
47 if ( s.get() == storage )
48 {
49 return false;
50 }
51
52 if ( s->id() == storage->id() )
53 {
54 QgsDebugError( QStringLiteral( "A storage with the same ID (%1) already exists" ).arg( storage->id() ) );
55 return false;
56 }
57 }
58
59 mStorages.emplace_back( storage );
60
61 // Forward storageChanged signal from storage to the registry
63
64 emit storageAdded( storage->id() );
65
66 return true;
67}
68
70{
71
73
74 QMutexLocker locker( &mMutex );
75
76 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
77 {
78 if ( ( *it )->id() == id )
79 {
80 mStorages.erase( it );
81 emit storageRemoved( id );
82 return true;
83 }
84 }
85 return false;
86}
87
88
89QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::storages() const
90{
91
92 QMutexLocker locker( &mMutex );
93
94 QList<QgsAuthConfigurationStorage *> storageList;
95 for ( const auto &s : mStorages )
96 {
97 storageList.append( s.get() );
98 }
99
100 return storageList;
101}
102
103QList<QgsAuthConfigurationStorage *> QgsAuthConfigurationStorageRegistry::readyStorages() const
104{
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
123 QMutexLocker locker( &mMutex );
124
125 QList<QgsAuthConfigurationStorage *> readyStorages;
126 for ( const auto &s : std::as_const( mStorages ) )
127 {
128 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
129 {
130 readyStorages.append( s.get() );
131 }
132 }
133
134 return readyStorages;
135}
136
138{
139
140 QMutexLocker locker( &mMutex );
141
142 for ( const auto &s : std::as_const( mStorages ) )
143 {
144 if ( s->isReady() && s->isEnabled() && s->capabilities().testFlag( capability ) )
145 {
146 return s.get();
147 }
148 }
149 return nullptr;
150
151}
152
154{
155
156 QMutexLocker locker( &mMutex );
157
158 for ( const auto &s : std::as_const( mStorages ) )
159 {
160 if ( s->id() == id )
161 {
162 return s.get();
163 }
164 }
165 return nullptr;
166}
167
169{
170
172
173 QMutexLocker locker( &mMutex );
174
175 std::vector<std::unique_ptr<QgsAuthConfigurationStorage>> orderedStorages;
176 for ( const auto &id : std::as_const( orderIds ) )
177 {
178 for ( auto it = mStorages.begin(); it != mStorages.end(); ++it )
179 {
180 if ( ( *it )->id() == id )
181 {
182 orderedStorages.push_back( std::move( *it ) );
183 mStorages.erase( it );
184 break;
185 }
186 }
187 }
188
189 // Append the remaining storages
190 for ( auto it = std::make_move_iterator( mStorages.begin() ); it != std::make_move_iterator( mStorages.end() ); ++it )
191 {
192 orderedStorages.push_back( std::move( *it ) );
193 }
194
195 mStorages = std::move( orderedStorages );
196}
197
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