Merge branch 'dev' into qt_migration
This commit is contained in:
commit
442e7eb015
127 changed files with 5657 additions and 1619 deletions
|
|
@ -4,7 +4,6 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHostInfo>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QJsonDocument>
|
||||
|
|
@ -16,9 +15,11 @@
|
|||
#include <QSysInfo>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QRegularExpression>
|
||||
#include <QQmlFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QMetaObject>
|
||||
|
||||
#include "amnezia_application.h"
|
||||
|
||||
#include "configurators/cloak_configurator.h"
|
||||
#include "configurators/vpn_configurator.h"
|
||||
#include "configurators/openvpn_configurator.h"
|
||||
|
|
@ -62,6 +63,7 @@
|
|||
#include "pages_logic/ShareConnectionLogic.h"
|
||||
#include "pages_logic/SitesLogic.h"
|
||||
#include "pages_logic/StartPageLogic.h"
|
||||
#include "pages_logic/ViewConfigLogic.h"
|
||||
#include "pages_logic/VpnLogic.h"
|
||||
#include "pages_logic/WizardLogic.h"
|
||||
|
||||
|
|
@ -74,30 +76,20 @@
|
|||
using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
||||
UiLogic::UiLogic(QObject *parent) :
|
||||
UiLogic::UiLogic(std::shared_ptr<Settings> settings, std::shared_ptr<VpnConfigurator> configurator,
|
||||
std::shared_ptr<ServerController> serverController,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_dialogConnectErrorText{}
|
||||
m_settings(settings),
|
||||
m_configurator(configurator),
|
||||
m_serverController(serverController)
|
||||
{
|
||||
m_containersModel = new ContainersModel(this);
|
||||
m_protocolsModel = new ProtocolsModel(this);
|
||||
m_vpnConnection = new VpnConnection();
|
||||
m_containersModel = new ContainersModel(settings, this);
|
||||
m_protocolsModel = new ProtocolsModel(settings, this);
|
||||
m_vpnConnection = new VpnConnection(settings, configurator, serverController);
|
||||
m_vpnConnection->moveToThread(&m_vpnConnectionThread);
|
||||
m_vpnConnectionThread.start();
|
||||
|
||||
m_appSettingsLogic = new AppSettingsLogic(this);
|
||||
m_generalSettingsLogic = new GeneralSettingsLogic(this);
|
||||
m_networkSettingsLogic = new NetworkSettingsLogic(this);
|
||||
m_newServerProtocolsLogic = new NewServerProtocolsLogic(this);
|
||||
m_qrDecoderLogic = new QrDecoderLogic(this);
|
||||
m_serverConfiguringProgressLogic = new ServerConfiguringProgressLogic(this);
|
||||
m_serverListLogic = new ServerListLogic(this);
|
||||
m_serverSettingsLogic = new ServerSettingsLogic(this);
|
||||
m_serverprotocolsLogic = new ServerContainersLogic(this);
|
||||
m_shareConnectionLogic = new ShareConnectionLogic(this);
|
||||
m_sitesLogic = new SitesLogic(this);
|
||||
m_startPageLogic = new StartPageLogic(this);
|
||||
m_vpnLogic = new VpnLogic(this);
|
||||
m_wizardLogic = new WizardLogic(this);
|
||||
|
||||
m_protocolLogicMap.insert(Proto::OpenVpn, new OpenVpnLogic(this));
|
||||
m_protocolLogicMap.insert(Proto::ShadowSocks, new ShadowSocksLogic(this));
|
||||
|
|
@ -139,55 +131,40 @@ void UiLogic::initalizeUiLogic()
|
|||
#ifdef Q_OS_ANDROID
|
||||
connect(AndroidController::instance(), &AndroidController::initialized, [this](bool status, bool connected, const QDateTime& connectionDate) {
|
||||
if (connected) {
|
||||
vpnLogic()->onConnectionStateChanged(VpnProtocol::Connected);
|
||||
pageLogic<VpnLogic>()->onConnectionStateChanged(VpnProtocol::Connected);
|
||||
}
|
||||
});
|
||||
if (!AndroidController::instance()->initialize()) {
|
||||
qDebug() << QString("Init failed") ;
|
||||
qCritical() << QString("Init failed") ;
|
||||
emit VpnProtocol::Error;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
qDebug() << "UiLogic::initalizeUiLogic()";
|
||||
|
||||
m_notificationHandler = NotificationHandler::create(qmlRoot());
|
||||
|
||||
connect(m_vpnConnection, &VpnConnection::connectionStateChanged, m_notificationHandler, &NotificationHandler::setConnectionState);
|
||||
connect(m_notificationHandler, &NotificationHandler::raiseRequested, this, &UiLogic::raise);
|
||||
connect(m_notificationHandler, &NotificationHandler::connectRequested, vpnLogic(), &VpnLogic::onConnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::disconnectRequested, vpnLogic(), &VpnLogic::onDisconnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::connectRequested, pageLogic<VpnLogic>(), &VpnLogic::onConnect);
|
||||
connect(m_notificationHandler, &NotificationHandler::disconnectRequested, pageLogic<VpnLogic>(), &VpnLogic::onDisconnect);
|
||||
|
||||
if (m_settings.serversCount() > 0) {
|
||||
if (m_settings.defaultServerIndex() < 0) m_settings.setDefaultServer(0);
|
||||
if (m_settings->serversCount() > 0) {
|
||||
if (m_settings->defaultServerIndex() < 0) m_settings->setDefaultServer(0);
|
||||
emit goToPage(Page::Vpn, true, false);
|
||||
}
|
||||
else {
|
||||
emit goToPage(Page::Start, true, false);
|
||||
}
|
||||
|
||||
selectedServerIndex = m_settings.defaultServerIndex();
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
|
||||
qInfo().noquote() << QString("Started %1 version %2").arg(APPLICATION_NAME).arg(APP_VERSION);
|
||||
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName()).arg(QSysInfo::currentCpuArchitecture());
|
||||
}
|
||||
|
||||
QString UiLogic::getDialogConnectErrorText() const
|
||||
{
|
||||
return m_dialogConnectErrorText;
|
||||
}
|
||||
|
||||
void UiLogic::setDialogConnectErrorText(const QString &dialogConnectErrorText)
|
||||
{
|
||||
if (m_dialogConnectErrorText != dialogConnectErrorText) {
|
||||
m_dialogConnectErrorText = dialogConnectErrorText;
|
||||
emit dialogConnectErrorTextChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void UiLogic::showOnStartup()
|
||||
{
|
||||
if (! m_settings.isStartMinimized()) {
|
||||
if (! m_settings->isStartMinimized()) {
|
||||
emit show();
|
||||
}
|
||||
else {
|
||||
|
|
@ -201,21 +178,7 @@ void UiLogic::showOnStartup()
|
|||
|
||||
void UiLogic::onUpdateAllPages()
|
||||
{
|
||||
for (PageLogicBase *logic : {
|
||||
(PageLogicBase *) m_appSettingsLogic,
|
||||
(PageLogicBase *) m_generalSettingsLogic,
|
||||
(PageLogicBase *) m_networkSettingsLogic,
|
||||
(PageLogicBase *) m_serverConfiguringProgressLogic,
|
||||
(PageLogicBase *) m_newServerProtocolsLogic,
|
||||
(PageLogicBase *) m_serverListLogic,
|
||||
(PageLogicBase *) m_serverSettingsLogic,
|
||||
(PageLogicBase *) m_serverprotocolsLogic,
|
||||
(PageLogicBase *) m_shareConnectionLogic,
|
||||
(PageLogicBase *) m_sitesLogic,
|
||||
(PageLogicBase *) m_startPageLogic,
|
||||
(PageLogicBase *) m_vpnLogic,
|
||||
(PageLogicBase *) m_wizardLogic
|
||||
}) {
|
||||
for (auto logic : m_logicMap) {
|
||||
logic->onUpdatePage();
|
||||
}
|
||||
}
|
||||
|
|
@ -235,30 +198,29 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
|||
qApp->quit();
|
||||
break;
|
||||
case Qt::Key_H:
|
||||
selectedServerIndex = m_settings.defaultServerIndex();
|
||||
selectedDockerContainer = m_settings.defaultContainer(selectedServerIndex);
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex);
|
||||
|
||||
//updateSharingPage(selectedServerIndex, m_settings.serverCredentials(selectedServerIndex), selectedDockerContainer);
|
||||
//updateSharingPage(selectedServerIndex, m_settings->serverCredentials(selectedServerIndex), selectedDockerContainer);
|
||||
emit goToPage(Page::ShareConnection);
|
||||
break;
|
||||
#endif
|
||||
case Qt::Key_C:
|
||||
qDebug().noquote() << "Def server" << m_settings.defaultServerIndex() << m_settings.defaultContainerName(m_settings.defaultServerIndex());
|
||||
//qDebug().noquote() << QJsonDocument(m_settings.containerConfig(m_settings.defaultServerIndex(), m_settings.defaultContainer(m_settings.defaultServerIndex()))).toJson();
|
||||
qDebug().noquote() << QJsonDocument(m_settings.defaultServer()).toJson();
|
||||
qDebug().noquote() << "Def server" << m_settings->defaultServerIndex() << m_settings->defaultContainerName(m_settings->defaultServerIndex());
|
||||
qDebug().noquote() << QJsonDocument(m_settings->defaultServer()).toJson();
|
||||
break;
|
||||
case Qt::Key_A:
|
||||
emit goToPage(Page::Start);
|
||||
break;
|
||||
case Qt::Key_S:
|
||||
selectedServerIndex = m_settings.defaultServerIndex();
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
emit goToPage(Page::ServerSettings);
|
||||
break;
|
||||
case Qt::Key_P:
|
||||
onGotoCurrentProtocolsPage();
|
||||
break;
|
||||
case Qt::Key_T:
|
||||
SshConfigurator::openSshTerminal(m_settings.serverCredentials(m_settings.defaultServerIndex()));
|
||||
m_configurator->sshConfigurator->openSshTerminal(m_settings->serverCredentials(m_settings->defaultServerIndex()));
|
||||
break;
|
||||
case Qt::Key_Escape:
|
||||
case Qt::Key_Back:
|
||||
|
|
@ -280,7 +242,7 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
|||
|
||||
void UiLogic::onCloseWindow()
|
||||
{
|
||||
if (m_settings.serversCount() == 0) qApp->quit();
|
||||
if (m_settings->serversCount() == 0) qApp->quit();
|
||||
else {
|
||||
hide();
|
||||
}
|
||||
|
|
@ -299,8 +261,8 @@ QString UiLogic::containerDesc(int container)
|
|||
|
||||
void UiLogic::onGotoCurrentProtocolsPage()
|
||||
{
|
||||
selectedServerIndex = m_settings.defaultServerIndex();
|
||||
selectedDockerContainer = m_settings.defaultContainer(selectedServerIndex);
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex);
|
||||
emit goToPage(Page::ServerContainers);
|
||||
}
|
||||
|
||||
|
|
@ -344,34 +306,34 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
|||
|
||||
PageFunc page_new_server_configuring;
|
||||
page_new_server_configuring.setEnabledFunc = [this] (bool enabled) -> void {
|
||||
serverConfiguringProgressLogic()->set_pageEnabled(enabled);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_pageEnabled(enabled);
|
||||
};
|
||||
ButtonFunc no_button;
|
||||
LabelFunc label_new_server_configuring_wait_info;
|
||||
label_new_server_configuring_wait_info.setTextFunc = [this] (const QString& text) -> void {
|
||||
serverConfiguringProgressLogic()->set_labelWaitInfoText(text);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_labelWaitInfoText(text);
|
||||
};
|
||||
label_new_server_configuring_wait_info.setVisibleFunc = [this] (bool visible) ->void {
|
||||
serverConfiguringProgressLogic()->set_labelWaitInfoVisible(visible);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_labelWaitInfoVisible(visible);
|
||||
};
|
||||
ProgressFunc progressBar_new_server_configuring;
|
||||
progressBar_new_server_configuring.setVisibleFunc = [this] (bool visible) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarVisible(visible);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarVisible(visible);
|
||||
};
|
||||
progressBar_new_server_configuring.setValueFunc = [this] (int value) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarValue(value);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarValue(value);
|
||||
};
|
||||
progressBar_new_server_configuring.getValueFunc = [this] (void) -> int {
|
||||
return serverConfiguringProgressLogic()->progressBarValue();
|
||||
return pageLogic<ServerConfiguringProgressLogic>()->progressBarValue();
|
||||
};
|
||||
progressBar_new_server_configuring.getMaximiumFunc = [this] (void) -> int {
|
||||
return serverConfiguringProgressLogic()->progressBarMaximium();
|
||||
return pageLogic<ServerConfiguringProgressLogic>()->progressBarMaximium();
|
||||
};
|
||||
progressBar_new_server_configuring.setTextVisibleFunc = [this] (bool visible) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarTextVisible(visible);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarTextVisible(visible);
|
||||
};
|
||||
progressBar_new_server_configuring.setTextFunc = [this] (const QString& text) ->void {
|
||||
serverConfiguringProgressLogic()->set_progressBarText(text);
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_progressBarText(text);
|
||||
};
|
||||
bool ok = installContainers(installCredentials, containers,
|
||||
page_new_server_configuring,
|
||||
|
|
@ -385,7 +347,7 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
|||
server.insert(config_key::userName, installCredentials.userName);
|
||||
server.insert(config_key::password, installCredentials.password);
|
||||
server.insert(config_key::port, installCredentials.port);
|
||||
server.insert(config_key::description, m_settings.nextAvailableServerName());
|
||||
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
||||
|
||||
QJsonArray containerConfigs;
|
||||
for (const QJsonObject &cfg : containers) {
|
||||
|
|
@ -394,8 +356,8 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
|||
server.insert(config_key::containers, containerConfigs);
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey()));
|
||||
|
||||
m_settings.addServer(server);
|
||||
m_settings.setDefaultServer(m_settings.serversCount() - 1);
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
onUpdateAllPages();
|
||||
|
||||
emit setStartPage(Page::Vpn);
|
||||
|
|
@ -442,9 +404,9 @@ bool UiLogic::installContainers(ServerCredentials credentials,
|
|||
progress.setTextVisibleFunc(true);
|
||||
progress.setTextFunc(QString("Installing %1 %2 %3").arg(cnt+1).arg(tr("of")).arg(containers.size()));
|
||||
|
||||
ErrorCode e = ServerController::setupContainer(credentials, i.key(), i.value());
|
||||
ErrorCode e = m_serverController->setupContainer(credentials, i.key(), i.value());
|
||||
qDebug() << "Setup server finished with code" << e;
|
||||
ServerController::disconnectFromHost(credentials);
|
||||
m_serverController->disconnectFromHost(credentials);
|
||||
|
||||
if (e) {
|
||||
if (page.setEnabledFunc) {
|
||||
|
|
@ -587,7 +549,7 @@ PageProtocolLogicBase *UiLogic::protocolLogic(Proto p)
|
|||
PageProtocolLogicBase *logic = m_protocolLogicMap.value(p);
|
||||
if (logic) return logic;
|
||||
else {
|
||||
qDebug() << "UiLogic::protocolLogic Warning: logic missing for" << p;
|
||||
qCritical() << "UiLogic::protocolLogic Warning: logic missing for" << p;
|
||||
return new PageProtocolLogicBase(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -607,6 +569,11 @@ NotificationHandler *UiLogic::notificationHandler() const
|
|||
return m_notificationHandler;
|
||||
}
|
||||
|
||||
void UiLogic::setQmlContextProperty(PageLogicBase *logic)
|
||||
{
|
||||
amnApp->qmlEngine()->rootContext()->setContextProperty(logic->metaObject()->className(), logic);
|
||||
}
|
||||
|
||||
PageEnumNS::Page UiLogic::currentPage()
|
||||
{
|
||||
return static_cast<PageEnumNS::Page>(currentPageValue());
|
||||
|
|
@ -632,13 +599,11 @@ void UiLogic::saveTextFile(const QString& desc, const QString& suggestedName, QS
|
|||
QUrl::fromLocalFile(docDir), "*" + ext);
|
||||
#endif
|
||||
|
||||
qDebug() << "UiLogic::saveTextFile" << fileName;
|
||||
if (fileName.isEmpty()) return;
|
||||
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
QFile save(fileName.toLocalFile());
|
||||
#else
|
||||
qDebug() << "UiLogic::saveTextFile" << QQmlFile::urlToLocalFileOrQrc(fileName);
|
||||
QFile save(QQmlFile::urlToLocalFileOrQrc(fileName));
|
||||
#endif
|
||||
|
||||
|
|
@ -681,7 +646,6 @@ void UiLogic::shareTempFile(const QString &suggestedName, QString ext, const QSt
|
|||
if (!fileName.endsWith(ext)) fileName.append(ext);
|
||||
|
||||
QFile::remove(fileName);
|
||||
qDebug() << "UiLogic::shareTempFile" << fileName;
|
||||
|
||||
QFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
|
|
@ -692,3 +656,24 @@ void UiLogic::shareTempFile(const QString &suggestedName, QString ext, const QSt
|
|||
filesToSend.append(fileName);
|
||||
MobileUtils::shareText(filesToSend);
|
||||
}
|
||||
|
||||
void UiLogic::registerPagesLogic()
|
||||
{
|
||||
amnApp->qmlEngine()->rootContext()->setContextProperty("UiLogic", this);
|
||||
|
||||
registerPageLogic<AppSettingsLogic>();
|
||||
registerPageLogic<GeneralSettingsLogic>();
|
||||
registerPageLogic<NetworkSettingsLogic>();
|
||||
registerPageLogic<NewServerProtocolsLogic>();
|
||||
registerPageLogic<QrDecoderLogic>();
|
||||
registerPageLogic<ServerConfiguringProgressLogic>();
|
||||
registerPageLogic<ServerListLogic>();
|
||||
registerPageLogic<ServerSettingsLogic>();
|
||||
registerPageLogic<ServerContainersLogic>();
|
||||
registerPageLogic<ShareConnectionLogic>();
|
||||
registerPageLogic<SitesLogic>();
|
||||
registerPageLogic<StartPageLogic>();
|
||||
registerPageLogic<ViewConfigLogic>();
|
||||
registerPageLogic<VpnLogic>();
|
||||
registerPageLogic<WizardLogic>();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue