From 0d7cb1b401a622892d65aa3d963023583982ce1a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 24 May 2020 18:23:00 -0400 Subject: [PATCH] add contact list --- src/app/profile/core.nim | 4 ++ src/app/profile/view.nim | 12 ++++++ src/app/profile/views/contact_list.nim | 46 +++++++++++++++++++++ src/models/profile.nim | 4 ++ ui/app/AppLayouts/Profile/ProfileLayout.qml | 38 +++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 src/app/profile/views/contact_list.nim diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index 9e34e6a7a4..643f10f5d2 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -32,3 +32,7 @@ proc init*(self: ProfileController, account: Account) = for mailserver_config in mailservers: let mailserver = MailServer(name: mailserver_config[0], endpoint: mailserver_config[1]) self.view.addMailServerToList(mailserver) + + self.view.addContactToList(Contact(name: "username1", address: "0x12345")) + self.view.addContactToList(Contact(name: "username2", address: "0x23456")) + self.view.addContactToList(Contact(name: "username3", address: "0x34567")) diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index 967cb6e288..3c218bc13e 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -1,5 +1,6 @@ import NimQml import views/mailservers_list +import views/contact_list import views/profile_info import ../../models/profile @@ -7,6 +8,7 @@ QtObject: type ProfileView* = ref object of QObject profile*: ProfileInfoView mailserversList*: MailServersList + contactList*: ContactList proc setup(self: ProfileView) = self.QObject.setup @@ -19,6 +21,7 @@ QtObject: result = ProfileView() result.profile = newProfileInfoView() result.mailserversList = newMailServersList() + result.contactList = newContactList() result.setup proc addMailServerToList*(self: ProfileView, mailserver: MailServer) = @@ -30,6 +33,15 @@ QtObject: QtProperty[QVariant] mailserversList: read = getMailserversList + proc addContactToList*(self: ProfileView, contact: Contact) = + self.contactList.addContactToList(contact) + + proc getContactList(self: ProfileView): QVariant {.slot.} = + return newQVariant(self.contactList) + + QtProperty[QVariant] contactList: + read = getContactList + proc getProfile(self: ProfileView): QVariant {.slot.} = return newQVariant(self.profile) diff --git a/src/app/profile/views/contact_list.nim b/src/app/profile/views/contact_list.nim new file mode 100644 index 0000000000..7e69f88026 --- /dev/null +++ b/src/app/profile/views/contact_list.nim @@ -0,0 +1,46 @@ +import NimQml +import Tables +import strformat +import ../../../models/profile + +type + ContactRoles {.pure.} = enum + Name = UserRole + 1, + Address = UserRole + 2 + +QtObject: + type ContactList* = ref object of QAbstractListModel + contacts*: seq[Contact] + + proc setup(self: ContactList) = self.QAbstractListModel.setup + + proc delete(self: ContactList) = self.QAbstractListModel.delete + + proc newContactList*(): ContactList = + new(result, delete) + result.contacts = @[] + result.setup + + method rowCount(self: ContactList, index: QModelIndex = nil): int = + return self.contacts.len + + method data(self: ContactList, index: QModelIndex, role: int): QVariant = + if not index.isValid: + return + if index.row < 0 or index.row >= self.contacts.len: + return + let contact = self.contacts[index.row] + case role.ContactRoles: + of ContactRoles.Name: result = newQVariant(contact.name) + of ContactRoles.Address: result = newQVariant(contact.address) + + method roleNames(self: ContactList): Table[int, string] = + { + ContactRoles.Name.int:"name", + ContactRoles.Address.int:"address", + }.toTable + + proc addContactToList*(self: ContactList, contact: Contact) = + self.beginInsertRows(newQModelIndex(), self.contacts.len, self.contacts.len) + self.contacts.add(contact) + self.endInsertRows() diff --git a/src/models/profile.nim b/src/models/profile.nim index 225a2e8003..5d6a9a4761 100644 --- a/src/models/profile.nim +++ b/src/models/profile.nim @@ -4,6 +4,10 @@ type MailServer* = ref object name*, endpoint*: string +type + Contact* = ref object + name*, address*: string + type Profile* = ref object username*, identicon*: string diff --git a/ui/app/AppLayouts/Profile/ProfileLayout.qml b/ui/app/AppLayouts/Profile/ProfileLayout.qml index 96adcbe1bd..d143c7fe96 100644 --- a/ui/app/AppLayouts/Profile/ProfileLayout.qml +++ b/ui/app/AppLayouts/Profile/ProfileLayout.qml @@ -72,6 +72,44 @@ Item { font.weight: Font.Bold font.pixelSize: 20 } + + Component { + id: contactsList + + Item { + height: 56 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.left: parent.left + anchors.leftMargin: 0 + Column { + Row { + Text { + text: name + font.weight: Font.Bold + font.pixelSize: 14 + } + } + Row { + Text { + text: address + font.weight: Font.Bold + font.pixelSize: 12 + } + } + } + } + } + + ListView { + id: contactListView + anchors.topMargin: 48 + anchors.top: element4.bottom + anchors.fill: parent + model: profileModel.contactList + delegate: contactsList + } + } Item {