2020-12-30 17:03:05 +03:00
|
|
|
#ifndef SETTINGS_H
|
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2021-01-26 15:01:15 +03:00
|
|
|
#include <QSettings>
|
2023-06-30 10:40:43 +09:00
|
|
|
#include <QString>
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2021-04-20 02:09:47 +03:00
|
|
|
#include <QJsonArray>
|
2023-06-30 10:40:43 +09:00
|
|
|
#include <QJsonDocument>
|
2021-04-20 02:09:47 +03:00
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
2021-09-09 20:15:44 +03:00
|
|
|
#include "containers/containers_defs.h"
|
2023-06-30 10:40:43 +09:00
|
|
|
#include "core/defs.h"
|
2022-08-05 14:31:12 +03:00
|
|
|
#include "secure_qsettings.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:
|
2023-06-30 10:40:43 +09:00
|
|
|
explicit Settings(QObject *parent = nullptr);
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2021-04-20 02:09:47 +03:00
|
|
|
ServerCredentials defaultServerCredentials() const;
|
2021-04-26 22:54:31 +03:00
|
|
|
ServerCredentials serverCredentials(int index) const;
|
2020-12-30 17:03:05 +03:00
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
QJsonArray serversArray() const
|
|
|
|
|
{
|
|
|
|
|
return QJsonDocument::fromJson(m_settings.value("Servers/serversList").toByteArray()).array();
|
|
|
|
|
}
|
|
|
|
|
void setServersArray(const QJsonArray &servers)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Servers/serversList", QJsonDocument(servers).toJson());
|
|
|
|
|
}
|
2021-04-20 02:09:47 +03:00
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
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-20 02:09:47 +03:00
|
|
|
|
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-11-30 16:56:24 +04:00
|
|
|
QJsonObject protocolConfig(int serverIndex, DockerContainer container, Proto proto);
|
|
|
|
|
void setProtocolConfig(int serverIndex, DockerContainer container, Proto proto, const QJsonObject &config);
|
2021-05-07 23:28:37 +03:00
|
|
|
|
2021-11-30 16:56:24 +04:00
|
|
|
void clearLastConnectionConfig(int serverIndex, DockerContainer container, Proto proto = Proto::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
|
2023-06-30 10:40:43 +09:00
|
|
|
bool isAutoConnect() const
|
|
|
|
|
{
|
|
|
|
|
return m_settings.value("Conf/autoConnect", false).toBool();
|
|
|
|
|
}
|
|
|
|
|
void setAutoConnect(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/autoConnect", enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isStartMinimized() const
|
|
|
|
|
{
|
|
|
|
|
return m_settings.value("Conf/startMinimized", false).toBool();
|
|
|
|
|
}
|
|
|
|
|
void setStartMinimized(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/startMinimized", enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isSaveLogs() const
|
|
|
|
|
{
|
|
|
|
|
return m_settings.value("Conf/saveLogs", false).toBool();
|
|
|
|
|
}
|
2022-12-28 06:50:46 +03:00
|
|
|
void setSaveLogs(bool enabled);
|
2022-01-30 17:35:57 +03:00
|
|
|
|
2021-05-27 22:18:36 +03:00
|
|
|
enum RouteMode {
|
|
|
|
|
VpnAllSites,
|
|
|
|
|
VpnOnlyForwardSites,
|
|
|
|
|
VpnAllExceptSites
|
|
|
|
|
};
|
2023-06-30 10:40:43 +09:00
|
|
|
Q_ENUM(RouteMode)
|
2021-01-26 15:01:15 +03:00
|
|
|
|
2021-05-27 22:18:36 +03:00
|
|
|
QString routeModeString(RouteMode mode) const;
|
2021-01-26 15:01:15 +03:00
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
RouteMode routeMode() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<RouteMode>(m_settings.value("Conf/routeMode", 0).toInt());
|
|
|
|
|
}
|
|
|
|
|
void setRouteMode(RouteMode mode)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/routeMode", mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap vpnSites(RouteMode mode) const
|
|
|
|
|
{
|
|
|
|
|
return m_settings.value("Conf/" + routeModeString(mode)).toMap();
|
|
|
|
|
}
|
|
|
|
|
void setVpnSites(RouteMode mode, const QVariantMap &sites)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/" + routeModeString(mode), sites);
|
|
|
|
|
m_settings.sync();
|
|
|
|
|
}
|
|
|
|
|
void addVpnSite(RouteMode mode, const QString &site, const QString &ip = "");
|
2022-01-23 19:16:40 +03:00
|
|
|
void addVpnSites(RouteMode mode, const QMap<QString, QString> &sites); // map <site, ip>
|
2021-05-27 22:18:36 +03:00
|
|
|
QStringList getVpnIps(RouteMode mode) const;
|
|
|
|
|
void removeVpnSite(RouteMode mode, const QString &site);
|
|
|
|
|
|
|
|
|
|
void addVpnIps(RouteMode mode, const QStringList &ip);
|
|
|
|
|
void removeVpnSites(RouteMode mode, const QStringList &sites);
|
|
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
bool useAmneziaDns() const
|
|
|
|
|
{
|
|
|
|
|
return m_settings.value("Conf/useAmneziaDns", true).toBool();
|
|
|
|
|
}
|
|
|
|
|
void setUseAmneziaDns(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/useAmneziaDns", enabled);
|
|
|
|
|
}
|
2021-05-27 22:18:36 +03:00
|
|
|
|
2021-05-10 05:25:20 -07:00
|
|
|
QString primaryDns() const;
|
|
|
|
|
QString secondaryDns() const;
|
2021-02-18 15:00:41 +03:00
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
// QString primaryDns() const { return m_primaryDns; }
|
|
|
|
|
void setPrimaryDns(const QString &primaryDns)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/primaryDns", primaryDns);
|
|
|
|
|
}
|
2021-02-18 15:00:41 +03:00
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
// QString secondaryDns() const { return m_secondaryDns; }
|
|
|
|
|
void setSecondaryDns(const QString &secondaryDns)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/secondaryDns", secondaryDns);
|
|
|
|
|
}
|
2021-02-18 15:00:41 +03:00
|
|
|
|
2021-05-10 05:25:20 -07:00
|
|
|
static const char cloudFlareNs1[];
|
|
|
|
|
static const char cloudFlareNs2[];
|
2021-04-20 02:09:47 +03:00
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
// static constexpr char openNicNs5[] = "94.103.153.176";
|
|
|
|
|
// static constexpr char openNicNs13[] = "144.76.103.143";
|
|
|
|
|
|
|
|
|
|
QByteArray backupAppConfig() const
|
|
|
|
|
{
|
|
|
|
|
return m_settings.backupAppConfig();
|
|
|
|
|
}
|
|
|
|
|
bool restoreAppConfig(const QByteArray &cfg)
|
|
|
|
|
{
|
|
|
|
|
return m_settings.restoreAppConfig(cfg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLocale getAppLanguage()
|
|
|
|
|
{
|
|
|
|
|
return m_settings.value("Conf/appLanguage", QLocale()).toLocale();
|
|
|
|
|
};
|
|
|
|
|
void setAppLanguage(QLocale locale)
|
|
|
|
|
{
|
|
|
|
|
m_settings.setValue("Conf/appLanguage", locale);
|
|
|
|
|
};
|
2022-08-05 18:59:47 +03:00
|
|
|
|
2022-12-28 06:50:46 +03:00
|
|
|
signals:
|
2023-01-16 17:11:00 +00:00
|
|
|
void saveLogsChanged();
|
2022-12-28 06:50:46 +03:00
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
private:
|
2022-08-05 14:31:12 +03:00
|
|
|
SecureQSettings m_settings;
|
2020-12-30 17:03:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SETTINGS_H
|