Skip to content

Commit

Permalink
only show welcome window if no settings exists
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanChain committed Jan 26, 2025
1 parent b62873a commit 29afda2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ int main(int argc, char *argv[]) {
LinuxSystemSupport::check();
#endif // Q_OS_LINUX

if (SanePreferences::shownWelcome->get() == false) {
if (!QFile::exists(getSettings().fileName())) {
WelcomeWindow *welcome = new WelcomeWindow();
welcome->show();
if (welcome->exec() == QDialog::Rejected) {
return 0;
} else {
SanePreferences::shownWelcome->set(true);
}
welcome->deleteLater();
}

SaneBreakApp *app = new SaneBreakApp();
Expand Down
9 changes: 9 additions & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

#include "preferences.h"

#include <QCoreApplication>
#include <QObject>
#include <QSettings>
#include <QString>
#include <QtContainerFwd>

Setting<bool>* SanePreferences::shownWelcome =
new Setting<bool>("shown-welcome", false);
QSettings getSettings() {
// We prefer settings file next to the app executable to make app more portable
QFile portableSettings(QCoreApplication::applicationDirPath() + "/SaneBreak.ini");
if (!portableSettings.exists()) return QSettings();
return QSettings(portableSettings.fileName(), QSettings::IniFormat);
};

Setting<int>* SanePreferences::smallEvery = new Setting<int>("break/small-every", 1200);
Setting<int>* SanePreferences::smallFor = new Setting<int>("break/small-for", 20);
Setting<int>* SanePreferences::bigAfter = new Setting<int>("break/big-after", 3);
Expand Down
9 changes: 2 additions & 7 deletions src/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
#ifndef SANE_PREFERENCES_H
#define SANE_PREFERENCES_H

#include <QCoreApplication>
#include <QFile>
#include <QObject>
#include <QSettings>
#include <QtContainerFwd>

QSettings getSettings();

class SettingWithSignal : public QObject {
Q_OBJECT
public:
SettingWithSignal(QObject *parent = 0) : QObject(parent) {}
QSettings getSettings() {
// We prefer settings file next to the app executable to make app more portable
QFile portableSettings(QCoreApplication::applicationDirPath() + "/SaneBreak.ini");
if (!portableSettings.exists()) return QSettings();
return QSettings(portableSettings.fileName(), QSettings::IniFormat);
};
signals:
void changed();
};
Expand Down

0 comments on commit 29afda2

Please sign in to comment.