diff --git a/client/amnezia_application.h b/client/amnezia_application.h index 675ffd811..02c600015 100644 --- a/client/amnezia_application.h +++ b/client/amnezia_application.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "settings.h" #include "vpnconnection.h" diff --git a/client/containers/containers_defs.cpp b/client/containers/containers_defs.cpp index 1e8046bf7..27f6f1dd4 100644 --- a/client/containers/containers_defs.cpp +++ b/client/containers/containers_defs.cpp @@ -217,8 +217,8 @@ QString ContainerProps::easySetupDescription(DockerContainer container) { switch (container) { case DockerContainer::OpenVpn: return tr("I just want to increase the level of privacy"); - case DockerContainer::Cloak: return tr("Some foreign sites are blocked, but VPN providers are not blocked"); - case DockerContainer::ShadowSocks: return tr("Many foreign websites and VPN providers are blocked"); + case DockerContainer::Cloak: return tr("Many foreign websites and VPN providers are blocked"); + case DockerContainer::ShadowSocks: return tr("Some foreign sites are blocked, but VPN providers are not blocked"); default: return ""; } } diff --git a/client/platforms/ios/QRCodeReaderBase.mm b/client/platforms/ios/QRCodeReaderBase.mm index bd0dbac38..af879e2f9 100644 --- a/client/platforms/ios/QRCodeReaderBase.mm +++ b/client/platforms/ios/QRCodeReaderBase.mm @@ -49,14 +49,15 @@ _videoPreviewPlayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession: _captureSession]; - CGFloat tabBarHeight = 20.0; + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; + QRect cameraRect = _qrCodeReader->cameraSize(); CGRect cameraCGRect = CGRectMake(cameraRect.x(), - cameraRect.y() + tabBarHeight, + cameraRect.y() + statusBarHeight, cameraRect.width(), cameraRect.height()); - [_videoPreviewPlayer setVideoGravity: AVLayerVideoGravityResizeAspect]; + [_videoPreviewPlayer setVideoGravity: AVLayerVideoGravityResizeAspectFill]; [_videoPreviewPlayer setFrame: cameraCGRect]; CALayer* layer = [UIApplication sharedApplication].keyWindow.layer; diff --git a/client/ui/controllers/importController.cpp b/client/ui/controllers/importController.cpp index 8e2ad5d1c..4ff972cce 100644 --- a/client/ui/controllers/importController.cpp +++ b/client/ui/controllers/importController.cpp @@ -42,8 +42,11 @@ namespace return ConfigTypes::Amnezia; } -#ifdef Q_OS_ANDROID +#if defined Q_OS_ANDROID ImportController *mInstance = nullptr; +#endif + +#ifdef Q_OS_ANDROID constexpr auto AndroidCameraActivity = "org.amnezia.vpn.qt.CameraActivity"; #endif } // namespace @@ -264,17 +267,6 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data) } #ifdef Q_OS_ANDROID -void ImportController::startDecodingQr() -{ - AndroidController::instance()->startQrReaderActivity(); -} - -void ImportController::stopDecodingQr() -{ - QJniObject::callStaticMethod(AndroidCameraActivity, "stopQrCodeReader", "()V"); - emit qrDecodingFinished(); -} - void ImportController::onNewQrCodeDataChunk(JNIEnv *env, jobject thiz, jstring data) { Q_UNUSED(thiz); @@ -296,6 +288,30 @@ void ImportController::onNewQrCodeDataChunk(JNIEnv *env, jobject thiz, jstring d mInstance->parseQrCodeChunk(parcelBody); } } +#endif + +#if defined Q_OS_ANDROID || defined Q_OS_IOS +void ImportController::startDecodingQr() +{ + m_qrCodeChunks.clear(); + m_totalQrCodeChunksCount = 0; + m_receivedQrCodeChunksCount = 0; + + #if defined Q_OS_IOS + m_isQrCodeProcessed = true; + #endif + #if defined Q_OS_ANDROID + AndroidController::instance()->startQrReaderActivity(); + #endif +} + +void ImportController::stopDecodingQr() +{ + #if defined Q_OS_ANDROID + QJniObject::callStaticMethod(AndroidCameraActivity, "stopQrCodeReader", "()V"); + #endif + emit qrDecodingFinished(); +} void ImportController::parseQrCodeChunk(const QString &code) { @@ -333,8 +349,10 @@ void ImportController::parseQrCodeChunk(const QString &code) bool ok = extractConfigFromQr(data); if (ok) { m_isQrCodeProcessed = false; + qDebug() << "stopDecodingQr"; stopDecodingQr(); } else { + qDebug() << "error while extracting data from qr"; m_qrCodeChunks.clear(); m_totalQrCodeChunksCount = 0; m_receivedQrCodeChunksCount = 0; @@ -344,8 +362,19 @@ void ImportController::parseQrCodeChunk(const QString &code) bool ok = extractConfigFromQr(ba); if (ok) { m_isQrCodeProcessed = false; + qDebug() << "stopDecodingQr"; stopDecodingQr(); } } } + +double ImportController::getQrCodeScanProgressBarValue() +{ + return (1.0 / m_totalQrCodeChunksCount) * m_receivedQrCodeChunksCount; +} + +QString ImportController::getQrCodeScanProgressString() +{ + return tr("Scanned %1 of %2.").arg(m_receivedQrCodeChunksCount).arg(m_totalQrCodeChunksCount); +} #endif diff --git a/client/ui/controllers/importController.h b/client/ui/controllers/importController.h index 9556bc6af..cccdf4b74 100644 --- a/client/ui/controllers/importController.h +++ b/client/ui/controllers/importController.h @@ -28,8 +28,12 @@ public slots: QString getConfig(); QString getConfigFileName(); -#if defined Q_OS_ANDROID +#if defined Q_OS_ANDROID || defined Q_OS_IOS void startDecodingQr(); + void parseQrCodeChunk(const QString &code); + + double getQrCodeScanProgressBarValue(); + QString getQrCodeScanProgressString(); #endif signals: @@ -43,10 +47,11 @@ private: QJsonObject extractOpenVpnConfig(const QString &data); QJsonObject extractWireGuardConfig(const QString &data); -#if defined Q_OS_ANDROID +#if defined Q_OS_ANDROID || defined Q_OS_IOS void stopDecodingQr(); +#endif +#if defined Q_OS_ANDROID static void onNewQrCodeDataChunk(JNIEnv *env, jobject thiz, jstring data); - void parseQrCodeChunk(const QString &code); #endif QSharedPointer m_serversModel; @@ -56,7 +61,7 @@ private: QJsonObject m_config; QString m_configFileName; -#if defined Q_OS_ANDROID +#if defined Q_OS_ANDROID || defined Q_OS_IOS QMap m_qrCodeChunks; bool m_isQrCodeProcessed; int m_totalQrCodeChunksCount; diff --git a/client/ui/models/containers_model.cpp b/client/ui/models/containers_model.cpp index 8d24e0192..dd1d8d4e3 100644 --- a/client/ui/models/containers_model.cpp +++ b/client/ui/models/containers_model.cpp @@ -176,7 +176,7 @@ ErrorCode ContainersModel::removeCurrentlyProcessedContainer() ErrorCode errorCode = serverController.removeContainer(credentials, dockerContainer); if (errorCode == ErrorCode::NoError) { - beginResetModel(); // todo change to begin remove rows? + beginResetModel(); m_settings->removeContainerConfig(m_currentlyProcessedServerIndex, dockerContainer); m_containers = m_settings->containers(m_currentlyProcessedServerIndex); diff --git a/client/ui/models/protocols/openvpnConfigModel.cpp b/client/ui/models/protocols/openvpnConfigModel.cpp index 1b73c987f..7ef3af5b3 100644 --- a/client/ui/models/protocols/openvpnConfigModel.cpp +++ b/client/ui/models/protocols/openvpnConfigModel.cpp @@ -79,8 +79,7 @@ QVariant OpenVpnConfigModel::data(const QModelIndex &index, int role) const void OpenVpnConfigModel::updateModel(const QJsonObject &config) { beginResetModel(); - m_container = - ContainerProps::containerFromString(config.value(config_key::container).toString()); // todo maybe unused + m_container = ContainerProps::containerFromString(config.value(config_key::container).toString()); m_fullConfig = config; QJsonObject protocolConfig = config.value(config_key::openvpn).toObject(); diff --git a/client/ui/models/servers_model.cpp b/client/ui/models/servers_model.cpp index 364fd71f9..0a117e35a 100644 --- a/client/ui/models/servers_model.cpp +++ b/client/ui/models/servers_model.cpp @@ -157,7 +157,6 @@ bool ServersModel::isDefaultServerHasWriteAccess() void ServersModel::addServer(const QJsonObject &server) { - // todo beginInsertRows()? beginResetModel(); m_settings->addServer(server); m_servers = m_settings->serversArray(); diff --git a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml index cc764451f..8e9085edd 100644 --- a/client/ui/qml/Pages2/PageProtocolCloakSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolCloakSettings.qml @@ -13,12 +13,10 @@ import "../Components" PageType { id: root - //todo move to main? Connections { target: InstallController function onUpdateContainerFinished() { - //todo change to notification PageController.showNotificationMessage(qsTr("Settings updated successfully")) } } diff --git a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml index bea239c78..ca13d7e50 100644 --- a/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolOpenVpnSettings.qml @@ -19,7 +19,6 @@ PageType { target: InstallController function onUpdateContainerFinished() { - //todo change to notification PageController.showNotificationMessage(qsTr("Settings updated successfully")) } } diff --git a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml index 643907907..1189290fc 100644 --- a/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml +++ b/client/ui/qml/Pages2/PageProtocolShadowSocksSettings.qml @@ -13,12 +13,10 @@ import "../Components" PageType { id: root - //todo move to main? Connections { target: InstallController function onUpdateContainerFinished() { - //todo change to notification PageController.showNotificationMessage(qsTr("Settings updated successfully")) } } diff --git a/client/ui/qml/Pages2/PageServiceSftpSettings.qml b/client/ui/qml/Pages2/PageServiceSftpSettings.qml index d37562a17..6783fecda 100644 --- a/client/ui/qml/Pages2/PageServiceSftpSettings.qml +++ b/client/ui/qml/Pages2/PageServiceSftpSettings.qml @@ -15,12 +15,10 @@ import "../Components" PageType { id: root - //todo move to main? Connections { target: InstallController function onUpdateContainerFinished() { - //todo change to notification PageController.showNotificationMessage(qsTr("Settings updated successfully")) } } diff --git a/client/ui/qml/Pages2/PageServiceTorWebsiteSettings.qml b/client/ui/qml/Pages2/PageServiceTorWebsiteSettings.qml index 5ddb9ed6f..40e1b3393 100644 --- a/client/ui/qml/Pages2/PageServiceTorWebsiteSettings.qml +++ b/client/ui/qml/Pages2/PageServiceTorWebsiteSettings.qml @@ -16,12 +16,10 @@ import "../Components" PageType { id: root - //todo move to main? Connections { target: InstallController function onUpdateContainerFinished() { - //todo change to notification PageController.showNotificationMessage(qsTr("Settings updated successfully")) } } diff --git a/client/ui/qml/Pages2/PageSettingsServerProtocol.qml b/client/ui/qml/Pages2/PageSettingsServerProtocol.qml index e417eea97..db86f7b22 100644 --- a/client/ui/qml/Pages2/PageSettingsServerProtocol.qml +++ b/client/ui/qml/Pages2/PageSettingsServerProtocol.qml @@ -55,16 +55,15 @@ PageType { anchors.topMargin: 32 ListView { - // todo change id naming - id: container + id: protocols width: parent.width - height: container.contentItem.height + height: protocols.contentItem.height clip: true interactive: false model: ProtocolsModel delegate: Item { - implicitWidth: container.width + implicitWidth: protocols.width implicitHeight: delegateContent.implicitHeight ColumnLayout { diff --git a/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml b/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml index cd0c08fbc..f01556672 100644 --- a/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml +++ b/client/ui/qml/Pages2/PageSetupWizardConfigSource.qml @@ -17,6 +17,7 @@ PageType { target: ImportController function onQrDecodingFinished() { + closePage() goToPage(PageEnum.PageSetupWizardViewConfig) } } @@ -86,7 +87,7 @@ It's okay if a friend passed the code.") clickedFunction: function() { ImportController.startDecodingQr() -// goToPage(PageEnum.PageSetupWizardQrReader) + goToPage(PageEnum.PageSetupWizardQrReader) } } diff --git a/client/ui/qml/Pages2/PageSetupWizardInstalling.qml b/client/ui/qml/Pages2/PageSetupWizardInstalling.qml index e194c21cb..3f135c155 100644 --- a/client/ui/qml/Pages2/PageSetupWizardInstalling.qml +++ b/client/ui/qml/Pages2/PageSetupWizardInstalling.qml @@ -68,7 +68,6 @@ PageType { } FlickableType { - id: fl anchors.fill: parent contentHeight: content.height @@ -82,7 +81,6 @@ PageType { spacing: 16 ListView { - // todo change id naming id: container width: parent.width height: container.contentItem.height diff --git a/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml b/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml index 65e00da8c..f9d55ddfc 100644 --- a/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml +++ b/client/ui/qml/Pages2/PageSetupWizardProtocolSettings.qml @@ -233,7 +233,6 @@ PageType { } Component.onCompleted: { - //todo move to protocols model? var defaultContainerProto = ContainerProps.defaultProtocol(dockerContainer) if (ProtocolProps.defaultPort(defaultContainerProto) < 0) { diff --git a/client/ui/qml/Pages2/PageSetupWizardQrReader.qml b/client/ui/qml/Pages2/PageSetupWizardQrReader.qml index 65d233eff..695175fde 100644 --- a/client/ui/qml/Pages2/PageSetupWizardQrReader.qml +++ b/client/ui/qml/Pages2/PageSetupWizardQrReader.qml @@ -14,39 +14,76 @@ import "../Config" PageType { id: root - ColumnLayout { - anchors.fill: parent + BackButtonType { + id: backButton + anchors.left: parent.left + anchors.top: parent.top - spacing: 0 + anchors.topMargin: 20 + } - BackButtonType { - Layout.topMargin: 20 - } + ParagraphTextType { + id: header - ParagraphTextType { - Layout.fillWidth: true + property string progressString - text: qsTr("Point the camera at the QR code and hold for a couple of seconds.") - } + anchors.left: parent.left + anchors.top: backButton.bottom + anchors.right: parent.right - ProgressBarType { + anchors.leftMargin: 16 + anchors.rightMargin: 16 - } + text: qsTr("Point the camera at the QR code and hold for a couple of seconds. ") + progressString + } - Item { - Layout.fillHeight: true - Layout.fillWidth: true + ProgressBarType { + id: progressBar - QRCodeReader { - id: qrCodeReader - Component.onCompleted: { - qrCodeReader.setCameraSize(Qt.rect(parent.x, - parent.y, - parent.width, - parent.height)) - qrCodeReader.startReading() - } - } + anchors.left: parent.left + anchors.top: header.bottom + anchors.right: parent.right + + anchors.leftMargin: 16 + anchors.rightMargin: 16 + } + + Rectangle { + id: qrCodeRectange + anchors.right: parent.right + anchors.left: parent.left + anchors.bottom: parent.bottom + anchors.top: progressBar.bottom + + anchors.topMargin: 34 + anchors.leftMargin: 16 + anchors.rightMargin: 16 + anchors.bottomMargin: 34 + + color: "transparent" + //radius: 16 + + QRCodeReader { + id: qrCodeReader + + onCodeReaded: function(code) { + ImportController.parseQrCodeChunk(code) + progressBar.value = ImportController.getQrCodeScanProgressBarValue() + header.progressString = ImportController.getQrCodeScanProgressString() + } + + Component.onCompleted: { + console.log(qrCodeRectange.x) + console.log(qrCodeRectange.y) + console.log(qrCodeRectange.width) + + qrCodeReader.setCameraSize(Qt.rect(qrCodeRectange.x, + qrCodeRectange.y, + qrCodeRectange.width, + qrCodeRectange.height)) + qrCodeReader.startReading() + } + Component.onDestruction: qrCodeReader.stopReading() } } } diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 5f3511d4d..99ca700d4 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -96,7 +96,7 @@ void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state) #endif #ifdef Q_OS_IOS - if (state == VpnProtocol::Connected) { + if (state == Vpn::ConnectionState::Connected) { m_checkTimer.start(); } else { @@ -337,7 +337,7 @@ void VpnConnection::connectToVpn(int serverIndex, if (!iosVpnProtocol->initialize()) { qDebug() << QString("Init failed") ; - emit VpnProtocol::Error; + emit Vpn::ConnectionState::Error; iosVpnProtocol->deleteLater(); return; }