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