diff --git a/src/app/modules/startup/login/account_item.nim b/src/app/modules/startup/login/account_item.nim deleted file mode 100644 index d07415f69e..0000000000 --- a/src/app/modules/startup/login/account_item.nim +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/app/modules/startup/login/controller.nim b/src/app/modules/startup/login/controller.nim index b6ea21a7dc..3d59a52047 100644 --- a/src/app/modules/startup/login/controller.nim +++ b/src/app/modules/startup/login/controller.nim @@ -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) @@ -42,4 +40,10 @@ 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)) \ No newline at end of file + #self.handleNodeLogin(NodeSignal(e)) + +method getOpenedAccounts*(self: Controller): seq[AccountDto] = + return self.accountsService.openedAccounts() + +method setSelectedAccountKeyUid*(self: Controller, keyUid: string) = + self.selectedAccountKeyUid = keyUid \ No newline at end of file diff --git a/src/app/modules/startup/login/controller_interface.nim b/src/app/modules/startup/login/controller_interface.nim index 8eb6d68db7..a7a17980ac 100644 --- a/src/app/modules/startup/login/controller_interface.nim +++ b/src/app/modules/startup/login/controller_interface.nim @@ -11,4 +11,7 @@ method init*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") 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") \ No newline at end of file diff --git a/src/app/modules/startup/login/item.nim b/src/app/modules/startup/login/item.nim new file mode 100644 index 0000000000..361566fcbc --- /dev/null +++ b/src/app/modules/startup/login/item.nim @@ -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 \ No newline at end of file diff --git a/src/app/modules/startup/login/model.nim b/src/app/modules/startup/login/model.nim index 35da5c4bef..8e2b80fb79 100644 --- a/src/app/modules/startup/login/model.nim +++ b/src/app/modules/startup/login/model.nim @@ -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() \ No newline at end of file + + proc getItemAtIndex*(self: Model, index: int): Item = + if(index < 0 or index >= self.items.len): + return + + return self.items[index] \ No newline at end of file diff --git a/src/app/modules/startup/login/module.nim b/src/app/modules/startup/login/module.nim index ea678aff7c..94ebd618a6 100644 --- a/src/app/modules/startup/login/module.nim +++ b/src/app/modules/startup/login/module.nim @@ -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,28 +50,26 @@ 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 method viewDidLoad*(self: Module) = self.moduleLoaded = true - self.delegate.loginDidLoad() \ No newline at end of file + self.delegate.loginDidLoad() + +method setSelectedAccount*(self: Module, item: Item) = + self.controller.setSelectedAccountKeyUid(item.getKeyUid()) + self.view.setSelectedAccount(item) \ No newline at end of file diff --git a/src/app/modules/startup/login/private_interfaces/module_view_delegate_interface.nim b/src/app/modules/startup/login/private_interfaces/module_view_delegate_interface.nim index a5a66c0e55..3f6bc59a36 100644 --- a/src/app/modules/startup/login/private_interfaces/module_view_delegate_interface.nim +++ b/src/app/modules/startup/login/private_interfaces/module_view_delegate_interface.nim @@ -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") \ No newline at end of file diff --git a/src/app/modules/startup/login/selected_account.nim b/src/app/modules/startup/login/selected_account.nim new file mode 100644 index 0000000000..c85a172e29 --- /dev/null +++ b/src/app/modules/startup/login/selected_account.nim @@ -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 \ No newline at end of file diff --git a/src/app/modules/startup/login/view.nim b/src/app/modules/startup/login/view.nim index 6e1148cf95..5eb3ab7a07 100644 --- a/src/app/modules/startup/login/view.nim +++ b/src/app/modules/startup/login/view.nim @@ -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() diff --git a/src/app/modules/startup/onboarding/item.nim b/src/app/modules/startup/onboarding/item.nim index d5a2cb2c42..4fdf491e8b 100644 --- a/src/app/modules/startup/onboarding/item.nim +++ b/src/app/modules/startup/onboarding/item.nim @@ -1,5 +1,3 @@ -import json - type Item* = object id: string diff --git a/ui/app/AppLayouts/Onboarding/popups/SelectAnotherAccountModal.qml b/ui/app/AppLayouts/Onboarding/popups/SelectAnotherAccountModal.qml index bb04ff7451..cd818a65e7 100644 --- a/ui/app/AppLayouts/Onboarding/popups/SelectAnotherAccountModal.qml +++ b/ui/app/AppLayouts/Onboarding/popups/SelectAnotherAccountModal.qml @@ -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) { diff --git a/ui/app/AppLayouts/Onboarding/stores/LoginStore.qml b/ui/app/AppLayouts/Onboarding/stores/LoginStore.qml index c7e08f50a7..6622e1cab3 100644 --- a/ui/app/AppLayouts/Onboarding/stores/LoginStore.qml +++ b/ui/app/AppLayouts/Onboarding/stores/LoginStore.qml @@ -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() } } diff --git a/ui/app/AppLayouts/Onboarding/views/LoginView.qml b/ui/app/AppLayouts/Onboarding/views/LoginView.qml index 18b94f1041..8280a00f07 100644 --- a/ui/app/AppLayouts/Onboarding/views/LoginView.qml +++ b/ui/app/AppLayouts/Onboarding/views/LoginView.qml @@ -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