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");
if (!m_translator->isEmpty())
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 (QCoreApplication::installTranslator(m_translator)) {
m_settings->setAppLanguage(locale);
@ -228,6 +234,8 @@ void AmneziaApplication::updateTranslator(const QLocale &locale)
m_engine->retranslate();
}
emit translationsUpdated();
}
bool AmneziaApplication::parseCommands()
@ -271,6 +279,7 @@ void AmneziaApplication::initModels()
m_languageModel.reset(new LanguageModel(m_settings, this));
m_engine->rootContext()->setContextProperty("LanguageModel", m_languageModel.get());
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_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());

View file

@ -65,6 +65,9 @@ public:
QQmlApplicationEngine *qmlEngine() const;
signals:
void translationsUpdated();
private:
void initModels();
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
}
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);
bool checkSshConnection();
signals:
void installContainerFinished(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;
}

View file

@ -43,13 +43,17 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) 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:
void changeLanguage(const LanguageSettings::AvailableLanguageEnum language);
int getCurrentLanguageIndex();
QString getCurrentLanuageName();
QString getCurrentLanguageName();
signals:
void updateTranslations(const QLocale &locale);
void translationsUpdated();
protected:
QHash<int, QByteArray> roleNames() const override;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -20,13 +20,9 @@ PageType {
Connections {
target: InstallController
function onInstallationErrorOccurred(errorMessage) {
PageController.showErrorMessage(errorMessage)
}
function onUpdateContainerFinished() {
//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
text: qsTr("Language")
descriptionText: LanguageModel.getCurrentLanuageName()
descriptionText: LanguageModel.currentLanguageName
rightImageSource: "qrc:/images/controls/chevron-right.svg"
clickedFunction: function() {

View file

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

View file

@ -94,7 +94,7 @@ PageType {
Layout.fillWidth: true
Layout.topMargin: 24
text: qsTr("Set up a server the easy way")
text: qsTr("Continue")
onClicked: function() {
if (!isCredentialsFilled()) {
@ -104,34 +104,41 @@ PageType {
InstallController.setShouldCreateServer(true)
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)
}
}
BasicButtonType {
Layout.fillWidth: true
Layout.topMargin: -8
// BasicButtonType {
// Layout.fillWidth: true
// Layout.topMargin: -8
defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91"
textColor: "#D7D8DB"
borderWidth: 1
// defaultColor: "transparent"
// hoveredColor: Qt.rgba(1, 1, 1, 0.08)
// pressedColor: Qt.rgba(1, 1, 1, 0.12)
// disabledColor: "#878B91"
// textColor: "#D7D8DB"
// borderWidth: 1
text: qsTr("Select protocol to install")
// text: qsTr("Select protocol to install")
onClicked: function() {
if (!isCredentialsFilled()) {
return
}
// onClicked: function() {
// if (!isCredentialsFilled()) {
// return
// }
InstallController.setShouldCreateServer(true)
InstallController.setCurrentlyInstalledServerCredentials(hostname.textField.text, username.textField.text, secretData.textField.text)
// InstallController.setShouldCreateServer(true)
// 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 {
id: root
property bool isEasySetup: true
SortFilterProxyModel {
id: proxyContainersModel
sourceModel: ContainersModel
@ -64,6 +66,10 @@ PageType {
headerText: qsTr("What is the level of internet control in your region?")
}
ButtonGroup {
id: buttonGroup
}
ListView {
id: containers
width: parent.width
@ -101,6 +107,7 @@ PageType {
ButtonGroup.group: buttonGroup
onClicked: function() {
isEasySetup = true
var defaultContainerProto = ContainerProps.defaultProtocol(dockerContainer)
containers.dockerContainer = dockerContainer
@ -117,9 +124,18 @@ PageType {
}
}
}
}
ButtonGroup {
id: buttonGroup
CardType {
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")
onClicked: function() {
ContainersModel.setCurrentlyProcessedContainerIndex(containers.dockerContainer)
goToPage(PageEnum.PageSetupWizardInstalling);
InstallController.install(containers.dockerContainer,
containers.containerDefaultPort,
containers.containerDefaultTransportProto)
if (root.isEasySetup) {
ContainersModel.setCurrentlyProcessedContainerIndex(containers.dockerContainer)
goToPage(PageEnum.PageSetupWizardInstalling);
InstallController.install(containers.dockerContainer,
containers.containerDefaultPort,
containers.containerDefaultTransportProto)
} else {
goToPage(PageEnum.PageSetupWizardProtocols)
}
}
}
}

View file

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

View file

@ -85,8 +85,7 @@ PageType {
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 {
id: tabBarStackView