Files
amnezia-client/client/ui/uilogic.h
T

190 lines
5.4 KiB
C++
Raw Normal View History

2021-07-28 16:13:29 +07:00
#ifndef UILOGIC_H
#define UILOGIC_H
#include <QRegularExpressionValidator>
2021-07-28 16:13:29 +07:00
#include <QQmlEngine>
2021-08-09 00:41:52 +07:00
#include <functional>
#include <QKeyEvent>
2021-10-26 12:59:20 +03:00
#include <QThread>
2021-07-28 16:13:29 +07:00
2022-08-29 01:32:42 +03:00
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
2021-09-09 20:15:44 +03:00
#include "property_helper.h"
2021-09-03 20:17:13 +03:00
#include "pages.h"
2021-07-28 16:13:29 +07:00
#include "protocols/vpnprotocol.h"
2021-09-09 20:15:44 +03:00
#include "containers/containers_defs.h"
2021-09-16 16:19:14 +03:00
2021-09-10 22:19:00 +03:00
#include "models/containers_model.h"
2021-09-16 16:19:14 +03:00
#include "models/protocols_model.h"
2021-07-28 16:13:29 +07:00
2021-11-26 17:43:02 +03:00
#include "notificationhandler.h"
2022-08-25 17:35:28 +03:00
class Settings;
class VpnConfigurator;
class ServerController;
2021-07-28 16:13:29 +07:00
2022-08-29 01:32:42 +03:00
class PageLogicBase;
2021-07-28 16:13:29 +07:00
2021-09-03 20:17:13 +03:00
class AppSettingsLogic;
class GeneralSettingsLogic;
class NetworkSettingsLogic;
2021-09-07 11:48:25 +03:00
class NewServerProtocolsLogic;
2021-12-20 02:29:23 +03:00
class QrDecoderLogic;
2021-09-20 21:51:28 +03:00
class ServerConfiguringProgressLogic;
2021-09-03 20:17:13 +03:00
class ServerListLogic;
class ServerSettingsLogic;
2021-09-07 19:26:58 +03:00
class ServerContainersLogic;
2021-09-03 20:17:13 +03:00
class ShareConnectionLogic;
class SitesLogic;
2021-09-04 12:53:58 +03:00
class StartPageLogic;
2022-08-29 01:32:42 +03:00
class ViewConfigLogic;
2021-09-03 20:17:13 +03:00
class VpnLogic;
class WizardLogic;
2023-02-20 09:46:50 +03:00
class AdvancedServerSettingsLogic;
2021-09-03 20:17:13 +03:00
2021-09-16 16:19:14 +03:00
class PageProtocolLogicBase;
2021-09-06 13:41:45 +03:00
class OpenVpnLogic;
class ShadowSocksLogic;
class CloakLogic;
2021-07-28 16:13:29 +07:00
2021-09-24 13:14:35 +03:00
class OtherProtocolsLogic;
2021-09-06 13:41:45 +03:00
class VpnConnection;
2021-09-03 20:17:13 +03:00
2021-08-09 00:41:52 +07:00
2021-07-28 16:13:29 +07:00
class UiLogic : public QObject
{
Q_OBJECT
2021-09-03 20:17:13 +03:00
2021-09-16 19:49:50 +03:00
AUTO_PROPERTY(bool, pageEnabled)
2021-11-06 13:47:52 +03:00
AUTO_PROPERTY(int, pagesStackDepth)
AUTO_PROPERTY(int, currentPageValue)
2023-02-20 09:46:50 +03:00
AUTO_PROPERTY(QString, popupWarningText)
2021-09-16 19:49:50 +03:00
2021-09-10 22:19:00 +03:00
READONLY_PROPERTY(QObject *, containersModel)
2021-09-16 16:19:14 +03:00
READONLY_PROPERTY(QObject *, protocolsModel)
2021-09-09 20:15:44 +03:00
2021-07-28 16:13:29 +07:00
public:
2022-08-25 17:35:28 +03:00
explicit UiLogic(std::shared_ptr<Settings> settings, std::shared_ptr<VpnConfigurator> configurator,
std::shared_ptr<ServerController> serverController, QObject *parent = nullptr);
2021-08-09 00:41:52 +07:00
~UiLogic();
void showOnStartup();
2021-07-28 16:13:29 +07:00
2022-08-25 12:47:02 +03:00
friend class PageLogicBase;
2021-09-03 20:17:13 +03:00
friend class AppSettingsLogic;
friend class GeneralSettingsLogic;
friend class NetworkSettingsLogic;
2021-09-20 21:51:28 +03:00
friend class ServerConfiguringProgressLogic;
2021-09-07 11:48:25 +03:00
friend class NewServerProtocolsLogic;
2021-09-03 20:17:13 +03:00
friend class ServerListLogic;
friend class ServerSettingsLogic;
2021-09-07 19:26:58 +03:00
friend class ServerContainersLogic;
2021-09-03 20:17:13 +03:00
friend class ShareConnectionLogic;
friend class SitesLogic;
2021-09-04 12:53:58 +03:00
friend class StartPageLogic;
2022-08-29 01:32:42 +03:00
friend class ViewConfigLogic;
2021-09-03 20:17:13 +03:00
friend class VpnLogic;
friend class WizardLogic;
2023-02-20 09:46:50 +03:00
friend class AdvancedServerSettingsLogic;
2021-09-03 20:17:13 +03:00
2021-09-16 16:19:14 +03:00
friend class PageProtocolLogicBase;
2021-09-06 13:41:45 +03:00
friend class OpenVpnLogic;
friend class ShadowSocksLogic;
friend class CloakLogic;
2021-09-24 13:14:35 +03:00
friend class OtherProtocolsLogic;
2021-11-06 13:47:52 +03:00
Q_INVOKABLE virtual void onUpdatePage() {} // UiLogic is set as logic class for some qml pages
2021-11-17 15:01:48 +03:00
Q_INVOKABLE void onUpdateAllPages();
2021-11-06 13:47:52 +03:00
2021-07-28 16:13:29 +07:00
Q_INVOKABLE void initalizeUiLogic();
2021-09-07 21:01:56 +03:00
Q_INVOKABLE void onCloseWindow();
2021-09-03 20:17:13 +03:00
2021-09-10 22:19:00 +03:00
Q_INVOKABLE QString containerName(int container);
Q_INVOKABLE QString containerDesc(int container);
2021-11-17 15:01:48 +03:00
Q_INVOKABLE void onGotoCurrentProtocolsPage();
Q_INVOKABLE void keyPressEvent(Qt::Key key);
Q_INVOKABLE void saveTextFile(const QString& desc, const QString &suggestedName, QString ext, const QString& data);
2022-02-01 19:48:59 +03:00
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
2021-11-15 18:17:28 +03:00
Q_INVOKABLE void copyToClipboard(const QString& text);
2021-09-03 20:17:13 +03:00
2023-02-22 10:01:43 +03:00
Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials);
2023-02-20 09:46:50 +03:00
2022-07-13 16:08:55 +06:00
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
2021-07-28 16:13:29 +07:00
signals:
2021-09-19 14:31:38 +03:00
void goToPage(PageEnumNS::Page page, bool reset = true, bool slide = true);
void goToProtocolPage(Proto protocol, bool reset = true, bool slide = true);
void goToShareProtocolPage(Proto protocol, bool reset = true, bool slide = true);
2021-11-06 13:47:52 +03:00
2021-07-28 16:13:29 +07:00
void closePage();
2021-09-19 14:31:38 +03:00
void setStartPage(PageEnumNS::Page page, bool slide = true);
2021-08-09 00:41:52 +07:00
void showPublicKeyWarning();
void showConnectErrorDialog();
void show();
void hide();
2021-11-17 20:24:45 +03:00
void raise();
2022-02-04 17:49:48 +03:00
void toggleLogPanel();
2023-02-20 09:46:50 +03:00
void showWarningMessage(QString message);
2021-07-28 16:13:29 +07:00
2021-08-09 00:41:52 +07:00
private slots:
2021-09-24 13:14:35 +03:00
// containers - INOUT arg
void installServer(QMap<DockerContainer, QJsonObject> &containers);
2021-07-28 16:13:29 +07:00
private:
2021-08-09 00:41:52 +07:00
PageEnumNS::Page currentPage();
2023-02-20 09:46:50 +03:00
bool isContainerAlreadyAddedToGui(DockerContainer container, const ServerCredentials &selectedServerCredentials);
2021-09-06 11:44:03 +03:00
public:
Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p);
2021-09-16 16:19:14 +03:00
2021-11-17 20:24:45 +03:00
QObject *qmlRoot() const;
void setQmlRoot(QObject *newQmlRoot);
2021-11-28 17:28:25 +03:00
NotificationHandler *notificationHandler() const;
2022-08-29 01:32:42 +03:00
void setQmlContextProperty(PageLogicBase *logic);
void registerPagesLogic();
template<typename T>
void registerPageLogic()
{
T* logic = new T(this);
m_logicMap[std::type_index(typeid(T))] = logic;
setQmlContextProperty(logic);
}
template<typename T>
T* pageLogic()
{
return static_cast<T *>(m_logicMap.value(std::type_index(typeid(T))));
}
2021-07-28 16:13:29 +07:00
private:
2021-11-17 20:24:45 +03:00
QObject *m_qmlRoot{nullptr};
2022-08-29 01:32:42 +03:00
QMap<std::type_index, PageLogicBase*> m_logicMap;
2021-09-06 11:44:03 +03:00
QMap<Proto, PageProtocolLogicBase *> m_protocolLogicMap;
2021-09-16 16:19:14 +03:00
2021-07-28 16:13:29 +07:00
VpnConnection* m_vpnConnection;
2021-10-26 12:59:20 +03:00
QThread m_vpnConnectionThread;
2022-08-25 17:35:28 +03:00
2022-08-25 12:47:02 +03:00
std::shared_ptr<Settings> m_settings;
2022-08-25 17:35:28 +03:00
std::shared_ptr<VpnConfigurator> m_configurator;
std::shared_ptr<ServerController> m_serverController;
2021-07-28 16:13:29 +07:00
2021-11-28 17:28:25 +03:00
NotificationHandler* m_notificationHandler;
2021-11-26 17:43:02 +03:00
2023-02-20 09:46:50 +03:00
int m_selectedServerIndex = -1; // server index to use when proto settings page opened
DockerContainer m_selectedDockerContainer; // same
ServerCredentials m_installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard
2021-07-28 16:13:29 +07:00
};
#endif // UILOGIC_H