yubioath-flutter/qml/Navigator.qml

201 lines
4.3 KiB
QML
Raw Permalink Normal View History

import QtQuick 2.9
import QtQuick.Controls 2.2
import "utils.js" as Utils
StackView {
2019-10-04 14:09:35 +03:00
property bool isShowingAbout
function clearAndPush(view) {
2020-06-15 10:10:33 +03:00
clear();
push(view, StackView.Immediate);
}
function goToSettings() {
2020-06-15 10:10:33 +03:00
if (currentItem.objectName !== "settingsView")
push(settingsView, StackView.Immediate);
}
function goToLoading() {
2020-06-15 10:10:33 +03:00
if (currentItem.objectName !== "loadingView")
push(loadingView, StackView.Immediate);
}
function goToEnterPasswordIfNotInSettings() {
2020-06-15 10:10:33 +03:00
if (currentItem.objectName !== "enterPasswordView" && currentItem.objectName !== "settingsView")
clearAndPush(enterPasswordView, StackView.Immediate);
}
function home() {
if (!!yubiKey.currentDevice) {
// If locked, prompt for password
2020-06-15 10:10:33 +03:00
if (!!yubiKey.currentDevice && yubiKey.currentDevice.hasPassword && !yubiKey.currentDeviceValidated) {
clearAndPush(enterPasswordView);
return ;
}
2020-06-15 10:10:33 +03:00
navigator.goToCredentials();
} else {
2020-06-15 10:10:33 +03:00
clearAndPush(credentialsView);
}
}
function goToCredentials(force) {
2020-06-15 10:10:33 +03:00
if (currentItem.objectName !== "credentialsView")
clearAndPush(credentialsView);
}
function goToCredentialsIfNotInSettings() {
2020-06-15 10:10:33 +03:00
if (currentItem.objectName !== "credentialsView" && currentItem.objectName !== "settingsView")
clearAndPush(credentialsView);
}
2020-05-13 15:08:30 +03:00
function goToNewCredential(credential) {
2020-06-15 10:10:33 +03:00
if (currentItem.objectName !== "newCredentialView")
push(newCredentialView.createObject(app, {
2020-06-15 10:10:33 +03:00
"credential": credential
}), StackView.Immediate);
}
function confirm(options) {
2020-06-15 10:10:33 +03:00
var popup = confirmationPopup.createObject(app, options);
popup.open();
}
function about() {
2019-10-04 14:09:35 +03:00
if (!isShowingAbout) {
2020-06-15 10:10:33 +03:00
var popup = aboutPopup.createObject(app);
popup.open();
2019-10-04 14:09:35 +03:00
}
}
function snackBar(message) {
var sb = snackBarComponent.createObject(app, {
2020-06-15 10:10:33 +03:00
"message": message
});
sb.open();
}
function snackBarError(message) {
var sbe = snackBarErrorComponent.createObject(app, {
2020-06-15 10:10:33 +03:00
"message": message
});
sbe.open();
}
function getErrorMessage(error_id) {
switch (error_id) {
2020-06-15 10:10:33 +03:00
case "no_credential_found":
return qsTr("No QR code found on screen");
case "incorrect_padding":
return qsTr("Secret key have the wrong format");
case "validate_failed":
return qsTr("Wrong password");
case "no_space":
return qsTr("No space available");
case "no_current_device":
return qsTr("No YubiKey found");
case "open_device_failed":
return qsTr("Failed to connect to YubiKey");
case "ccid_error":
return qsTr("Failed to connect to YubiKey");
case "timeout":
return qsTr("Failed to read from slots");
case "failed_to_parse_uri":
return qsTr("Failed to read credential from QR code");
case "no_pcscd":
return qsTr("Is the pcscd/smart card service running?");
case "no_device_custom_reader":
return qsTr("No device found");
default:
2020-06-15 10:10:33 +03:00
return qsTr("Unknown error");
}
}
2020-06-15 10:10:33 +03:00
initialItem: credentialsView
onCurrentItemChanged: {
if (currentItem)
currentItem.forceActiveFocus();
}
Accessible.ignored: true
Component {
id: credentialsView
2020-06-15 10:10:33 +03:00
CredentialsView {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: settingsView
2020-06-15 10:10:33 +03:00
SettingsView {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: newCredentialView
2020-06-15 10:10:33 +03:00
NewCredentialView {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: enterPasswordView
2020-06-15 10:10:33 +03:00
EnterPasswordView {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: loadingView
2020-06-15 10:10:33 +03:00
LoadingView {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: confirmationPopup
2020-06-15 10:10:33 +03:00
ConfirmationPopup {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: aboutPopup
2020-06-15 10:10:33 +03:00
AboutPopup {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: snackBarComponent
2020-06-15 10:10:33 +03:00
SnackBar {
}
2020-06-15 10:10:33 +03:00
}
Component {
id: snackBarErrorComponent
2020-06-15 10:10:33 +03:00
SnackBar {
buttonColor: yubicoRed
}
2020-06-15 10:10:33 +03:00
}
2020-06-15 10:10:33 +03:00
}