added server availability check after entering credentials

- moved the protocol self-selection button to the PageSetupWizardEasy page
This commit is contained in:
vladimir.kuznetsov 2023-07-31 20:38:13 +09:00
parent aa66133813
commit 0058edc24e
21 changed files with 1002 additions and 463 deletions

View file

@ -221,6 +221,12 @@ void AmneziaApplication::updateTranslator(const QLocale &locale)
QResource::registerResource(":/translations.qrc"); QResource::registerResource(":/translations.qrc");
if (!m_translator->isEmpty()) if (!m_translator->isEmpty())
QCoreApplication::removeTranslator(m_translator); QCoreApplication::removeTranslator(m_translator);
if (locale == QLocale::English) {
m_settings->setAppLanguage(locale);
m_engine->retranslate();
}
if (m_translator->load(locale, QString("amneziavpn"), QLatin1String("_"), QLatin1String(":/i18n"))) { if (m_translator->load(locale, QString("amneziavpn"), QLatin1String("_"), QLatin1String(":/i18n"))) {
if (QCoreApplication::installTranslator(m_translator)) { if (QCoreApplication::installTranslator(m_translator)) {
m_settings->setAppLanguage(locale); m_settings->setAppLanguage(locale);
@ -228,6 +234,8 @@ void AmneziaApplication::updateTranslator(const QLocale &locale)
m_engine->retranslate(); m_engine->retranslate();
} }
emit translationsUpdated();
} }
bool AmneziaApplication::parseCommands() bool AmneziaApplication::parseCommands()
@ -271,6 +279,7 @@ void AmneziaApplication::initModels()
m_languageModel.reset(new LanguageModel(m_settings, this)); m_languageModel.reset(new LanguageModel(m_settings, this));
m_engine->rootContext()->setContextProperty("LanguageModel", m_languageModel.get()); m_engine->rootContext()->setContextProperty("LanguageModel", m_languageModel.get());
connect(m_languageModel.get(), &LanguageModel::updateTranslations, this, &AmneziaApplication::updateTranslator); connect(m_languageModel.get(), &LanguageModel::updateTranslations, this, &AmneziaApplication::updateTranslator);
connect(this, &AmneziaApplication::translationsUpdated, m_languageModel.get(), &LanguageModel::translationsUpdated);
m_protocolsModel.reset(new ProtocolsModel(m_settings, this)); m_protocolsModel.reset(new ProtocolsModel(m_settings, this));
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get()); m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());

View file

@ -65,6 +65,9 @@ public:
QQmlApplicationEngine *qmlEngine() const; QQmlApplicationEngine *qmlEngine() const;
signals:
void translationsUpdated();
private: private:
void initModels(); void initModels();
void initControllers(); void initControllers();

File diff suppressed because it is too large Load diff

View file

@ -392,3 +392,24 @@ void InstallController::mountSftpDrive(const QString &port, const QString &passw
#endif #endif
} }
bool InstallController::checkSshConnection()
{
ServerController serverController(m_settings);
ErrorCode errorCode = ErrorCode::NoError;
QString output;
output = serverController.checkSshConnection(m_currentlyInstalledServerCredentials, &errorCode);
if (errorCode != ErrorCode::NoError) {
emit installationErrorOccurred(errorString(errorCode));
return false;
} else {
if (output.contains(tr("Please login as the user"))) {
output.replace("\n", "");
emit installationErrorOccurred(output);
return false;
}
}
return true;
}

View file

@ -37,6 +37,8 @@ public slots:
void mountSftpDrive(const QString &port, const QString &password, const QString &username); void mountSftpDrive(const QString &port, const QString &password, const QString &username);
bool checkSshConnection();
signals: signals:
void installContainerFinished(QString finishMessage); void installContainerFinished(QString finishMessage);
void installServerFinished(QString finishMessage); void installServerFinished(QString finishMessage);

View file

@ -55,7 +55,7 @@ int LanguageModel::getCurrentLanguageIndex()
} }
} }
QString LanguageModel::getCurrentLanuageName() QString LanguageModel::getCurrentLanguageName()
{ {
return m_availableLanguages[getCurrentLanguageIndex()].name; return m_availableLanguages[getCurrentLanguageIndex()].name;
} }

View file

@ -43,13 +43,17 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Q_PROPERTY(QString currentLanguageName READ getCurrentLanguageName NOTIFY translationsUpdated)
Q_PROPERTY(int currentLanguageIndex READ getCurrentLanguageIndex NOTIFY translationsUpdated)
public slots: public slots:
void changeLanguage(const LanguageSettings::AvailableLanguageEnum language); void changeLanguage(const LanguageSettings::AvailableLanguageEnum language);
int getCurrentLanguageIndex(); int getCurrentLanguageIndex();
QString getCurrentLanuageName(); QString getCurrentLanguageName();
signals: signals:
void updateTranslations(const QLocale &locale); void updateTranslations(const QLocale &locale);
void translationsUpdated();
protected: protected:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;

View file

@ -59,7 +59,7 @@ DrawerType {
interactive: false interactive: false
model: LanguageModel model: LanguageModel
currentIndex: LanguageModel.getCurrentLanguageIndex() currentIndex: LanguageModel.currentLanguageIndex
ButtonGroup { ButtonGroup {
id: buttonGroup id: buttonGroup
@ -127,6 +127,7 @@ DrawerType {
onClicked: { onClicked: {
listView.currentIndex = index listView.currentIndex = index
LanguageModel.changeLanguage(languageIndex) LanguageModel.changeLanguage(languageIndex)
root.close()
} }
} }
} }

View file

@ -55,6 +55,8 @@ Popup {
BasicButtonType { BasicButtonType {
visible: closeButtonVisible visible: closeButtonVisible
implicitHeight: 32
defaultColor: "white" defaultColor: "white"
hoveredColor: "#C1C2C5" hoveredColor: "#C1C2C5"
pressedColor: "#AEB0B7" pressedColor: "#AEB0B7"

View file

@ -17,13 +17,9 @@ PageType {
Connections { Connections {
target: InstallController target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
function onUpdateContainerFinished() { function onUpdateContainerFinished() {
//todo change to notification //todo change to notification
PageController.showErrorMessage(qsTr("Settings updated successfully")) PageController.showNotificationMessage(qsTr("Settings updated successfully"))
} }
} }

View file

@ -18,13 +18,9 @@ PageType {
Connections { Connections {
target: InstallController target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
function onUpdateContainerFinished() { function onUpdateContainerFinished() {
//todo change to notification //todo change to notification
PageController.showErrorMessage(qsTr("Settings updated successfully")) PageController.showNotificationMessage(qsTr("Settings updated successfully"))
} }
} }

View file

@ -17,13 +17,9 @@ PageType {
Connections { Connections {
target: InstallController target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
function onUpdateContainerFinished() { function onUpdateContainerFinished() {
//todo change to notification //todo change to notification
PageController.showErrorMessage(qsTr("Settings updated successfully")) PageController.showNotificationMessage(qsTr("Settings updated successfully"))
} }
} }

View file

@ -19,13 +19,9 @@ PageType {
Connections { Connections {
target: InstallController target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
function onUpdateContainerFinished() { function onUpdateContainerFinished() {
//todo change to notification //todo change to notification
PageController.showErrorMessage(qsTr("Settings updated successfully")) PageController.showNotificationMessage(qsTr("Settings updated successfully"))
} }
} }

View file

@ -20,13 +20,9 @@ PageType {
Connections { Connections {
target: InstallController target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
function onUpdateContainerFinished() { function onUpdateContainerFinished() {
//todo change to notification //todo change to notification
PageController.showErrorMessage(qsTr("Settings updated successfully")) PageController.showNotificationMessage(qsTr("Settings updated successfully"))
} }
} }

View file

@ -48,7 +48,7 @@ PageType {
Layout.topMargin: 16 Layout.topMargin: 16
text: qsTr("Language") text: qsTr("Language")
descriptionText: LanguageModel.getCurrentLanuageName() descriptionText: LanguageModel.currentLanguageName
rightImageSource: "qrc:/images/controls/chevron-right.svg" rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() { clickedFunction: function() {

View file

@ -28,11 +28,6 @@ PageType {
PageController.showErrorMessage(message) PageController.showErrorMessage(message)
} }
function onInstallationErrorOccurred(errorMessage) {
closePage() // close deInstalling page
PageController.showErrorMessage(errorMessage)
}
function onRemoveCurrentlyProcessedServerFinished(finishedMessage) { function onRemoveCurrentlyProcessedServerFinished(finishedMessage) {
if (!ServersModel.getServersCount()) { if (!ServersModel.getServersCount()) {
PageController.replaceStartPage() PageController.replaceStartPage()

View file

@ -94,7 +94,7 @@ PageType {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 24 Layout.topMargin: 24
text: qsTr("Set up a server the easy way") text: qsTr("Continue")
onClicked: function() { onClicked: function() {
if (!isCredentialsFilled()) { if (!isCredentialsFilled()) {
@ -104,34 +104,41 @@ PageType {
InstallController.setShouldCreateServer(true) InstallController.setShouldCreateServer(true)
InstallController.setCurrentlyInstalledServerCredentials(hostname.textField.text, username.textField.text, secretData.textField.text) InstallController.setCurrentlyInstalledServerCredentials(hostname.textField.text, username.textField.text, secretData.textField.text)
PageController.showBusyIndicator(true)
var isConnectionOpened = InstallController.checkSshConnection()
PageController.showBusyIndicator(false)
if (!isConnectionOpened) {
return
}
goToPage(PageEnum.PageSetupWizardEasy) goToPage(PageEnum.PageSetupWizardEasy)
} }
} }
BasicButtonType { // BasicButtonType {
Layout.fillWidth: true // Layout.fillWidth: true
Layout.topMargin: -8 // Layout.topMargin: -8
defaultColor: "transparent" // defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08) // hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12) // pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91" // disabledColor: "#878B91"
textColor: "#D7D8DB" // textColor: "#D7D8DB"
borderWidth: 1 // borderWidth: 1
text: qsTr("Select protocol to install") // text: qsTr("Select protocol to install")
onClicked: function() { // onClicked: function() {
if (!isCredentialsFilled()) { // if (!isCredentialsFilled()) {
return // return
} // }
InstallController.setShouldCreateServer(true) // InstallController.setShouldCreateServer(true)
InstallController.setCurrentlyInstalledServerCredentials(hostname.textField.text, username.textField.text, secretData.textField.text) // InstallController.setCurrentlyInstalledServerCredentials(hostname.textField.text, username.textField.text, secretData.textField.text)
goToPage(PageEnum.PageSetupWizardProtocols) // goToPage(PageEnum.PageSetupWizardProtocols)
} // }
} // }
} }
} }

View file

@ -15,6 +15,8 @@ import "../Config"
PageType { PageType {
id: root id: root
property bool isEasySetup: true
SortFilterProxyModel { SortFilterProxyModel {
id: proxyContainersModel id: proxyContainersModel
sourceModel: ContainersModel sourceModel: ContainersModel
@ -64,6 +66,10 @@ PageType {
headerText: qsTr("What is the level of internet control in your region?") headerText: qsTr("What is the level of internet control in your region?")
} }
ButtonGroup {
id: buttonGroup
}
ListView { ListView {
id: containers id: containers
width: parent.width width: parent.width
@ -101,6 +107,7 @@ PageType {
ButtonGroup.group: buttonGroup ButtonGroup.group: buttonGroup
onClicked: function() { onClicked: function() {
isEasySetup = true
var defaultContainerProto = ContainerProps.defaultProtocol(dockerContainer) var defaultContainerProto = ContainerProps.defaultProtocol(dockerContainer)
containers.dockerContainer = dockerContainer containers.dockerContainer = dockerContainer
@ -117,9 +124,18 @@ PageType {
} }
} }
} }
}
ButtonGroup { CardType {
id: buttonGroup implicitWidth: parent.width
headerText: qsTr("Set up a VPN yourself")
bodyText: qsTr("I want to choose a VPN protocol")
ButtonGroup.group: buttonGroup
onClicked: function() {
isEasySetup = false
} }
} }
@ -132,11 +148,15 @@ PageType {
text: qsTr("Continue") text: qsTr("Continue")
onClicked: function() { onClicked: function() {
ContainersModel.setCurrentlyProcessedContainerIndex(containers.dockerContainer) if (root.isEasySetup) {
goToPage(PageEnum.PageSetupWizardInstalling); ContainersModel.setCurrentlyProcessedContainerIndex(containers.dockerContainer)
InstallController.install(containers.dockerContainer, goToPage(PageEnum.PageSetupWizardInstalling);
containers.containerDefaultPort, InstallController.install(containers.dockerContainer,
containers.containerDefaultTransportProto) containers.containerDefaultPort,
containers.containerDefaultTransportProto)
} else {
goToPage(PageEnum.PageSetupWizardProtocols)
}
} }
} }
} }

View file

@ -17,11 +17,6 @@ PageType {
Connections { Connections {
target: InstallController target: InstallController
function onInstallationErrorOccurred(errorMessage) {
closePage()
PageController.showErrorMessage(errorMessage)
}
function onInstallContainerFinished(finishedMessage) { function onInstallContainerFinished(finishedMessage) {
goToStartPage() goToStartPage()
if (stackView.currentItem.objectName === PageController.getPagePath(PageEnum.PageHome)) { if (stackView.currentItem.objectName === PageController.getPagePath(PageEnum.PageHome)) {

View file

@ -85,8 +85,7 @@ PageType {
text: qsTr("I have nothing") text: qsTr("I have nothing")
onClicked: { onClicked: Qt.openUrlExternally("https://ru-docs.amnezia.org/guides/hosting-instructions")
}
} }
} }

View file

@ -45,6 +45,26 @@ PageType {
} }
} }
Connections {
target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
var needCloseCurrentPage = false
var currentPageName = stackView.currentItem.objectName
if (currentPageName === PageController.getPagePath(PageEnum.PageSetupWizardInstalling)) {
needCloseCurrentPage = true
} else if (currentPageName === PageController.getPagePath(PageEnum.PageDeinstalling)) {
needCloseCurrentPage = true
}
if (needCloseCurrentPage) {
PageController.closePage()
}
}
}
StackViewType { StackViewType {
id: tabBarStackView id: tabBarStackView