Commit af0a6260 authored by LNJ's avatar LNJ 🖖

Add front end for QR code scanning

Co-authored-by: melvo's avatarMelvin Keskin <melvo@olomono.de>
Co-authored-by: default avatarJonah Brüchert <jbb@kaidan.im>
parent 6ee280bf
......@@ -7,7 +7,7 @@
<file alias="qml/AboutDialog.qml">src/qml/AboutDialog.qml</file>
<file alias="qml/GlobalDrawer.qml">src/qml/GlobalDrawer.qml</file>
<file alias="qml/EmptyChatPage.qml">src/qml/EmptyChatPage.qml</file>
<file alias="qml/QrCodeScannerPage.qml">src/qml/QrCodeScannerPage.qml</file>
<file alias="qml/elements/SubRequestAcceptSheet.qml">src/qml/elements/SubRequestAcceptSheet.qml</file>
<file alias="qml/elements/RosterAddContactSheet.qml">src/qml/elements/RosterAddContactSheet.qml</file>
<file alias="qml/elements/RosterRemoveContactSheet.qml">src/qml/elements/RosterRemoveContactSheet.qml</file>
......@@ -25,12 +25,10 @@
<file alias="qml/elements/MediaPreviewOther.qml">src/qml/elements/MediaPreviewOther.qml</file>
<file alias="qml/elements/EmojiPicker.qml">src/qml/elements/EmojiPicker.qml</file>
<file alias="qml/elements/TextAvatar.qml">src/qml/elements/TextAvatar.qml</file>
<file alias="qml/settings/SettingsItem.qml">src/qml/settings/SettingsItem.qml</file>
<file alias="qml/settings/SettingsPage.qml">src/qml/settings/SettingsPage.qml</file>
<file alias="qml/settings/SettingsSheet.qml">src/qml/settings/SettingsSheet.qml</file>
<file alias="qml/settings/ChangePassword.qml">src/qml/settings/ChangePassword.qml</file>
<file alias="qtquickcontrols2.conf">misc/qtquickcontrols2.conf</file>
</qresource>
</RCC>
......@@ -38,6 +38,14 @@ import im.kaidan.kaidan 1.0
Kirigami.Page {
title: qsTr("Log in")
actions.contextualActions: [
Kirigami.Action {
text: qsTr("Log in using a QR-Code")
icon.name: "view-barcode"
onTriggered: pageStack.layers.push(qrCodeScannerPage)
}
]
ColumnLayout {
anchors.fill: parent
......@@ -87,26 +95,39 @@ Kirigami.Page {
Controls.Button {
id: connectButton
Layout.fillWidth: true
highlighted: true
Kirigami.Theme.backgroundColor: Material.accent
text: qsTr("Connect")
state: kaidan.connectionState !== Enums.StateDisconnected ? "connecting" : ""
states: [
State {
name: "connecting"
PropertyChanges {
target: connectButton
enabled: false
}
PropertyChanges {
target: connectLabel
text: "<i>" + qsTr("Connecting…") + "</i>"
color: "black"
}
}
]
onClicked: {
// connect to given account data
kaidan.jid = jidField.text.toLowerCase()
kaidan.jid = jidField.text
kaidan.password = passField.text
kaidan.mainConnect()
}
Controls.Label {
id: connectLabel
anchors.centerIn: connectButton
text: qsTr("Connect")
color: Kirigami.Theme.highlightedTextColor
textFormat: Text.StyledText
}
}
// connect when return was pressed
......@@ -123,14 +144,6 @@ Kirigami.Page {
}
}
function handleConnectionState(state) {
if (state === Enums.StateConnecting) {
connectButton.state = "connecting"
} else {
connectButton.state = ""
}
}
function handleConnectionError() {
var error = kaidan.disconnReason
if (error === Enums.ConnAuthenticationFailed) {
......@@ -153,12 +166,10 @@ Kirigami.Page {
}
Component.onCompleted: {
kaidan.connectionStateChanged.connect(handleConnectionState)
kaidan.disconnReasonChanged.connect(handleConnectionError)
}
Component.onDestruction: {
kaidan.connectionStateChanged.disconnect(handleConnectionState)
kaidan.disconnReasonChanged.disconnect(handleConnectionError)
}
}
/*
* Kaidan - A user-friendly XMPP client for every device!
*
* Copyright (C) 2016-2019 Kaidan developers and contributors
* (see the LICENSE file for a full list of copyright authors)
*
* Kaidan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the author of Kaidan gives
* permission to link the code of its release with the OpenSSL
* project's "OpenSSL" library (or with modified versions of it that
* use the same license as the "OpenSSL" library), and distribute the
* linked executables. You must obey the GNU General Public License in
* all respects for all of the code used other than "OpenSSL". If you
* modify this file, you may extend this exception to your version of
* the file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
* Kaidan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtQuick.Controls 2.3 as Controls
import QtMultimedia 5.9
import org.kde.kirigami 2.4 as Kirigami
import im.kaidan.kaidan 1.0
// QR code scanner output and decoding for logging in by a decoded XMPP URI
Kirigami.Page {
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
title: qsTr("Scan QR code")
// message to be shown if no camera can be found
Kirigami.InlineMessage {
visible: {
camera.availability === Camera.Unavailable ||
camera.availability === Camera.ResourceMissing
}
anchors.centerIn: parent
width: 300
height: 60
text: qsTr("There is no camera available.")
}
// message to be shown if the found camera is not usable
Kirigami.InlineMessage {
visible: camera.availability === Camera.Busy
anchors.centerIn: parent
width: 300
height: 60
text: qsTr("Your camera is busy.\nTry to close other applications using the camera.")
}
// video output from the camera which is shown on the screen and decoded by a filter
VideoOutput {
id: viewfinder
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectCrop
source: camera
autoOrientation: true
filters: [scannerFilter]
}
// filter which converst the video frames to images and decodes a containing QR code
QrCodeScannerFilter {
id: scannerFilter
onScanningSucceeded: {
pageStack.layers.pop()
// login by the data from the decoded QR code
kaidan.loginByUri(result)
}
}
// camera with continuous focus in the center of the video
Camera {
id: camera
focus {
focusMode: Camera.FocusContinuous
focusPointMode: Camera.FocusPointCenter
}
}
}
......@@ -71,6 +71,7 @@ Kirigami.ApplicationWindow {
Component {id: rosterPage; RosterPage {}}
Component {id: emptyChatPage; EmptyChatPage {}}
Component {id: settingsPage; SettingsPage {}}
Component {id: qrCodeScannerPage; QrCodeScannerPage {}}
function passiveNotification(text) {
showPassiveNotification(text, "long")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment