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>
|
2018-01-09 07:36:20 +00:00
|
|
|
#include <QRect>
|
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)
|
2017-09-03 07:20:07 +00:00
|
|
|
Q_PROPERTY(bool startWithWindows READ startWithWindows WRITE setStartWithWindows NOTIFY startWithWindowsChanged)
|
2018-01-11 08:54:38 +00:00
|
|
|
Q_PROPERTY(QString logsPath READ logsPath CONSTANT)
|
2017-12-21 13:15:29 +00:00
|
|
|
Q_PROPERTY(QString profilePath READ profilePath CONSTANT)
|
2017-09-03 19:41:03 +00:00
|
|
|
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
|
2017-12-21 13:15:29 +00:00
|
|
|
Q_PROPERTY(QString appUpdatesUrl READ appUpdatesUrl CONSTANT)
|
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; }
|
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); }
|
|
|
|
|
2018-01-11 08:54:38 +00:00
|
|
|
bool console() const { return iniBool("base/console"); }
|
|
|
|
void setConsole(bool on) { setIniValue("base/console", on); }
|
|
|
|
|
2017-08-30 16:31:52 +00:00
|
|
|
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
|
|
|
|
2018-01-20 08:57:22 +00:00
|
|
|
int iniVersion() const { return iniInt("base/version"); }
|
|
|
|
void setIniVersion(int v) { setIniValue("base/version", v); }
|
|
|
|
|
2018-01-09 07:36:20 +00:00
|
|
|
QRect windowGeometry() const { return iniValue("window/geometry").toRect(); }
|
|
|
|
void setWindowGeometry(const QRect &v) { setIniValue("window/geometry", v); }
|
|
|
|
|
|
|
|
bool windowMaximized() const { return iniBool("window/maximized"); }
|
|
|
|
void setWindowMaximized(bool on) { setIniValue("window/maximized", on); }
|
|
|
|
|
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);
|
|
|
|
|
2018-01-11 08:54:38 +00:00
|
|
|
QString logsPath() const;
|
2017-12-01 14:13:06 +00:00
|
|
|
|
2017-12-21 13:15:29 +00:00
|
|
|
QString profilePath() const { return m_profilePath; }
|
|
|
|
|
2018-01-11 08:54:38 +00:00
|
|
|
QString statFilePath() const;
|
|
|
|
|
2017-09-03 19:41:03 +00:00
|
|
|
QString errorMessage() const { return m_errorMessage; }
|
|
|
|
|
2017-12-21 13:15:29 +00:00
|
|
|
QString appUpdatesUrl() const { return APP_UPDATES_URL; }
|
|
|
|
|
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:
|
2018-01-09 08:25:51 +00:00
|
|
|
bool readConf(FirewallConf &conf, bool &isNew);
|
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);
|
|
|
|
|
2018-01-20 08:57:22 +00:00
|
|
|
QVariant migrateConf(const QVariant &confVar);
|
|
|
|
void removeMigratedKeys();
|
|
|
|
|
2017-08-30 16:20:31 +00:00
|
|
|
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();
|
|
|
|
|
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;
|
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
|