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
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return QJsonDocument::fromJson(m_settings.value("Servers/serversList").toByteArray()).array();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
void setServersArray(const QJsonArray &servers)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Servers/serversList", QJsonDocument(servers).toJson());
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
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
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Servers/defaultServerIndex", 0).toInt();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
void setDefaultServer(int index)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Servers/defaultServerIndex", index);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/autoConnect", false).toBool();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
void setAutoConnect(bool enabled)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/autoConnect", enabled);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isStartMinimized() const
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/startMinimized", false).toBool();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
void setStartMinimized(bool enabled)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/startMinimized", enabled);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 06:19:50 +02:00
|
|
|
bool isNewsNotifications() const
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/newsNotifications", true).toBool();
|
2026-01-30 06:19:50 +02:00
|
|
|
}
|
|
|
|
|
void setNewsNotifications(bool enabled)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/newsNotifications", enabled);
|
2026-01-30 06:19:50 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
bool isSaveLogs() const
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/saveLogs", false).toBool();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
2022-12-28 06:50:46 +03:00
|
|
|
void setSaveLogs(bool enabled);
|
2022-01-30 17:35:57 +03:00
|
|
|
|
2024-03-20 21:22:29 +07:00
|
|
|
QDateTime getLogEnableDate();
|
|
|
|
|
void setLogEnableDate(QDateTime date);
|
|
|
|
|
|
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-09-10 17:40:18 -07:00
|
|
|
RouteMode routeMode() const;
|
2026-02-26 04:41:08 +01:00
|
|
|
void setRouteMode(RouteMode mode) { m_settings.setValue("Conf/routeMode", mode); }
|
2023-06-30 10:40:43 +09:00
|
|
|
|
2024-04-25 20:01:00 +07:00
|
|
|
bool isSitesSplitTunnelingEnabled() const;
|
2024-04-06 22:29:51 +07:00
|
|
|
void setSitesSplitTunnelingEnabled(bool enabled);
|
|
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
QVariantMap vpnSites(RouteMode mode) const
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/" + routeModeString(mode)).toMap();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
void setVpnSites(RouteMode mode, const QVariantMap &sites)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/" + routeModeString(mode), sites);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
2023-08-08 19:10:14 +05:00
|
|
|
bool 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-08-08 19:10:14 +05:00
|
|
|
void removeAllVpnSites(RouteMode mode);
|
2021-05-27 22:18:36 +03:00
|
|
|
|
2023-06-30 10:40:43 +09:00
|
|
|
bool useAmneziaDns() const
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/useAmneziaDns", true).toBool();
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
|
|
|
|
void setUseAmneziaDns(bool enabled)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/useAmneziaDns", enabled);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
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)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/primaryDns", primaryDns);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
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)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/secondaryDns", secondaryDns);
|
2023-06-30 10:40:43 +09:00
|
|
|
}
|
2021-02-18 15:00:41 +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()
|
|
|
|
|
{
|
2025-09-29 05:47:54 +03:00
|
|
|
QString localeStr = m_settings.value("Conf/appLanguage", QLocale::system().name()).toString();
|
2025-06-05 06:13:37 +04:00
|
|
|
return QLocale(localeStr);
|
2023-06-30 10:40:43 +09:00
|
|
|
};
|
|
|
|
|
void setAppLanguage(QLocale locale)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/appLanguage", locale.name());
|
2023-06-30 10:40:43 +09:00
|
|
|
};
|
2022-08-05 18:59:47 +03:00
|
|
|
|
2023-10-01 12:06:50 +03:00
|
|
|
bool isScreenshotsEnabled() const
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
return m_settings.value("Conf/screenshotsEnabled", true).toBool();
|
2023-10-01 12:06:50 +03:00
|
|
|
}
|
|
|
|
|
void setScreenshotsEnabled(bool enabled)
|
|
|
|
|
{
|
2026-02-26 04:41:08 +01:00
|
|
|
m_settings.setValue("Conf/screenshotsEnabled", enabled);
|
2024-03-06 04:18:19 +03:00
|
|
|
emit screenshotsEnabledChanged(enabled);
|
2023-10-01 12:06:50 +03:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 22:59:49 +09:00
|
|
|
void clearSettings();
|
|
|
|
|
|
2024-04-01 18:45:00 +07:00
|
|
|
enum AppsRouteMode {
|
|
|
|
|
VpnAllApps,
|
|
|
|
|
VpnOnlyForwardApps,
|
|
|
|
|
VpnAllExceptApps
|
|
|
|
|
};
|
|
|
|
|
Q_ENUM(AppsRouteMode)
|
|
|
|
|
|
|
|
|
|
QString appsRouteModeString(AppsRouteMode mode) const;
|
|
|
|
|
|
|
|
|
|
AppsRouteMode getAppsRouteMode() const;
|
|
|
|
|
void setAppsRouteMode(AppsRouteMode mode);
|
|
|
|
|
|
|
|
|
|
QVector<InstalledAppInfo> getVpnApps(AppsRouteMode mode) const;
|
|
|
|
|
void setVpnApps(AppsRouteMode mode, const QVector<InstalledAppInfo> &apps);
|
|
|
|
|
|
2024-04-25 20:01:00 +07:00
|
|
|
bool isAppsSplitTunnelingEnabled() const;
|
2024-04-06 22:29:51 +07:00
|
|
|
void setAppsSplitTunnelingEnabled(bool enabled);
|
|
|
|
|
|
2024-04-25 20:01:00 +07:00
|
|
|
bool isKillSwitchEnabled() const;
|
|
|
|
|
void setKillSwitchEnabled(bool enabled);
|
2025-05-02 23:54:36 -07:00
|
|
|
|
|
|
|
|
bool isStrictKillSwitchEnabled() const;
|
|
|
|
|
void setStrictKillSwitchEnabled(bool enabled);
|
|
|
|
|
|
2024-04-18 20:02:34 +07:00
|
|
|
QString getInstallationUuid(const bool needCreate);
|
|
|
|
|
|
2024-08-20 16:54:05 +07:00
|
|
|
void resetGatewayEndpoint();
|
|
|
|
|
void setGatewayEndpoint(const QString &endpoint);
|
2024-09-09 16:27:29 +04:00
|
|
|
void setDevGatewayEndpoint();
|
2025-12-29 19:18:03 +08:00
|
|
|
QString getGatewayEndpoint(bool isTestPurchase = false);
|
|
|
|
|
bool isDevGatewayEnv(bool isTestPurchase = false);
|
2024-09-09 16:27:29 +04:00
|
|
|
void toggleDevGatewayEnv(bool enabled);
|
2024-08-20 16:54:05 +07:00
|
|
|
|
2025-01-07 06:38:32 +03:00
|
|
|
bool isHomeAdLabelVisible();
|
|
|
|
|
void disableHomeAdLabel();
|
|
|
|
|
|
2025-05-13 12:29:33 +08:00
|
|
|
bool isPremV1MigrationReminderActive();
|
|
|
|
|
void disablePremV1MigrationReminder();
|
|
|
|
|
|
2025-05-02 23:54:36 -07:00
|
|
|
QStringList allowedDnsServers() const;
|
|
|
|
|
void setAllowedDnsServers(const QStringList &servers);
|
|
|
|
|
|
2025-10-06 08:06:36 +04:00
|
|
|
QStringList readNewsIds() const;
|
|
|
|
|
void setReadNewsIds(const QStringList &ids);
|
|
|
|
|
|
2022-12-28 06:50:46 +03:00
|
|
|
signals:
|
2024-01-20 16:40:12 +03:00
|
|
|
void saveLogsChanged(bool enabled);
|
2024-03-06 04:18:19 +03:00
|
|
|
void screenshotsEnabledChanged(bool enabled);
|
2024-03-04 18:08:55 +03:00
|
|
|
void serverRemoved(int serverIndex);
|
|
|
|
|
void settingsCleared();
|
2022-12-28 06:50:46 +03:00
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
private:
|
2024-04-18 20:02:34 +07:00
|
|
|
void setInstallationUuid(const QString &uuid);
|
|
|
|
|
|
2024-01-10 23:05:22 +07:00
|
|
|
mutable SecureQSettings m_settings;
|
2024-08-20 16:54:05 +07:00
|
|
|
|
|
|
|
|
QString m_gatewayEndpoint;
|
2020-12-30 17:03:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SETTINGS_H
|