Skip to content

Commit

Permalink
added PageSettings and PageSettingsServersList.
Browse files Browse the repository at this point in the history
- replaced PageLoader with PageType with stackView property.
- added error handling when installing a server/container
  • Loading branch information
Nethius committed May 25, 2023
1 parent ca6b7fb commit e00656d
Show file tree
Hide file tree
Showing 31 changed files with 488 additions and 144 deletions.
4 changes: 4 additions & 0 deletions client/images/controls/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions client/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@
<file>ui/qml/Controls2/DropDownType.qml</file>
<file>ui/qml/Pages2/PageSetupWizardStart.qml</file>
<file>ui/qml/main2.qml</file>
<file>ui/qml/PageLoader.qml</file>
<file>images/amneziaBigLogo.png</file>
<file>images/amneziaBigLogo.svg</file>
<file>ui/qml/Controls2/FlickableType.qml</file>
Expand Down Expand Up @@ -215,7 +214,7 @@
<file>images/controls/settings-2.svg</file>
<file>images/controls/share-2.svg</file>
<file>ui/qml/Pages2/PageHome.qml</file>
<file>ui/qml/Pages2/PageSettings.qml</file>
<file>ui/qml/Pages2/PageSettingsServersList.qml</file>
<file>ui/qml/Pages2/PageShare.qml</file>
<file>ui/qml/Controls2/TextTypes/Header1TextType.qml</file>
<file>ui/qml/Controls2/TextTypes/LabelTextType.qml</file>
Expand All @@ -230,5 +229,10 @@
<file>ui/qml/Controls2/ProgressBarType.qml</file>
<file>ui/qml/Components/ConnectionTypeSelectionDrawer.qml</file>
<file>ui/qml/Components/ContainersPageHomeListView.qml</file>
<file>ui/qml/Controls2/TextTypes/CaptionTextType.qml</file>
<file>images/controls/settings.svg</file>
<file>ui/qml/Pages2/PageSettings.qml</file>
<file>ui/qml/Controls2/PageType.qml</file>
<file>ui/qml/Controls2/PopupType.qml</file>
</qresource>
</RCC>
22 changes: 11 additions & 11 deletions client/ui/controllers/installController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QJsonObject>

#include "core/servercontroller.h"
#include "core/errorstrings.h"

InstallController::InstallController(const QSharedPointer<ServersModel> &serversModel,
const QSharedPointer<ContainersModel> &containersModel,
Expand All @@ -12,7 +13,7 @@ InstallController::InstallController(const QSharedPointer<ServersModel> &servers

}

ErrorCode InstallController::install(DockerContainer container, int port, TransportProto transportProto)
void InstallController::install(DockerContainer container, int port, TransportProto transportProto)
{
Proto mainProto = ContainerProps::defaultProtocol(container);

Expand All @@ -26,13 +27,13 @@ ErrorCode InstallController::install(DockerContainer container, int port, Transp
};

if (m_shouldCreateServer) {
return installServer(container, config);
installServer(container, config);
} else {
return installContainer(container, config);
installContainer(container, config);
}
}

ErrorCode InstallController::installServer(DockerContainer container, QJsonObject& config)
void InstallController::installServer(DockerContainer container, QJsonObject& config)
{
//todo check if container already installed
ServerController serverController(m_settings);
Expand All @@ -51,15 +52,14 @@ ErrorCode InstallController::installServer(DockerContainer container, QJsonObjec
m_settings->addServer(server);
m_settings->setDefaultServer(m_settings->serversCount() - 1);

//todo change to server finished
emit installContainerFinished();
emit installServerFinished();
return;
}

//todo error processing
return errorCode;
emit installationErrorOccurred(errorString(errorCode));
}

ErrorCode InstallController::installContainer(DockerContainer container, QJsonObject& config)
void InstallController::installContainer(DockerContainer container, QJsonObject& config)
{
//todo check if container already installed
ServerCredentials serverCredentials = m_serversModel->getCurrentlyProcessedServerCredentials();
Expand All @@ -69,10 +69,10 @@ ErrorCode InstallController::installContainer(DockerContainer container, QJsonOb
if (errorCode == ErrorCode::NoError) {
m_containersModel->setData(m_containersModel->index(container), config, ContainersModel::Roles::ConfigRole);
emit installContainerFinished();
return;
}

//todo error processing
return errorCode;
emit installationErrorOccurred(errorString(errorCode));
}

void InstallController::setCurrentlyInstalledServerCredentials(const QString &hostName, const QString &userName, const QString &secretData)
Expand Down
9 changes: 6 additions & 3 deletions client/ui/controllers/installController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ class InstallController : public QObject
QObject *parent = nullptr);

public slots:
ErrorCode install(DockerContainer container, int port, TransportProto transportProto);
void install(DockerContainer container, int port, TransportProto transportProto);
void setCurrentlyInstalledServerCredentials(const QString &hostName, const QString &userName, const QString &secretData);
void setShouldCreateServer(bool shouldCreateServer);

signals:
void installContainerFinished();
void installServerFinished();

void installationErrorOccurred(QString errorMessage);
private:
ErrorCode installServer(DockerContainer container, QJsonObject& config);
ErrorCode installContainer(DockerContainer container, QJsonObject& config);
void installServer(DockerContainer container, QJsonObject& config);
void installContainer(DockerContainer container, QJsonObject& config);

QSharedPointer<ServersModel> m_serversModel;
QSharedPointer<ContainersModel> m_containersModel;
Expand Down
8 changes: 4 additions & 4 deletions client/ui/controllers/pageController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
{
}

void PageController::setStartPage()
QString PageController::getInitialPage()
{
if (m_serversModel->getServersCount()) {
if (m_serversModel->getDefaultServerIndex() < 0) {
m_serversModel->setDefaultServerIndex(0);
}
emit goToPage(PageLoader::PageEnum::PageStart, false);
return getPagePath(PageLoader::PageEnum::PageStart);
} else {
emit goToPage(PageLoader::PageEnum::PageSetupWizardStart, false);
return getPagePath(PageLoader::PageEnum::PageSetupWizardStart);
}
}

QString PageController::getPagePath(PageLoader::PageEnum page)
{
QMetaEnum metaEnum = QMetaEnum::fromType<PageLoader::PageEnum>();
QString pageName = metaEnum.valueToKey(static_cast<int>(page));
return "Pages2/" + pageName + ".qml";
return "qrc:/ui/qml/Pages2/" + pageName + ".qml";
}
6 changes: 3 additions & 3 deletions client/ui/controllers/pageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class PageController : public QObject
QObject *parent = nullptr);

public slots:
void setStartPage();
QString getInitialPage();
QString getPagePath(PageLoader::PageEnum page);

signals:
void goToPage(PageLoader::PageEnum page, bool slide = true);
void closePage();
void goToPageHome();
void showErrorMessage(QString errorMessage);

private:
QSharedPointer<ServersModel> m_serversModel;
Expand Down
10 changes: 9 additions & 1 deletion client/ui/models/servers_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(m_settings->serverCredentials(index.row()));
case IsDefaultRole:
return index.row() == m_settings->defaultServerIndex();
case IsCurrentlyProcessedRole:
return index.row() == m_currenlyProcessedServerIndex;
}

return QVariant();
Expand All @@ -59,7 +61,7 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
//todo mode to setData?
void ServersModel::setDefaultServerIndex(int index)
{
// beginResetModel();
// beginResetModel();
m_settings->setDefaultServer(index);
// endResetModel();
}
Expand All @@ -84,11 +86,17 @@ ServerCredentials ServersModel::getCurrentlyProcessedServerCredentials()
return qvariant_cast<ServerCredentials>(data(index(m_currenlyProcessedServerIndex), CredentialsRole));
}

void ServersModel::addServer()
{

}

QHash<int, QByteArray> ServersModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[HostNameRole] = "hostName";
roles[CredentialsRole] = "credentials";
roles[IsDefaultRole] = "isDefault";
roles[IsCurrentlyProcessedRole] = "isCurrentlyProcessed";
return roles;
}
6 changes: 5 additions & 1 deletion client/ui/models/servers_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class ServersModel : public QAbstractListModel
NameRole = Qt::UserRole + 1,
HostNameRole,
CredentialsRole,
IsDefaultRole
IsDefaultRole,
IsCurrentlyProcessedRole
};

ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
Expand All @@ -32,11 +33,14 @@ class ServersModel : public QAbstractListModel
public slots:
void setDefaultServerIndex(int index);
const int getDefaultServerIndex();

const int getServersCount();

void setCurrentlyProcessedServerIndex(int index);
ServerCredentials getCurrentlyProcessedServerCredentials();

void addServer();

protected:
QHash<int, QByteArray> roleNames() const override;

Expand Down
25 changes: 13 additions & 12 deletions client/ui/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ class PageType : public QObject
namespace PageEnumNS
{
Q_NAMESPACE
enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
ServerContainers, ServersList, ShareConnection, Sites,
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig,
AdvancedServerSettings, ClientManagement, ClientInfo,

PageSetupWizardStart, PageTest, PageSetupWizardCredentials, PageSetupWizardProtocols, PageSetupWizardEasy,
PageSetupWizardProtocolSettings, PageSetupWizardInstalling, PageSetupWizardConfigSource,
PageSetupWizardTextKey,

PageStart, PageHome, PageSettings, PageShare};
enum class Page { Start = 0, NewServer, NewServerProtocols, Vpn,
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
ServerContainers, ServersList, ShareConnection, Sites,
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig,
AdvancedServerSettings, ClientManagement, ClientInfo,

PageSetupWizardStart, PageTest, PageSetupWizardCredentials, PageSetupWizardProtocols, PageSetupWizardEasy,
PageSetupWizardProtocolSettings, PageSetupWizardInstalling, PageSetupWizardConfigSource, PageSetupWizardTextKey,

PageSettings, PageSettingsServersList,

PageStart, PageHome, PageShare};
Q_ENUM_NS(Page)

static void declareQmlPageEnum() {
Expand Down
8 changes: 4 additions & 4 deletions client/ui/qml/Components/ConnectionTypeSelectionDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Drawer {
text: "IP, логин и пароль от сервера"
buttonImage: "qrc:/images/controls/chevron-right.svg"

onClickedFunc: function() {
PageController.goToPage(PageEnum.PageSetupWizardCredentials)
clickedFunction: function() {
goToPage(PageEnum.PageSetupWizardCredentials)
root.visible = false
}
}
Expand All @@ -73,8 +73,8 @@ Drawer {
text: "QR-код, ключ или файл настроек"
buttonImage: "qrc:/images/controls/chevron-right.svg"

onClickedFunc: function() {
PageController.goToPage(PageEnum.PageSetupWizardConfigSource)
clickedFunction: function() {
goToPage(PageEnum.PageSetupWizardConfigSource)
root.visible = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/ui/qml/Components/ContainersPageHomeListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ListView {
} else {
ContainersModel.setCurrentlyInstalledContainerIndex(proxyContainersModel.mapToSource(index))
InstallController.setShouldCreateServer(false)
PageController.goToPage(PageEnum.PageSetupWizardProtocolSettings)
goToPage(PageEnum.PageSetupWizardProtocolSettings)
containersDropDown.menuVisible = false
menu.visible = false
}
Expand Down
2 changes: 1 addition & 1 deletion client/ui/qml/Controls2/Header2Type.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Item {
if (backButtonFunction && typeof backButtonFunction === "function") {
backButtonFunction()
} else {
PageController.closePage()
closePage()
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions client/ui/qml/Controls2/HeaderType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Item {
if (backButtonFunction && typeof backButtonFunction === "function") {
backButtonFunction()
} else {
PageController.closePage()
closePage()
}
}
}
Expand All @@ -61,8 +61,8 @@ Item {
visible: image ? true : false

onClicked: {
if (actionButtonImage && typeof actionButtonImage === "function") {
actionButtonImage()
if (actionButtonFunction && typeof actionButtonFunction === "function") {
actionButtonFunction()
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions client/ui/qml/Controls2/LabelWithButtonType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Item {
property string text
property string descriptionText

property var onClickedFunc
property var clickedFunction

property alias buttonImage: button.image
property string iconImage
Expand Down Expand Up @@ -68,8 +68,8 @@ Item {
hoverEnabled: false
image: buttonImage
onClicked: {
if (onClickedFunc && typeof onClickedFunc === "function") {
onClickedFunc()
if (clickedFunction && typeof clickedFunction === "function") {
clickedFunction()
}
}

Expand Down
31 changes: 31 additions & 0 deletions client/ui/qml/Controls2/PageType.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Item {
id: root

property StackView stackView: StackView.view

function goToPage(page, slide = true) {
if (slide) {
root.stackView.push(PageController.getPagePath(page), {}, StackView.PushTransition)
} else {
root.stackView.push(PageController.getPagePath(page), {}, StackView.Immediate)
}
}

function closePage() {
if (root.stackView.depth <= 1) {
return
}

root.stackView.pop()
}

function goToStartPage() {
while (root.stackView.depth > 1) {
root.stackView.pop()
}
}
}
Loading

0 comments on commit e00656d

Please sign in to comment.