added button 'Reset settings and remove all data from the application'

This commit is contained in:
vladimir.kuznetsov 2023-07-14 22:59:49 +09:00
parent 3aaa7b62ef
commit 75489c00c2
18 changed files with 585 additions and 432 deletions

View file

@ -16,12 +16,19 @@ InstallController::InstallController(const QSharedPointer<ServersModel> &servers
void InstallController::install(DockerContainer container, int port, TransportProto transportProto)
{
Proto mainProto = ContainerProps::defaultProtocol(container);
QJsonObject containerConfig;
QJsonObject containerConfig { { config_key::port, QString::number(port) },
{ config_key::transport_proto,
ProtocolProps::transportProtoToString(transportProto, mainProto) } };
QJsonObject config { { config_key::container, ContainerProps::containerToString(container) },
{ ProtocolProps::protoToString(mainProto), containerConfig } };
containerConfig.insert(config_key::port, QString::number(port));
containerConfig.insert(config_key::transport_proto, ProtocolProps::transportProtoToString(transportProto, mainProto));
if (container == DockerContainer::Sftp) {
containerConfig.insert(config_key::userName, protocols::sftp::defaultUserName);
containerConfig.insert(config_key::password, Utils::getRandomString(10));
}
QJsonObject config;
config.insert(config_key::container, ContainerProps::containerToString(container));
config.insert(ProtocolProps::protoToString(mainProto), containerConfig);
if (m_shouldCreateServer) {
if (isServerAlreadyExists()) {

View file

@ -27,6 +27,7 @@ namespace PageLoader
PageSettingsApplication,
PageSettingsBackup,
PageSettingsAbout,
PageSettingsLogging,
PageSetupWizardStart,
PageSetupWizardCredentials,

View file

@ -46,14 +46,15 @@ void SettingsController::setSecondaryDns(const QString &dns)
emit secondaryDnsChanged();
}
bool SettingsController::isSaveLogsEnabled()
bool SettingsController::isLoggingEnable()
{
return m_settings->isSaveLogs();
}
void SettingsController::setSaveLogs(bool enable)
void SettingsController::toggleLogging(bool enable)
{
m_settings->setSaveLogs(enable);
emit loggingStateChanged();
}
void SettingsController::openLogsFolder()
@ -101,3 +102,8 @@ QString SettingsController::getAppVersion()
{
return m_appVersion;
}
void SettingsController::clearSettings()
{
m_settings->clearSettings();
}

View file

@ -16,6 +16,7 @@ public:
Q_PROPERTY(QString primaryDns READ getPrimaryDns WRITE setPrimaryDns NOTIFY primaryDnsChanged)
Q_PROPERTY(QString secondaryDns READ getSecondaryDns WRITE setSecondaryDns NOTIFY secondaryDnsChanged)
Q_PROPERTY(bool isLoggingEnable READ isLoggingEnable WRITE toggleLogging NOTIFY loggingStateChanged)
public slots:
void setAmneziaDns(bool enable);
@ -27,8 +28,8 @@ public slots:
QString getSecondaryDns();
void setSecondaryDns(const QString &dns);
bool isSaveLogsEnabled();
void setSaveLogs(bool enable);
bool isLoggingEnable();
void toggleLogging(bool enable);
void openLogsFolder();
void exportLogsFile();
@ -39,9 +40,12 @@ public slots:
QString getAppVersion();
void clearSettings();
signals:
void primaryDnsChanged();
void secondaryDnsChanged();
void loggingStateChanged();
private:
QSharedPointer<ServersModel> m_serversModel;

View file

@ -54,3 +54,8 @@ int LanguageModel::getCurrentLanguageIndex()
default: return static_cast<int>(LanguageSettings::AvailableLanguageEnum::English); break;
}
}
QString LanguageModel::getCurrentLanuageName()
{
return m_availableLanguages[getCurrentLanguageIndex()].name;
}

View file

@ -46,6 +46,7 @@ public:
public slots:
void changeLanguage(const LanguageSettings::AvailableLanguageEnum language);
int getCurrentLanguageIndex();
QString getCurrentLanuageName();
signals:
void updateTranslations(const QLocale &locale);

View file

@ -89,7 +89,7 @@ void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int port, TransportProto tp)
{
ServerController serverController(m_settings);
QJsonObject config = serverController.createContainerInitialConfig(c, port, tp);
QJsonObject config; // = serverController.createContainerInitialConfig(c, port, tp);
emit uiLogic()->goToPage(Page::ServerConfiguringProgress);
qApp->processEvents();

View file

@ -17,14 +17,16 @@ Item {
property string textColor: "#d7d8db"
implicitWidth: content.implicitWidth
implicitHeight: content.implicitHeight
implicitWidth: content.implicitWidth + content.anchors.topMargin + content.anchors.bottomMargin
implicitHeight: content.implicitHeight + content.anchors.leftMargin + content.anchors.rightMargin
RowLayout {
id: content
anchors.fill: parent
anchors.leftMargin: 16
anchors.rightMargin: 16
anchors.topMargin: 16
anchors.bottomMargin: 16
Rectangle {
id: leftImageBackground
@ -56,8 +58,6 @@ Item {
color: root.textColor
Layout.fillWidth: true
Layout.topMargin: 16
Layout.bottomMargin: description.visible ? 0 : 16
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
@ -72,7 +72,6 @@ Item {
visible: root.descriptionText !== ""
Layout.fillWidth: true
Layout.bottomMargin: 16
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter

View file

@ -48,6 +48,7 @@ PageType {
Layout.topMargin: 16
text: qsTr("Language")
descriptionText: LanguageModel.getCurrentLanuageName()
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
@ -60,6 +61,22 @@ PageType {
}
DividerType {}
LabelWithButtonType {
Layout.fillWidth: true
text: qsTr("Logging")
descriptionText: SettingsController.isLoggingEnable ? qsTr("Enabled") : qsTr("Disabled")
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
goToPage(PageEnum.PageSettingsLogging)
}
}
DividerType {}
LabelWithButtonType {
Layout.fillWidth: true
@ -67,10 +84,27 @@ PageType {
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {
questionDrawer.headerText = qsTr("Reset settings and remove all data from the application?")
questionDrawer.descriptionText = qsTr("All settings will be reset to default. All installed AmneziaVPN services will still remain on the server.")
questionDrawer.yesButtonText = qsTr("Continue")
questionDrawer.noButtonText = qsTr("Cancel")
questionDrawer.yesButtonFunction = function() {
questionDrawer.visible = false
SettingsController.clearSettings()
}
questionDrawer.noButtonFunction = function() {
questionDrawer.visible = false
}
questionDrawer.visible = true
}
}
DividerType {}
QuestionDrawer {
id: questionDrawer
}
}
}
}

View file

@ -44,96 +44,6 @@ PageType {
headerText: qsTr("Backup")
}
SwitcherType {
Layout.fillWidth: true
Layout.topMargin: 16
text: qsTr("Save logs")
checked: SettingsController.isSaveLogsEnabled()
onCheckedChanged: {
if (checked !== SettingsController.isSaveLogsEnabled()) {
SettingsController.setSaveLogs(checked)
}
}
}
RowLayout {
Layout.fillWidth: true
ColumnLayout {
Layout.alignment: Qt.AlignBaseline
Layout.preferredWidth: root.width / 3
ImageButtonType {
Layout.alignment: Qt.AlignHCenter
implicitWidth: 56
implicitHeight: 56
image: "qrc:/images/controls/folder-open.svg"
onClicked: SettingsController.openLogsFolder()
}
CaptionTextType {
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
text: qsTr("Open folder with logs")
color: "#D7D8DB"
}
}
ColumnLayout {
Layout.alignment: Qt.AlignBaseline
Layout.preferredWidth: root.width / 3
ImageButtonType {
Layout.alignment: Qt.AlignHCenter
implicitWidth: 56
implicitHeight: 56
image: "qrc:/images/controls/save.svg"
onClicked: SettingsController.exportLogsFile()
}
CaptionTextType {
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
text: qsTr("Save logs to file")
color: "#D7D8DB"
}
}
ColumnLayout {
Layout.alignment: Qt.AlignBaseline
Layout.preferredWidth: root.width / 3
ImageButtonType {
Layout.alignment: Qt.AlignHCenter
implicitWidth: 56
implicitHeight: 56
image: "qrc:/images/controls/delete.svg"
onClicked: SettingsController.clearLogs()
}
CaptionTextType {
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
text: qsTr("Clear logs")
color: "#D7D8DB"
}
}
}
ListItemTitleType {
Layout.fillWidth: true
Layout.topMargin: 10

View file

@ -0,0 +1,138 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import PageEnum 1.0
import "./"
import "../Controls2"
import "../Config"
import "../Controls2/TextTypes"
PageType {
id: root
BackButtonType {
id: backButton
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 20
}
FlickableType {
id: fl
anchors.top: backButton.bottom
anchors.bottom: parent.bottom
contentHeight: content.height
ColumnLayout {
id: content
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 16
anchors.rightMargin: 16
spacing: 16
HeaderType {
Layout.fillWidth: true
headerText: qsTr("Logging")
}
SwitcherType {
Layout.fillWidth: true
Layout.topMargin: 16
text: qsTr("Save logs")
checked: SettingsController.isLoggingEnable
onCheckedChanged: {
if (checked !== SettingsController.isLoggingEnable) {
SettingsController.isLoggingEnable = checked
}
}
}
RowLayout {
Layout.fillWidth: true
ColumnLayout {
Layout.alignment: Qt.AlignBaseline
Layout.preferredWidth: root.width / 3
ImageButtonType {
Layout.alignment: Qt.AlignHCenter
implicitWidth: 56
implicitHeight: 56
image: "qrc:/images/controls/folder-open.svg"
onClicked: SettingsController.openLogsFolder()
}
CaptionTextType {
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
text: qsTr("Open folder with logs")
color: "#D7D8DB"
}
}
ColumnLayout {
Layout.alignment: Qt.AlignBaseline
Layout.preferredWidth: root.width / 3
ImageButtonType {
Layout.alignment: Qt.AlignHCenter
implicitWidth: 56
implicitHeight: 56
image: "qrc:/images/controls/save.svg"
onClicked: SettingsController.exportLogsFile()
}
CaptionTextType {
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
text: qsTr("Save logs to file")
color: "#D7D8DB"
}
}
ColumnLayout {
Layout.alignment: Qt.AlignBaseline
Layout.preferredWidth: root.width / 3
ImageButtonType {
Layout.alignment: Qt.AlignHCenter
implicitWidth: 56
implicitHeight: 56
image: "qrc:/images/controls/delete.svg"
onClicked: SettingsController.clearLogs()
}
CaptionTextType {
horizontalAlignment: Text.AlignHCenter
Layout.fillWidth: true
text: qsTr("Clear logs")
color: "#D7D8DB"
}
}
}
}
}
}