2021-08-09 00:41:52 +07:00
|
|
|
#ifndef SERVERSMODEL_H
|
|
|
|
|
#define SERVERSMODEL_H
|
|
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2023-05-06 06:52:23 +03:00
|
|
|
|
|
|
|
|
#include "settings.h"
|
2024-04-12 20:00:21 +05:00
|
|
|
#include "core/controllers/serverController.h"
|
2021-08-09 00:41:52 +07:00
|
|
|
|
|
|
|
|
class ServersModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
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-02-19 19:54:15 +05:00
|
|
|
IsServerFromApiRole,
|
|
|
|
|
|
|
|
|
|
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;
|
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();
|
|
|
|
|
|
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)
|
|
|
|
|
Q_PROPERTY(QString defaultServerDescriptionExpanded READ getDefaultServerDescriptionExpanded NOTIFY defaultServerDefaultContainerChanged)
|
2024-02-21 18:27:27 +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
|
|
|
|
2024-02-19 19:54:15 +05:00
|
|
|
Q_PROPERTY(int processedIndex READ getProcessedServerIndex WRITE setProcessedServerIndex NOTIFY processedServerIndexChanged)
|
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();
|
|
|
|
|
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
|
|
|
|
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();
|
2023-05-25 15:40:17 +08:00
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
QJsonObject getServerConfig(const int serverIndex);
|
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-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-02-21 18:27:27 +07:00
|
|
|
bool isDefaultServerDefaultContainerHasSplitTunneling();
|
|
|
|
|
|
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);
|
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
|
|
|
|
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();
|
2021-08-09 00:41:52 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // SERVERSMODEL_H
|