2026-04-30 14:53:03 +08:00
|
|
|
#include "containersModel.h"
|
2021-09-10 22:19:00 +03:00
|
|
|
|
2023-12-08 13:50:03 +07:00
|
|
|
#include <QJsonArray>
|
2023-05-27 22:46:41 +08:00
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
#include "core/models/protocolConfig.h"
|
|
|
|
|
|
|
|
|
|
using namespace amnezia;
|
|
|
|
|
|
2025-12-18 22:25:20 +08:00
|
|
|
ContainersModel::ContainersModel(QObject *parent) : QAbstractListModel(parent)
|
2021-09-10 22:19:00 +03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ContainersModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(parent);
|
2026-04-30 14:53:03 +08:00
|
|
|
return ContainerUtils::allContainers().size();
|
2021-09-10 22:19:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
2026-04-30 14:53:03 +08:00
|
|
|
if (!index.isValid() || index.row() < 0 || index.row() >= ContainerUtils::allContainers().size()) {
|
2021-09-10 22:19:00 +03:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
DockerContainer container = ContainerUtils::allContainers().at(index.row());
|
|
|
|
|
bool isThirdPartyConfig = false;
|
|
|
|
|
if (m_containers.contains(container)) {
|
|
|
|
|
const ContainerConfig& config = m_containers.value(container);
|
|
|
|
|
isThirdPartyConfig = config.protocolConfig.isThirdPartyConfig();
|
|
|
|
|
}
|
2023-05-12 23:54:31 +08:00
|
|
|
|
|
|
|
|
switch (role) {
|
2025-12-18 22:25:20 +08:00
|
|
|
case NameRole: {
|
|
|
|
|
if (container == DockerContainer::Awg && !isThirdPartyConfig) {
|
|
|
|
|
return "AmneziaWG Legacy";
|
|
|
|
|
}
|
2026-04-30 14:53:03 +08:00
|
|
|
return ContainerUtils::containerHumanNames().value(container);
|
2025-12-18 22:25:20 +08:00
|
|
|
}
|
|
|
|
|
case DescriptionRole: {
|
|
|
|
|
if (container == DockerContainer::Awg && !isThirdPartyConfig) {
|
2026-04-30 14:53:03 +08:00
|
|
|
return QObject::tr("AmneziaWG is a special protocol from Amnezia based on WireGuard. "
|
|
|
|
|
"It provides high connection speed and ensures stable operation even in the most challenging network conditions.");
|
2025-12-18 22:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
return ContainerUtils::containerDescriptions().value(container);
|
2025-12-18 22:25:20 +08:00
|
|
|
}
|
2026-04-30 14:53:03 +08:00
|
|
|
case DetailedDescriptionRole: return ContainerUtils::containerDetailedDescriptions().value(container);
|
2023-06-21 20:56:00 +09:00
|
|
|
case ConfigRole: {
|
|
|
|
|
if (container == DockerContainer::None) {
|
|
|
|
|
return QJsonObject();
|
2023-06-07 13:17:48 +03:00
|
|
|
}
|
2026-04-30 14:53:03 +08:00
|
|
|
if (m_containers.contains(container)) {
|
|
|
|
|
return m_containers.value(container).toJson();
|
|
|
|
|
}
|
|
|
|
|
return QJsonObject();
|
2023-06-21 20:56:00 +09:00
|
|
|
}
|
2025-12-18 22:25:20 +08:00
|
|
|
case IsThirdPartyConfigRole: return isThirdPartyConfig;
|
2026-04-30 14:53:03 +08:00
|
|
|
case ServiceTypeRole: return ContainerUtils::containerService(container);
|
2023-06-21 20:56:00 +09:00
|
|
|
case DockerContainerRole: return container;
|
2026-04-30 14:53:03 +08:00
|
|
|
case ContainerStringRole: return ContainerUtils::containerToString(container);
|
|
|
|
|
case IsEasySetupContainerRole: return ContainerUtils::isEasySetupContainer(container);
|
|
|
|
|
case EasySetupHeaderRole: return ContainerUtils::easySetupHeader(container);
|
|
|
|
|
case EasySetupDescriptionRole: return ContainerUtils::easySetupDescription(container);
|
|
|
|
|
case EasySetupOrderRole: return ContainerUtils::easySetupOrder(container);
|
2025-12-11 15:18:36 +08:00
|
|
|
case IsInstallationAllowedRole: return ContainersModel::isInstallationAllowed(container);
|
2023-06-21 20:56:00 +09:00
|
|
|
case IsInstalledRole: return m_containers.contains(container);
|
2024-04-01 20:20:02 +07:00
|
|
|
case IsCurrentlyProcessedRole: return container == static_cast<DockerContainer>(m_processedContainerIndex);
|
2026-04-30 14:53:03 +08:00
|
|
|
case IsSupportedRole: return ContainerUtils::isSupportedByCurrentPlatform(container);
|
|
|
|
|
case IsShareableRole: return ContainerUtils::isShareable(container);
|
2026-06-04 15:45:53 +01:00
|
|
|
case IsUnsupportedContainerRole: return ContainerUtils::isUnsupportedContainer(container);
|
2026-04-30 14:53:03 +08:00
|
|
|
case IsVpnContainerRole: return ContainerUtils::containerService(container) == ServiceType::Vpn;
|
|
|
|
|
case IsServiceContainerRole: return ContainerUtils::containerService(container) == ServiceType::Other;
|
|
|
|
|
case IsIpsecRole: return container == DockerContainer::Ipsec;
|
|
|
|
|
case IsDnsRole: return container == DockerContainer::Dns;
|
|
|
|
|
case IsSftpRole: return container == DockerContainer::Sftp;
|
|
|
|
|
case IsTorWebsiteRole: return container == DockerContainer::TorWebSite;
|
|
|
|
|
case IsSocks5ProxyRole: return container == DockerContainer::Socks5Proxy;
|
2026-05-18 14:52:58 +03:00
|
|
|
case IsMtProxyRole: return container == DockerContainer::MtProxy;
|
2026-05-18 15:01:09 +03:00
|
|
|
case IsTelemtRole: return container == DockerContainer::Telemt;
|
2026-04-30 14:53:03 +08:00
|
|
|
case InstallPageOrderRole: return ContainerUtils::installPageOrder(container);
|
2021-09-10 22:19:00 +03:00
|
|
|
}
|
2023-05-12 23:54:31 +08:00
|
|
|
|
2021-09-10 22:19:00 +03:00
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 00:13:08 +09:00
|
|
|
QVariant ContainersModel::data(const int index, int role) const
|
|
|
|
|
{
|
|
|
|
|
QModelIndex modelIndex = this->index(index);
|
|
|
|
|
return data(modelIndex, role);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
void ContainersModel::updateModel(const QMap<DockerContainer, ContainerConfig> &containers)
|
2021-09-10 22:19:00 +03:00
|
|
|
{
|
|
|
|
|
beginResetModel();
|
2026-04-30 14:53:03 +08:00
|
|
|
m_containers = containers;
|
2021-09-10 22:19:00 +03:00
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
void ContainersModel::setProcessedContainerIndex(int index)
|
2023-10-20 20:52:14 +05:00
|
|
|
{
|
2024-04-01 20:20:02 +07:00
|
|
|
m_processedContainerIndex = index;
|
2023-10-20 20:52:14 +05:00
|
|
|
}
|
|
|
|
|
|
2024-04-01 20:20:02 +07:00
|
|
|
QString ContainersModel::getProcessedContainerName()
|
2023-07-13 11:29:26 +09:00
|
|
|
{
|
2026-04-30 14:53:03 +08:00
|
|
|
return ContainerUtils::containerHumanNames().value(static_cast<DockerContainer>(m_processedContainerIndex));
|
2023-07-13 11:29:26 +09:00
|
|
|
}
|
|
|
|
|
|
2023-12-08 13:50:03 +07:00
|
|
|
QJsonObject ContainersModel::getContainerConfig(const int containerIndex)
|
2023-05-27 22:46:41 +08:00
|
|
|
{
|
2023-12-08 13:50:03 +07:00
|
|
|
return qvariant_cast<QJsonObject>(data(index(containerIndex), ConfigRole));
|
2023-06-27 19:07:42 +09:00
|
|
|
}
|
|
|
|
|
|
2024-04-07 01:42:17 +07:00
|
|
|
bool ContainersModel::isSupportedByCurrentPlatform(const int containerIndex)
|
|
|
|
|
{
|
|
|
|
|
return qvariant_cast<bool>(data(index(containerIndex), IsSupportedRole));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ContainersModel::isServiceContainer(const int containerIndex)
|
|
|
|
|
{
|
2026-04-30 14:53:03 +08:00
|
|
|
return qvariant_cast<ServiceType>(data(index(containerIndex), ServiceTypeRole) == ServiceType::Other);
|
2024-04-07 01:42:17 +07:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 16:54:05 +07:00
|
|
|
bool ContainersModel::hasInstalledServices()
|
|
|
|
|
{
|
|
|
|
|
for (const auto &container : m_containers.keys()) {
|
2026-04-30 14:53:03 +08:00
|
|
|
if (ContainerUtils::containerService(container) == ServiceType::Other) {
|
2024-08-20 16:54:05 +07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ContainersModel::hasInstalledProtocols()
|
|
|
|
|
{
|
|
|
|
|
for (const auto &container : m_containers.keys()) {
|
2026-04-30 14:53:03 +08:00
|
|
|
if (ContainerUtils::containerService(container) == ServiceType::Vpn) {
|
2024-08-20 16:54:05 +07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 15:18:36 +08:00
|
|
|
bool ContainersModel::isInstallationAllowed(DockerContainer container)
|
|
|
|
|
{
|
2026-06-04 15:45:53 +01:00
|
|
|
return container != DockerContainer::Awg
|
|
|
|
|
&& !ContainerUtils::isUnsupportedContainer(container);
|
2025-12-11 15:18:36 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-30 14:53:03 +08:00
|
|
|
void ContainersModel::openContainerSettings(int containerIndex)
|
|
|
|
|
{
|
|
|
|
|
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
|
|
|
|
|
|
|
|
|
// This method will be connected to QML signals to open appropriate settings page
|
|
|
|
|
// The actual navigation will be handled in QML based on container type
|
|
|
|
|
// For now, we emit a signal that QML can listen to
|
|
|
|
|
// In a full implementation, this would directly call PageController or emit a signal
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 20:56:00 +09:00
|
|
|
QHash<int, QByteArray> ContainersModel::roleNames() const
|
|
|
|
|
{
|
2023-05-12 11:36:09 +08:00
|
|
|
QHash<int, QByteArray> roles;
|
2023-05-12 23:54:31 +08:00
|
|
|
roles[NameRole] = "name";
|
2023-08-20 13:36:54 +05:00
|
|
|
roles[DescriptionRole] = "description";
|
|
|
|
|
roles[DetailedDescriptionRole] = "detailedDescription";
|
2023-05-12 23:54:31 +08:00
|
|
|
roles[ServiceTypeRole] = "serviceType";
|
2023-05-17 23:28:27 +08:00
|
|
|
roles[DockerContainerRole] = "dockerContainer";
|
2026-04-30 14:53:03 +08:00
|
|
|
roles[ContainerStringRole] = "containerString";
|
2023-07-13 11:29:26 +09:00
|
|
|
roles[ConfigRole] = "config";
|
2025-12-11 15:18:36 +08:00
|
|
|
roles[IsThirdPartyConfigRole] = "isThirdPartyConfig";
|
2023-05-22 00:10:51 +08:00
|
|
|
|
|
|
|
|
roles[IsEasySetupContainerRole] = "isEasySetupContainer";
|
|
|
|
|
roles[EasySetupHeaderRole] = "easySetupHeader";
|
|
|
|
|
roles[EasySetupDescriptionRole] = "easySetupDescription";
|
2023-09-18 21:06:10 +05:00
|
|
|
roles[EasySetupOrderRole] = "easySetupOrder";
|
2023-05-22 00:10:51 +08:00
|
|
|
|
2023-05-12 23:54:31 +08:00
|
|
|
roles[IsInstalledRole] = "isInstalled";
|
2023-06-13 20:03:20 +09:00
|
|
|
roles[IsCurrentlyProcessedRole] = "isCurrentlyProcessed";
|
2023-05-22 00:10:51 +08:00
|
|
|
roles[IsSupportedRole] = "isSupported";
|
2023-08-22 14:37:29 +05:00
|
|
|
roles[IsShareableRole] = "isShareable";
|
2026-06-04 15:45:53 +01:00
|
|
|
roles[IsUnsupportedContainerRole] = "isUnsupportedContainer";
|
2025-12-11 15:18:36 +08:00
|
|
|
roles[IsInstallationAllowedRole] = "isInstallationAllowed";
|
2024-07-02 22:00:28 +02:00
|
|
|
roles[InstallPageOrderRole] = "installPageOrder";
|
2026-04-30 14:53:03 +08:00
|
|
|
|
|
|
|
|
roles[IsVpnContainerRole] = "isVpnContainer";
|
|
|
|
|
roles[IsServiceContainerRole] = "isServiceContainer";
|
|
|
|
|
roles[IsIpsecRole] = "isIpsec";
|
|
|
|
|
roles[IsDnsRole] = "isDns";
|
|
|
|
|
roles[IsSftpRole] = "isSftp";
|
|
|
|
|
roles[IsTorWebsiteRole] = "isTorWebsite";
|
|
|
|
|
roles[IsSocks5ProxyRole] = "isSocks5Proxy";
|
2026-05-18 14:52:58 +03:00
|
|
|
roles[IsMtProxyRole] = "isMtProxy";
|
2026-05-18 15:01:09 +03:00
|
|
|
roles[IsTelemtRole] = "isTelemt";
|
2023-05-12 11:36:09 +08:00
|
|
|
return roles;
|
|
|
|
|
}
|