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-08-30 16:20:31 +00:00
|
|
|
class FirewallConf;
|
|
|
|
|
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)
|
2017-09-03 07:20:07 +00:00
|
|
|
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);
|
|
|
|
|
2017-09-13 11:08:27 +00:00
|
|
|
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
|
|
|
|
2017-09-03 07:20:07 +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();
|
2017-09-03 07:20:07 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
bool readConfFlags(FirewallConf &conf) const;
|
|
|
|
bool writeConfFlags(const FirewallConf &conf);
|
|
|
|
|
|
|
|
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;
|
|
|
|
int iniUInt(const QString &key, int defaultValue = 0) const;
|
|
|
|
int iniReal(const QString &key, qreal defaultValue = 0) const;
|
|
|
|
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();
|
|
|
|
|
2017-09-03 07:20:07 +00:00
|
|
|
static QString startupShortcutPath();
|
|
|
|
|
2017-08-30 16:20:31 +00:00
|
|
|
private:
|
2017-09-13 11:08:27 +00:00
|
|
|
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
|