Implement config checking (#1859)
* Add error handling functions to ConfigHandler Refurbished functions setValue and value which were previously unused. These functions now set/get a setting with error handling. Currently recognizes only errors recognizable by QSettings. * Make use of value and setValue in ConfigHandler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add checker for unrecognized general options Extraneous config options in [General] will be reported as errors. Added some placeholder functions to be implemented in future commits. * Introduce keysFromGroup function Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Check shortcut names for duplicates Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix notification spam Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Implement shortcut conflict checking Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix reading of fallbacks on error If there is a config error, some values would not be loaded correctly. Using the newly implemented function ConfigHandler::contains instead of QSettings::contains solves this issue. These changes reveal u bug that causes a crash on startup. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix crashes introduced in previous commit Because ConfigHandler is a dependency of most other classes, calling functions from those classes inside ConfigHandler caused infinite recursions in some cases. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add config file watcher Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add missing config options Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix bug in shortcut conflict detection Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add error resolved notification Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add GUI error message overlay Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add indicator in config window Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Use ConfigHandler::fileChanged in ConfigWindow Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix watcher sometimes not firing Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Improve config file watching performance Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add new way to handle config This is only a fundamental implementation. Future commits will replace everything with this new paradigm. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix getButtons and related functions Also refactored related code to use QList instead of QVector because QSettings does not work well with QVector. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make good use of the new way * Implement proper checking for basic types Everything is covered, apart from KeySequence. * Move fallback path to ExistingDir value handler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Use consistent naming scheme in ConfigHandler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Implement config getters/setters via macro Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Surround text with tr and clang-format Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix colors being saved obfuscated Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add ValueHandler::represenation Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move ValueHandler to separate files Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * confighandler.cpp: rename macro CUSTOM to OPTION Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix bug with shortcut conflict checker Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Update docs and fix setAllTheButtons Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Handle filenamePattern properly Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing build due to wrong function name Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix QSet error due to Qt version mismatch Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Replace QSharedPointer::get with data for older Qt versions Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing build on MacOS and ubuntu 18.04 Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add column headers to recognizedGeneralOptions map Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix ubuntu 18.04 error Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix false positive when shortcuts empty Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix wrong shortcut group prefix Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Implement proper shortcut checking Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add shortcut map in ConfigHandler Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move ConfigShortcuts functions to ShortcutsWidget Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix minor bugs Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add fallback scheme: Pictures, HOME, TMP Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add config --check CLI option Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add config error log to GUI Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Rename ValueHandler::description to expected * Convert Qt's #AARRGGBB to #RRGGBBAA and vice versa Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove obsolete `saveAfterCopyPath` Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix errors in example config Also added an additional ; in front of actual comments to differentiate them from commented options. Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Allow special value 'picker' in userColors Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Allow only name, #RRGGBB, and #RRGGBBAA color formats Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
@@ -42,7 +42,7 @@ GeneralConf::GeneralConf(QWidget* parent)
|
||||
initCopyPathAfterSave();
|
||||
initUseJpgForClipboard();
|
||||
initSaveAfterCopy();
|
||||
initUploadHistoryMaxSize();
|
||||
inituploadHistoryMax();
|
||||
initUndoLimit();
|
||||
|
||||
m_layout->addStretch();
|
||||
@@ -55,31 +55,27 @@ GeneralConf::GeneralConf(QWidget* parent)
|
||||
void GeneralConf::_updateComponents(bool allowEmptySavePath)
|
||||
{
|
||||
ConfigHandler config;
|
||||
m_helpMessage->setChecked(config.showHelpValue());
|
||||
m_sidePanelButton->setChecked(config.showSidePanelButtonValue());
|
||||
m_sysNotifications->setChecked(config.desktopNotificationValue());
|
||||
m_autostart->setChecked(config.startupLaunchValue());
|
||||
m_copyAndCloseAfterUpload->setChecked(
|
||||
config.copyAndCloseAfterUploadEnabled());
|
||||
m_saveAfterCopy->setChecked(config.saveAfterCopyValue());
|
||||
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
|
||||
m_helpMessage->setChecked(config.showHelp());
|
||||
m_sidePanelButton->setChecked(config.showSidePanelButton());
|
||||
m_sysNotifications->setChecked(config.showDesktopNotification());
|
||||
m_autostart->setChecked(config.startupLaunch());
|
||||
m_copyAndCloseAfterUpload->setChecked(config.copyAndCloseAfterUpload());
|
||||
m_saveAfterCopy->setChecked(config.saveAfterCopy());
|
||||
m_copyPathAfterSave->setChecked(config.copyPathAfterSave());
|
||||
m_useJpgForClipboard->setChecked(config.useJpgForClipboard());
|
||||
m_historyConfirmationToDelete->setChecked(
|
||||
config.historyConfirmationToDelete());
|
||||
m_checkForUpdates->setChecked(config.checkForUpdates());
|
||||
m_showStartupLaunchMessage->setChecked(config.showStartupLaunchMessage());
|
||||
m_screenshotPathFixedCheck->setChecked(config.savePathFixed());
|
||||
m_uploadHistoryMaxSize->setValue(config.uploadHistoryMaxSizeValue());
|
||||
m_uploadHistoryMax->setValue(config.uploadHistoryMax());
|
||||
m_undoLimit->setValue(config.undoLimit());
|
||||
|
||||
if (allowEmptySavePath || !config.savePath().isEmpty()) {
|
||||
m_savePath->setText(config.savePath());
|
||||
} else {
|
||||
ConfigHandler().setSavePath(
|
||||
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
|
||||
}
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
m_showTray->setChecked(!config.disabledTrayIconValue());
|
||||
m_showTray->setChecked(!config.disabledTrayIcon());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -100,7 +96,7 @@ void GeneralConf::showSidePanelButtonChanged(bool checked)
|
||||
|
||||
void GeneralConf::showDesktopNotificationChanged(bool checked)
|
||||
{
|
||||
ConfigHandler().setDesktopNotification(checked);
|
||||
ConfigHandler().setShowDesktopNotification(checked);
|
||||
}
|
||||
|
||||
void GeneralConf::showTrayIconChanged(bool checked)
|
||||
@@ -344,7 +340,7 @@ void GeneralConf::initCopyAndCloseAfterUpload()
|
||||
m_scrollAreaLayout->addWidget(m_copyAndCloseAfterUpload);
|
||||
|
||||
connect(m_copyAndCloseAfterUpload, &QCheckBox::clicked, [](bool checked) {
|
||||
ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked);
|
||||
ConfigHandler().setCopyAndCloseAfterUpload(checked);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -368,10 +364,6 @@ void GeneralConf::initSaveAfterCopy()
|
||||
QHBoxLayout* pathLayout = new QHBoxLayout();
|
||||
|
||||
QString path = ConfigHandler().savePath();
|
||||
if (path.isEmpty()) {
|
||||
path =
|
||||
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||
}
|
||||
m_savePath = new QLineEdit(path, this);
|
||||
m_savePath->setDisabled(true);
|
||||
QString foreground = this->palette().windowText().color().name();
|
||||
@@ -401,7 +393,7 @@ void GeneralConf::historyConfirmationToDelete(bool checked)
|
||||
ConfigHandler().setHistoryConfirmationToDelete(checked);
|
||||
}
|
||||
|
||||
void GeneralConf::initUploadHistoryMaxSize()
|
||||
void GeneralConf::inituploadHistoryMax()
|
||||
{
|
||||
QGroupBox* box = new QGroupBox(tr("Latest Uploads Max Size"));
|
||||
box->setFlat(true);
|
||||
@@ -410,22 +402,22 @@ void GeneralConf::initUploadHistoryMaxSize()
|
||||
QVBoxLayout* vboxLayout = new QVBoxLayout();
|
||||
box->setLayout(vboxLayout);
|
||||
|
||||
m_uploadHistoryMaxSize = new QSpinBox(this);
|
||||
m_uploadHistoryMaxSize->setMaximum(50);
|
||||
m_uploadHistoryMax = new QSpinBox(this);
|
||||
m_uploadHistoryMax->setMaximum(50);
|
||||
QString foreground = this->palette().windowText().color().name();
|
||||
m_uploadHistoryMaxSize->setStyleSheet(
|
||||
m_uploadHistoryMax->setStyleSheet(
|
||||
QStringLiteral("color: %1").arg(foreground));
|
||||
|
||||
connect(m_uploadHistoryMaxSize,
|
||||
connect(m_uploadHistoryMax,
|
||||
SIGNAL(valueChanged(int)),
|
||||
this,
|
||||
SLOT(uploadHistoryMaxSizeChanged(int)));
|
||||
vboxLayout->addWidget(m_uploadHistoryMaxSize);
|
||||
SLOT(uploadHistoryMaxChanged(int)));
|
||||
vboxLayout->addWidget(m_uploadHistoryMax);
|
||||
}
|
||||
|
||||
void GeneralConf::uploadHistoryMaxSizeChanged(int max)
|
||||
void GeneralConf::uploadHistoryMaxChanged(int max)
|
||||
{
|
||||
ConfigHandler().setUploadHistoryMaxSize(max);
|
||||
ConfigHandler().setUploadHistoryMax(max);
|
||||
}
|
||||
|
||||
void GeneralConf::initUndoLimit()
|
||||
@@ -479,10 +471,6 @@ void GeneralConf::saveAfterCopyChanged(bool checked)
|
||||
void GeneralConf::changeSavePath()
|
||||
{
|
||||
QString path = ConfigHandler().savePath();
|
||||
if (path.isEmpty()) {
|
||||
path =
|
||||
QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||
}
|
||||
path = chooseFolder(path);
|
||||
if (!path.isEmpty()) {
|
||||
m_savePath->setText(path);
|
||||
@@ -496,7 +484,7 @@ void GeneralConf::initCopyPathAfterSave()
|
||||
m_copyPathAfterSave->setToolTip(tr("Copy file path after save"));
|
||||
m_scrollAreaLayout->addWidget(m_copyPathAfterSave);
|
||||
connect(m_copyPathAfterSave, &QCheckBox::clicked, [](bool checked) {
|
||||
ConfigHandler().setCopyPathAfterSaveEnabled(checked);
|
||||
ConfigHandler().setCopyPathAfterSave(checked);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user