added qr code scanner for ios
This commit is contained in:
parent
c1c68cf72d
commit
14fa0b4fd3
19 changed files with 128 additions and 69 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <QCommandLineParser>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QThread>
|
||||
|
||||
#include "settings.h"
|
||||
#include "vpnconnection.h"
|
||||
|
|
|
@ -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 "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<void>(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<void>(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
|
||||
|
|
|
@ -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<ServersModel> 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<int, QByteArray> m_qrCodeChunks;
|
||||
bool m_isQrCodeProcessed;
|
||||
int m_totalQrCodeChunksCount;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ PageType {
|
|||
target: InstallController
|
||||
|
||||
function onUpdateContainerFinished() {
|
||||
//todo change to notification
|
||||
PageController.showNotificationMessage(qsTr("Settings updated successfully"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -233,7 +233,6 @@ PageType {
|
|||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
//todo move to protocols model?
|
||||
var defaultContainerProto = ContainerProps.defaultProtocol(dockerContainer)
|
||||
|
||||
if (ProtocolProps.defaultPort(defaultContainerProto) < 0) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue