2020-12-30 17:03:05 +03:00
|
|
|
#ifndef SETTINGS_H
|
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
2021-01-26 15:01:15 +03:00
|
|
|
#include <QSettings>
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2021-04-20 02:09:47 +03:00
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
#include "core/defs.h"
|
2021-05-07 23:28:37 +03:00
|
|
|
#include "protocols/protocols_defs.h"
|
2021-01-06 17:12:24 +03:00
|
|
|
|
|
|
|
|
using namespace amnezia;
|
|
|
|
|
|
2020-12-30 17:03:05 +03:00
|
|
|
class QSettings;
|
|
|
|
|
|
|
|
|
|
class Settings : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit Settings(QObject* parent = nullptr);
|
|
|
|
|
|
2021-04-20 02:09:47 +03:00
|
|
|
ServerCredentials defaultServerCredentials() const;
|
2021-04-26 22:54:31 +03:00
|
|
|
ServerCredentials serverCredentials(int index) const;
|
2021-04-20 02:09:47 +03:00
|
|
|
//void setServerCredentials(const ServerCredentials &credentials);
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2021-04-26 22:54:31 +03:00
|
|
|
QJsonArray serversArray() const { return QJsonDocument::fromJson(m_settings.value("Servers/serversList").toByteArray()).array(); }
|
2021-04-20 02:09:47 +03:00
|
|
|
void setServersArray(const QJsonArray &servers) { m_settings.setValue("Servers/serversList", QJsonDocument(servers).toJson()); }
|
|
|
|
|
|
|
|
|
|
// Servers section
|
|
|
|
|
int serversCount() const;
|
|
|
|
|
QJsonObject server(int index) const;
|
|
|
|
|
void addServer(const QJsonObject &server);
|
|
|
|
|
void removeServer(int index);
|
|
|
|
|
bool editServer(int index, const QJsonObject &server);
|
|
|
|
|
|
|
|
|
|
int defaultServerIndex() const { return m_settings.value("Servers/defaultServerIndex", 0).toInt(); }
|
|
|
|
|
void setDefaultServer(int index) { m_settings.setValue("Servers/defaultServerIndex", index); }
|
|
|
|
|
QJsonObject defaultServer() const { return server(defaultServerIndex()); }
|
|
|
|
|
|
2021-04-26 22:54:31 +03:00
|
|
|
void setDefaultContainer(int serverIndex, DockerContainer container);
|
2021-04-20 02:09:47 +03:00
|
|
|
DockerContainer defaultContainer(int serverIndex) const;
|
|
|
|
|
QString defaultContainerName(int serverIndex) const;
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2021-05-07 23:28:37 +03:00
|
|
|
QMap<DockerContainer, QJsonObject> containers(int serverIndex) const;
|
|
|
|
|
void setContainers(int serverIndex, const QMap<DockerContainer, QJsonObject> &containers);
|
|
|
|
|
|
2021-04-26 22:54:31 +03:00
|
|
|
QJsonObject containerConfig(int serverIndex, DockerContainer container);
|
2021-05-07 23:28:37 +03:00
|
|
|
void setContainerConfig(int serverIndex, DockerContainer container, const QJsonObject &config);
|
|
|
|
|
void removeContainerConfig(int serverIndex, DockerContainer container);
|
|
|
|
|
|
2021-04-26 22:54:31 +03:00
|
|
|
QJsonObject protocolConfig(int serverIndex, DockerContainer container, Protocol proto);
|
2021-05-07 23:28:37 +03:00
|
|
|
void setProtocolConfig(int serverIndex, DockerContainer container, Protocol proto, const QJsonObject &config);
|
|
|
|
|
|
|
|
|
|
void clearLastConnectionConfig(int serverIndex, DockerContainer container, Protocol proto = Protocol::Any);
|
2021-04-26 22:54:31 +03:00
|
|
|
|
2021-05-10 14:19:36 +03:00
|
|
|
bool haveAuthData(int serverIndex) const;
|
2021-04-26 22:54:31 +03:00
|
|
|
QString nextAvailableServerName() const;
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2021-04-20 02:09:47 +03:00
|
|
|
// App settings section
|
2021-05-11 17:04:04 +03:00
|
|
|
bool isAutoConnect() const { return m_settings.value("Conf/autoConnect", false).toBool(); }
|
2021-02-24 21:58:32 +03:00
|
|
|
void setAutoConnect(bool enabled) { m_settings.setValue("Conf/autoConnect", enabled); }
|
|
|
|
|
|
2021-05-11 17:04:04 +03:00
|
|
|
bool isStartMinimized() const { return m_settings.value("Conf/startMinimized", false).toBool(); }
|
|
|
|
|
void setStartMinimized(bool enabled) { m_settings.setValue("Conf/startMinimized", enabled); }
|
|
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
bool customRouting() const { return m_settings.value("Conf/customRouting", false).toBool(); }
|
|
|
|
|
void setCustomRouting(bool customRouting) { m_settings.setValue("Conf/customRouting", customRouting); }
|
2021-01-26 15:01:15 +03:00
|
|
|
|
|
|
|
|
// list of sites to pass blocking added by user
|
2021-02-18 15:00:41 +03:00
|
|
|
QStringList customSites() { return m_settings.value("Conf/customSites").toStringList(); }
|
|
|
|
|
void setCustomSites(const QStringList &customSites) { m_settings.setValue("Conf/customSites", customSites); }
|
2021-01-26 15:01:15 +03:00
|
|
|
|
|
|
|
|
// list of ips to pass blocking generated from customSites
|
2021-02-18 15:00:41 +03:00
|
|
|
QStringList customIps() { return m_settings.value("Conf/customIps").toStringList(); }
|
|
|
|
|
void setCustomIps(const QStringList &customIps) { m_settings.setValue("Conf/customIps", customIps); }
|
|
|
|
|
|
2021-05-10 05:25:20 -07:00
|
|
|
QString primaryDns() const;
|
|
|
|
|
QString secondaryDns() const;
|
2021-02-18 15:00:41 +03:00
|
|
|
|
|
|
|
|
//QString primaryDns() const { return m_primaryDns; }
|
|
|
|
|
void setPrimaryDns(const QString &primaryDns) { m_settings.setValue("Conf/primaryDns", primaryDns); }
|
|
|
|
|
|
|
|
|
|
//QString secondaryDns() const { return m_secondaryDns; }
|
|
|
|
|
void setSecondaryDns(const QString &secondaryDns) { m_settings.setValue("Conf/secondaryDns", secondaryDns); }
|
|
|
|
|
|
2021-05-10 05:25:20 -07:00
|
|
|
static const char cloudFlareNs1[];
|
|
|
|
|
static const char cloudFlareNs2[];
|
2021-04-20 02:09:47 +03:00
|
|
|
|
2021-05-14 23:29:09 +03:00
|
|
|
// static constexpr char openNicNs5[] = "94.103.153.176";
|
|
|
|
|
// static constexpr char openNicNs13[] = "144.76.103.143";
|
2021-04-20 02:09:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2021-01-26 15:01:15 +03:00
|
|
|
|
|
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
private:
|
2021-01-26 15:01:15 +03:00
|
|
|
QSettings m_settings;
|
2021-04-20 02:09:47 +03:00
|
|
|
|
2020-12-30 17:03:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SETTINGS_H
|