2023-05-22 22:11:20 +08:00
|
|
|
#ifndef IMPORTCONTROLLER_H
|
|
|
|
|
#define IMPORTCONTROLLER_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
#include "containers/containers_defs.h"
|
2023-07-24 16:31:04 +09:00
|
|
|
#include "core/defs.h"
|
2023-05-22 22:11:20 +08:00
|
|
|
#include "ui/models/containers_model.h"
|
2023-07-24 16:31:04 +09:00
|
|
|
#include "ui/models/servers_model.h"
|
2023-05-22 22:11:20 +08:00
|
|
|
|
|
|
|
|
class ImportController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit ImportController(const QSharedPointer<ServersModel> &serversModel,
|
|
|
|
|
const QSharedPointer<ContainersModel> &containersModel,
|
2023-07-24 16:31:04 +09:00
|
|
|
const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
|
2023-05-22 22:11:20 +08:00
|
|
|
|
|
|
|
|
public slots:
|
2023-06-05 15:49:10 +08:00
|
|
|
void importConfig();
|
2023-08-30 15:10:44 +05:00
|
|
|
void extractConfigFromFile(const QString &fileName);
|
2023-09-01 01:08:44 +03:00
|
|
|
void extractConfigFromData(QString data);
|
2023-06-05 15:49:10 +08:00
|
|
|
void extractConfigFromCode(QString code);
|
2023-07-25 16:56:10 +09:00
|
|
|
bool extractConfigFromQr(const QByteArray &data);
|
2023-06-05 15:49:10 +08:00
|
|
|
QString getConfig();
|
|
|
|
|
QString getConfigFileName();
|
2023-05-22 22:11:20 +08:00
|
|
|
|
2023-08-13 11:28:32 +05:00
|
|
|
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
2023-07-25 16:56:10 +09:00
|
|
|
void startDecodingQr();
|
2023-11-21 22:48:52 +03:00
|
|
|
bool parseQrCodeChunk(const QString &code);
|
2023-08-13 11:28:32 +05:00
|
|
|
|
|
|
|
|
double getQrCodeScanProgressBarValue();
|
|
|
|
|
QString getQrCodeScanProgressString();
|
2023-07-25 16:56:10 +09:00
|
|
|
#endif
|
|
|
|
|
|
2023-11-21 22:48:52 +03:00
|
|
|
#if defined Q_OS_ANDROID
|
|
|
|
|
static bool decodeQrCode(const QString &code);
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
signals:
|
|
|
|
|
void importFinished();
|
2024-02-09 23:23:26 +05:00
|
|
|
void importErrorOccurred(const QString &errorMessage, bool goToPageHome = false);
|
2023-06-13 20:03:20 +09:00
|
|
|
|
2023-07-25 16:56:10 +09:00
|
|
|
void qrDecodingFinished();
|
|
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
private:
|
2023-06-05 15:49:10 +08:00
|
|
|
QJsonObject extractAmneziaConfig(QString &data);
|
|
|
|
|
QJsonObject extractOpenVpnConfig(const QString &data);
|
|
|
|
|
QJsonObject extractWireGuardConfig(const QString &data);
|
2023-05-22 22:11:20 +08:00
|
|
|
|
2023-08-13 11:28:32 +05:00
|
|
|
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
2023-07-25 16:56:10 +09:00
|
|
|
void stopDecodingQr();
|
2023-08-13 11:28:32 +05:00
|
|
|
#endif
|
2023-07-25 16:56:10 +09:00
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
QSharedPointer<ServersModel> m_serversModel;
|
|
|
|
|
QSharedPointer<ContainersModel> m_containersModel;
|
|
|
|
|
std::shared_ptr<Settings> m_settings;
|
|
|
|
|
|
2023-06-05 15:49:10 +08:00
|
|
|
QJsonObject m_config;
|
|
|
|
|
QString m_configFileName;
|
2023-07-25 16:56:10 +09:00
|
|
|
|
2023-08-13 11:28:32 +05:00
|
|
|
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
2023-07-25 16:56:10 +09:00
|
|
|
QMap<int, QByteArray> m_qrCodeChunks;
|
|
|
|
|
bool m_isQrCodeProcessed;
|
|
|
|
|
int m_totalQrCodeChunksCount;
|
|
|
|
|
int m_receivedQrCodeChunksCount;
|
|
|
|
|
#endif
|
2023-05-22 22:11:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // IMPORTCONTROLLER_H
|