mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-23 22:58:15 +00:00
feat(components/contacts/ContactsListModel): supports remove contact action
This commit is contained in:
parent
e4d507ec33
commit
c8a7651b99
4 changed files with 51 additions and 8 deletions
|
|
@ -45,10 +45,7 @@ class ContactModel : public QObject {
|
|||
);
|
||||
|
||||
public:
|
||||
ContactModel (
|
||||
QObject *parent,
|
||||
std::shared_ptr<linphone::Friend> linphone_friend
|
||||
) : QObject(parent) {
|
||||
ContactModel (std::shared_ptr<linphone::Friend> linphone_friend) {
|
||||
m_linphone_friend = linphone_friend;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#include "../../app/App.hpp"
|
||||
#include "../core/CoreManager.hpp"
|
||||
#include "ContactsListProxyModel.hpp"
|
||||
|
||||
|
|
@ -14,7 +15,11 @@ ContactsListModel::ContactsListModel (QObject *parent): QAbstractListModel(paren
|
|||
|
||||
// Init contacts with linphone friends list.
|
||||
for (const auto &friend_ : m_linphone_friends->getFriends()) {
|
||||
ContactModel *contact = new ContactModel(this, friend_);
|
||||
ContactModel *contact = new ContactModel(friend_);
|
||||
App::getInstance()->getEngine()->setObjectOwnership(
|
||||
contact, QQmlEngine::CppOwnership
|
||||
);
|
||||
|
||||
m_friend_to_contact[friend_.get()] = contact;
|
||||
m_list << contact;
|
||||
}
|
||||
|
|
@ -38,6 +43,30 @@ QVariant ContactsListModel::data (const QModelIndex &index, int role) const {
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
bool ContactsListModel::removeRow (int row, const QModelIndex &) {
|
||||
return removeRows(row, 1);
|
||||
}
|
||||
|
||||
bool ContactsListModel::removeRows (int row, int count, const QModelIndex &parent) {
|
||||
int limit = row + count - 1;
|
||||
|
||||
if (row < 0 || count < 0 || limit >= m_list.count())
|
||||
return false;
|
||||
|
||||
beginRemoveRows(parent, row, limit);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ContactModel *contact = m_list[row];
|
||||
|
||||
m_list.removeAt(row);
|
||||
contact->deleteLater();
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddress) const {
|
||||
|
|
@ -52,3 +81,11 @@ ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddre
|
|||
|
||||
return contact;
|
||||
}
|
||||
|
||||
void ContactsListModel::removeContact (ContactModel *contact) {
|
||||
qInfo() << "Removing contact:" << contact;
|
||||
|
||||
int index = m_list.indexOf(contact);
|
||||
if (index == -1 || !removeRow(index))
|
||||
qWarning() << "Unable to remove contact:" << index;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,16 +15,24 @@ class ContactsListModel : public QAbstractListModel {
|
|||
public:
|
||||
ContactsListModel (QObject *parent = Q_NULLPTR);
|
||||
|
||||
int rowCount (const QModelIndex &) const {
|
||||
int rowCount (const QModelIndex &index = QModelIndex()) const {
|
||||
return m_list.count();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> roleNames () const;
|
||||
QVariant data (const QModelIndex &index, int role) const;
|
||||
|
||||
bool removeRow (int row, const QModelIndex &parent = QModelIndex());
|
||||
bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
|
||||
|
||||
public slots:
|
||||
// See: http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#data-ownership
|
||||
// The returned value must have a explicit parent or a QQmlEngine::CppOwnership.
|
||||
ContactModel *mapSipAddressToContact (const QString &sipAddress) const;
|
||||
|
||||
void removeContact (ContactModel *contact);
|
||||
|
||||
private:
|
||||
QList<ContactModel *> m_list;
|
||||
QHash<const linphone::Friend *, ContactModel* > m_friend_to_contact;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@ ColumnLayout {
|
|||
Utils.openConfirmDialog(window, {
|
||||
descriptionText: qsTr('removeContactDescription'),
|
||||
exitHandler: function (status) {
|
||||
// TODO
|
||||
console.log('remove contact', status)
|
||||
if (status) {
|
||||
ContactsListModel.removeContact(contact)
|
||||
}
|
||||
},
|
||||
title: qsTr('removeContactTitle')
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue