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

136 lines
3.8 KiB
C++
Raw Normal View History

2020-11-23 16:20:25 +03:00
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
2021-01-09 19:55:16 +03:00
#include <QLabel>
2021-02-25 21:16:00 +03:00
#include <QListWidget>
2020-11-23 16:20:25 +03:00
#include <QMainWindow>
2021-01-09 19:55:16 +03:00
#include <QProgressBar>
#include <QPushButton>
2021-02-24 21:58:32 +03:00
#include <QRegExpValidator>
2021-04-20 02:09:47 +03:00
#include <QStack>
2021-01-26 15:01:15 +03:00
#include <QStringListModel>
2021-01-09 19:55:16 +03:00
#include <QSystemTrayIcon>
2020-11-23 16:20:25 +03:00
2021-03-17 03:45:38 +03:00
#include "3rd/QRCodeGenerator/QRCodeGenerator.h"
2021-01-03 21:18:20 +03:00
#include "framelesswindow.h"
2021-01-06 17:12:24 +03:00
#include "protocols/vpnprotocol.h"
2020-12-26 15:03:51 +03:00
2021-01-26 15:01:15 +03:00
#include "settings.h"
2020-12-26 15:03:51 +03:00
class VpnConnection;
2020-11-23 16:20:25 +03:00
namespace Ui {
class MainWindow;
}
/**
* @brief The MainWindow class - Main application window
*/
2021-01-03 23:55:04 +03:00
#ifdef Q_OS_WIN
2021-01-03 21:18:20 +03:00
class MainWindow : public CFramelessWindow
2021-01-03 23:55:04 +03:00
#else
class MainWindow : public QMainWindow
#endif
2020-11-23 16:20:25 +03:00
{
Q_OBJECT
public:
2020-12-04 00:45:21 +03:00
explicit MainWindow(QWidget *parent = nullptr);
2020-11-23 16:20:25 +03:00
~MainWindow();
2021-04-26 22:54:31 +03:00
enum Page {Start, NewServer, NewServer_2, Vpn, GeneralSettings, AppSettings, NetworkSettings,
2021-04-20 02:09:47 +03:00
ServerSettings, ServerVpnProtocols, ServersList, ShareConnection, Sites,
OpenVpnSettings, ShadowSocksSettings, CloakSettings};
2021-01-09 19:55:16 +03:00
Q_ENUM(Page)
2020-11-23 16:20:25 +03:00
private slots:
2020-12-30 17:03:05 +03:00
void onBytesChanged(quint64 receivedBytes, quint64 sentBytes);
void onConnectionStateChanged(VpnProtocol::ConnectionState state);
2021-01-08 16:51:58 +03:00
void onVpnProtocolError(amnezia::ErrorCode errorCode);
2021-01-09 19:55:16 +03:00
void onPushButtonConnectClicked(bool checked);
2021-04-26 22:54:31 +03:00
void onPushButtonNewServerConnect(bool);
void onPushButtonNewServerConnectConfigure(bool);
void onPushButtonNewServerImport(bool);
2021-01-09 19:55:16 +03:00
void onPushButtonReinstallServer(bool);
void onPushButtonClearServer(bool);
void onPushButtonForgetServer(bool);
2021-01-26 15:01:15 +03:00
void onPushButtonAddCustomSitesClicked();
2021-02-25 21:16:00 +03:00
void onPushButtonDeleteCustomSiteClicked(const QString &siteToDelete);
2021-01-26 15:01:15 +03:00
2021-01-09 19:55:16 +03:00
void onTrayActionConnect(); // connect from context menu
void setTrayState(VpnProtocol::ConnectionState state);
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
void onConnect();
void onDisconnect();
2020-12-16 06:02:22 +03:00
2021-01-03 19:14:54 +03:00
2020-11-23 16:20:25 +03:00
private:
2021-01-09 19:55:16 +03:00
void goToPage(Page page, bool reset = true, bool slide = true);
2021-04-20 02:09:47 +03:00
void closePage();
2021-01-09 19:55:16 +03:00
QWidget *getPageWidget(Page page);
Page currentPage();
2021-04-26 22:54:31 +03:00
bool installServer(ServerCredentials credentials, QList<DockerContainer> containers, QJsonArray configs,
QWidget *page, QProgressBar *progress, QPushButton *button, QLabel *info);
2021-01-09 19:55:16 +03:00
void setupTray();
void setTrayIcon(const QString &iconPath);
void setupUiConnections();
2021-04-26 22:54:31 +03:00
void setupProtocolsPageConnections();
void setupNewServerPageConnections();
2021-04-20 02:09:47 +03:00
2021-02-18 15:00:41 +03:00
void updateSettings();
2021-04-26 22:54:31 +03:00
void updateServersPage();
void updateShareCodePage();
void updateOpenVpnPage(const QJsonObject &openvpnConfig);
2021-01-26 15:01:15 +03:00
2021-02-25 21:16:00 +03:00
void makeSitesListItem(QListWidget* listWidget, const QString &address);
2021-04-20 02:09:47 +03:00
void makeServersListItem(QListWidget* listWidget, const QJsonObject &server, bool isDefault, int index);
2020-12-16 06:02:22 +03:00
2021-03-17 03:45:38 +03:00
void updateQRCodeImage(const QString &text, QLabel *label);
2021-04-26 22:54:31 +03:00
2021-03-17 03:45:38 +03:00
private:
2020-11-23 16:20:25 +03:00
Ui::MainWindow *ui;
2020-12-26 15:03:51 +03:00
VpnConnection* m_vpnConnection;
2021-01-26 15:01:15 +03:00
Settings m_settings;
2021-01-03 19:14:54 +03:00
2021-01-09 19:55:16 +03:00
QAction* m_trayActionConnect;
QAction* m_trayActionDisconnect;
QSystemTrayIcon m_tray;
QMenu* m_menu;
2021-02-24 21:58:32 +03:00
QRegExpValidator m_ipAddressValidator;
2021-03-17 03:45:38 +03:00
QRegExpValidator m_ipAddressPortValidator;
CQR_Encode m_qrEncode;
2021-01-26 15:01:15 +03:00
2021-01-03 19:14:54 +03:00
bool canMove = false;
QPoint offset;
bool eventFilter(QObject *obj, QEvent *event) override;
void keyPressEvent(QKeyEvent* event) override;
2021-01-09 19:55:16 +03:00
void closeEvent(QCloseEvent *event) override;
2021-01-16 21:04:16 +03:00
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
2021-01-09 19:55:16 +03:00
const QString ConnectedTrayIconName = "active.png";
const QString DisconnectedTrayIconName = "default.png";
const QString ErrorTrayIconName = "error.png";
2021-04-20 02:09:47 +03:00
QStack<Page> pagesStack;
int selectedServerIndex = -1; // server index to use when proto settings page opened
2021-04-26 22:54:31 +03:00
ServerCredentials installCredentials; // used to save cred between pages new_server and new_server_2
2020-11-23 16:20:25 +03:00
};
#endif // MAINWINDOW_H