UTPass/qml/pages/settings/ImportZip.qml

100 lines
2.7 KiB
QML
Raw Normal View History

2019-09-20 19:29:39 +00:00
import QtQuick 2.4
import Ubuntu.Components 1.3
import Ubuntu.Content 1.3
import Ubuntu.Components.Popups 1.3
import Pass 1.0
import Utils 1.0
import "../headers"
import "../../dialogs"
Page {
id: importZipPage
property var activeTransfer
header: StackHeader {
id: importZipHeader
title: i18n.tr("Zip Password Store Import")
}
ContentPeerPicker {
anchors.top: importZipHeader.bottom
anchors.bottom: parent.bottom
anchors.topMargin: importZipPage.header.height
width: parent.width
visible: parent.visible
showTitle: false
contentType: ContentType.Text
handler: ContentHandler.Source
onPeerSelected: {
peer.selectionType = ContentTransfer.Single
importZipPage.activeTransfer = peer.request()
importZipPage.activeTransfer.stateChanged.connect(function () {
if (importZipPage.activeTransfer.state === ContentTransfer.Charged) {
console.log("Charged")
console.log(importZipPage.activeTransfer.items[0].url)
var status = Utils.unzip(
importZipPage.activeTransfer.items[0].url,
Pass.getPasswordStore())
Utils.rmFile(importZipPage.activeTransfer.items[0].url)
if (status) {
PopupUtils.open(dialogImportZipPageSuccess)
} else {
PopupUtils.open(dialogImportZipPageError)
}
importZipPage.activeTransfer = null
}
})
}
onCancelPressed: {
pageStack.pop()
}
}
ContentTransferHint {
id: transferHint
anchors.fill: parent
activeTransfer: importZipPage.activeTransfer
}
Component {
id: importZipPageImportValidation
SimpleValidationDialog {
text: i18n.tr(
"Importing a new zip will delete<br>any existing password store!<br>Continue ?")
onCanceled: {
pageStack.pop()
}
}
}
Component {
id: dialogImportZipPageError
ErrorDialog {
textError: i18n.tr("Password store import failed !")
}
}
Component {
id: dialogImportZipPageSuccess
SuccessDialog {
textSuccess: i18n.tr("Password store sucessfully imported !")
onDialogClosed: {
pageStack.pop()
}
}
}
Component.onCompleted: {
PopupUtils.open(importZipPageImportValidation, importZipPage)
}
}