2025-02-07 22:22:14 +07:00
|
|
|
#ifndef APICONFIGSCONTROLLER_H
|
|
|
|
|
#define APICONFIGSCONTROLLER_H
|
|
|
|
|
|
2026-04-08 11:21:12 +07:00
|
|
|
#include <QList>
|
2025-02-07 22:22:14 +07:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
#include "configurators/openvpn_configurator.h"
|
2026-04-08 11:21:12 +07:00
|
|
|
#include "ui/models/api/apiBenefitsModel.h"
|
2025-02-15 11:50:42 +07:00
|
|
|
#include "ui/models/api/apiServicesModel.h"
|
2026-04-08 11:21:12 +07:00
|
|
|
#include "ui/models/api/apiSubscriptionPlansModel.h"
|
2025-02-07 22:22:14 +07:00
|
|
|
#include "ui/models/servers_model.h"
|
|
|
|
|
|
|
|
|
|
class ApiConfigsController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2025-02-15 11:50:42 +07:00
|
|
|
ApiConfigsController(const QSharedPointer<ServersModel> &serversModel, const QSharedPointer<ApiServicesModel> &apiServicesModel,
|
2026-04-08 11:21:12 +07:00
|
|
|
const QSharedPointer<ApiSubscriptionPlansModel> &subscriptionPlansModel,
|
|
|
|
|
const QSharedPointer<ApiBenefitsModel> &benefitsModel, const std::shared_ptr<Settings> &settings,
|
|
|
|
|
QObject *parent = nullptr);
|
2025-02-07 22:22:14 +07:00
|
|
|
|
2025-02-12 12:43:11 +07:00
|
|
|
Q_PROPERTY(QList<QString> qrCodes READ getQrCodes NOTIFY vpnKeyExportReady)
|
|
|
|
|
Q_PROPERTY(int qrCodesCount READ getQrCodesCount NOTIFY vpnKeyExportReady)
|
2025-02-22 14:42:09 +07:00
|
|
|
Q_PROPERTY(QString vpnKey READ getVpnKey NOTIFY vpnKeyExportReady)
|
2025-02-12 12:43:11 +07:00
|
|
|
|
2025-02-07 22:22:14 +07:00
|
|
|
public slots:
|
2025-02-10 15:10:59 +07:00
|
|
|
bool exportNativeConfig(const QString &serverCountryCode, const QString &fileName);
|
2025-02-20 13:44:19 +07:00
|
|
|
bool revokeNativeConfig(const QString &serverCountryCode);
|
2025-10-07 19:16:28 +04:00
|
|
|
bool exportVpnKey(const QString &fileName);
|
2025-02-12 12:43:11 +07:00
|
|
|
void prepareVpnKeyExport();
|
2025-02-22 14:42:09 +07:00
|
|
|
void copyVpnKeyToClipboard();
|
2025-02-10 15:10:59 +07:00
|
|
|
|
2025-02-15 11:50:42 +07:00
|
|
|
bool fillAvailableServices();
|
2025-12-29 19:18:03 +08:00
|
|
|
bool importService();
|
2026-04-08 11:21:12 +07:00
|
|
|
bool importPremiumFromAppStore(const QString &storeProductId);
|
|
|
|
|
bool restoreServiceFromAppStore();
|
|
|
|
|
bool importFreeFromGateway();
|
|
|
|
|
bool importTrialFromGateway(const QString &email);
|
2025-02-15 11:50:42 +07:00
|
|
|
bool updateServiceFromGateway(const int serverIndex, const QString &newCountryCode, const QString &newCountryName,
|
|
|
|
|
bool reloadServiceConfig = false);
|
|
|
|
|
bool updateServiceFromTelegram(const int serverIndex);
|
2025-10-03 14:45:12 +08:00
|
|
|
bool deactivateDevice(const bool isRemoveEvent);
|
2025-02-28 18:17:43 +03:00
|
|
|
bool deactivateExternalDevice(const QString &uuid, const QString &serverCountryCode);
|
2025-02-15 11:50:42 +07:00
|
|
|
|
|
|
|
|
bool isConfigValid();
|
|
|
|
|
|
2025-07-03 09:58:23 +08:00
|
|
|
void setCurrentProtocol(const QString &protocolName);
|
|
|
|
|
bool isVlessProtocol();
|
|
|
|
|
|
2025-02-10 15:10:59 +07:00
|
|
|
signals:
|
|
|
|
|
void errorOccurred(ErrorCode errorCode);
|
2026-04-08 11:21:12 +07:00
|
|
|
void trialEmailError(const QString &message);
|
2026-03-24 17:45:02 +03:00
|
|
|
void subscriptionExpiredOnServer();
|
2026-03-25 14:48:32 +03:00
|
|
|
void subscriptionRefreshNeeded();
|
2025-02-15 11:50:42 +07:00
|
|
|
|
2026-04-08 11:21:12 +07:00
|
|
|
void installServerFromApiFinished(const QString &message, int preferredDefaultServerIndex = -1);
|
2025-02-15 11:50:42 +07:00
|
|
|
void changeApiCountryFinished(const QString &message);
|
|
|
|
|
void reloadServerFromApiFinished(const QString &message);
|
|
|
|
|
void updateServerFromApiFinished();
|
|
|
|
|
|
2025-02-12 12:43:11 +07:00
|
|
|
void vpnKeyExportReady();
|
2025-02-07 22:22:14 +07:00
|
|
|
|
|
|
|
|
private:
|
2025-02-12 12:43:11 +07:00
|
|
|
QList<QString> getQrCodes();
|
|
|
|
|
int getQrCodesCount();
|
2025-02-22 14:42:09 +07:00
|
|
|
QString getVpnKey();
|
2025-02-12 12:43:11 +07:00
|
|
|
|
2025-12-29 19:18:03 +08:00
|
|
|
ErrorCode executeRequest(const QString &endpoint, const QJsonObject &apiPayload, QByteArray &responseBody, bool isTestPurchase = false);
|
2026-04-08 11:21:12 +07:00
|
|
|
ErrorCode importServiceFromBilling(const QByteArray &responseBody, const bool isTestPurchase, int &duplicateServerIndex);
|
2025-07-03 09:58:23 +08:00
|
|
|
|
2025-02-12 12:43:11 +07:00
|
|
|
QList<QString> m_qrCodes;
|
2025-02-22 14:42:09 +07:00
|
|
|
QString m_vpnKey;
|
2025-02-12 12:43:11 +07:00
|
|
|
|
2025-02-07 22:22:14 +07:00
|
|
|
QSharedPointer<ServersModel> m_serversModel;
|
2025-02-15 11:50:42 +07:00
|
|
|
QSharedPointer<ApiServicesModel> m_apiServicesModel;
|
2025-02-07 22:22:14 +07:00
|
|
|
std::shared_ptr<Settings> m_settings;
|
2026-04-08 11:21:12 +07:00
|
|
|
|
|
|
|
|
QSharedPointer<ApiSubscriptionPlansModel> m_subscriptionPlansModel;
|
|
|
|
|
QSharedPointer<ApiBenefitsModel> m_benefitsModel;
|
2025-02-07 22:22:14 +07:00
|
|
|
};
|
|
|
|
|
|
2026-04-08 11:21:12 +07:00
|
|
|
#endif
|