add contact list

This commit is contained in:
Iuri Matias 2020-05-24 18:23:00 -04:00
parent c6ed2c8852
commit 0d7cb1b401
5 changed files with 104 additions and 0 deletions

View File

@ -32,3 +32,7 @@ proc init*(self: ProfileController, account: Account) =
for mailserver_config in mailservers: for mailserver_config in mailservers:
let mailserver = MailServer(name: mailserver_config[0], endpoint: mailserver_config[1]) let mailserver = MailServer(name: mailserver_config[0], endpoint: mailserver_config[1])
self.view.addMailServerToList(mailserver) 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"))

View File

@ -1,5 +1,6 @@
import NimQml import NimQml
import views/mailservers_list import views/mailservers_list
import views/contact_list
import views/profile_info import views/profile_info
import ../../models/profile import ../../models/profile
@ -7,6 +8,7 @@ QtObject:
type ProfileView* = ref object of QObject type ProfileView* = ref object of QObject
profile*: ProfileInfoView profile*: ProfileInfoView
mailserversList*: MailServersList mailserversList*: MailServersList
contactList*: ContactList
proc setup(self: ProfileView) = proc setup(self: ProfileView) =
self.QObject.setup self.QObject.setup
@ -19,6 +21,7 @@ QtObject:
result = ProfileView() result = ProfileView()
result.profile = newProfileInfoView() result.profile = newProfileInfoView()
result.mailserversList = newMailServersList() result.mailserversList = newMailServersList()
result.contactList = newContactList()
result.setup result.setup
proc addMailServerToList*(self: ProfileView, mailserver: MailServer) = proc addMailServerToList*(self: ProfileView, mailserver: MailServer) =
@ -30,6 +33,15 @@ QtObject:
QtProperty[QVariant] mailserversList: QtProperty[QVariant] mailserversList:
read = getMailserversList 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.} = proc getProfile(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.profile) return newQVariant(self.profile)

View File

@ -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()

View File

@ -4,6 +4,10 @@ type
MailServer* = ref object MailServer* = ref object
name*, endpoint*: string name*, endpoint*: string
type
Contact* = ref object
name*, address*: string
type Profile* = ref object type Profile* = ref object
username*, identicon*: string username*, identicon*: string

View File

@ -72,6 +72,44 @@ Item {
font.weight: Font.Bold font.weight: Font.Bold
font.pixelSize: 20 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 { Item {