Show error when settings cannot be restored or saved
* State the error type and location of the relevant file * Help debugging problems related to settings
This commit is contained in:
parent
6546d9bc23
commit
10c656cc5e
|
@ -40,6 +40,7 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QGuiApplication>
|
||||
#include <QMap>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkReply>
|
||||
#include <QPalette>
|
||||
#include <QQmlEngine>
|
||||
|
@ -111,6 +112,19 @@ SyncthingApplet::~SyncthingApplet()
|
|||
#endif
|
||||
}
|
||||
|
||||
void showErrorIfSet(const QString &errorMessage)
|
||||
{
|
||||
if (errorMessage.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
auto msgBox = new QMessageBox();
|
||||
msgBox->setWindowTitle(QStringLiteral(APP_NAME));
|
||||
msgBox->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
msgBox->setText(errorMessage);
|
||||
msgBox->setIcon(QMessageBox::Critical);
|
||||
msgBox->show();
|
||||
}
|
||||
|
||||
void SyncthingApplet::init()
|
||||
{
|
||||
LOAD_QT_TRANSLATIONS;
|
||||
|
@ -170,9 +184,12 @@ void SyncthingApplet::init()
|
|||
if (settings.firstLaunch || settings.fakeFirstLaunch) {
|
||||
showWizard();
|
||||
settings.firstLaunch = false;
|
||||
Settings::save();
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
// show error when settings cannot be restored
|
||||
showErrorIfSet(settings.error);
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
|
@ -319,6 +336,12 @@ void SyncthingApplet::updateStatusIconAndTooltip()
|
|||
emit connectionStatusChanged();
|
||||
}
|
||||
|
||||
void SyncthingApplet::saveSettings()
|
||||
{
|
||||
Settings::save();
|
||||
showErrorIfSet(Settings::values().error);
|
||||
}
|
||||
|
||||
QIcon SyncthingApplet::loadForkAwesomeIcon(const QString &name, int size) const
|
||||
{
|
||||
const auto icon = QtForkAwesome::iconFromId(name);
|
||||
|
@ -348,7 +371,7 @@ void SyncthingApplet::showSettingsDlg()
|
|||
// save plasmoid specific settings to disk when applied
|
||||
connect(m_settingsDlg, &SettingsDialog::applied, this, &SyncthingApplet::configChanged);
|
||||
// save global/general settings to disk when applied
|
||||
connect(m_settingsDlg, &SettingsDialog::applied, &Settings::save);
|
||||
connect(m_settingsDlg, &SettingsDialog::applied, this, &SyncthingApplet::saveSettings);
|
||||
}
|
||||
centerWidget(m_settingsDlg);
|
||||
m_settingsDlg->show();
|
||||
|
|
|
@ -139,6 +139,7 @@ public Q_SLOTS:
|
|||
void showDirectoryErrors(unsigned int directoryIndex);
|
||||
void copyToClipboard(const QString &text);
|
||||
void updateStatusIconAndTooltip();
|
||||
void saveSettings();
|
||||
QIcon loadForkAwesomeIcon(const QString &name, int size = 32) const;
|
||||
QString formatFileSize(quint64 fileSizeInByte) const;
|
||||
QString substituteTilde(const QString &path) const;
|
||||
|
|
|
@ -144,6 +144,9 @@ static void trigger(bool tray, bool webUi, bool wizard)
|
|||
void shutdownSyncthingTray()
|
||||
{
|
||||
Settings::save();
|
||||
if (const auto &error = Settings::values().error; !error.isEmpty()) {
|
||||
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), error);
|
||||
}
|
||||
Settings::Launcher::terminate();
|
||||
}
|
||||
|
||||
|
@ -226,6 +229,9 @@ int runApplication(int argc, const char *const *argv)
|
|||
settings.enableWipFeatures = true;
|
||||
}
|
||||
LOAD_QT_TRANSLATIONS;
|
||||
if (!settings.error.isEmpty()) {
|
||||
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), settings.error);
|
||||
}
|
||||
SyncthingLauncher launcher;
|
||||
SyncthingLauncher::setMainInstance(&launcher);
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
|
|
|
@ -253,7 +253,7 @@ SettingsDialog *TrayWidget::settingsDialog()
|
|||
// note: QCoreApplication::aboutToQuit() does not work reliably but terminating only at the
|
||||
// end of the session is a common use-case for the tray application. So workaround this
|
||||
// by simply saving the settings immediately.
|
||||
connect(s_settingsDlg, &SettingsDialog::applied, &Settings::save);
|
||||
connect(s_settingsDlg, &SettingsDialog::applied, this, &TrayWidget::saveSettings);
|
||||
}
|
||||
return s_settingsDlg;
|
||||
}
|
||||
|
@ -323,6 +323,14 @@ void TrayWidget::applySettingsChangesFromWizard()
|
|||
}
|
||||
}
|
||||
|
||||
void TrayWidget::saveSettings()
|
||||
{
|
||||
Settings::save();
|
||||
if (const auto &error = Settings::values().error; !error.isEmpty()) {
|
||||
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), error);
|
||||
}
|
||||
}
|
||||
|
||||
void TrayWidget::showAboutDialog()
|
||||
{
|
||||
if (!s_aboutDlg) {
|
||||
|
|
|
@ -78,6 +78,7 @@ public Q_SLOTS:
|
|||
void quitTray();
|
||||
void applySettings(const QString &connectionConfig = QString());
|
||||
void applySettingsChangesFromWizard();
|
||||
void saveSettings();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
|
|
@ -89,7 +89,7 @@ find_package(${PACKAGE_NAMESPACE_PREFIX}c++utilities${CONFIGURATION_PACKAGE_SUFF
|
|||
use_cpp_utilities(VISIBILITY PUBLIC)
|
||||
|
||||
# find qtutilities
|
||||
find_package(${PACKAGE_NAMESPACE_PREFIX}qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.10.0 REQUIRED)
|
||||
find_package(${PACKAGE_NAMESPACE_PREFIX}qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.11.0 REQUIRED)
|
||||
use_qt_utilities()
|
||||
|
||||
# find backend libraries
|
||||
|
|
|
@ -265,11 +265,12 @@ static void setVarFromEnv(bool &var, const char *envVar)
|
|||
}
|
||||
}
|
||||
|
||||
void restore()
|
||||
bool restore()
|
||||
{
|
||||
auto s = QtUtilities::getSettings(QStringLiteral(PROJECT_NAME));
|
||||
auto &v = values();
|
||||
auto &settings = *s;
|
||||
v.error = QtUtilities::errorMessageForSettings(settings);
|
||||
|
||||
const auto version = QVersionNumber::fromString(settings.value(QStringLiteral("v")).toString());
|
||||
settings.beginGroup(QStringLiteral("tray"));
|
||||
|
@ -417,13 +418,15 @@ void restore()
|
|||
// restore developer settings from environment variables
|
||||
setVarFromEnv(v.fakeFirstLaunch, PROJECT_VARNAME_UPPER "_FAKE_FIRST_LAUNCH");
|
||||
setVarFromEnv(v.enableWipFeatures, PROJECT_VARNAME_UPPER "_ENABLE_WIP_FEATURES");
|
||||
|
||||
return v.error.isEmpty();
|
||||
}
|
||||
|
||||
void save()
|
||||
bool save()
|
||||
{
|
||||
auto s = QtUtilities::getSettings(QStringLiteral(PROJECT_NAME));
|
||||
auto &settings = *s;
|
||||
const auto &v = values();
|
||||
auto &v = values();
|
||||
|
||||
settings.setValue(QStringLiteral("v"), QStringLiteral(APP_VERSION));
|
||||
settings.beginGroup(QStringLiteral("tray"));
|
||||
|
@ -530,6 +533,10 @@ void save()
|
|||
#endif
|
||||
|
||||
v.qt.save(settings);
|
||||
|
||||
settings.sync();
|
||||
v.error = QtUtilities::errorMessageForSettings(settings);
|
||||
return v.error.isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -155,6 +155,7 @@ struct SYNCTHINGWIDGETS_EXPORT Settings {
|
|||
bool fakeFirstLaunch = false; // not persistent, for testing purposes only
|
||||
bool enableWipFeatures = false; // not persistent, for testing purposes only
|
||||
bool isPlasmoid = false; // not persistent, set by the Plasmoid
|
||||
QString error; // not persistent, whether an error occured on last restore()/save()
|
||||
Connection connection;
|
||||
NotifyOn notifyOn;
|
||||
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
|
||||
|
@ -181,8 +182,8 @@ struct SYNCTHINGWIDGETS_EXPORT Settings {
|
|||
};
|
||||
|
||||
SYNCTHINGWIDGETS_EXPORT Settings &values();
|
||||
SYNCTHINGWIDGETS_EXPORT void restore();
|
||||
SYNCTHINGWIDGETS_EXPORT void save();
|
||||
SYNCTHINGWIDGETS_EXPORT bool restore();
|
||||
SYNCTHINGWIDGETS_EXPORT bool save();
|
||||
} // namespace Settings
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
|
Loading…
Reference in New Issue