Commit e6c45503 authored by Ronan Abhamon's avatar Ronan Abhamon

not stable, crash with `mapSipAddressToContact`

parent a20c32af
...@@ -11,8 +11,10 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren ...@@ -11,8 +11,10 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore()); shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
// Init contacts with linphone friends list. // Init contacts with linphone friends list.
for (auto&& contact : core->getFriendsLists().front()->getFriends()) { for (const auto &friend_ : core->getFriendsLists().front()->getFriends()) {
m_list << new ContactModel(contact); ContactModel *contact = new ContactModel(friend_);
m_friend_to_contact[friend_.get()] = contact;
m_list << contact;
} }
} }
...@@ -37,5 +39,9 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const { ...@@ -37,5 +39,9 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) { ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) {
return ContactsListProxyModel::getContactsListModel()->m_list.front(); return m_friend_to_contact[
CoreManager::getInstance()->getCore()->getFriendsLists().front()->findFriendByUri(
sipAddress.toStdString()
).get()
];
} }
...@@ -23,10 +23,11 @@ public: ...@@ -23,10 +23,11 @@ public:
QVariant data (const QModelIndex &index, int role) const; QVariant data (const QModelIndex &index, int role) const;
public slots: public slots:
static ContactModel *mapSipAddressToContact (const QString &sipAddress); ContactModel *mapSipAddressToContact (const QString &sipAddress);
private: private:
QList<ContactModel *> m_list; QList<ContactModel *> m_list;
QHash<linphone::Friend *, ContactModel* > m_friend_to_contact;
}; };
#endif // CONTACTS_LIST_MODEL_H #endif // CONTACTS_LIST_MODEL_H
...@@ -122,7 +122,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) ...@@ -122,7 +122,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact)
const list<shared_ptr<linphone::Address> > addresses = const list<shared_ptr<linphone::Address> > addresses =
contact.m_linphone_friend->getAddresses(); contact.m_linphone_friend->getAddresses();
auto&& it = addresses.cbegin(); auto it = addresses.cbegin();
// It exists at least one sip address. // It exists at least one sip address.
weight += computeStringWeight( weight += computeStringWeight(
......
...@@ -29,7 +29,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { ...@@ -29,7 +29,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore()); shared_ptr<linphone::Core> core(CoreManager::getInstance()->getCore());
// Insert chat rooms events. // Insert chat rooms events.
for (auto&& chat_room : core->getChatRooms()) { for (const auto &chat_room : core->getChatRooms()) {
list<shared_ptr<linphone::ChatMessage> > history = chat_room->getHistory(0); list<shared_ptr<linphone::ChatMessage> > history = chat_room->getHistory(0);
if (history.size() == 0) if (history.size() == 0)
...@@ -50,7 +50,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { ...@@ -50,7 +50,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
// Insert calls events. // Insert calls events.
QHash<QString, bool> address_done; QHash<QString, bool> address_done;
for (auto&& call_log : core->getCallLogs()) { for (const auto &call_log : core->getCallLogs()) {
// Get a sip uri to check. // Get a sip uri to check.
QString address = Utils::linphoneStringToQString( QString address = Utils::linphoneStringToQString(
call_log->getRemoteAddress()->asString() call_log->getRemoteAddress()->asString()
...@@ -69,7 +69,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { ...@@ -69,7 +69,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) {
map["sipAddresses"] = address; map["sipAddresses"] = address;
// Search existing entry. // Search existing entry.
auto&& it = find_if( auto it = find_if(
m_entries.begin(), m_entries.end(), [&address](const QVariantMap &map) { m_entries.begin(), m_entries.end(), [&address](const QVariantMap &map) {
return address == map["sipAddresses"].toString(); return address == map["sipAddresses"].toString();
} }
......
...@@ -64,7 +64,7 @@ ColumnLayout { ...@@ -64,7 +64,7 @@ ColumnLayout {
delegate: Item { delegate: Item {
property var contact: ContactsListModel.mapSipAddressToContact( property var contact: ContactsListModel.mapSipAddressToContact(
$timelineEntry $timelineEntry.sipAddresses
) )
height: TimelineStyle.contact.height height: TimelineStyle.contact.height
......
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