mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-07 15:08:24 +00:00
feat(components/contacts): set parent to ContactModel because qt can delete it in qml...
This commit is contained in:
parent
179cbeddf3
commit
57813f0088
6 changed files with 18 additions and 15 deletions
|
|
@ -45,7 +45,10 @@ class ContactModel : public QObject {
|
|||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
|
|||
|
||||
// Init contacts with linphone friends list.
|
||||
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_list << contact;
|
||||
}
|
||||
|
|
@ -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 *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(
|
||||
sipAddress.toStdString()
|
||||
).get()
|
||||
];
|
||||
);
|
||||
|
||||
qInfo() << "Map sip address to contact:" << sipAddress << "->" << contact;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,6 @@ public:
|
|||
QHash<int, QByteArray> roleNames () const;
|
||||
QVariant data (const QModelIndex &index, int role) const;
|
||||
|
||||
ContactModel *mapLinphoneFriendToContact (
|
||||
const std::shared_ptr<linphone::Friend> &friend_
|
||||
) const;
|
||||
|
||||
public slots:
|
||||
ContactModel *mapSipAddressToContact (const QString &sipAddress) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ const QRegExp ContactsListProxyModel::m_search_separators("^[^_.-;@ ][_.-;@ ]");
|
|||
// -------------------------------------------------------------------
|
||||
|
||||
ContactsListProxyModel::ContactsListProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
|
||||
if (m_list == nullptr)
|
||||
qFatal("Contacts list model is undefined.");
|
||||
|
||||
setSourceModel(m_list);
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import Utils 1.0
|
|||
// ===================================================================
|
||||
|
||||
Rectangle {
|
||||
id: item
|
||||
|
||||
property alias actions: actionBar.data
|
||||
property alias sipAddressColor: description.sipAddressColor
|
||||
property alias usernameColor: description.usernameColor
|
||||
|
|
@ -16,6 +18,9 @@ Rectangle {
|
|||
// Can be a contact object or just a sip address.
|
||||
property var contact
|
||||
|
||||
// Override contact.sipAddress if used.
|
||||
property var sipAddress
|
||||
|
||||
color: 'transparent' // No color by default.
|
||||
height: ContactStyle.height
|
||||
|
||||
|
|
@ -46,7 +51,7 @@ Rectangle {
|
|||
Layout.fillWidth: true
|
||||
sipAddress: Utils.isString(contact)
|
||||
? contact
|
||||
: contact.sipAddress
|
||||
: item.sipAddress || contact.sipAddress
|
||||
username: avatar.username
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ ColumnLayout {
|
|||
: TimelineStyle.contact.backgroundColor.b
|
||||
)
|
||||
contact: parent.contact
|
||||
sipAddress: $timelineEntry.sipAddresses
|
||||
sipAddressColor: view.currentIndex === index
|
||||
? TimelineStyle.contact.sipAddress.color.selected
|
||||
: TimelineStyle.contact.sipAddress.color.normal
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue