From e1fb1a3938787ad2175908ae5f36ce6452fc3b09 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 9 Feb 2017 17:05:05 +0100 Subject: [PATCH] feat(ui/modules/Linphone/Calls/Calls): change current call when stream is running --- .../src/components/calls/CallsListModel.cpp | 26 ++++- .../src/components/calls/CallsListModel.hpp | 3 + .../ui/modules/Common/SmartConnect.qml | 6 +- .../ui/modules/Linphone/Calls/Calls.qml | 108 +++++++++--------- 4 files changed, 82 insertions(+), 61 deletions(-) diff --git a/linphone-desktop/src/components/calls/CallsListModel.cpp b/linphone-desktop/src/components/calls/CallsListModel.cpp index e72b3ad32..3e90d16cc 100644 --- a/linphone-desktop/src/components/calls/CallsListModel.cpp +++ b/linphone-desktop/src/components/calls/CallsListModel.cpp @@ -36,6 +36,19 @@ using namespace std; // ============================================================================= +inline QList::iterator findCall ( + QList &list, + const shared_ptr &linphone_call +) { + return find_if( + list.begin(), list.end(), [linphone_call](CallModel *call) { + return linphone_call == call->getLinphoneCall(); + } + ); +} + +// ----------------------------------------------------------------------------- + CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) { m_core_handlers = CoreManager::getInstance()->getHandlers(); QObject::connect( @@ -52,6 +65,12 @@ CallsListModel::CallsListModel (QObject *parent) : QAbstractListModel(parent) { removeCall(linphone_call); break; + case linphone::CallStateStreamsRunning: { + int index = static_cast(distance(m_list.begin(), findCall(m_list, linphone_call))); + emit callRunning(index, &linphone_call->getData("call-model")); + } + break; + default: break; } @@ -82,12 +101,7 @@ QVariant CallsListModel::data (const QModelIndex &index, int role) const { } CallModel *CallsListModel::getCall (const shared_ptr &linphone_call) const { - auto it = find_if( - m_list.begin(), m_list.end(), [linphone_call](CallModel *call) { - return linphone_call == call->getLinphoneCall(); - } - ); - + auto it = findCall(*(const_cast *>(&m_list)), linphone_call); return it != m_list.end() ? *it : nullptr; } diff --git a/linphone-desktop/src/components/calls/CallsListModel.hpp b/linphone-desktop/src/components/calls/CallsListModel.hpp index f3d485469..d5decabb3 100644 --- a/linphone-desktop/src/components/calls/CallsListModel.hpp +++ b/linphone-desktop/src/components/calls/CallsListModel.hpp @@ -48,6 +48,9 @@ public: Q_INVOKABLE void launchAudioCall (const QString &sip_uri) const; Q_INVOKABLE void launchVideoCall (const QString &sip_uri) const; +signals: + void callRunning (int index, CallModel *call); + private: bool removeRow (int row, const QModelIndex &parent = QModelIndex()); bool removeRows (int row, int count, const QModelIndex &parent = QModelIndex()) override; diff --git a/linphone-desktop/ui/modules/Common/SmartConnect.qml b/linphone-desktop/ui/modules/Common/SmartConnect.qml index b6f2d3049..982be4fc1 100644 --- a/linphone-desktop/ui/modules/Common/SmartConnect.qml +++ b/linphone-desktop/ui/modules/Common/SmartConnect.qml @@ -20,7 +20,11 @@ Item { Component.onDestruction: { for (var signalName in handlers) { handlers[signalName].forEach(function (value) { - value[0][signalName].disconnect(value[1]) + var component = value[0][signalName] + + if (component) { + component.disconnect(value[1]) + } }) } } diff --git a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml index 8ade6fc4a..8cd4bbf74 100644 --- a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml +++ b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml @@ -11,9 +11,10 @@ ListView { // --------------------------------------------------------------------------- - readonly property var selectedCall: smartConnect.selectedCall + readonly property var selectedCall: _selectedCall property var _mapStatusToParams + property var _selectedCall // --------------------------------------------------------------------------- @@ -102,6 +103,57 @@ ListView { string: 'paused' } }) + + model.rowsAboutToBeRemoved.connect(function (_, first, last) { + var index = calls.currentIndex + + if (index >= first && index <= last) { // Remove current call. + if (model.rowCount() - (last - first + 1) <= 0) { + _selectedCall = null + } else { + if (first === 0) { + _selectedCall = model.data(model.index(last + 1, 0)) + } else { + _selectedCall = model.data(model.index(0, 0)) + } + } + } + }) + + model.rowsRemoved.connect(function (_, first, last) { + var index = calls.currentIndex + + // The current call has been removed. + if (index >= first && index <= last) { + if (model.rowCount() === 0) { + calls.currentIndex = -1 // No calls. + } else { + calls.currentIndex = 0 // The first call becomes the selected call. + } + } + + // Update the current index of the selected call if it was after the removed calls. + else if (last < index) { + calls.currentIndex = index - (last - first + 1) + } + }) + + // The last inserted outgoing element become the selected call. + model.rowsInserted.connect(function (_, first, last) { + for (var index = last; index >= first; index--) { + var call = model.data(model.index(index, 0)) + + if (call.isOutgoing) { + calls.currentIndex = first + _selectedCall = model.data(model.index(first, 0)) + } + } + }) + + model.callRunning.connect(function (index, call) { + calls.currentIndex = index + _selectedCall = call + }) } // --------------------------------------------------------------------------- @@ -161,58 +213,6 @@ ListView { } } - // --------------------------------------------------------------------------- - // SmartConnect that updates the current selected call and the current index. - // --------------------------------------------------------------------------- - - SmartConnect { - id: smartConnect - - property var selectedCall - - Component.onCompleted: { - this.connect(model, 'rowsAboutToBeRemoved', function (_, first, last) { - var index = calls.currentIndex - - if (index >= first && index <= last) { // Remove current call. - if (model.rowCount() - (last - first + 1) <= 0) { - selectedCall = null - } else { - if (first === 0) { - selectedCall = model.data(model.index(last + 1, 0)) - } else { - selectedCall = model.data(model.index(0, 0)) - } - } - } - }) - - this.connect(model, 'rowsRemoved', function (_, first, last) { - var index = calls.currentIndex - - // The current call has been removed. - if (index >= first && index <= last) { - if (model.rowCount() === 0) { - calls.currentIndex = -1 // No calls. - } else { - calls.currentIndex = 0 // The first call becomes the selected call. - } - } - - // Update the current index of the selected call if it was after the removed calls. - else if (last < index) { - calls.currentIndex = index - (last - first + 1) - } - }) - - // The last inserted element become the selected call. - this.connect(model, 'rowsInserted', function (_, first, last) { - calls.currentIndex = first - selectedCall = model.data(model.index(first, 0)) - }) - } - } - // --------------------------------------------------------------------------- delegate: CallControls { @@ -245,7 +245,7 @@ ListView { width: parent.width onClicked: { - smartConnect.selectedCall = $call + _selectedCall = $call calls.currentIndex = index }