Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
c8a7651b
Commit
c8a7651b
authored
Nov 23, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(components/contacts/ContactsListModel): supports `remove contact` action
parent
e4d507ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
8 deletions
+51
-8
ContactModel.hpp
tests/src/components/contacts/ContactModel.hpp
+1
-4
ContactsListModel.cpp
tests/src/components/contacts/ContactsListModel.cpp
+38
-1
ContactsListModel.hpp
tests/src/components/contacts/ContactsListModel.hpp
+9
-1
Contacts.qml
tests/ui/views/App/MainWindow/Contacts.qml
+3
-2
No files found.
tests/src/components/contacts/ContactModel.hpp
View file @
c8a7651b
...
...
@@ -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
;
}
...
...
tests/src/components/contacts/ContactsListModel.cpp
View file @
c8a7651b
#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
;
}
tests/src/components/contacts/ContactsListModel.hpp
View file @
c8a7651b
...
...
@@ -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
;
...
...
tests/ui/views/App/MainWindow/Contacts.qml
View file @
c8a7651b
...
...
@@ -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
'
)
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment