diff --git a/linphone-app/src/components/chat/ChatProxyModel.cpp b/linphone-app/src/components/chat/ChatProxyModel.cpp index 1e6bf522d..2093873e5 100644 --- a/linphone-app/src/components/chat/ChatProxyModel.cpp +++ b/linphone-app/src/components/chat/ChatProxyModel.cpp @@ -248,14 +248,14 @@ void ChatProxyModel::resetMessageCount(){ } } -std::shared_ptr ChatProxyModel::getChatRoom () const{ +std::shared_ptr ChatProxyModel::getChatModel () const{ return mChatModel; } -void ChatProxyModel::setChatRoom (std::shared_ptr chatModel){ +void ChatProxyModel::setChatModel (std::shared_ptr chatModel){ mChatRoom = chatModel->getChatRoom(); reload(); - emit chatRoomChanged(); + emit chatModelChanged(); } // ----------------------------------------------------------------------------- diff --git a/linphone-app/src/components/chat/ChatProxyModel.hpp b/linphone-app/src/components/chat/ChatProxyModel.hpp index f5c891296..c3c50bd82 100644 --- a/linphone-app/src/components/chat/ChatProxyModel.hpp +++ b/linphone-app/src/components/chat/ChatProxyModel.hpp @@ -39,7 +39,7 @@ class ChatProxyModel : public QSortFilterProxyModel { Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress WRITE setFullPeerAddress NOTIFY fullPeerAddressChanged); Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress WRITE setFullLocalAddress NOTIFY fullLocalAddressChanged); Q_PROPERTY(int isSecure READ getIsSecure WRITE setIsSecure NOTIFY isSecureChanged); - Q_PROPERTY(std::shared_ptr chatRoom READ getChatRoom WRITE setChatRoom NOTIFY chatRoomChanged); + Q_PROPERTY(std::shared_ptr chatModel READ getChatModel WRITE setChatModel NOTIFY chatModelChanged); //Q_PROPERTY(bool isSecure MEMBER mIsSecure NOTIFY isSecureChanged); Q_PROPERTY(bool isRemoteComposing READ getIsRemoteComposing NOTIFY isRemoteComposingChanged); //Q_PROPERTY(bool isSecure READ getIsSecure NOTIFY isSecureChanged); @@ -75,7 +75,7 @@ signals: bool isRemoteComposingChanged (bool status); bool isSecureChanged(bool secure); - void chatRoomChanged(); + void chatModelChanged(); void moreEntriesLoaded (int n); @@ -100,8 +100,8 @@ private: int getIsSecure () const; void setIsSecure (const int &secure); - std::shared_ptr getChatRoom () const; - void setChatRoom (std::shared_ptr chatRoom); + std::shared_ptr getChatModel() const; + void setChatModel (std::shared_ptr chatModel); bool getIsRemoteComposing () const; diff --git a/linphone-app/src/components/timeline/TimelineListModel.cpp b/linphone-app/src/components/timeline/TimelineListModel.cpp index e92680cac..22c3de205 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.cpp +++ b/linphone-app/src/components/timeline/TimelineListModel.cpp @@ -36,10 +36,18 @@ TimelineListModel::TimelineListModel (QObject *parent) : QAbstractListModel(pare } // ----------------------------------------------------------------------------- + +TimelineModel * TimelineListModel::getAt(const int& index){ + return mTimelines[index]; +} + void TimelineListModel::reset(){ initTimeline(); } +void TimelineListModel::update(){ + +} int TimelineListModel::rowCount (const QModelIndex &) const { return mTimelines.count(); } @@ -126,6 +134,36 @@ void TimelineListModel::initTimeline () { } */ } + +TimelineModel * TimelineListModel::getTimeline(std::shared_ptr chatRoom, const bool &create){ + if(chatRoom){ + for(auto it = mTimelines.begin() ; it != mTimelines.end() ; ++it){ + if( (*it)->getChatModel()->getChatRoom() == chatRoom){ + return *it; + } + } + if(create) + return new TimelineModel(chatRoom); + } + return nullptr; +} + +void TimelineListModel::updateTimelines () { + CoreManager *coreManager = CoreManager::getInstance(); + auto currentAddress = coreManager->getAccountSettingsModel()->getUsedSipAddress(); + + std::list> allChatRooms = coreManager->getCore()->getChatRooms(); + QList models; + for(auto itAllChatRooms = allChatRooms.begin() ; itAllChatRooms != allChatRooms.end() ; ++itAllChatRooms){ + if((*itAllChatRooms)->getMe()->getAddress()->weakEqual(currentAddress)){ + models << getTimeline(*itAllChatRooms, true); + //models << new TimelineModel(*itAllChatRooms); + } + } + //beginInsertRows(QModelIndex(), 0, models.count()-1); + + mTimelines = models; +} /* // Create a new TimelineModel and put it in the list void TimelineListModel::add(){ diff --git a/linphone-app/src/components/timeline/TimelineListModel.hpp b/linphone-app/src/components/timeline/TimelineListModel.hpp index 1525f958e..91c3cb25c 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.hpp +++ b/linphone-app/src/components/timeline/TimelineListModel.hpp @@ -22,6 +22,7 @@ #define TIMELINE_LIST_MODEL_H_ #include +#include "components/chat/ChatModel.hpp" class TimelineModel; // ============================================================================= @@ -33,6 +34,9 @@ public: TimelineListModel (QObject *parent = Q_NULLPTR); void reset(); + void update(); + TimelineModel * getAt(const int& index); + TimelineModel * getTimeline(std::shared_ptr chatRoom, const bool &create); int rowCount (const QModelIndex &index = QModelIndex()) const override; @@ -46,7 +50,10 @@ private: bool removeRow (int row, const QModelIndex &parent = QModelIndex()); bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; + + void initTimeline (); + void updateTimelines(); QList mTimelines; }; diff --git a/linphone-app/src/components/timeline/TimelineModel.cpp b/linphone-app/src/components/timeline/TimelineModel.cpp index 30c3d669d..a8be81e68 100644 --- a/linphone-app/src/components/timeline/TimelineModel.cpp +++ b/linphone-app/src/components/timeline/TimelineModel.cpp @@ -65,6 +65,6 @@ int TimelineModel::getPresenceStatus() const{ return 0; } -std::shared_ptr TimelineModel::getChatRoom() const{ +std::shared_ptr TimelineModel::getChatModel() const{ return mChatModel; } diff --git a/linphone-app/src/components/timeline/TimelineModel.hpp b/linphone-app/src/components/timeline/TimelineModel.hpp index 591cc32fb..8b4a00b6f 100644 --- a/linphone-app/src/components/timeline/TimelineModel.hpp +++ b/linphone-app/src/components/timeline/TimelineModel.hpp @@ -40,7 +40,7 @@ public: Q_PROPERTY(QString fullPeerAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged) Q_PROPERTY(QString fullLocalAddress READ getFullLocalAddress NOTIFY fullLocalAddressChanged) - Q_PROPERTY(std::shared_ptr chatRoom READ getChatRoom CONSTANT) + Q_PROPERTY(std::shared_ptr chatModel READ getChatModel CONSTANT) // Contact Q_PROPERTY(QString sipAddress READ getFullPeerAddress NOTIFY fullPeerAddressChanged) @@ -57,7 +57,7 @@ public: int getPresenceStatus() const; - std::shared_ptr getChatRoom() const; + Q_INVOKABLE std::shared_ptr getChatModel() const; QDateTime mTimestamp; std::shared_ptr mChatModel; diff --git a/linphone-app/src/components/timeline/TimelineProxyModel.cpp b/linphone-app/src/components/timeline/TimelineProxyModel.cpp index 800a4d379..ad8f6f7cf 100644 --- a/linphone-app/src/components/timeline/TimelineProxyModel.cpp +++ b/linphone-app/src/components/timeline/TimelineProxyModel.cpp @@ -35,10 +35,41 @@ // ----------------------------------------------------------------------------- TimelineProxyModel::TimelineProxyModel (QObject *parent) : QSortFilterProxyModel(parent) { - setSourceModel(CoreManager::getInstance()->getTimelineListModel()); + CoreManager *coreManager = CoreManager::getInstance(); + AccountSettingsModel *accountSettingsModel = coreManager->getAccountSettingsModel(); + setSourceModel(CoreManager::getInstance()->getTimelineListModel()); + + QObject::connect(accountSettingsModel, &AccountSettingsModel::accountSettingsUpdated, this, [this]() { + dynamic_cast(sourceModel())->update(); + invalidate(); + updateCurrentSelection(); + }); + QObject::connect(coreManager->getSipAddressesModel(), &SipAddressesModel::sipAddressReset, this, [this]() { + dynamic_cast(sourceModel())->reset(); + invalidate();// Invalidate and reload GUI if the model has been reset + updateCurrentSelection(); + }); sort(0); } +// ----------------------------------------------------------------------------- +void TimelineProxyModel::setCurrentChatModel(std::shared_ptr data){ + mCurrentChatModel = data; + emit currentChatModelChanged(mCurrentChatModel); + emit currentTimelineChanged(dynamic_cast(sourceModel())->getTimeline(mCurrentChatModel->getChatRoom(), false)); +} + +std::shared_ptr TimelineProxyModel::getCurrentChatModel()const{ + return mCurrentChatModel; +} + +void TimelineProxyModel::updateCurrentSelection(){ + auto currentAddress = CoreManager::getInstance()->getAccountSettingsModel()->getUsedSipAddress(); + if(mCurrentChatModel && !mCurrentChatModel->getChatRoom()->getMe()->getAddress()->weakEqual(currentAddress) ){ + setCurrentChatModel(nullptr); + } +} + // ----------------------------------------------------------------------------- bool TimelineProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const { diff --git a/linphone-app/src/components/timeline/TimelineProxyModel.hpp b/linphone-app/src/components/timeline/TimelineProxyModel.hpp index c5b8e3b94..a2fd7e34d 100644 --- a/linphone-app/src/components/timeline/TimelineProxyModel.hpp +++ b/linphone-app/src/components/timeline/TimelineProxyModel.hpp @@ -24,12 +24,28 @@ #include // ============================================================================= +#include "../chat/ChatModel.hpp" + +class TimelineModel; + class TimelineProxyModel : public QSortFilterProxyModel { - Q_OBJECT; + Q_OBJECT public: TimelineProxyModel (QObject *parent = Q_NULLPTR); + + Q_PROPERTY(std::shared_ptr currentChatModel WRITE setCurrentChatModel READ getCurrentChatModel NOTIFY currentChatModelChanged) + + void updateCurrentSelection(); + + Q_INVOKABLE void setCurrentChatModel(std::shared_ptr data); + std::shared_ptr getCurrentChatModel() const; + +signals: + void currentChatModelChanged(std::shared_ptr currentChatModel); + void currentTimelineChanged(TimelineModel * currentTimeline); + protected: @@ -39,6 +55,9 @@ protected: QString getLocalAddress () const; QString getCleanedLocalAddress () const; void handleLocalAddressChanged (const QString &localAddress); + + + std::shared_ptr mCurrentChatModel; }; diff --git a/linphone-app/ui/modules/Linphone/Timeline/Timeline.qml b/linphone-app/ui/modules/Linphone/Timeline/Timeline.qml index 3eb71ab70..c7da01565 100644 --- a/linphone-app/ui/modules/Linphone/Timeline/Timeline.qml +++ b/linphone-app/ui/modules/Linphone/Timeline/Timeline.qml @@ -23,7 +23,7 @@ Rectangle { signal entrySelected (TimelineModel entry) // --------------------------------------------------------------------------- - +/* function setSelectedEntry (peerAddress, localAddress) { Logic.setSelectedEntry(peerAddress, localAddress) } @@ -31,7 +31,7 @@ Rectangle { function resetSelectedEntry () { Logic.resetSelectedEntry() } - +*/ // --------------------------------------------------------------------------- color: TimelineStyle.color @@ -41,14 +41,20 @@ Rectangle { spacing: 0 // ------------------------------------------------------------------------- + + Connections { + target: model + onCurrentTimelineChanged:entrySelected(currentTimeline) + } +/* Connections { target: model onDataChanged: Logic.handleDataChanged(topLeft, bottomRight, roles) onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved(parent, first, last) } - +*/ // ------------------------------------------------------------------------- // Legend. // ------------------------------------------------------------------------- @@ -144,13 +150,15 @@ Rectangle { anchors.fill: parent onClicked: { view.currentIndex = index - timeline.entrySelected(modelData) + //timeline.model.setCurrentChatModel(modelData.getChatModel())// using member doesn't work + timeline.model.currentChatModel = modelData.chatModel + //timeline.entrySelected(modelData) //timeline.entrySelected($timelineEntry.sipAddress, $timelineEntry.isSecure) } } } - onCountChanged: Logic.handleCountChanged(count) + // onCountChanged: Logic.handleCountChanged(count) } } } diff --git a/linphone-app/ui/views/App/Main/Conversation.qml b/linphone-app/ui/views/App/Main/Conversation.qml index c2f7b55f6..6ebd3d79b 100644 --- a/linphone-app/ui/views/App/Main/Conversation.qml +++ b/linphone-app/ui/views/App/Main/Conversation.qml @@ -18,7 +18,7 @@ ColumnLayout { property string fullPeerAddress property string fullLocalAddress property int isSecure - property var chatRoom + property var chatModel readonly property var _sipAddressObserver: SipAddressesModel.getSipAddressObserver((fullPeerAddress?fullPeerAddress:peerAddress), (fullLocalAddress?fullLocalAddress:localAddress)) @@ -173,7 +173,7 @@ ColumnLayout { resetMessageCount() } isSecure: conversation.isSecure - chatRoom: conversation.chatRoom + chatModel: conversation.chatModel peerAddress: conversation.peerAddress fullPeerAddress: conversation.fullPeerAddress fullLocalAddress: conversation.fullLocalAddress diff --git a/linphone-app/ui/views/App/Main/MainWindow.js b/linphone-app/ui/views/App/Main/MainWindow.js index ec9ee9f7b..3d4053cc6 100644 --- a/linphone-app/ui/views/App/Main/MainWindow.js +++ b/linphone-app/ui/views/App/Main/MainWindow.js @@ -117,12 +117,12 @@ function updateSelectedEntry (view, props) { timeline.resetSelectedEntry() } else { menu.resetSelectedEntry() - +/* if (view === 'Conversation') { timeline.setSelectedEntry(props.peerAddress, props.localAddress) } else if (view === 'ContactEdit') { timeline.resetSelectedEntry() - } + }*/ } } diff --git a/linphone-app/ui/views/App/Main/MainWindow.qml b/linphone-app/ui/views/App/Main/MainWindow.qml index 1ce1556a9..5cab562a6 100644 --- a/linphone-app/ui/views/App/Main/MainWindow.qml +++ b/linphone-app/ui/views/App/Main/MainWindow.qml @@ -270,7 +270,7 @@ ApplicationWindow { fullPeerAddress: entry.fullPeerAddress, fullLocalAddress: AccountSettingsModel.fullSipAddress, localAddress: AccountSettingsModel.sipAddress, - chatRoom:entry.chatRoom + chatModel:entry.chatModel }): setView('HistoryView', {})