diff --git a/OTPListModel.py b/OTPListModel.py index 7d3579b576f202e2d41401d4e2d18536f7dd97ee..c5ccbc4d86cd915502a5009ec9a0857abf08b4f8 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 154a7035a25f2becd308bd15ed22c578eda19a2f..c1992315fe3d9e963d589077fabb81be897c6718 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 b0495a1441e6ee1f55ee058b524d4eddb53b72f9..87997cda9ec84c8999099bf2e12dd3df84571bcd 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