Handle config issues in Dolphin integration
* Check whether URL is present * Allow user to enter API key manually
This commit is contained in:
parent
35903fc996
commit
10747bfdf9
|
@ -12,6 +12,7 @@
|
|||
#include <qtutilities/resources/resources.h>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
|
||||
|
@ -107,6 +108,14 @@ void SyncthingFileItemActionStaticData::selectSyncthingConfig()
|
|||
}
|
||||
}
|
||||
|
||||
void SyncthingFileItemActionStaticData::appendNoteToError(QString &errorMessage, const QString &newSyncthingConfigFilePath) const
|
||||
{
|
||||
if (!m_configFilePath.isEmpty() && m_configFilePath != newSyncthingConfigFilePath) {
|
||||
errorMessage += QChar('\n');
|
||||
errorMessage += tr("(still using config from \"%1\")").arg(m_configFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(const QString &syncthingConfigFilePath)
|
||||
{
|
||||
clearCurrentError();
|
||||
|
@ -121,15 +130,32 @@ bool SyncthingFileItemActionStaticData::applySyncthingConfiguration(const QStrin
|
|||
SyncthingConfig config;
|
||||
if (!config.restore(syncthingConfigFilePath)) {
|
||||
auto errorMessage = tr("Unable to load Syncthing config from \"%1\"").arg(syncthingConfigFilePath);
|
||||
if (!m_configFilePath.isEmpty() && m_configFilePath != syncthingConfigFilePath) {
|
||||
errorMessage += QChar('\n');
|
||||
errorMessage += tr("(still using config from \"%1\")").arg(m_configFilePath);
|
||||
}
|
||||
appendNoteToError(errorMessage, syncthingConfigFilePath);
|
||||
setCurrentError(errorMessage);
|
||||
return false;
|
||||
}
|
||||
cerr << "Syncthing config loaded from \"" << syncthingConfigFilePath.toLocal8Bit().data() << "\"" << endl;
|
||||
|
||||
// check whether the URL is present
|
||||
if (config.guiAddress.isEmpty()) {
|
||||
auto errorMessage = tr("Syncthing config from \"%1\" does not contain GUI address.").arg(syncthingConfigFilePath);
|
||||
appendNoteToError(errorMessage, syncthingConfigFilePath);
|
||||
setCurrentError(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check whether the API key is present
|
||||
if (config.guiApiKey.isEmpty()) {
|
||||
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:"));
|
||||
if (config.guiApiKey.isEmpty()) {
|
||||
auto errorMessage = tr("No API key supplied for \"%1\".").arg(config.guiAddress);
|
||||
appendNoteToError(errorMessage, syncthingConfigFilePath);
|
||||
setCurrentError(errorMessage);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// make connection settings
|
||||
SyncthingConnectionSettings settings;
|
||||
settings.syncthingUrl = config.syncthingUrl();
|
||||
|
|
|
@ -41,6 +41,8 @@ Q_SIGNALS:
|
|||
void hasErrorChanged(bool hasError);
|
||||
|
||||
private:
|
||||
void appendNoteToError(QString &errorMessage, const QString &newSyncthingConfigFilePath) const;
|
||||
|
||||
Data::SyncthingConnection m_connection;
|
||||
QString m_configFilePath;
|
||||
QString m_currentError;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<configuration version="28">
|
||||
<gui enabled="true" tls="false" debugging="false">
|
||||
<address>localhost:4001</address>
|
||||
<user>nobody</user>
|
||||
<password>$2a$12$35MnbsQgQNn1hzPYK/lWXOaP.U5D2TO0nuuQy2M4gsqJB4ff4q2RK</password>
|
||||
<apikey></apikey>
|
||||
<theme>default</theme>
|
||||
</gui>
|
||||
</configuration>
|
|
@ -0,0 +1,9 @@
|
|||
<configuration version="28">
|
||||
<gui enabled="true" tls="false" debugging="false">
|
||||
<address></address>
|
||||
<user>nobody</user>
|
||||
<password>$2a$12$35MnbsQgQNn1hzPYK/lWXOaP.U5D2TO0nuuQy2M4gsqJB4ff4q2RK</password>
|
||||
<apikey>not-secret</apikey>
|
||||
<theme>default</theme>
|
||||
</gui>
|
||||
</configuration>
|
Loading…
Reference in New Issue