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
217e2f45
Commit
217e2f45
authored
Feb 21, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(src/components/sip-addresses/SipAddressesModel): deal with calls
parent
4b97a94d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
42 deletions
+59
-42
SipAddressesModel.cpp
...esktop/src/components/sip-addresses/SipAddressesModel.cpp
+47
-31
SipAddressesModel.hpp
...esktop/src/components/sip-addresses/SipAddressesModel.hpp
+12
-11
No files found.
linphone-desktop/src/components/sip-addresses/SipAddressesModel.cpp
View file @
217e2f45
...
...
@@ -36,6 +36,7 @@ using namespace std;
SipAddressesModel
::
SipAddressesModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
{
initSipAddresses
();
ContactsListModel
*
contacts
=
CoreManager
::
getInstance
()
->
getContactsListModel
();
QObject
::
connect
(
contacts
,
&
ContactsListModel
::
contactAdded
,
this
,
&
SipAddressesModel
::
handleContactAdded
);
...
...
@@ -46,7 +47,7 @@ SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(pare
&
(
*
m_core_handlers
),
&
CoreHandlers
::
messageReceived
,
this
,
[
this
](
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
const
QString
&
sip_address
=
::
Utils
::
linphoneStringToQString
(
message
->
getFromAddress
()
->
asStringUriOnly
());
addOrUpdateSipAddress
(
sip_address
,
nullptr
,
message
);
addOrUpdateSipAddress
(
sip_address
,
message
);
}
);
...
...
@@ -74,6 +75,20 @@ SipAddressesModel::SipAddressesModel (QObject *parent) : QAbstractListModel(pare
removeContactOfSipAddress
(
sip_address
);
}
);
QObject
::
connect
(
&
(
*
CoreManager
::
getInstance
()
->
getHandlers
()),
&
CoreHandlers
::
callStateChanged
,
this
,
[
this
](
const
std
::
shared_ptr
<
linphone
::
Call
>
&
call
,
linphone
::
CallState
state
)
{
// Ignore aborted calls.
if
(
call
->
getCallLog
()
->
getStatus
()
==
linphone
::
CallStatus
::
CallStatusAborted
)
return
;
if
(
state
==
linphone
::
CallStateEnd
||
state
==
linphone
::
CallStateError
)
addOrUpdateSipAddress
(
::
Utils
::
linphoneStringToQString
(
call
->
getRemoteAddress
()
->
asStringUriOnly
()),
call
);
}
);
}
// -----------------------------------------------------------------------------
...
...
@@ -126,16 +141,14 @@ void SipAddressesModel::connectToChatModel (ChatModel *chat_model) {
}
);
for
(
auto
&
signal
:
{
&
ChatModel
::
messageSent
,
&
ChatModel
::
messageReceived
})
{
QObject
::
connect
(
chat_model
,
signal
,
this
,
[
this
](
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
addOrUpdateSipAddress
(
::
Utils
::
linphoneStringToQString
(
message
->
getToAddress
()
->
asStringUriOnly
()),
nullptr
,
message
);
}
);
}
QObject
::
connect
(
chat_model
,
&
ChatModel
::
messageSent
,
this
,
[
this
](
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
addOrUpdateSipAddress
(
::
Utils
::
linphoneStringToQString
(
message
->
getToAddress
()
->
asStringUriOnly
()),
message
);
}
);
QObject
::
connect
(
chat_model
,
&
ChatModel
::
messagesCountReset
,
this
,
[
this
,
chat_model
]()
{
...
...
@@ -230,30 +243,31 @@ void SipAddressesModel::handleContactRemoved (const ContactModel *contact) {
removeContactOfSipAddress
(
sip_address
.
toString
());
}
void
SipAddressesModel
::
addOrUpdateSipAddress
(
QVariantMap
&
map
,
ContactModel
*
contact
,
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
if
(
contact
)
{
map
[
"contact"
]
=
QVariant
::
fromValue
(
contact
);
updateObservers
(
map
[
"sipAddress"
].
toString
(),
contact
);
}
// -----------------------------------------------------------------------------
if
(
message
)
{
map
[
"timestamp"
]
=
QDateTime
::
fromMSecsSinceEpoch
(
message
->
getTime
()
*
1000
);
map
[
"unreadMessagesCount"
]
=
message
->
getChatRoom
()
->
getUnreadMessagesCount
();
}
void
SipAddressesModel
::
addOrUpdateSipAddress
(
QVariantMap
&
map
,
ContactModel
*
contact
)
{
map
[
"contact"
]
=
QVariant
::
fromValue
(
contact
);
updateObservers
(
map
[
"sipAddress"
].
toString
(),
contact
);
}
void
SipAddressesModel
::
addOrUpdateSipAddress
(
const
QString
&
sip_address
,
ContactModel
*
contact
,
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
void
SipAddressesModel
::
addOrUpdateSipAddress
(
QVariantMap
&
map
,
const
shared_ptr
<
linphone
::
Call
>
&
call
)
{
const
shared_ptr
<
linphone
::
CallLog
>
call_log
=
call
->
getCallLog
();
map
[
"timestamp"
]
=
call_log
->
getStatus
()
==
linphone
::
CallStatus
::
CallStatusSuccess
?
QDateTime
::
fromMSecsSinceEpoch
((
call_log
->
getStartDate
()
+
call_log
->
getDuration
())
*
1000
)
:
QDateTime
::
fromMSecsSinceEpoch
(
call_log
->
getStartDate
()
*
1000
);
}
void
SipAddressesModel
::
addOrUpdateSipAddress
(
QVariantMap
&
map
,
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
map
[
"timestamp"
]
=
QDateTime
::
fromMSecsSinceEpoch
(
message
->
getTime
()
*
1000
);
map
[
"unreadMessagesCount"
]
=
message
->
getChatRoom
()
->
getUnreadMessagesCount
();
}
template
<
typename
T
>
void
SipAddressesModel
::
addOrUpdateSipAddress
(
const
QString
&
sip_address
,
T
data
)
{
auto
it
=
m_sip_addresses
.
find
(
sip_address
);
if
(
it
!=
m_sip_addresses
.
end
())
{
addOrUpdateSipAddress
(
*
it
,
contact
,
message
);
addOrUpdateSipAddress
(
*
it
,
data
);
int
row
=
m_refs
.
indexOf
(
&
(
*
it
));
Q_ASSERT
(
row
!=
-
1
);
...
...
@@ -264,7 +278,7 @@ void SipAddressesModel::addOrUpdateSipAddress (
QVariantMap
map
;
map
[
"sipAddress"
]
=
sip_address
;
addOrUpdateSipAddress
(
map
,
contact
,
message
);
addOrUpdateSipAddress
(
map
,
data
);
int
row
=
m_refs
.
count
();
...
...
@@ -278,6 +292,8 @@ void SipAddressesModel::addOrUpdateSipAddress (
endInsertRows
();
}
// -----------------------------------------------------------------------------
void
SipAddressesModel
::
removeContactOfSipAddress
(
const
QString
&
sip_address
)
{
auto
it
=
m_sip_addresses
.
find
(
sip_address
);
if
(
it
==
m_sip_addresses
.
end
())
{
...
...
linphone-desktop/src/components/sip-addresses/SipAddressesModel.hpp
View file @
217e2f45
...
...
@@ -59,17 +59,18 @@ private:
void
handleContactAdded
(
ContactModel
*
contact
);
void
handleContactRemoved
(
const
ContactModel
*
contact
);
void
addOrUpdateSipAddress
(
QVariantMap
&
map
,
ContactModel
*
contact
,
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
void
addOrUpdateSipAddress
(
const
QString
&
sip_address
,
ContactModel
*
contact
=
nullptr
,
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
=
std
::
shared_ptr
<
linphone
::
ChatMessage
>
()
);
// ---------------------------------------------------------------------------
// A sip address exists in this list if a contact is linked to it, or a call, or a message.
void
addOrUpdateSipAddress
(
QVariantMap
&
map
,
ContactModel
*
contact
);
void
addOrUpdateSipAddress
(
QVariantMap
&
map
,
const
std
::
shared_ptr
<
linphone
::
Call
>
&
call
);
void
addOrUpdateSipAddress
(
QVariantMap
&
map
,
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
template
<
class
T
>
void
addOrUpdateSipAddress
(
const
QString
&
sip_address
,
T
data
);
// ---------------------------------------------------------------------------
void
removeContactOfSipAddress
(
const
QString
&
sip_address
);
...
...
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