Store API key for Dolphin integration persistently
Only storing the key for the last selected config should be sufficient.
This commit is contained in:
parent
ad42c24c96
commit
d3c6eda0a6
|
@ -52,7 +52,7 @@ void SyncthingFileItemActionStaticData::initialize()
|
||||||
}
|
}
|
||||||
return SyncthingConfig::locateConfigFile();
|
return SyncthingConfig::locateConfigFile();
|
||||||
}();
|
}();
|
||||||
applySyncthingConfiguration(m_configFilePath);
|
applySyncthingConfiguration(m_configFilePath, settingsFile.value(QStringLiteral("syncthingApiKey")).toString(), true);
|
||||||
|
|
||||||
// prevent unnecessary API calls (for the purpose of the context menu)
|
// prevent unnecessary API calls (for the purpose of the context menu)
|
||||||
m_connection.disablePolling();
|
m_connection.disablePolling();
|
||||||
|
@ -102,9 +102,8 @@ void SyncthingFileItemActionStaticData::showAboutDialog()
|
||||||
void SyncthingFileItemActionStaticData::selectSyncthingConfig()
|
void SyncthingFileItemActionStaticData::selectSyncthingConfig()
|
||||||
{
|
{
|
||||||
const auto configFilePath = QFileDialog::getOpenFileName(nullptr, tr("Select Syncthing config file") + QStringLiteral(" - " APP_NAME));
|
const auto configFilePath = QFileDialog::getOpenFileName(nullptr, tr("Select Syncthing config file") + QStringLiteral(" - " APP_NAME));
|
||||||
if (!configFilePath.isEmpty() && applySyncthingConfiguration(configFilePath)) {
|
if (!configFilePath.isEmpty()) {
|
||||||
QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME))
|
applySyncthingConfiguration(configFilePath, QString(), false);
|
||||||
.setValue(QStringLiteral("syncthingConfigPath"), m_configFilePath = configFilePath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +115,8 @@ void SyncthingFileItemActionStaticData::appendNoteToError(QString &errorMessage,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(const QString &syncthingConfigFilePath)
|
bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(
|
||||||
|
const QString &syncthingConfigFilePath, const QString &syncthingApiKey, bool skipSavingConfig)
|
||||||
{
|
{
|
||||||
clearCurrentError();
|
clearCurrentError();
|
||||||
|
|
||||||
|
@ -145,6 +145,9 @@ bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(const QStrin
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether the API key is present
|
// check whether the API key is present
|
||||||
|
if (config.guiApiKey.isEmpty()) {
|
||||||
|
config.guiApiKey = syncthingApiKey;
|
||||||
|
}
|
||||||
if (config.guiApiKey.isEmpty()) {
|
if (config.guiApiKey.isEmpty()) {
|
||||||
config.guiApiKey = QInputDialog::getText(
|
config.guiApiKey = QInputDialog::getText(
|
||||||
nullptr, tr("Enter API key"), tr("The selected config file does not contain an API key. Please enter the API key manually:"));
|
nullptr, tr("Enter API key"), tr("The selected config file does not contain an API key. Please enter the API key manually:"));
|
||||||
|
@ -157,9 +160,9 @@ bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(const QStrin
|
||||||
}
|
}
|
||||||
|
|
||||||
// make connection settings
|
// make connection settings
|
||||||
SyncthingConnectionSettings settings;
|
SyncthingConnectionSettings connectionSettings;
|
||||||
settings.syncthingUrl = config.syncthingUrl();
|
connectionSettings.syncthingUrl = config.syncthingUrl();
|
||||||
settings.apiKey.append(config.guiApiKey);
|
connectionSettings.apiKey.append(config.guiApiKey);
|
||||||
|
|
||||||
// establish connection
|
// establish connection
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -168,7 +171,15 @@ bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(const QStrin
|
||||||
reconnectInterval = 10000;
|
reconnectInterval = 10000;
|
||||||
}
|
}
|
||||||
m_connection.setAutoReconnectInterval(reconnectInterval);
|
m_connection.setAutoReconnectInterval(reconnectInterval);
|
||||||
m_connection.reconnect(settings);
|
m_connection.reconnect(connectionSettings);
|
||||||
|
|
||||||
|
// save new config persistently
|
||||||
|
if (!skipSavingConfig) {
|
||||||
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
|
||||||
|
settings.setValue(QStringLiteral("syncthingConfigPath"), m_configFilePath = syncthingConfigFilePath);
|
||||||
|
settings.setValue(QStringLiteral("syncthingApiKey"), config.guiApiKey);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void initialize();
|
void initialize();
|
||||||
bool applySyncthingConfiguration(const QString &syncthingConfigFilePath);
|
bool applySyncthingConfiguration(const QString &syncthingConfigFilePath, const QString &syncthingApiKey, bool skipSavingConfig);
|
||||||
void logConnectionStatus();
|
void logConnectionStatus();
|
||||||
void logConnectionError(const QString &errorMessage, Data::SyncthingErrorCategory errorCategory);
|
void logConnectionError(const QString &errorMessage, Data::SyncthingErrorCategory errorCategory);
|
||||||
void rescanDir(const QString &dirId, const QString &relpath = QString());
|
void rescanDir(const QString &dirId, const QString &relpath = QString());
|
||||||
|
|
Loading…
Reference in New Issue