Commit fc88ff95 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(components/contacts/Contacts): use `setData` on wrapped...

feat(components/contacts/Contacts): use `setData` on wrapped `linphone::Friend` instead of a hashtable to map `ContactModel` from `linphone::Friend`
parent 1459d293
...@@ -46,6 +46,7 @@ class ContactModel : public QObject { ...@@ -46,6 +46,7 @@ class ContactModel : public QObject {
public: public:
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend) { ContactModel (std::shared_ptr<linphone::Friend> linphone_friend) {
linphone_friend->setData("contact-model", *this);
m_linphone_friend = linphone_friend; m_linphone_friend = linphone_friend;
} }
......
...@@ -22,7 +22,6 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren ...@@ -22,7 +22,6 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
contact, QQmlEngine::CppOwnership contact, QQmlEngine::CppOwnership
); );
m_friend_to_contact[friend_.get()] = contact;
m_list << contact; m_list << contact;
} }
} }
...@@ -61,7 +60,6 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren ...@@ -61,7 +60,6 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
ContactModel *contact = m_list[row]; ContactModel *contact = m_list[row];
m_list.removeAt(row); m_list.removeAt(row);
m_friend_to_contact.remove(contact->m_linphone_friend.get());
m_linphone_friends->removeFriend(contact->m_linphone_friend); m_linphone_friends->removeFriend(contact->m_linphone_friend);
contact->deleteLater(); contact->deleteLater();
...@@ -76,15 +74,19 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren ...@@ -76,15 +74,19 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const { ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const {
// Maybe use a hashtable in future version to get a lower cost? // Maybe use a hashtable in future version to get a lower cost?
ContactModel *contact = m_friend_to_contact.value( std::shared_ptr<linphone::Friend> friend_ = m_linphone_friends->findFriendByUri(
m_linphone_friends->findFriendByUri( Utils::qStringToLinphoneString(sipAddress)
Utils::qStringToLinphoneString(sipAddress)
).get()
); );
qInfo() << "Map sip address to contact:" << sipAddress << "->" << contact; if (!friend_) {
qInfo() << "Map sip address to contact:" << sipAddress << "-> nullptr";
return nullptr;
}
ContactModel &contact = friend_->getData<ContactModel>("contact-model");
qInfo() << "Map sip address to contact:" << sipAddress << "->" << &contact;
return contact; return &contact;
} }
void ContactsListModel::removeContact (ContactModel *contact) { void ContactsListModel::removeContact (ContactModel *contact) {
......
...@@ -35,8 +35,6 @@ public slots: ...@@ -35,8 +35,6 @@ public slots:
private: private:
QList<ContactModel *> m_list; QList<ContactModel *> m_list;
QHash<const linphone::Friend *, ContactModel *> m_friend_to_contact;
std::shared_ptr<linphone::FriendList> m_linphone_friends; std::shared_ptr<linphone::FriendList> m_linphone_friends;
}; };
......
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