From e6c455030551afa5a82e0e57bd8a3cd6e373182f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 22 Nov 2016 10:27:30 +0100 Subject: [PATCH] not stable, crash with `mapSipAddressToContact` --- tests/src/components/contacts/ContactsListModel.cpp | 12 +++++++++--- tests/src/components/contacts/ContactsListModel.hpp | 3 ++- .../components/contacts/ContactsListProxyModel.cpp | 2 +- tests/src/components/timeline/TimelineModel.cpp | 6 +++--- tests/ui/modules/Linphone/Timeline.qml | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp index 626137617..eb0b3d5e1 100644 --- a/tests/src/components/contacts/ContactsListModel.cpp +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -11,8 +11,10 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren shared_ptr core(CoreManager::getInstance()->getCore()); // Init contacts with linphone friends list. - for (auto&& contact : core->getFriendsLists().front()->getFriends()) { - m_list << new ContactModel(contact); + for (const auto &friend_ : core->getFriendsLists().front()->getFriends()) { + 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 { // ------------------------------------------------------------------- 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() + ]; } diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index d5bb46492..222246e45 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -23,10 +23,11 @@ public: QVariant data (const QModelIndex &index, int role) const; public slots: - static ContactModel *mapSipAddressToContact (const QString &sipAddress); + ContactModel *mapSipAddressToContact (const QString &sipAddress); private: QList m_list; + QHash m_friend_to_contact; }; #endif // CONTACTS_LIST_MODEL_H diff --git a/tests/src/components/contacts/ContactsListProxyModel.cpp b/tests/src/components/contacts/ContactsListProxyModel.cpp index bf6cc2940..40461d86d 100644 --- a/tests/src/components/contacts/ContactsListProxyModel.cpp +++ b/tests/src/components/contacts/ContactsListProxyModel.cpp @@ -122,7 +122,7 @@ float ContactsListProxyModel::computeContactWeight (const ContactModel &contact) const list > addresses = contact.m_linphone_friend->getAddresses(); - auto&& it = addresses.cbegin(); + auto it = addresses.cbegin(); // It exists at least one sip address. weight += computeStringWeight( diff --git a/tests/src/components/timeline/TimelineModel.cpp b/tests/src/components/timeline/TimelineModel.cpp index 5157bce07..08104824d 100644 --- a/tests/src/components/timeline/TimelineModel.cpp +++ b/tests/src/components/timeline/TimelineModel.cpp @@ -29,7 +29,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { shared_ptr core(CoreManager::getInstance()->getCore()); // Insert chat rooms events. - for (auto&& chat_room : core->getChatRooms()) { + for (const auto &chat_room : core->getChatRooms()) { list > history = chat_room->getHistory(0); if (history.size() == 0) @@ -50,7 +50,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { // Insert calls events. QHash address_done; - for (auto&& call_log : core->getCallLogs()) { + for (const auto &call_log : core->getCallLogs()) { // Get a sip uri to check. QString address = Utils::linphoneStringToQString( call_log->getRemoteAddress()->asString() @@ -69,7 +69,7 @@ TimelineModel::TimelineModel (QObject *parent): QAbstractListModel(parent) { map["sipAddresses"] = address; // Search existing entry. - auto&& it = find_if( + auto it = find_if( m_entries.begin(), m_entries.end(), [&address](const QVariantMap &map) { return address == map["sipAddresses"].toString(); } diff --git a/tests/ui/modules/Linphone/Timeline.qml b/tests/ui/modules/Linphone/Timeline.qml index 4b1f59bf2..bd70be321 100644 --- a/tests/ui/modules/Linphone/Timeline.qml +++ b/tests/ui/modules/Linphone/Timeline.qml @@ -64,7 +64,7 @@ ColumnLayout { delegate: Item { property var contact: ContactsListModel.mapSipAddressToContact( - $timelineEntry + $timelineEntry.sipAddresses ) height: TimelineStyle.contact.height