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
7aeba275
Commit
7aeba275
authored
Jun 28, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ChatProxyModel): use a unique `ChatModel` if many proxies use a same sip address
parent
0d0a2d42
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
161 additions
and
122 deletions
+161
-122
CMakeLists.txt
CMakeLists.txt
+2
-0
settings_video_normal.svg
assets/images/settings_video_normal.svg
+12
-0
App.cpp
src/app/App.cpp
+1
-1
ChatModel.cpp
src/components/chat/ChatModel.cpp
+11
-41
ChatModel.hpp
src/components/chat/ChatModel.hpp
+4
-6
ChatProxyModel.cpp
src/components/chat/ChatProxyModel.cpp
+70
-54
ChatProxyModel.hpp
src/components/chat/ChatProxyModel.hpp
+6
-1
CoreManager.cpp
src/components/core/CoreManager.cpp
+28
-0
CoreManager.hpp
src/components/core/CoreManager.hpp
+6
-0
SipAddressesModel.cpp
src/components/sip-addresses/SipAddressesModel.cpp
+19
-17
SipAddressesModel.hpp
src/components/sip-addresses/SipAddressesModel.hpp
+2
-2
No files found.
CMakeLists.txt
View file @
7aeba275
...
...
@@ -63,6 +63,8 @@ if (NOT WIN32)
endif
()
endif
()
set
(
CUSTOM_FLAGS
"
${
CUSTOM_FLAGS
}
-DQT_NO_EXCEPTIONS"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
CUSTOM_FLAGS
}
"
)
# See: http://stackoverflow.com/a/1372836
if
(
WIN32
)
...
...
assets/images/settings_video_normal.svg
0 → 100644
View file @
7aeba275
<?xml version="1.0" encoding="UTF-8"?>
<svg
width=
"23px"
height=
"14px"
viewBox=
"0 0 23 14"
version=
"1.1"
xmlns=
"http://www.w3.org/2000/svg"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
>
<!-- Generator: Sketch 42 (36781) - http://www.bohemiancoding.com/sketch -->
<title>
settings_video_default
</title>
<desc>
Created with Sketch.
</desc>
<defs></defs>
<g
id=
"Symbols"
stroke=
"none"
stroke-width=
"1"
fill=
"none"
fill-rule=
"evenodd"
stroke-linecap=
"round"
stroke-linejoin=
"round"
>
<g
id=
"settings_video_default"
stroke-width=
"1.5"
stroke=
"#FFFFFF"
>
<polygon
id=
"videocall_icon"
points=
"22.25 6.89355494 22.25 1.08716608 16.4942742 5.63134348 16.4942742 0.75 0.75 0.75 0.75 13.25 16.4942742 13.25 16.4942742 8.36865652 22.25 12.9128339"
></polygon>
</g>
</g>
</svg>
src/app/App.cpp
View file @
7aeba275
...
...
@@ -373,7 +373,6 @@ void App::registerTypes () {
registerType
<
CallsListProxyModel
>
(
"CallsListProxyModel"
);
registerType
<
Camera
>
(
"Camera"
);
registerType
<
CameraPreview
>
(
"CameraPreview"
);
registerType
<
ChatModel
>
(
"ChatModel"
);
registerType
<
ChatProxyModel
>
(
"ChatProxyModel"
);
registerType
<
ConferenceHelperModel
>
(
"ConferenceHelperModel"
);
registerType
<
ConferenceModel
>
(
"ConferenceModel"
);
...
...
@@ -392,6 +391,7 @@ void App::registerTypes () {
registerMetaType
<
ChatModel
::
EntryType
>
(
"ChatModel::EntryType"
);
registerUncreatableType
(
CallModel
,
"CallModel"
);
registerUncreatableType
(
ChatModel
,
"ChatModel"
);
registerUncreatableType
(
ConferenceHelperModel
::
ConferenceAddModel
,
"ConferenceAddModel"
);
registerUncreatableType
(
ContactModel
,
"ContactModel"
);
registerUncreatableType
(
SipAddressObserver
,
"SipAddressObserver"
);
...
...
src/components/chat/ChatModel.cpp
View file @
7aeba275
...
...
@@ -189,13 +189,13 @@ private:
// -----------------------------------------------------------------------------
ChatModel
::
ChatModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
{
ChatModel
::
ChatModel
(
const
QString
&
sipAddress
)
{
CoreManager
*
core
=
CoreManager
::
getInstance
();
mCoreHandlers
=
core
->
getHandlers
();
mMessageHandlers
=
make_shared
<
MessageHandlers
>
(
this
);
core
->
getSipAddressesModel
()
->
connectToChatModel
(
thi
s
);
setSipAddress
(
sipAddres
s
);
{
CoreHandlers
*
coreHandlers
=
mCoreHandlers
.
get
();
...
...
@@ -262,27 +262,16 @@ bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
}
QString
ChatModel
::
getSipAddress
()
const
{
if
(
!
mChatRoom
)
return
QString
(
""
);
return
::
Utils
::
coreStringToAppString
(
mChatRoom
->
getPeerAddress
()
->
asStringUriOnly
()
);
}
void
ChatModel
::
setSipAddress
(
const
QString
&
sipAddress
)
{
if
(
sipAddress
==
getSipAddress
()
||
sipAddress
.
isEmpty
())
return
;
beginResetModel
();
// Invalid old sip address entries.
mEntries
.
clear
();
shared_ptr
<
linphone
::
Core
>
core
=
CoreManager
::
getInstance
()
->
getCore
();
mChatRoom
=
core
->
getChatRoomFromUri
(
::
Utils
::
appStringToCoreString
(
sipAddress
));
updateIsRemoteComposing
(
);
Q_CHECK_PTR
(
mChatRoom
.
get
()
);
if
(
mChatRoom
->
getUnreadMessagesCount
()
>
0
)
resetMessagesCount
();
...
...
@@ -304,10 +293,6 @@ void ChatModel::setSipAddress (const QString &sipAddress) {
// Get calls.
for
(
auto
&
callLog
:
core
->
getCallHistoryForAddress
(
mChatRoom
->
getPeerAddress
()))
insertCall
(
callLog
);
endResetModel
();
emit
sipAddressChanged
(
sipAddress
);
}
bool
ChatModel
::
getIsRemoteComposing
()
const
{
...
...
@@ -342,9 +327,6 @@ void ChatModel::removeAllEntries () {
// -----------------------------------------------------------------------------
void
ChatModel
::
sendMessage
(
const
QString
&
message
)
{
if
(
!
mChatRoom
)
return
;
shared_ptr
<
linphone
::
ChatMessage
>
_message
=
mChatRoom
->
createMessage
(
::
Utils
::
appStringToCoreString
(
message
));
_message
->
setListener
(
mMessageHandlers
);
...
...
@@ -355,9 +337,6 @@ void ChatModel::sendMessage (const QString &message) {
}
void
ChatModel
::
resendMessage
(
int
id
)
{
if
(
!
mChatRoom
)
return
;
if
(
id
<
0
||
id
>
mEntries
.
count
())
{
qWarning
()
<<
QStringLiteral
(
"Entry %1 not exists."
).
arg
(
id
);
return
;
...
...
@@ -387,9 +366,6 @@ void ChatModel::resendMessage (int id) {
}
void
ChatModel
::
sendFileMessage
(
const
QString
&
path
)
{
if
(
!
mChatRoom
)
return
;
QFile
file
(
path
);
if
(
!
file
.
exists
())
return
;
...
...
@@ -483,15 +459,12 @@ bool ChatModel::fileWasDownloaded (int id) {
}
void
ChatModel
::
compose
()
{
return
mChatRoom
->
compose
();
mChatRoom
->
compose
();
}
// -----------------------------------------------------------------------------
const
ChatModel
::
ChatEntryData
ChatModel
::
getFileMessageEntry
(
int
id
)
{
if
(
!
mChatRoom
)
return
ChatEntryData
();
if
(
id
<
0
||
id
>
mEntries
.
count
())
{
qWarning
()
<<
QStringLiteral
(
"Entry %1 not exists."
).
arg
(
id
);
return
ChatEntryData
();
...
...
@@ -650,14 +623,6 @@ void ChatModel::resetMessagesCount () {
emit
messagesCountReset
();
}
void
ChatModel
::
updateIsRemoteComposing
()
{
bool
isRemoteComposing
=
mChatRoom
->
isRemoteComposing
();
if
(
isRemoteComposing
!=
mIsRemoteComposing
)
{
mIsRemoteComposing
=
isRemoteComposing
;
emit
isRemoteComposingChanged
(
mIsRemoteComposing
);
}
}
// -----------------------------------------------------------------------------
void
ChatModel
::
handleCallStateChanged
(
const
shared_ptr
<
linphone
::
Call
>
&
call
,
linphone
::
CallState
state
)
{
...
...
@@ -669,8 +634,13 @@ void ChatModel::handleCallStateChanged (const shared_ptr<linphone::Call> &call,
}
void
ChatModel
::
handleIsComposingChanged
(
const
shared_ptr
<
linphone
::
ChatRoom
>
&
chatRoom
)
{
if
(
mChatRoom
==
chatRoom
)
updateIsRemoteComposing
();
if
(
mChatRoom
==
chatRoom
)
{
bool
isRemoteComposing
=
mChatRoom
->
isRemoteComposing
();
if
(
isRemoteComposing
!=
mIsRemoteComposing
)
{
mIsRemoteComposing
=
isRemoteComposing
;
emit
isRemoteComposingChanged
(
mIsRemoteComposing
);
}
}
}
void
ChatModel
::
handleMessageReceived
(
const
shared_ptr
<
linphone
::
ChatMessage
>
&
message
)
{
...
...
src/components/chat/ChatModel.hpp
View file @
7aeba275
...
...
@@ -37,7 +37,7 @@ class ChatModel : public QAbstractListModel {
Q_OBJECT
;
Q_PROPERTY
(
QString
sipAddress
READ
getSipAddress
WRITE
setSipAddress
NOTIFY
sipAddressChanged
);
Q_PROPERTY
(
QString
sipAddress
READ
getSipAddress
CONSTANT
);
Q_PROPERTY
(
bool
isRemoteComposing
READ
getIsRemoteComposing
NOTIFY
isRemoteComposingChanged
);
public:
...
...
@@ -75,7 +75,7 @@ public:
Q_ENUM
(
MessageStatus
);
ChatModel
(
QObject
*
parent
=
Q_NULLPTR
);
ChatModel
(
const
QString
&
sipAddress
);
~
ChatModel
();
int
rowCount
(
const
QModelIndex
&
index
=
QModelIndex
())
const
override
;
...
...
@@ -87,7 +87,6 @@ public:
bool
removeRows
(
int
row
,
int
count
,
const
QModelIndex
&
parent
=
QModelIndex
())
override
;
QString
getSipAddress
()
const
;
void
setSipAddress
(
const
QString
&
sipAddress
);
bool
getIsRemoteComposing
()
const
;
...
...
@@ -111,7 +110,6 @@ public:
void
compose
();
signals:
void
sipAddressChanged
(
const
QString
&
sipAddress
);
bool
isRemoteComposingChanged
(
bool
status
);
void
allEntriesRemoved
();
...
...
@@ -124,6 +122,8 @@ signals:
private:
typedef
QPair
<
QVariantMap
,
std
::
shared_ptr
<
void
>
>
ChatEntryData
;
void
setSipAddress
(
const
QString
&
sipAddress
);
const
ChatEntryData
getFileMessageEntry
(
int
id
);
void
fillMessageEntry
(
QVariantMap
&
dest
,
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
...
...
@@ -137,8 +137,6 @@ private:
void
resetMessagesCount
();
void
updateIsRemoteComposing
();
void
handleCallStateChanged
(
const
std
::
shared_ptr
<
linphone
::
Call
>
&
call
,
linphone
::
CallState
state
);
void
handleIsComposingChanged
(
const
std
::
shared_ptr
<
linphone
::
ChatRoom
>
&
chatRoom
);
void
handleMessageReceived
(
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
...
...
src/components/chat/ChatProxyModel.cpp
View file @
7aeba275
...
...
@@ -20,6 +20,8 @@
* Author: Ronan Abhamon
*/
#include "../core/CoreManager.hpp"
#include "ChatProxyModel.hpp"
using
namespace
std
;
...
...
@@ -29,9 +31,7 @@ using namespace std;
// Fetch the L last filtered chat entries.
class
ChatProxyModel
::
ChatModelFilter
:
public
QSortFilterProxyModel
{
public:
ChatModelFilter
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
setSourceModel
(
&
mChatModel
);
}
ChatModelFilter
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{}
ChatModel
::
EntryType
getEntryTypeFilter
()
{
return
mEntryTypeFilter
;
...
...
@@ -54,7 +54,6 @@ protected:
}
private:
ChatModel
mChatModel
;
ChatModel
::
EntryType
mEntryTypeFilter
=
ChatModel
::
EntryType
::
GenericEntry
;
};
...
...
@@ -63,47 +62,32 @@ private:
const
int
ChatProxyModel
::
ENTRIES_CHUNK_SIZE
=
50
;
ChatProxyModel
::
ChatProxyModel
(
QObject
*
parent
)
:
QSortFilterProxyModel
(
parent
)
{
mChatModelFilter
=
new
ChatModelFilter
(
this
);
setSourceModel
(
mChatModelFilter
);
ChatModel
*
chat
=
static_cast
<
ChatModel
*>
(
mChatModelFilter
->
sourceModel
());
QObject
::
connect
(
chat
,
&
ChatModel
::
sipAddressChanged
,
this
,
[
this
](
const
QString
&
sipAddress
)
{
emit
sipAddressChanged
(
sipAddress
);
});
QObject
::
connect
(
chat
,
&
ChatModel
::
isRemoteComposingChanged
,
this
,
[
this
](
bool
status
)
{
emit
isRemoteComposingChanged
(
status
);
});
QObject
::
connect
(
chat
,
&
ChatModel
::
messageReceived
,
this
,
[
this
](
const
shared_ptr
<
linphone
::
ChatMessage
>
&
)
{
mMaxDisplayedEntries
++
;
});
QObject
::
connect
(
chat
,
&
ChatModel
::
messageSent
,
this
,
[
this
](
const
shared_ptr
<
linphone
::
ChatMessage
>
&
)
{
mMaxDisplayedEntries
++
;
});
setSourceModel
(
new
ChatModelFilter
(
this
));
}
// -----------------------------------------------------------------------------
#define CREATE_PARENT_MODEL_FUNCTION_WITH_ID(METHOD) \
void ChatProxyModel::METHOD(int id) { \
QModelIndex sourceIndex = mapToSource(index(id, 0)); \
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->METHOD( \
mChatModelFilter->mapToSource(sourceIndex).row() \
); \
}
#define GET_CHAT_MODEL() \
if (!mChatModel) \
return; \
mChatModel
#define CREATE_PARENT_MODEL_FUNCTION(METHOD) \
void ChatProxyModel::METHOD() { \
static_cast<ChatModel *>(mChatModelFilter->sourceModel()
)->METHOD(); \
GET_CHAT_MODEL(
)->METHOD(); \
}
#define CREATE_PARENT_MODEL_FUNCTION_WITH_PARAM(METHOD, ARG_TYPE) \
void ChatProxyModel::METHOD(ARG_TYPE value) { \
static_cast<ChatModel *>(mChatModelFilter->sourceModel())->METHOD(value); \
GET_CHAT_MODEL()->METHOD(value); \
}
#define CREATE_PARENT_MODEL_FUNCTION_WITH_ID(METHOD) \
void ChatProxyModel::METHOD(int id) { \
QModelIndex sourceIndex = mapToSource(index(id, 0)); \
GET_CHAT_MODEL()->METHOD( \
static_cast<ChatModelFilter *>(sourceModel())->mapToSource(sourceIndex).row() \
); \
}
CREATE_PARENT_MODEL_FUNCTION
(
compose
);
...
...
@@ -118,31 +102,16 @@ CREATE_PARENT_MODEL_FUNCTION_WITH_ID(openFileDirectory);
CREATE_PARENT_MODEL_FUNCTION_WITH_ID
(
removeEntry
);
CREATE_PARENT_MODEL_FUNCTION_WITH_ID
(
resendMessage
);
#undef GET_CHAT_MODEL
#undef CREATE_PARENT_MODEL_FUNCTION
#undef CREATE_PARENT_MODEL_FUNCTION_WITH_PARAM
#undef CREATE_PARENT_MODEL_FUNCTION_WITH_ID
// -----------------------------------------------------------------------------
QString
ChatProxyModel
::
getSipAddress
()
const
{
return
static_cast
<
ChatModel
*>
(
mChatModelFilter
->
sourceModel
())
->
getSipAddress
();
}
void
ChatProxyModel
::
setSipAddress
(
const
QString
&
sipAddress
)
{
static_cast
<
ChatModel
*>
(
mChatModelFilter
->
sourceModel
())
->
setSipAddress
(
sipAddress
);
}
bool
ChatProxyModel
::
getIsRemoteComposing
()
const
{
return
static_cast
<
ChatModel
*>
(
mChatModelFilter
->
sourceModel
())
->
getIsRemoteComposing
();
}
// -----------------------------------------------------------------------------
void
ChatProxyModel
::
loadMoreEntries
()
{
int
count
=
rowCount
();
int
parentCount
=
mChatModelFilter
->
rowCount
();
int
parentCount
=
sourceModel
()
->
rowCount
();
if
(
count
<
parentCount
)
{
// Do not increase `mMaxDisplayedEntries` if it's not necessary...
...
...
@@ -159,8 +128,10 @@ void ChatProxyModel::loadMoreEntries () {
}
void
ChatProxyModel
::
setEntryTypeFilter
(
ChatModel
::
EntryType
type
)
{
if
(
mChatModelFilter
->
getEntryTypeFilter
()
!=
type
)
{
mChatModelFilter
->
setEntryTypeFilter
(
type
);
ChatModelFilter
*
chatModelFilter
=
static_cast
<
ChatModelFilter
*>
(
sourceModel
());
if
(
chatModelFilter
->
getEntryTypeFilter
()
!=
type
)
{
chatModelFilter
->
setEntryTypeFilter
(
type
);
emit
entryTypeFilterChanged
(
type
);
}
}
...
...
@@ -168,5 +139,50 @@ void ChatProxyModel::setEntryTypeFilter (ChatModel::EntryType type) {
// -----------------------------------------------------------------------------
bool
ChatProxyModel
::
filterAcceptsRow
(
int
sourceRow
,
const
QModelIndex
&
)
const
{
return
mChatModelFilter
->
rowCount
()
-
sourceRow
<=
mMaxDisplayedEntries
;
return
sourceModel
()
->
rowCount
()
-
sourceRow
<=
mMaxDisplayedEntries
;
}
// -----------------------------------------------------------------------------
QString
ChatProxyModel
::
getSipAddress
()
const
{
return
mChatModel
?
mChatModel
->
getSipAddress
()
:
QString
(
""
);
}
void
ChatProxyModel
::
setSipAddress
(
const
QString
&
sipAddress
)
{
mMaxDisplayedEntries
=
ENTRIES_CHUNK_SIZE
;
if
(
mChatModel
)
{
ChatModel
*
chatModel
=
mChatModel
.
get
();
QObject
::
disconnect
(
chatModel
,
&
ChatModel
::
isRemoteComposingChanged
,
this
,
&
ChatProxyModel
::
handleIsRemoteComposingChanged
);
QObject
::
disconnect
(
chatModel
,
&
ChatModel
::
messageReceived
,
this
,
&
ChatProxyModel
::
handleMessageReceived
);
QObject
::
disconnect
(
chatModel
,
&
ChatModel
::
messageSent
,
this
,
&
ChatProxyModel
::
handleMessageSent
);
}
mChatModel
=
CoreManager
::
getInstance
()
->
getChatModelFromSipAddress
(
sipAddress
);
if
(
mChatModel
)
{
ChatModel
*
chatModel
=
mChatModel
.
get
();
QObject
::
connect
(
chatModel
,
&
ChatModel
::
isRemoteComposingChanged
,
this
,
&
ChatProxyModel
::
handleIsRemoteComposingChanged
);
QObject
::
connect
(
chatModel
,
&
ChatModel
::
messageReceived
,
this
,
&
ChatProxyModel
::
handleMessageReceived
);
QObject
::
connect
(
chatModel
,
&
ChatModel
::
messageSent
,
this
,
&
ChatProxyModel
::
handleMessageSent
);
}
static_cast
<
ChatModelFilter
*>
(
sourceModel
())
->
setSourceModel
(
mChatModel
.
get
());
}
bool
ChatProxyModel
::
getIsRemoteComposing
()
const
{
return
mChatModel
?
mChatModel
->
getIsRemoteComposing
()
:
false
;
}
// -----------------------------------------------------------------------------
void
ChatProxyModel
::
handleIsRemoteComposingChanged
(
bool
status
)
{
emit
isRemoteComposingChanged
(
status
);
}
void
ChatProxyModel
::
handleMessageReceived
(
const
shared_ptr
<
linphone
::
ChatMessage
>
&
)
{
mMaxDisplayedEntries
++
;
}
void
ChatProxyModel
::
handleMessageSent
(
const
shared_ptr
<
linphone
::
ChatMessage
>
&
)
{
mMaxDisplayedEntries
++
;
}
src/components/chat/ChatProxyModel.hpp
View file @
7aeba275
...
...
@@ -74,9 +74,14 @@ private:
bool
getIsRemoteComposing
()
const
;
ChatModelFilter
*
mChatModelFilter
;
void
handleIsRemoteComposingChanged
(
bool
status
);
void
handleMessageReceived
(
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
void
handleMessageSent
(
const
std
::
shared_ptr
<
linphone
::
ChatMessage
>
&
message
);
int
mMaxDisplayedEntries
=
ENTRIES_CHUNK_SIZE
;
std
::
shared_ptr
<
ChatModel
>
mChatModel
;
static
const
int
ENTRIES_CHUNK_SIZE
;
};
...
...
src/components/core/CoreManager.cpp
View file @
7aeba275
...
...
@@ -73,6 +73,34 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) :
// -----------------------------------------------------------------------------
shared_ptr
<
ChatModel
>
CoreManager
::
getChatModelFromSipAddress
(
const
QString
&
sipAddress
)
{
if
(
!
sipAddress
.
length
())
return
nullptr
;
Q_ASSERT
(
mCore
->
createAddress
(
::
Utils
::
appStringToCoreString
(
sipAddress
))
!=
nullptr
);
// Create a new chat model.
if
(
!
mChatModels
.
contains
(
sipAddress
))
{
auto
deleter
=
[
this
](
ChatModel
*
chatModel
)
{
mChatModels
.
remove
(
chatModel
->
getSipAddress
());
};
shared_ptr
<
ChatModel
>
chatModel
(
new
ChatModel
(
sipAddress
),
deleter
);
mChatModels
[
sipAddress
]
=
chatModel
;
emit
chatModelCreated
(
chatModel
);
return
chatModel
;
}
// Returns an existing chat model.
shared_ptr
<
ChatModel
>
chatModel
=
mChatModels
[
sipAddress
].
lock
();
Q_CHECK_PTR
(
chatModel
.
get
());
return
chatModel
;
}
// -----------------------------------------------------------------------------
void
CoreManager
::
init
(
QObject
*
parent
,
const
QString
&
configPath
)
{
if
(
mInstance
)
return
;
...
...
src/components/core/CoreManager.hpp
View file @
7aeba275
...
...
@@ -58,6 +58,8 @@ public:
return
mHandlers
;
}
std
::
shared_ptr
<
ChatModel
>
getChatModelFromSipAddress
(
const
QString
&
sipAddress
);
// ---------------------------------------------------------------------------
// Video render lock.
// ---------------------------------------------------------------------------
...
...
@@ -126,6 +128,8 @@ signals:
void
coreCreated
();
void
coreStarted
();
void
chatModelCreated
(
const
std
::
shared_ptr
<
ChatModel
>
chatModel
);
void
logsUploaded
(
const
QString
&
url
);
private:
...
...
@@ -154,6 +158,8 @@ private:
SettingsModel
*
mSettingsModel
;
AccountSettingsModel
*
mAccountSettingsModel
;
QHash
<
QString
,
std
::
weak_ptr
<
ChatModel
>
>
mChatModels
;
QTimer
*
mCbsTimer
;
QFuture
<
void
>
mPromiseBuild
;
...
...
src/components/sip-addresses/SipAddressesModel.cpp
View file @
7aeba275
...
...
@@ -38,13 +38,15 @@ using namespace std;
SipAddressesModel
::
SipAddressesModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
{
initSipAddresses
();
mCoreHandlers
=
CoreManager
::
getInstance
()
->
getHandlers
();
CoreManager
*
coreManager
=
CoreManager
::
getInstance
();
ContactsListModel
*
contacts
=
CoreManager
::
getInstance
()
->
getContactsListModel
();
mCoreHandlers
=
coreManager
->
getHandlers
();
QObject
::
connect
(
coreManager
,
&
CoreManager
::
chatModelCreated
,
this
,
&
SipAddressesModel
::
handleChatModelCreated
);
ContactsListModel
*
contacts
=
CoreManager
::
getInstance
()
->
getContactsListModel
();
QObject
::
connect
(
contacts
,
&
ContactsListModel
::
contactAdded
,
this
,
&
SipAddressesModel
::
handleContactAdded
);
QObject
::
connect
(
contacts
,
&
ContactsListModel
::
contactRemoved
,
this
,
&
SipAddressesModel
::
handleContactRemoved
);
QObject
::
connect
(
contacts
,
&
ContactsListModel
::
sipAddressAdded
,
this
,
&
SipAddressesModel
::
handleSipAddressAdded
);
QObject
::
connect
(
contacts
,
&
ContactsListModel
::
sipAddressRemoved
,
this
,
&
SipAddressesModel
::
handleSipAddressRemoved
);
...
...
@@ -81,20 +83,6 @@ QVariant SipAddressesModel::data (const QModelIndex &index, int role) const {
// -----------------------------------------------------------------------------
void
SipAddressesModel
::
connectToChatModel
(
ChatModel
*
chatModel
)
{
QObject
::
connect
(
chatModel
,
&
ChatModel
::
allEntriesRemoved
,
this
,
[
this
,
chatModel
]
{
handleAllEntriesRemoved
(
chatModel
->
getSipAddress
());
});
QObject
::
connect
(
chatModel
,
&
ChatModel
::
messageSent
,
this
,
&
SipAddressesModel
::
handleMessageSent
);
QObject
::
connect
(
chatModel
,
&
ChatModel
::
messagesCountReset
,
this
,
[
this
,
chatModel
]
{
handleMessagesCountReset
(
chatModel
->
getSipAddress
());
});
}
// -----------------------------------------------------------------------------
QVariantMap
SipAddressesModel
::
find
(
const
QString
&
sipAddress
)
const
{
auto
it
=
mSipAddresses
.
find
(
sipAddress
);
return
it
==
mSipAddresses
.
end
()
?
QVariantMap
()
:
*
it
;
...
...
@@ -225,6 +213,20 @@ bool SipAddressesModel::removeRows (int row, int count, const QModelIndex &paren
// -----------------------------------------------------------------------------
void
SipAddressesModel
::
handleChatModelCreated
(
const
std
::
shared_ptr
<
ChatModel
>
&
chatModel
)
{
ChatModel
*
ptr
=
chatModel
.
get
();
QObject
::
connect
(
ptr
,
&
ChatModel
::
allEntriesRemoved
,
this
,
[
this
,
ptr
]
{
handleAllEntriesRemoved
(
ptr
->
getSipAddress
());
});
QObject
::
connect
(
ptr
,
&
ChatModel
::
messageSent
,
this
,
&
SipAddressesModel
::
handleMessageSent
);
QObject
::
connect
(
ptr
,
&
ChatModel
::
messagesCountReset
,
this
,
[
this
,
ptr
]
{
handleMessagesCountReset
(
ptr
->
getSipAddress
());
});
}
void
SipAddressesModel
::
handleContactAdded
(
ContactModel
*
contact
)
{
for
(
const
auto
&
sipAddress
:
contact
->
getVcardModel
()
->
getSipAddresses
())
addOrUpdateSipAddress
(
sipAddress
.
toString
(),
contact
);
...
...
src/components/sip-addresses/SipAddressesModel.hpp
View file @
7aeba275
...
...
@@ -46,8 +46,6 @@ public:
QHash
<
int
,
QByteArray
>
roleNames
()
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
void
connectToChatModel
(
ChatModel
*
chatModel
);
Q_INVOKABLE
QVariantMap
find
(
const
QString
&
sipAddress
)
const
;
Q_INVOKABLE
ContactModel
*
mapSipAddressToContact
(
const
QString
&
sipAddress
)
const
;
Q_INVOKABLE
SipAddressObserver
*
getSipAddressObserver
(
const
QString
&
sipAddress
);
...
...
@@ -72,6 +70,8 @@ private:
// ---------------------------------------------------------------------------
void
handleChatModelCreated
(
const
std
::
shared_ptr
<
ChatModel
>
&
chatModel
);
void
handleContactAdded
(
ContactModel
*
contact
);
void
handleContactRemoved
(
const
ContactModel
*
contact
);
...
...
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