From 63426c5957363475ef9ada83672b3482e1d09808 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Wed, 26 Sep 2018 13:39:24 -0400 Subject: [PATCH] Add page for adding item manually. Add dialog on long pressing for removing items. Add slots for interacting with these screens. --- OTPListModel.py | 18 +++++++++++++++++- qml/additem.qml | 47 ++++++++++++++++++++++++++++++++++++----------- qml/otplist.qml | 28 +++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/OTPListModel.py b/OTPListModel.py index 7d3579b..c5ccbc4 100644 --- a/OTPListModel.py +++ b/OTPListModel.py @@ -103,7 +103,7 @@ class OPTListModel(QtCore.QAbstractListModel): if(jsonDict != None): for item in jsonDict: self._items.append(OTPModel(item["name"],item["OTPType"],keyring.get_password(SERVICE,item["name"]),item["icon"],item["timeout"],item["algo"])) - self.dataChanged.emit(self.index(0,0),self.index(size-1,0)) + self.modelReset.emit() def save(self): dict=[] @@ -118,6 +118,22 @@ class OPTListModel(QtCore.QAbstractListModel): dict.append(dItem) keyring.set_password(SERVICE,"__config",json.dumps(dict)) + @QtCore.Slot(str,str,str) + def addItem(self, name="",OTPType="",secret=""): + self._items.append(OTPModel(name,OTPType,secret)) + self.modelReset.emit() + self.save() + + @QtCore.Slot(object) + def removeItem(self, model): + self._items.remove(model) + self.modelReset.emit() + keyring.delete_password(SERVICE,model.name) + self.save() + + @QtCore.Slot(int,result=object) + def getItem(self,index): + return self._items[index] def rowCount(self, parent=QtCore.QModelIndex()): return len(self._items) diff --git a/qml/additem.qml b/qml/additem.qml index 154a703..c199231 100644 --- a/qml/additem.qml +++ b/qml/additem.qml @@ -12,22 +12,47 @@ Item { anchors.fill: parent ToolButton { id:back - text: "⬅" + icon.name: "arrow-left" Layout.alignment: Qt.AlignLeft onClicked: tools.parent.parent.goBack() } } } - ColumnLayout { - id: col - spacing: 2 - anchors.top: tools.bottom - anchors.bottom: parent.bottom - anchors.left: parent.left - anchors.right: parent.right - RowLayout { - id:settingsDefaultTimeGroup - Layout.fillWidth: true + GridLayout { + id:grid + anchors.top: tools.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + rowSpacing: 2 + columns: 2 + + Text { + text: "Account Name:" + } + TextField { + id: account + } + Text { + text: "Account Secret:" + } + TextField { + id:secret + echoMode: TextInput.Password + } + Text { + text: "Account Type:" + } + ComboBox { + id:otpType + model: ["TOTP"] //TODO: later add HOTP + } + Text {} + Button { + text: "Add" + onClicked: { + otpListModel.addItem(account.text,otpType.currentText,secret.text) } + } } } \ No newline at end of file diff --git a/qml/otplist.qml b/qml/otplist.qml index b0495a1..87997cd 100644 --- a/qml/otplist.qml +++ b/qml/otplist.qml @@ -1,6 +1,7 @@ import QtQuick 2.2 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.3 +import QtQuick.Dialogs 1.3 Item { ToolBar { @@ -50,6 +51,13 @@ Item { } } } + MessageDialog { + id: removeDialog + visible: false + title: "Remove Item" + text: "Remove code for ?" + standardButtons: StandardButton.Yes | StandardButton.No + } ListView { id: otpList anchors.top: otpTimeout.bottom @@ -69,7 +77,7 @@ Item { color: "grey" } MouseArea { - anchors.fill: parent + anchors.fill: parent onClicked: { if(display.OTPType == "TOTP") { if(!timeoutTimer.running) { @@ -85,10 +93,28 @@ Item { } } } + onPressAndHold: { + removeDialog.text = "Remove entry for "+display.name+" ?" + removeDialog.yes.connect(removeOTPItem) + removeDialog.open() + } + function removeOTPItem() { + removeDialog.accepted.disconnect(removeOTPItem) + otpListModel.removeItem(otpListModel.getItem(otpList.currentIndex)) + } function removeCode() { otpCode.text = "" timeoutTimer.stopTOTP.disconnect(removeCode) } + onPressed: { + rect.color = "lightgrey" + } + onReleased: { + rect.color = "transparent" + } + onCanceled: { + rect.color = "transparent" + } } RowLayout { anchors.verticalCenter: parent.verticalCenter -- GitLab