Commit 63426c59 authored by Kevin Whitaker's avatar Kevin Whitaker

Add page for adding item manually. Add dialog on long pressing for removing...

Add page for adding item manually. Add dialog on long pressing for removing items. Add slots for interacting with these screens.
parent c155fb56
......@@ -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)
......
......@@ -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
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment