selecting among multiple accounts on login added
This commit is contained in:
parent
30f11c06d4
commit
8974a8db5e
|
@ -1,63 +0,0 @@
|
|||
import NimQml
|
||||
|
||||
QtObject:
|
||||
type AccountItem* = ref object of QObject
|
||||
name: string
|
||||
identicon: string
|
||||
keyUid: string
|
||||
thumbnailImage: string
|
||||
largeImage: string
|
||||
|
||||
proc setup(self: AccountItem) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: AccountItem) =
|
||||
self.QObject.delete
|
||||
|
||||
proc setAccountItemData*(self: AccountItem, name, identicon, keyUid,
|
||||
thumbnailImage, largeImage: string) =
|
||||
self.name = name
|
||||
self.identicon = identicon
|
||||
self.keyUid = keyUid
|
||||
self.thumbnailImage = thumbnailImage
|
||||
self.largeImage = largeImage
|
||||
|
||||
proc newAccountItem*(): AccountItem =
|
||||
new(result, delete)
|
||||
result.setup
|
||||
|
||||
proc newAccountItem*(name, identicon, keyUid, thumbnailImage,
|
||||
largeImage: string): AccountItem =
|
||||
new(result, delete)
|
||||
result.setup
|
||||
result.setAccountItemData(name, identicon, keyUid, thumbnailImage, largeImage)
|
||||
|
||||
proc getName(self: AccountItem): string {.slot.} =
|
||||
result = self.name
|
||||
|
||||
QtProperty[string] name:
|
||||
read = getName
|
||||
|
||||
proc getIdenticon(self: AccountItem): string {.slot.} =
|
||||
result = self.identicon
|
||||
|
||||
QtProperty[string] identicon:
|
||||
read = getIdenticon
|
||||
|
||||
proc getKeyUid(self: AccountItem): string {.slot.} =
|
||||
result = self.keyUid
|
||||
|
||||
QtProperty[string] keyUid:
|
||||
read = getKeyUid
|
||||
|
||||
proc getThumbnailImage(self: AccountItem): string {.slot.} =
|
||||
result = self.thumbnailImage
|
||||
|
||||
QtProperty[string] thumbnailImage:
|
||||
read = getThumbnailImage
|
||||
|
||||
proc getLargeImage(self: AccountItem): string {.slot.} =
|
||||
result = self.largeImage
|
||||
|
||||
QtProperty[string] largeImage:
|
||||
read = getLargeImage
|
|
@ -14,6 +14,7 @@ type
|
|||
delegate: io_interface.AccessInterface
|
||||
appService: AppService
|
||||
accountsService: accounts_service.ServiceInterface
|
||||
selectedAccountKeyUid: string
|
||||
|
||||
proc newController*(delegate: io_interface.AccessInterface,
|
||||
appService: AppService,
|
||||
|
@ -27,9 +28,6 @@ proc newController*(delegate: io_interface.AccessInterface,
|
|||
method delete*(self: Controller) =
|
||||
discard
|
||||
|
||||
method getOpenedAccounts*(self: Controller): seq[AccountDto] =
|
||||
return self.accountsService.openedAccounts()
|
||||
|
||||
method init*(self: Controller) =
|
||||
self.appService.status.events.on(SignalType.NodeStopped.event) do(e:Args):
|
||||
echo "-NEW-LOGIN-- NodeStopped: ", repr(e)
|
||||
|
@ -43,3 +41,9 @@ method init*(self: Controller) =
|
|||
self.appService.status.events.on(SignalType.NodeLogin.event) do(e:Args):
|
||||
echo "-NEW-LOGIN-- NodeLogin: ", repr(e)
|
||||
#self.handleNodeLogin(NodeSignal(e))
|
||||
|
||||
method getOpenedAccounts*(self: Controller): seq[AccountDto] =
|
||||
return self.accountsService.openedAccounts()
|
||||
|
||||
method setSelectedAccountKeyUid*(self: Controller, keyUid: string) =
|
||||
self.selectedAccountKeyUid = keyUid
|
|
@ -12,3 +12,6 @@ method init*(self: AccessInterface) {.base.} =
|
|||
|
||||
method getOpenedAccounts*(self: AccessInterface): seq[AccountDto] {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setSelectedAccountKeyUid*(self: AccessInterface, keyUid: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -0,0 +1,30 @@
|
|||
type
|
||||
Item* = object
|
||||
name: string
|
||||
identicon: string
|
||||
thumbnailImage: string
|
||||
largeImage: string
|
||||
keyUid: string
|
||||
|
||||
proc initItem*(name, identicon, thumbnailImage, largeImage, keyUid: string):
|
||||
Item =
|
||||
result.name = name
|
||||
result.identicon = identicon
|
||||
result.thumbnailImage = thumbnailImage
|
||||
result.largeImage = largeImage
|
||||
result.keyUid = keyUid
|
||||
|
||||
proc getName*(self: Item): string =
|
||||
return self.name
|
||||
|
||||
proc getIdenticon*(self: Item): string =
|
||||
return self.identicon
|
||||
|
||||
proc getThumbnailImage*(self: Item): string =
|
||||
result = self.thumbnailImage
|
||||
|
||||
proc getLargeImage*(self: Item): string =
|
||||
result = self.largeImage
|
||||
|
||||
proc getKeyUid*(self: Item): string =
|
||||
return self.keyUid
|
|
@ -1,15 +1,19 @@
|
|||
import NimQml, Tables, strutils, strformat
|
||||
|
||||
import account_item
|
||||
import item
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
Account = UserRole + 1
|
||||
Name = UserRole + 1
|
||||
Identicon
|
||||
ThumbnailImage
|
||||
LargeImage
|
||||
KeyUid
|
||||
|
||||
QtObject:
|
||||
type
|
||||
Model* = ref object of QAbstractListModel
|
||||
items: seq[AccountItem]
|
||||
items: seq[Item]
|
||||
|
||||
proc delete(self: Model) =
|
||||
self.items = @[]
|
||||
|
@ -22,21 +26,16 @@ QtObject:
|
|||
new(result, delete)
|
||||
result.setup
|
||||
|
||||
proc countChanged*(self: Model) {.signal.}
|
||||
|
||||
proc count*(self: Model): int {.slot.} =
|
||||
self.items.len
|
||||
|
||||
QtProperty[int] count:
|
||||
read = count
|
||||
notify = countChanged
|
||||
|
||||
method rowCount(self: Model, index: QModelIndex = nil): int =
|
||||
return self.items.len
|
||||
|
||||
method roleNames(self: Model): Table[int, string] =
|
||||
{
|
||||
ModelRole.Account.int:"account"
|
||||
ModelRole.Name.int:"username",
|
||||
ModelRole.Identicon.int:"identicon",
|
||||
ModelRole.ThumbnailImage.int:"thumbnailImage",
|
||||
ModelRole.LargeImage.int:"largeImage",
|
||||
ModelRole.KeyUid.int:"keyUid"
|
||||
}.toTable
|
||||
|
||||
method data(self: Model, index: QModelIndex, role: int): QVariant =
|
||||
|
@ -50,11 +49,24 @@ QtObject:
|
|||
let enumRole = role.ModelRole
|
||||
|
||||
case enumRole:
|
||||
of ModelRole.Account:
|
||||
result = newQVariant(item)
|
||||
of ModelRole.Name:
|
||||
result = newQVariant(item.getName())
|
||||
of ModelRole.Identicon:
|
||||
result = newQVariant(item.getIdenticon())
|
||||
of ModelRole.ThumbnailImage:
|
||||
result = newQVariant(item.getThumbnailImage())
|
||||
of ModelRole.LargeImage:
|
||||
result = newQVariant(item.getLargeImage())
|
||||
of ModelRole.KeyUid:
|
||||
result = newQVariant(item.getKeyUid())
|
||||
|
||||
proc setItems*(self: Model, items: seq[AccountItem]) =
|
||||
proc setItems*(self: Model, items: seq[Item]) =
|
||||
self.beginResetModel()
|
||||
self.items = items
|
||||
self.endResetModel()
|
||||
self.countChanged()
|
||||
|
||||
proc getItemAtIndex*(self: Model, index: int): Item =
|
||||
if(index < 0 or index >= self.items.len):
|
||||
return
|
||||
|
||||
return self.items[index]
|
|
@ -1,7 +1,7 @@
|
|||
import NimQml
|
||||
import io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
import view, controller, account_item
|
||||
import view, controller, item
|
||||
import ../../../../app/boot/global_singleton
|
||||
|
||||
import ../../../../app_service/[main]
|
||||
|
@ -50,24 +50,18 @@ method load*(self: Module) =
|
|||
|
||||
let openedAccounts = self.controller.getOpenedAccounts()
|
||||
if(openedAccounts.len > 0):
|
||||
var accounts: seq[AccountItem]
|
||||
var items: seq[Item]
|
||||
for acc in openedAccounts:
|
||||
var thumbnailImage: string
|
||||
var largeImage: string
|
||||
self.extractImages(acc, thumbnailImage, largeImage)
|
||||
accounts.add(newAccountItem(acc.name, acc.identicon, acc.keyUid,
|
||||
thumbnailImage, largeImage))
|
||||
items.add(initItem(acc.name, acc.identicon, thumbnailImage, largeImage,
|
||||
acc.keyUid))
|
||||
|
||||
self.view.setAccountsList(accounts)
|
||||
self.view.setModelItems(items)
|
||||
|
||||
# set the first account as a slected one
|
||||
let selected = openedAccounts[0]
|
||||
var thumbnailImage: string
|
||||
var largeImage: string
|
||||
self.extractImages(selected, thumbnailImage, largeImage)
|
||||
|
||||
self.view.setSelectedAccount(selected.name, selected.identicon, selected.keyUid,
|
||||
thumbnailImage, largeImage)
|
||||
# set the first account as slected one
|
||||
self.setSelectedAccount(items[0])
|
||||
|
||||
method isLoaded*(self: Module): bool =
|
||||
return self.moduleLoaded
|
||||
|
@ -75,3 +69,7 @@ method isLoaded*(self: Module): bool =
|
|||
method viewDidLoad*(self: Module) =
|
||||
self.moduleLoaded = true
|
||||
self.delegate.loginDidLoad()
|
||||
|
||||
method setSelectedAccount*(self: Module, item: Item) =
|
||||
self.controller.setSelectedAccountKeyUid(item.getKeyUid())
|
||||
self.view.setSelectedAccount(item)
|
|
@ -1,2 +1,7 @@
|
|||
import ../item
|
||||
|
||||
method viewDidLoad*(self: AccessInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setSelectedAccount*(self: AccessInterface, item: Item) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
|
@ -0,0 +1,49 @@
|
|||
import NimQml
|
||||
import item
|
||||
|
||||
QtObject:
|
||||
type SelectedAccount* = ref object of QObject
|
||||
item: Item
|
||||
|
||||
proc setup(self: SelectedAccount) =
|
||||
self.QObject.setup
|
||||
|
||||
proc delete*(self: SelectedAccount) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newSelectedAccount*(): SelectedAccount =
|
||||
new(result, delete)
|
||||
result.setup
|
||||
|
||||
proc setSelectedAccountData*(self: SelectedAccount, item: Item) =
|
||||
self.item = item
|
||||
|
||||
proc getName(self: SelectedAccount): string {.slot.} =
|
||||
return self.item.getName()
|
||||
|
||||
QtProperty[string] username:
|
||||
read = getName
|
||||
|
||||
proc getIdenticon(self: SelectedAccount): string {.slot.} =
|
||||
return self.item.getIdenticon()
|
||||
|
||||
QtProperty[string] identicon:
|
||||
read = getIdenticon
|
||||
|
||||
proc getKeyUid(self: SelectedAccount): string {.slot.} =
|
||||
return self.item.getKeyUid()
|
||||
|
||||
QtProperty[string] keyUid:
|
||||
read = getKeyUid
|
||||
|
||||
proc getThumbnailImage(self: SelectedAccount): string {.slot.} =
|
||||
return self.item.getThumbnailImage()
|
||||
|
||||
QtProperty[string] thumbnailImage:
|
||||
read = getThumbnailImage
|
||||
|
||||
proc getLargeImage(self: SelectedAccount): string {.slot.} =
|
||||
return self.item.getLargeImage()
|
||||
|
||||
QtProperty[string] largeImage:
|
||||
read = getLargeImage
|
|
@ -1,12 +1,12 @@
|
|||
import NimQml
|
||||
import account_item, model
|
||||
import model, item, selected_account
|
||||
import io_interface
|
||||
|
||||
QtObject:
|
||||
type
|
||||
View* = ref object of QObject
|
||||
delegate: io_interface.AccessInterface
|
||||
selectedAccount: AccountItem
|
||||
selectedAccount: SelectedAccount
|
||||
selectedAccountVariant: QVariant
|
||||
model: Model
|
||||
modelVariant: QVariant
|
||||
|
@ -22,7 +22,7 @@ QtObject:
|
|||
new(result, delete)
|
||||
result.QObject.setup
|
||||
result.delegate = delegate
|
||||
result.selectedAccount = newAccountItem()
|
||||
result.selectedAccount = newSelectedAccount()
|
||||
result.selectedAccountVariant = newQVariant(result.selectedAccount)
|
||||
result.model = newModel()
|
||||
result.modelVariant = newQVariant(result.model)
|
||||
|
@ -35,12 +35,14 @@ QtObject:
|
|||
proc getSelectedAccount(self: View): QVariant {.slot.} =
|
||||
return self.selectedAccountVariant
|
||||
|
||||
proc setSelectedAccount*(self: View, name, identicon, keyUid, thumbnailImage,
|
||||
largeImage: string) =
|
||||
self.selectedAccount.setAccountItemData(name, identicon, keyUid, thumbnailImage,
|
||||
largeImage)
|
||||
proc setSelectedAccount*(self: View, item: Item) =
|
||||
self.selectedAccount.setSelectedAccountData(item)
|
||||
self.selectedAccountChanged()
|
||||
|
||||
proc setSelectedAccountByIndex*(self: View, index: int) {.slot.} =
|
||||
let item = self.model.getItemAtIndex(index)
|
||||
self.delegate.setSelectedAccount(item)
|
||||
|
||||
QtProperty[QVariant] selectedAccount:
|
||||
read = getSelectedAccount
|
||||
notify = selectedAccountChanged
|
||||
|
@ -50,7 +52,7 @@ QtObject:
|
|||
proc getModel(self: View): QVariant {.slot.} =
|
||||
return self.modelVariant
|
||||
|
||||
proc setAccountsList*(self: View, accounts: seq[AccountItem]) =
|
||||
proc setModelItems*(self: View, accounts: seq[Item]) =
|
||||
self.model.setItems(accounts)
|
||||
self.modelChanged()
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import json
|
||||
|
||||
type
|
||||
Item* = object
|
||||
id: string
|
||||
|
|
|
@ -22,9 +22,9 @@ ModalPopup {
|
|||
id: accountList
|
||||
anchors.fill: parent
|
||||
|
||||
model: LoginStore.loginModelInst
|
||||
model: LoginStore.loginModul.accountsModel
|
||||
isSelected: function (index, keyUid) {
|
||||
return LoginStore.loginModelInst.currentAccount.keyUid === keyUid
|
||||
return LoginStore.currentAccount.keyUid === keyUid
|
||||
}
|
||||
|
||||
onAccountSelect: function(index) {
|
||||
|
|
|
@ -3,11 +3,11 @@ pragma Singleton
|
|||
import QtQuick 2.13
|
||||
|
||||
QtObject {
|
||||
property var loginModelInst: loginModel
|
||||
property var currentAccount: loginModel.currentAccount
|
||||
property var loginModul: loginModule
|
||||
property var currentAccount: loginModule.selectedAccount
|
||||
|
||||
function login(password) {
|
||||
loginModel.login(password)
|
||||
loginModul.login(password)
|
||||
}
|
||||
|
||||
function tryToObtainPassword() {
|
||||
|
@ -15,10 +15,10 @@ QtObject {
|
|||
}
|
||||
|
||||
function setCurrentAccount(index) {
|
||||
loginModel.setCurrentAccount(index)
|
||||
loginModul.setSelectedAccountByIndex(index)
|
||||
}
|
||||
|
||||
function rowCount() {
|
||||
return loginModel.rowCount()
|
||||
return loginModul.accountsModel.rowCount()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ Item {
|
|||
|
||||
loading = true
|
||||
LoginStore.login(password)
|
||||
applicationWindow.checkForStoringPassToKeychain(LoginStore.currentAccount.username, password, false)
|
||||
// NEED TO HANDLE IT
|
||||
//applicationWindow.checkForStoringPassToKeychain(LoginStore.currentAccount.username, password, false)
|
||||
txtPassword.textField.clear()
|
||||
}
|
||||
|
||||
|
@ -53,21 +54,22 @@ Item {
|
|||
resetLogin()
|
||||
}
|
||||
|
||||
Connections{
|
||||
id: connection
|
||||
target: LoginStore.loginModelInst
|
||||
// NEED TO HANDLE IT
|
||||
// Connections{
|
||||
// id: connection
|
||||
// target: LoginStore.loginModelInst
|
||||
|
||||
onObtainingPasswordError: {
|
||||
enabled = false
|
||||
obtainingPasswordErrorNotification.confirmationText = errorDescription
|
||||
obtainingPasswordErrorNotification.open()
|
||||
}
|
||||
// onObtainingPasswordError: {
|
||||
// enabled = false
|
||||
// obtainingPasswordErrorNotification.confirmationText = errorDescription
|
||||
// obtainingPasswordErrorNotification.open()
|
||||
// }
|
||||
|
||||
onObtainingPasswordSuccess: {
|
||||
enabled = false
|
||||
doLogin(password)
|
||||
}
|
||||
}
|
||||
// onObtainingPasswordSuccess: {
|
||||
// enabled = false
|
||||
// doLogin(password)
|
||||
// }
|
||||
// }
|
||||
|
||||
ConfirmationDialog {
|
||||
id: obtainingPasswordErrorNotification
|
||||
|
@ -93,7 +95,8 @@ Item {
|
|||
StatusSmartIdenticon {
|
||||
id: userImage
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
image.source : LoginStore.currentAccount.thumbnailImage
|
||||
image.source: LoginStore.currentAccount.thumbnailImage ||
|
||||
LoginStore.currentAccount.identicon
|
||||
image.isIdenticon: true
|
||||
}
|
||||
|
||||
|
@ -224,24 +227,25 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: LoginStore.loginModelInst
|
||||
ignoreUnknownSignals: true
|
||||
onLoginResponseChanged: {
|
||||
if (error) {
|
||||
// SQLITE_NOTADB: "file is not a database"
|
||||
if (error === "file is not a database") {
|
||||
errMsg.text = errMsg.incorrectPasswordMsg
|
||||
} else {
|
||||
//% "Login failed: %1"
|
||||
errMsg.text = qsTrId("login-failed---1").arg(error.toUpperCase())
|
||||
}
|
||||
errMsg.visible = true
|
||||
loading = false
|
||||
txtPassword.textField.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
// NEED TO HANDLE IT
|
||||
// Connections {
|
||||
// target: LoginStore.loginModelInst
|
||||
// ignoreUnknownSignals: true
|
||||
// onLoginResponseChanged: {
|
||||
// if (error) {
|
||||
// // SQLITE_NOTADB: "file is not a database"
|
||||
// if (error === "file is not a database") {
|
||||
// errMsg.text = errMsg.incorrectPasswordMsg
|
||||
// } else {
|
||||
// //% "Login failed: %1"
|
||||
// errMsg.text = qsTrId("login-failed---1").arg(error.toUpperCase())
|
||||
// }
|
||||
// errMsg.visible = true
|
||||
// loading = false
|
||||
// txtPassword.textField.forceActiveFocus()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
StatusQControls.StatusFlatButton {
|
||||
id: generateKeysLinkText
|
||||
|
|
Loading…
Reference in New Issue