feat(components/contacts/Contacts): use setData on wrapped linphone::Friend instead of a hashtable to map ContactModel from linphone::Friend

This commit is contained in:
Ronan Abhamon 2016-11-24 14:06:23 +01:00
parent 1459d29311
commit fc88ff95d3
3 changed files with 11 additions and 10 deletions

View file

@ -46,6 +46,7 @@ class ContactModel : public QObject {
public:
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend) {
linphone_friend->setData("contact-model", *this);
m_linphone_friend = linphone_friend;
}

View file

@ -22,7 +22,6 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
contact, QQmlEngine::CppOwnership
);
m_friend_to_contact[friend_.get()] = contact;
m_list << contact;
}
}
@ -61,7 +60,6 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
ContactModel *contact = m_list[row];
m_list.removeAt(row);
m_friend_to_contact.remove(contact->m_linphone_friend.get());
m_linphone_friends->removeFriend(contact->m_linphone_friend);
contact->deleteLater();
@ -76,15 +74,19 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const {
// Maybe use a hashtable in future version to get a lower cost?
ContactModel *contact = m_friend_to_contact.value(
m_linphone_friends->findFriendByUri(
Utils::qStringToLinphoneString(sipAddress)
).get()
std::shared_ptr<linphone::Friend> friend_ = m_linphone_friends->findFriendByUri(
Utils::qStringToLinphoneString(sipAddress)
);
qInfo() << "Map sip address to contact:" << sipAddress << "->" << contact;
if (!friend_) {
qInfo() << "Map sip address to contact:" << sipAddress << "-> nullptr";
return nullptr;
}
return contact;
ContactModel &contact = friend_->getData<ContactModel>("contact-model");
qInfo() << "Map sip address to contact:" << sipAddress << "->" << &contact;
return &contact;
}
void ContactsListModel::removeContact (ContactModel *contact) {

View file

@ -35,8 +35,6 @@ public slots:
private:
QList<ContactModel *> m_list;
QHash<const linphone::Friend *, ContactModel *> m_friend_to_contact;
std::shared_ptr<linphone::FriendList> m_linphone_friends;
};