1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 23:17:15 +00:00
UTPass/qml/pages/PasswordList.qml

206 lines
5.7 KiB
QML
Raw Normal View History

2025-01-10 15:28:42 +01:00
import "../components"
import "../dialogs"
import Lomiri.Components 1.3
2025-01-15 23:40:35 +01:00
import Lomiri.Components.Popups 1.3
2019-09-20 21:29:39 +02:00
import Pass 1.0
2025-01-10 15:28:42 +01:00
import Qt.labs.folderlistmodel 2.1
import QtQuick 2.4
2025-01-15 23:40:35 +01:00
import "headers"
2019-09-20 21:29:39 +02:00
Page {
id: passwordListPage
property string __passwordStorePath
property var __passwords
function __searchPasswords(filter) {
var ret = [];
if (__passwords) {
for (var i = 0; i < __passwords.length; i++) {
if (__passwords[i].toUpperCase().indexOf(filter.toUpperCase()) > -1)
ret.push(__passwords[i]);
}
}
return ret;
}
function __searchUpdateModel(text) {
var ret = __searchPasswords(text);
passwordListSearch.model.clear();
for (var i = 0; i < ret.length; i++) {
if (ret[i])
passwordListSearch.model.append({
"fileName": ret[i]
});
}
}
2019-09-20 21:29:39 +02:00
anchors.fill: parent
2025-01-10 15:28:42 +01:00
Component.onCompleted: {
__passwordStorePath = "file:" + Pass.password_store;
Pass.onShowSucceed.connect(function(filename, text) {
pageStack.push(Qt.resolvedUrl("../pages/Password.qml"), {
"plainText": text,
"title": filename
});
});
Pass.onShowFailed.connect(function(message) {
PopupUtils.open(passwordPageDecryptError);
});
Pass.onLsSucceed.connect(function(passwords) {
__passwords = passwords;
});
Pass.ls();
2019-09-20 21:29:39 +02:00
}
2025-01-20 14:46:47 +01:00
Column {
id: passwordListEmpty
2019-09-20 21:29:39 +02:00
anchors.top: passwordListHeader.bottom
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
2025-01-20 14:46:47 +01:00
anchors.leftMargin: units.gu(2)
anchors.rightMargin: units.gu(2)
visible: passwordListNav.model.count === 0
2025-01-20 14:46:47 +01:00
Rectangle {
width: parent.width
height: units.gu(1)
2025-01-28 10:17:57 +01:00
color: theme.palette.normal.background
2025-01-20 14:46:47 +01:00
}
Text {
text: i18n.tr("No password found")
width: parent.width
horizontalAlignment: Text.AlignHCenter
2025-01-28 10:17:57 +01:00
color: theme.palette.normal.backgroundText
2025-01-20 14:46:47 +01:00
}
Rectangle {
width: parent.width
height: units.gu(1)
2025-01-28 10:17:57 +01:00
color: theme.palette.normal.background
2025-01-20 14:46:47 +01:00
}
Text {
text: i18n.tr("You can import a password store by cloning or")
width: parent.width
horizontalAlignment: Text.AlignHCenter
2025-01-28 10:17:57 +01:00
color: theme.palette.normal.backgroundText
2025-01-20 14:46:47 +01:00
}
2025-01-10 15:28:42 +01:00
2019-09-20 21:29:39 +02:00
Text {
2025-01-20 14:46:47 +01:00
text: i18n.tr("importing a password store zip in the settings")
width: parent.width
2019-09-20 21:29:39 +02:00
horizontalAlignment: Text.AlignHCenter
2025-01-28 10:17:57 +01:00
color: theme.palette.normal.backgroundText
2019-09-20 21:29:39 +02:00
}
2025-01-10 15:28:42 +01:00
2019-09-20 21:29:39 +02:00
}
ListView {
id: passwordListNav
2019-09-20 21:29:39 +02:00
anchors.top: passwordListHeader.bottom
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
spacing: 1
visible: passwordListNav.model.count !== 0 && passwordListHeader.searchBarIsActive
2019-09-20 21:29:39 +02:00
model: FolderListModel {
nameFilters: ["*.gpg"]
rootFolder: __passwordStorePath
folder: __passwordStorePath
2019-09-20 21:29:39 +02:00
showDirs: true
}
2025-01-10 15:28:42 +01:00
delegate: Component {
FileDir {
fName: fileName
fIsDir: fileIsDir
onClicked: {
var path = passwordListNav.model.folder + "/" + fileName;
if (fileIsDir) {
passwordListNav.model.folder = path;
backAction.visible = true;
passwordListHeader.title = fileName;
} else {
console.debug("pass show %1".arg(path));
Pass.show(path);
}
}
}
}
}
ListView {
id: passwordListSearch
anchors.top: passwordListHeader.bottom
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.left: parent.left
visible: passwordListNav.model.count !== 0 && !passwordListHeader.searchBarIsActive
model: ListModel {
}
delegate: Component {
FileDir {
fName: fileName
fIsDir: false
onClicked: {
var path = __passwordStorePath + "/" + fileName;
console.debug("pass show %1".arg(path));
Pass.show(path);
}
}
2019-09-20 21:29:39 +02:00
}
2025-01-10 15:28:42 +01:00
2019-09-20 21:29:39 +02:00
}
2025-01-15 23:40:35 +01:00
Component {
id: passwordPageDecryptError
ErrorDialog {
textError: i18n.tr("Decryption failed !")
}
}
2025-01-10 15:28:42 +01:00
header: MainHeader {
id: passwordListHeader
onSearchBarActived: __searchUpdateModel("")
onSearchBarTextChanged: __searchUpdateModel(text)
2025-01-10 15:28:42 +01:00
leadingActionBar.height: units.gu(4)
leadingActionBar.actions: [
Action {
id: backAction
iconName: "back"
text: i18n.tr("Back")
visible: false
onTriggered: {
passwordListNav.model.folder = passwordListNav.model.parentFolder;
console.debug(passwordListNav.model.folder);
if (passwordListNav.model.rootFolder === passwordListNav.model.folder) {
2025-01-10 15:28:42 +01:00
backAction.visible = false;
passwordListHeader.title = i18n.tr("UTPass");
} else {
passwordListHeader.title = folderModel.folder;
}
2025-01-10 15:28:42 +01:00
}
}
]
2019-09-20 21:29:39 +02:00
}
2025-01-10 15:28:42 +01:00
2019-09-20 21:29:39 +02:00
}