Move setting connection config from wizard into its own function
This commit is contained in:
parent
bd5b93d311
commit
99872b262e
|
@ -4,6 +4,7 @@
|
|||
#include "../misc/syncthinglauncher.h"
|
||||
|
||||
#include <syncthingconnector/qstringhash.h>
|
||||
#include <syncthingconnector/syncthingconfig.h>
|
||||
#include <syncthingconnector/syncthingconnection.h>
|
||||
#include <syncthingconnector/syncthingconnectionsettings.h>
|
||||
#include <syncthingconnector/syncthingnotifier.h>
|
||||
|
@ -579,6 +580,33 @@ Systemd::ServiceStatus Systemd::status(SyncthingConnection &connection) const
|
|||
const auto isRelevant = service->isSystemdAvailable() && connection.isLocal();
|
||||
return ServiceStatus{ isRelevant, service->isRunning(), considerForReconnect && isRelevant, showButton && isRelevant, service->isUserScope() };
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Add the specified \a config as primary config possibly backing up the current primary config as secondary config.
|
||||
*/
|
||||
void Connection::addConfigFromWizard(const Data::SyncthingConfig &config)
|
||||
{
|
||||
// skip if settings basically don't change
|
||||
const auto url = config.syncthingUrl();
|
||||
const auto apiKey = config.guiApiKey.toUtf8();
|
||||
if (url == primary.syncthingUrl && config.guiUser == primary.userName && config.guiApiKey == primary.apiKey) {
|
||||
primary.authEnabled = false; // just disable auth to solely rely on the API key
|
||||
return;
|
||||
}
|
||||
|
||||
// backup previous primary config unless fields going to be overridden are empty anyways
|
||||
if (!primary.syncthingUrl.isEmpty() || !primary.userName.isEmpty() || !primary.password.isEmpty() || !primary.apiKey.isEmpty()) {
|
||||
auto &backup = secondary.emplace_back(primary);
|
||||
backup.label = QCoreApplication::translate("Settings::Connection", "Backup of %1 (created by wizard)").arg(backup.label);
|
||||
}
|
||||
|
||||
primary.syncthingUrl = url;
|
||||
primary.userName = config.guiUser;
|
||||
primary.authEnabled = false;
|
||||
primary.password.clear();
|
||||
primary.apiKey = apiKey;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace Settings
|
||||
|
|
|
@ -28,6 +28,7 @@ class QtSettings;
|
|||
}
|
||||
|
||||
namespace Data {
|
||||
struct SyncthingConfig;
|
||||
class SyncthingProcess;
|
||||
class SyncthingLauncher;
|
||||
class SyncthingNotifier;
|
||||
|
@ -44,6 +45,8 @@ namespace Settings {
|
|||
struct SYNCTHINGWIDGETS_EXPORT Connection {
|
||||
Data::SyncthingConnectionSettings primary;
|
||||
std::vector<Data::SyncthingConnectionSettings> secondary;
|
||||
|
||||
void addConfigFromWizard(const Data::SyncthingConfig &config);
|
||||
};
|
||||
|
||||
struct SYNCTHINGWIDGETS_EXPORT NotifyOn {
|
||||
|
|
|
@ -96,27 +96,13 @@ bool Wizard::changeSettings()
|
|||
{
|
||||
const auto &detection = setupDetection();
|
||||
auto &settings = Settings::values();
|
||||
auto &primary = settings.connection.primary;
|
||||
|
||||
switch (mainConfig()) {
|
||||
case MainConfiguration::None:
|
||||
break;
|
||||
case MainConfiguration::CurrentlyRunning: {
|
||||
// apply changes to current primary config if necessary
|
||||
const auto url = detection.config.syncthingUrl();
|
||||
const auto apiKey = detection.config.guiApiKey.toUtf8();
|
||||
if (url != primary.syncthingUrl || detection.config.guiUser != primary.userName || detection.config.guiApiKey != primary.apiKey) {
|
||||
if (!primary.syncthingUrl.isEmpty() || !primary.userName.isEmpty() || !primary.password.isEmpty() || !primary.apiKey.isEmpty()) {
|
||||
// backup previous primary config unless fields going to be overridden are empty anyways
|
||||
auto &backup = settings.connection.secondary.emplace_back(primary);
|
||||
backup.label = tr("Backup of %1 (created by wizard)").arg(backup.label);
|
||||
}
|
||||
primary.syncthingUrl = url;
|
||||
primary.userName = detection.config.guiUser;
|
||||
primary.authEnabled = false;
|
||||
primary.password.clear();
|
||||
primary.apiKey = apiKey;
|
||||
}
|
||||
settings.connection.addConfigFromWizard(detection.config);
|
||||
break;
|
||||
}
|
||||
case MainConfiguration::LauncherExternal:
|
||||
|
|
Loading…
Reference in New Issue