Read all saved Gateways (for selecting in Systray) (#181)

This commit is contained in:
gmarco 2022-10-07 06:37:51 +02:00 committed by GitHub
parent 75a24c89cd
commit fab25848e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -446,8 +446,14 @@ bool GPClient::connected() const
QList<GPGateway> GPClient::allGateways() const QList<GPGateway> GPClient::allGateways() const
{ {
const QString gatewaysJson = settings::get(portal() + "_gateways").toString();
return GPGateway::fromJson(gatewaysJson); QList<GPGateway> gateways;
for (auto g :settings::get_all("_gateways$") ){
gateways.append(GPGateway::fromJson(settings::get(g).toString()));
}
return gateways;
} }
void GPClient::setAllGateways(QList<GPGateway> gateways) void GPClient::setAllGateways(QList<GPGateway> gateways)
@ -475,6 +481,7 @@ void GPClient::setCurrentGateway(const GPGateway gateway)
LOGI << "Updating the current gateway to " << gateway.name(); LOGI << "Updating the current gateway to " << gateway.name();
settings::save(portal() + "_selectedGateway", gateway.name()); settings::save(portal() + "_selectedGateway", gateway.name());
ui->portalInput->setText(gateway.address());
populateGatewayMenu(); populateGatewayMenu();
} }

View File

@ -115,6 +115,12 @@ QVariant gpclient::helper::settings::get(const QString &key, const QVariant &def
return _settings->value(key, defaultValue); return _settings->value(key, defaultValue);
} }
QStringList gpclient::helper::settings::get_all(const QString &key, const QVariant &defaultValue)
{
QRegularExpression re(key);
return _settings->allKeys().filter(re);
}
void gpclient::helper::settings::save(const QString &key, const QVariant &value) void gpclient::helper::settings::save(const QString &key, const QVariant &value)
{ {
_settings->setValue(key, value); _settings->setValue(key, value);

View File

@ -34,6 +34,7 @@ namespace gpclient {
static const QStringList reservedKeys {"extraArgs", "clientos"}; static const QStringList reservedKeys {"extraArgs", "clientos"};
QVariant get(const QString &key, const QVariant &defaultValue = QVariant()); QVariant get(const QString &key, const QVariant &defaultValue = QVariant());
QStringList get_all(const QString &key, const QVariant &defaultValue = QVariant());
void save(const QString &key, const QVariant &value); void save(const QString &key, const QVariant &value);
void clear(); void clear();
} }