fort/src/ui/fortsettings.h

104 lines
3.1 KiB
C
Raw Normal View History

2017-08-30 16:20:31 +00:00
#ifndef FORTSETTINGS_H
#define FORTSETTINGS_H
#include <QObject>
2017-09-20 15:43:43 +00:00
#include <QHash>
2017-08-30 16:20:31 +00:00
#include <QSettings>
2017-09-09 00:08:11 +00:00
#include "../common/version.h"
2017-12-06 02:51:40 +00:00
QT_FORWARD_DECLARE_CLASS(FirewallConf)
2017-08-30 16:20:31 +00:00
2017-09-20 15:43:43 +00:00
typedef QHash<QString, QByteArray> TasksMap;
2017-08-30 16:20:31 +00:00
class FortSettings : public QObject
{
Q_OBJECT
2017-08-30 16:31:52 +00:00
Q_PROPERTY(bool debug READ debug WRITE setDebug NOTIFY iniChanged)
Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY iniChanged)
2017-09-09 00:08:11 +00:00
Q_PROPERTY(QString updatesUrl READ updatesUrl CONSTANT)
Q_PROPERTY(bool startWithWindows READ startWithWindows WRITE setStartWithWindows NOTIFY startWithWindowsChanged)
2017-09-03 19:41:03 +00:00
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
2017-08-30 16:20:31 +00:00
public:
explicit FortSettings(const QStringList &args,
QObject *parent = nullptr);
bool hasProvBoot() const { return m_hasProvBoot; }
bool provBoot() const { return m_provBoot; }
2017-09-03 09:20:37 +00:00
2017-08-30 16:31:52 +00:00
bool debug() const { return iniBool("base/debug"); }
void setDebug(bool on) { setIniValue("base/debug", on); }
QString language() const { return iniText("base/language", "en"); }
2017-09-09 00:08:11 +00:00
void setLanguage(const QString &v) { setIniValue("base/language", v); }
2017-08-30 16:31:52 +00:00
2017-09-09 00:08:11 +00:00
QString updatesUrl() const { return APP_UPDATES_URL; }
2017-08-30 16:31:52 +00:00
bool startWithWindows() const;
void setStartWithWindows(bool start);
2017-09-20 15:43:43 +00:00
TasksMap tasks() const;
bool setTasks(const TasksMap &map);
2017-12-01 14:13:06 +00:00
QString statFilePath() const;
2017-09-03 19:41:03 +00:00
QString errorMessage() const { return m_errorMessage; }
2017-08-30 16:20:31 +00:00
signals:
2017-08-30 16:31:52 +00:00
void iniChanged();
void startWithWindowsChanged();
2017-09-03 19:41:03 +00:00
void errorMessageChanged();
2017-08-30 16:20:31 +00:00
public slots:
2017-09-03 19:41:03 +00:00
bool readConf(FirewallConf &conf);
2017-08-30 16:20:31 +00:00
bool writeConf(const FirewallConf &conf);
2017-12-11 06:05:49 +00:00
bool readConfIni(FirewallConf &conf) const;
bool writeConfIni(const FirewallConf &conf);
2017-08-30 16:20:31 +00:00
private:
void processArguments(const QStringList &args);
void setupIni();
2017-09-03 19:41:03 +00:00
void setErrorMessage(const QString &errorMessage);
2017-09-20 15:43:43 +00:00
QString confFilePath() const;
QString confBackupFilePath() const;
2017-09-03 19:41:03 +00:00
bool tryToReadConf(FirewallConf &conf, const QString &filePath);
2017-08-30 16:20:31 +00:00
bool tryToWriteConf(const FirewallConf &conf, const QString &filePath);
bool iniBool(const QString &key, bool defaultValue = false) const;
int iniInt(const QString &key, int defaultValue = 0) const;
2017-12-11 06:05:49 +00:00
uint iniUInt(const QString &key, int defaultValue = 0) const;
2017-12-14 08:44:10 +00:00
qreal iniReal(const QString &key, qreal defaultValue = 0) const;
2017-08-30 16:20:31 +00:00
QString iniText(const QString &key, const QString &defaultValue = QString()) const;
QStringList iniList(const QString &key) const;
QVariant iniValue(const QString &key,
const QVariant &defaultValue = QVariant()) const;
2017-08-30 16:31:52 +00:00
void setIniValue(const QString &key, const QVariant &value,
const QVariant &defaultValue = QVariant());
2017-08-30 16:20:31 +00:00
2017-09-20 15:43:43 +00:00
void removeIniKey(const QString &key);
QStringList iniChildKeys(const QString &prefix) const;
bool iniSync();
static QString startupShortcutPath();
2017-08-30 16:20:31 +00:00
private:
uint m_hasProvBoot : 1;
uint m_provBoot : 1;
2017-09-03 09:20:37 +00:00
2017-08-30 16:20:31 +00:00
QString m_profilePath;
2017-09-03 19:41:03 +00:00
QString m_errorMessage;
2017-08-30 16:20:31 +00:00
QSettings *m_ini;
};
#endif // FORTSETTINGS_H