Skip to content

Commit

Permalink
cabana: display warning if failed to write settings (#29873)
Browse files Browse the repository at this point in the history
* display warning if failed to write_settings

* use Settings::filePath()
  • Loading branch information
deanlee authored Sep 12, 2023
1 parent ac2d052 commit f63dc51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion tools/cabana/mainwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,13 @@ void MainWindow::closeEvent(QCloseEvent *event) {
settings.video_splitter_state = video_splitter->saveState();
}
settings.message_header_state = messages_widget->saveHeaderState();
settings.save();

auto status = settings.save();
if (status == QSettings::AccessError) {
QString error = tr("Failed to write settings to [%1]: access denied").arg(Settings::filePath());
qDebug() << error;
QMessageBox::warning(this, tr("Failed to write settings"), error);
}
QWidget::closeEvent(event);
}

Expand Down
5 changes: 3 additions & 2 deletions tools/cabana/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
#include <QFileDialog>
#include <QFormLayout>
#include <QPushButton>
#include <QSettings>
#include <QStandardPaths>

#include "tools/cabana/util.h"

Settings settings;

void Settings::save() {
QSettings::Status Settings::save() {
QSettings s(filePath(), QSettings::IniFormat);
s.setValue("fps", fps);
s.setValue("max_cached_minutes", max_cached_minutes);
Expand All @@ -35,6 +34,8 @@ void Settings::save() {
s.setValue("log_path", log_path);
s.setValue("drag_direction", drag_direction);
s.setValue("suppress_defined_signals", suppress_defined_signals);
s.sync();
return s.status();
}

void Settings::load() {
Expand Down
3 changes: 2 additions & 1 deletion tools/cabana/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QDialog>
#include <QGroupBox>
#include <QLineEdit>
#include <QSettings>
#include <QSpinBox>

#define LIGHT_THEME 1
Expand All @@ -24,7 +25,7 @@ class Settings : public QObject {
};

Settings() {}
void save();
QSettings::Status save();
void load();
inline static QString filePath() { return QApplication::applicationDirPath() + "/settings"; }

Expand Down

0 comments on commit f63dc51

Please sign in to comment.