2021-08-09 00:41:52 +07:00
|
|
|
#ifndef SERVERSMODEL_H
|
|
|
|
|
#define SERVERSMODEL_H
|
|
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2023-05-06 06:52:23 +03:00
|
|
|
|
2024-04-12 20:00:21 +05:00
|
|
|
#include "core/controllers/serverController.h"
|
2024-08-20 16:54:05 +07:00
|
|
|
#include "settings.h"
|
2021-08-09 00:41:52 +07:00
|
|
|
|
|
|
|
|
class ServersModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2025-10-06 08:06:36 +04:00
|
|
|
struct GatewayStacks
|
|
|
|
|
{
|
|
|
|
|
QSet<QString> userCountryCodes;
|
|
|
|
|
QSet<QString> serviceTypes;
|
|
|
|
|
|
|
|
|
|
bool isEmpty() const { return userCountryCodes.isEmpty() && serviceTypes.isEmpty(); }
|
|
|
|
|
bool operator==(const GatewayStacks &other) const;
|
|
|
|
|
QJsonObject toJson() const;
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-21 20:56:00 +09:00
|
|
|
enum Roles {
|
2023-05-17 23:28:27 +08:00
|
|
|
NameRole = Qt::UserRole + 1,
|
2023-12-08 13:50:03 +07:00
|
|
|
ServerDescriptionRole,
|
2024-02-19 19:54:15 +05:00
|
|
|
CollapsedServerDescriptionRole,
|
|
|
|
|
ExpandedServerDescriptionRole,
|
2023-05-17 23:28:27 +08:00
|
|
|
HostNameRole,
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
CredentialsRole,
|
2023-06-20 10:25:24 +09:00
|
|
|
CredentialsLoginRole,
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2023-05-25 15:40:17 +08:00
|
|
|
IsDefaultRole,
|
2023-06-23 15:24:40 +09:00
|
|
|
IsCurrentlyProcessedRole,
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2023-06-27 19:07:42 +09:00
|
|
|
HasWriteAccessRole,
|
2023-12-08 13:50:03 +07:00
|
|
|
|
|
|
|
|
ContainsAmneziaDnsRole,
|
|
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
DefaultContainerRole,
|
|
|
|
|
|
2024-02-29 17:22:17 +07:00
|
|
|
HasInstalledContainers,
|
2024-08-20 16:54:05 +07:00
|
|
|
|
|
|
|
|
IsServerFromTelegramApiRole,
|
|
|
|
|
IsServerFromGatewayApiRole,
|
|
|
|
|
ApiConfigRole,
|
|
|
|
|
IsCountrySelectionAvailableRole,
|
|
|
|
|
ApiAvailableCountriesRole,
|
|
|
|
|
ApiServerCountryCodeRole,
|
2025-11-03 10:26:22 +08:00
|
|
|
IsAdVisibleRole,
|
|
|
|
|
AdHeaderRole,
|
|
|
|
|
AdDescriptionRole,
|
|
|
|
|
AdEndpointRole,
|
2026-04-17 15:01:24 +08:00
|
|
|
IsRenewalAvailableRole,
|
2024-02-19 19:54:15 +05:00
|
|
|
|
2026-03-25 14:48:32 +03:00
|
|
|
IsSubscriptionExpiredRole,
|
|
|
|
|
IsSubscriptionExpiringSoonRole,
|
|
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
HasAmneziaDns
|
2021-08-09 00:41:52 +07:00
|
|
|
};
|
|
|
|
|
|
2023-05-12 11:36:09 +08:00
|
|
|
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
|
|
|
|
|
2021-08-09 00:41:52 +07:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
|
|
2023-05-12 11:36:09 +08:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
2024-12-09 09:32:49 +03:00
|
|
|
bool setData(const int index, const QVariant &value, int role = Qt::EditRole);
|
2021-08-09 00:41:52 +07:00
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
2023-06-20 10:25:24 +09:00
|
|
|
QVariant data(const int index, int role = Qt::DisplayRole) const;
|
2021-08-09 00:41:52 +07:00
|
|
|
|
2023-07-31 00:13:08 +09:00
|
|
|
void resetModel();
|
|
|
|
|
|
2025-10-06 08:06:36 +04:00
|
|
|
GatewayStacks gatewayStacks() const { return m_gatewayStacks; }
|
|
|
|
|
|
2023-06-23 15:24:40 +09:00
|
|
|
Q_PROPERTY(int defaultIndex READ getDefaultServerIndex WRITE setDefaultServerIndex NOTIFY defaultServerIndexChanged)
|
2023-08-16 12:11:34 +05:00
|
|
|
Q_PROPERTY(QString defaultServerName READ getDefaultServerName NOTIFY defaultServerNameChanged)
|
2024-02-19 19:54:15 +05:00
|
|
|
Q_PROPERTY(QString defaultServerDefaultContainerName READ getDefaultServerDefaultContainerName NOTIFY defaultServerDefaultContainerChanged)
|
|
|
|
|
Q_PROPERTY(QString defaultServerDescriptionCollapsed READ getDefaultServerDescriptionCollapsed NOTIFY defaultServerDefaultContainerChanged)
|
2024-08-20 16:54:05 +07:00
|
|
|
Q_PROPERTY(QString defaultServerImagePathCollapsed READ getDefaultServerImagePathCollapsed NOTIFY defaultServerDefaultContainerChanged)
|
2024-02-19 19:54:15 +05:00
|
|
|
Q_PROPERTY(QString defaultServerDescriptionExpanded READ getDefaultServerDescriptionExpanded NOTIFY defaultServerDefaultContainerChanged)
|
2024-08-20 16:54:05 +07:00
|
|
|
Q_PROPERTY(bool isDefaultServerDefaultContainerHasSplitTunneling READ isDefaultServerDefaultContainerHasSplitTunneling NOTIFY
|
|
|
|
|
defaultServerDefaultContainerChanged)
|
2024-02-21 22:57:15 +05:00
|
|
|
Q_PROPERTY(bool isDefaultServerFromApi READ isDefaultServerFromApi NOTIFY defaultServerIndexChanged)
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2025-10-06 08:06:36 +04:00
|
|
|
Q_PROPERTY(bool hasServersFromGatewayApi READ hasServersFromGatewayApi NOTIFY hasServersFromGatewayApiChanged)
|
|
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
Q_PROPERTY(int processedIndex READ getProcessedServerIndex WRITE setProcessedServerIndex NOTIFY processedServerIndexChanged)
|
2025-07-02 06:07:56 +04:00
|
|
|
Q_PROPERTY(bool processedServerIsPremium READ processedServerIsPremium NOTIFY processedServerChanged)
|
|
|
|
|
|
2025-11-03 10:26:22 +08:00
|
|
|
Q_PROPERTY(bool isAdVisible READ isAdVisible NOTIFY defaultServerIndexChanged)
|
|
|
|
|
Q_PROPERTY(QString adHeader READ adHeader NOTIFY defaultServerIndexChanged)
|
|
|
|
|
Q_PROPERTY(QString adDescription READ adDescription NOTIFY defaultServerIndexChanged)
|
|
|
|
|
|
2025-07-02 06:07:56 +04:00
|
|
|
bool processedServerIsPremium() const;
|
2023-06-23 15:24:40 +09:00
|
|
|
|
2023-05-12 11:36:09 +08:00
|
|
|
public slots:
|
2023-06-23 15:24:40 +09:00
|
|
|
void setDefaultServerIndex(const int index);
|
2023-05-15 13:38:17 +08:00
|
|
|
const int getDefaultServerIndex();
|
2023-07-31 00:13:08 +09:00
|
|
|
const QString getDefaultServerName();
|
2023-12-08 13:50:03 +07:00
|
|
|
const QString getDefaultServerDescriptionCollapsed();
|
2024-08-20 16:54:05 +07:00
|
|
|
const QString getDefaultServerImagePathCollapsed();
|
2023-12-08 13:50:03 +07:00
|
|
|
const QString getDefaultServerDescriptionExpanded();
|
2024-02-19 19:54:15 +05:00
|
|
|
const QString getDefaultServerDefaultContainerName();
|
2023-06-01 11:25:33 +08:00
|
|
|
bool isDefaultServerCurrentlyProcessed();
|
2024-02-21 22:57:15 +05:00
|
|
|
bool isDefaultServerFromApi();
|
2023-06-23 15:24:40 +09:00
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
bool isProcessedServerHasWriteAccess();
|
2023-06-27 19:07:42 +09:00
|
|
|
bool isDefaultServerHasWriteAccess();
|
2023-07-31 00:13:08 +09:00
|
|
|
bool hasServerWithWriteAccess();
|
2023-05-25 15:40:17 +08:00
|
|
|
|
2025-10-06 08:06:36 +04:00
|
|
|
bool hasServersFromGatewayApi();
|
|
|
|
|
|
2023-05-15 13:38:17 +08:00
|
|
|
const int getServersCount();
|
2023-05-12 11:36:09 +08:00
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
void setProcessedServerIndex(const int index);
|
|
|
|
|
int getProcessedServerIndex();
|
2023-05-17 23:28:27 +08:00
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
const ServerCredentials getProcessedServerCredentials();
|
2023-12-08 13:50:03 +07:00
|
|
|
const ServerCredentials getServerCredentials(const int index);
|
2023-07-18 11:15:04 +09:00
|
|
|
|
2023-06-01 11:25:33 +08:00
|
|
|
void addServer(const QJsonObject &server);
|
2024-02-19 19:54:15 +05:00
|
|
|
void editServer(const QJsonObject &server, const int serverIndex);
|
2023-06-01 11:25:33 +08:00
|
|
|
void removeServer();
|
2025-05-13 12:29:33 +08:00
|
|
|
void removeServer(const int serverIndex);
|
2023-05-25 15:40:17 +08:00
|
|
|
|
2025-07-02 06:07:56 +04:00
|
|
|
QJsonObject getServerConfig(const int serverIndex) const;
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
void reloadDefaultServerContainerConfig();
|
2023-12-08 13:50:03 +07:00
|
|
|
void updateContainerConfig(const int containerIndex, const QJsonObject config);
|
|
|
|
|
void addContainerConfig(const int containerIndex, const QJsonObject config);
|
|
|
|
|
|
2023-12-21 23:34:27 +07:00
|
|
|
void clearCachedProfile(const DockerContainer container);
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2024-04-12 20:00:21 +05:00
|
|
|
ErrorCode removeContainer(const QSharedPointer<ServerController> &serverController, const int containerIndex);
|
|
|
|
|
ErrorCode removeAllContainers(const QSharedPointer<ServerController> &serverController);
|
|
|
|
|
ErrorCode rebootServer(const QSharedPointer<ServerController> &serverController);
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2024-02-13 20:20:13 +05:00
|
|
|
void setDefaultContainer(const int serverIndex, const int containerIndex);
|
2023-12-08 13:50:03 +07:00
|
|
|
|
|
|
|
|
QStringList getAllInstalledServicesName(const int serverIndex);
|
|
|
|
|
|
|
|
|
|
void toggleAmneziaDns(bool enabled);
|
2024-04-01 20:20:02 +07:00
|
|
|
QPair<QString, QString> getDnsPair(const int serverIndex);
|
2023-10-12 20:48:03 +05:00
|
|
|
|
2024-02-09 23:23:26 +05:00
|
|
|
bool isServerFromApiAlreadyExists(const quint16 crc);
|
2024-08-20 16:54:05 +07:00
|
|
|
bool isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol);
|
2026-04-08 11:21:12 +07:00
|
|
|
int indexOfServerWithVpnKey(const QString &vpnKey) const;
|
2024-01-17 00:34:23 +07:00
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
QVariant getDefaultServerData(const QString roleString);
|
|
|
|
|
|
|
|
|
|
QVariant getProcessedServerData(const QString roleString);
|
2024-12-09 09:32:49 +03:00
|
|
|
bool setProcessedServerData(const QString &roleString, const QVariant &value);
|
2024-02-19 19:54:15 +05:00
|
|
|
|
2024-02-21 18:27:27 +07:00
|
|
|
bool isDefaultServerDefaultContainerHasSplitTunneling();
|
|
|
|
|
|
2024-08-20 16:54:05 +07:00
|
|
|
bool isServerFromApi(const int serverIndex);
|
|
|
|
|
bool isApiKeyExpired(const int serverIndex);
|
|
|
|
|
void removeApiConfig(const int serverIndex);
|
|
|
|
|
|
2025-11-03 10:26:22 +08:00
|
|
|
bool isAdVisible();
|
|
|
|
|
QString adHeader();
|
|
|
|
|
QString adDescription();
|
|
|
|
|
|
2021-08-09 00:41:52 +07:00
|
|
|
protected:
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
2023-06-21 20:56:00 +09:00
|
|
|
signals:
|
2024-02-19 19:54:15 +05:00
|
|
|
void processedServerIndexChanged(const int index);
|
2024-12-09 09:32:49 +03:00
|
|
|
// emitted when the processed server index or processed server data is changed
|
|
|
|
|
void processedServerChanged();
|
|
|
|
|
|
2023-10-18 00:36:40 +05:00
|
|
|
void defaultServerIndexChanged(const int index);
|
2023-08-16 12:11:34 +05:00
|
|
|
void defaultServerNameChanged();
|
2023-12-08 13:50:03 +07:00
|
|
|
void defaultServerDescriptionChanged();
|
|
|
|
|
|
2024-02-09 23:23:26 +05:00
|
|
|
void containersUpdated(const QJsonArray &containers);
|
2024-02-19 19:54:15 +05:00
|
|
|
void defaultServerContainersUpdated(const QJsonArray &containers);
|
|
|
|
|
void defaultServerDefaultContainerChanged(const int containerIndex);
|
2023-06-21 20:56:00 +09:00
|
|
|
|
2025-02-15 11:50:42 +07:00
|
|
|
void updateApiCountryModel();
|
2024-08-20 16:54:05 +07:00
|
|
|
void updateApiServicesModel();
|
|
|
|
|
|
2025-10-06 08:06:36 +04:00
|
|
|
void hasServersFromGatewayApiChanged();
|
|
|
|
|
void gatewayStacksExpanded();
|
|
|
|
|
|
2021-08-09 00:41:52 +07:00
|
|
|
private:
|
2023-06-30 18:14:47 +03:00
|
|
|
ServerCredentials serverCredentials(int index) const;
|
2024-02-29 17:22:17 +07:00
|
|
|
|
2023-12-08 13:50:03 +07:00
|
|
|
void updateContainersModel();
|
2024-02-19 19:54:15 +05:00
|
|
|
void updateDefaultServerContainersModel();
|
|
|
|
|
|
|
|
|
|
QString getServerDescription(const QJsonObject &server, const int index) const;
|
2023-12-08 13:50:03 +07:00
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
bool isAmneziaDnsContainerInstalled(const int serverIndex) const;
|
2023-06-30 18:14:47 +03:00
|
|
|
|
2024-02-29 17:22:17 +07:00
|
|
|
bool serverHasInstalledContainers(const int serverIndex) const;
|
|
|
|
|
|
2023-06-07 13:17:48 +03:00
|
|
|
QJsonArray m_servers;
|
|
|
|
|
|
2023-05-06 06:52:23 +03:00
|
|
|
std::shared_ptr<Settings> m_settings;
|
2023-05-17 23:28:27 +08:00
|
|
|
|
2023-06-07 13:17:48 +03:00
|
|
|
int m_defaultServerIndex;
|
2024-02-19 19:54:15 +05:00
|
|
|
int m_processedServerIndex;
|
2023-12-08 13:50:03 +07:00
|
|
|
|
|
|
|
|
bool m_isAmneziaDnsEnabled = m_settings->useAmneziaDns();
|
2025-10-06 08:06:36 +04:00
|
|
|
|
|
|
|
|
GatewayStacks m_gatewayStacks;
|
|
|
|
|
void recomputeGatewayStacks();
|
2021-08-09 00:41:52 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SERVERSMODEL_H
|