Commit e1fb1a39 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone/Calls/Calls): change current call when stream is running

parent 9304442b
......@@ -36,6 +36,19 @@ using namespace std;
// =============================================================================
inline QList<CallModel *>::iterator findCall (
QList<CallModel *> &list,
const shared_ptr<linphone::Call> &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<int>(distance(m_list.begin(), findCall(m_list, linphone_call)));
emit callRunning(index, &linphone_call->getData<CallModel>("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> &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<QList<CallModel *> *>(&m_list)), linphone_call);
return it != m_list.end() ? *it : nullptr;
}
......
......@@ -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;
......
......@@ -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])
}
})
}
}
......
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment