Commit 57813f00 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/contacts): set parent to `ContactModel` because qt can delete it in qml...

parent 179cbedd
...@@ -45,7 +45,10 @@ class ContactModel : public QObject { ...@@ -45,7 +45,10 @@ class ContactModel : public QObject {
); );
public: public:
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend) { ContactModel (
QObject *parent,
std::shared_ptr<linphone::Friend> linphone_friend
) : QObject(parent) {
m_linphone_friend = linphone_friend; m_linphone_friend = linphone_friend;
} }
......
...@@ -14,7 +14,7 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren ...@@ -14,7 +14,7 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
// Init contacts with linphone friends list. // Init contacts with linphone friends list.
for (const auto &friend_ : m_linphone_friends->getFriends()) { for (const auto &friend_ : m_linphone_friends->getFriends()) {
ContactModel *contact = new ContactModel(friend_); ContactModel *contact = new ContactModel(this, friend_);
m_friend_to_contact[friend_.get()] = contact; m_friend_to_contact[friend_.get()] = contact;
m_list << contact; m_list << contact;
} }
...@@ -40,18 +40,13 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const { ...@@ -40,18 +40,13 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
ContactModel *ContactsListModel::mapLinphoneFriendToContact (
const shared_ptr<linphone::Friend> &friend_
) const {
return m_friend_to_contact[friend_.get()];
}
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const { ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const {
ContactModel *contact = m_friend_to_contact[ // Maybe use a hashtable in future version to get a lower cost?
ContactModel *contact = m_friend_to_contact.value(
m_linphone_friends->findFriendByUri( m_linphone_friends->findFriendByUri(
sipAddress.toStdString() sipAddress.toStdString()
).get() ).get()
]; );
qInfo() << "Map sip address to contact:" << sipAddress << "->" << contact; qInfo() << "Map sip address to contact:" << sipAddress << "->" << contact;
......
...@@ -22,10 +22,6 @@ public: ...@@ -22,10 +22,6 @@ public:
QHash<int, QByteArray> roleNames () const; QHash<int, QByteArray> roleNames () const;
QVariant data (const QModelIndex &index, int role) const; QVariant data (const QModelIndex &index, int role) const;
ContactModel *mapLinphoneFriendToContact (
const std::shared_ptr<linphone::Friend> &friend_
) const;
public slots: public slots:
ContactModel *mapSipAddressToContact (const QString &sipAddress) const; ContactModel *mapSipAddressToContact (const QString &sipAddress) const;
......
...@@ -31,6 +31,9 @@ const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]"); ...@@ -31,6 +31,9 @@ const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]");
// ------------------------------------------------------------------- // -------------------------------------------------------------------
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
if (m_list == nullptr)
qFatal("Contacts list model is undefined.");
setSourceModel(m_list); setSourceModel(m_list);
setFilterCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive);
......
...@@ -9,6 +9,8 @@ import Utils 1.0 ...@@ -9,6 +9,8 @@ import Utils 1.0
// =================================================================== // ===================================================================
Rectangle { Rectangle {
id: item
property alias actions: actionBar.data property alias actions: actionBar.data
property alias sipAddressColor: description.sipAddressColor property alias sipAddressColor: description.sipAddressColor
property alias usernameColor: description.usernameColor property alias usernameColor: description.usernameColor
...@@ -16,6 +18,9 @@ Rectangle { ...@@ -16,6 +18,9 @@ Rectangle {
// Can be a contact object or just a sip address. // Can be a contact object or just a sip address.
property var contact property var contact
// Override contact.sipAddress if used.
property var sipAddress
color: 'transparent' // No color by default. color: 'transparent' // No color by default.
height: ContactStyle.height height: ContactStyle.height
...@@ -46,7 +51,7 @@ Rectangle { ...@@ -46,7 +51,7 @@ Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
sipAddress: Utils.isString(contact) sipAddress: Utils.isString(contact)
? contact ? contact
: contact.sipAddress : item.sipAddress || contact.sipAddress
username: avatar.username username: avatar.username
} }
......
...@@ -88,6 +88,7 @@ ColumnLayout { ...@@ -88,6 +88,7 @@ ColumnLayout {
: TimelineStyle.contact.backgroundColor.b : TimelineStyle.contact.backgroundColor.b
) )
contact: parent.contact contact: parent.contact
sipAddress: $timelineEntry.sipAddresses
sipAddressColor: view.currentIndex === index sipAddressColor: view.currentIndex === index
? TimelineStyle.contact.sipAddress.color.selected ? TimelineStyle.contact.sipAddress.color.selected
: TimelineStyle.contact.sipAddress.color.normal : TimelineStyle.contact.sipAddress.color.normal
......
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