From 9d8b263218c0ab818ee02c8796d6dc8882a3d276 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 27 Apr 2017 17:33:17 +0200 Subject: [PATCH] fix(ui/modules/Linphone/Calls/Calls): handle calls correctly --- .../ui/modules/Linphone/Calls/Calls.js | 54 ++++++++----------- .../ui/modules/Linphone/Calls/Calls.qml | 9 ++-- .../ui/modules/Linphone/Timeline/Timeline.js | 2 +- .../ui/modules/Linphone/Timeline/Timeline.qml | 2 +- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/linphone-desktop/ui/modules/Linphone/Calls/Calls.js b/linphone-desktop/ui/modules/Linphone/Calls/Calls.js index 404583361..0758146b9 100644 --- a/linphone-desktop/ui/modules/Linphone/Calls/Calls.js +++ b/linphone-desktop/ui/modules/Linphone/Calls/Calls.js @@ -97,39 +97,29 @@ function handleCallRunning (index, call) { calls._selectedCall = call } +function handleCountChanged (count) { + if (count === 0) { + return 0 + } + + var index = calls.currentIndex + if (index !== -1) { + return + } + + var model = calls.model + index = count - 1 + + calls.currentIndex = index + calls._selectedCall = model.data(model.index(index, 0)) +} + function handleRowsAboutToBeRemoved (_, first, last) { var index = calls.currentIndex - if (index >= first && index <= last) { // Remove current call. - var model = calls.model - - if (model.rowCount() - (last - first + 1) <= 0) { - calls._selectedCall = null - } else { - if (first === 0) { - calls._selectedCall = model.data(model.index(last + 1, 0)) - } else { - calls._selectedCall = model.data(model.index(0, 0)) - } - } - } -} - -function handleRowsRemoved (_, first, last) { - var index = calls.currentIndex - - // The current call has been removed. if (index >= first && index <= last) { - if (calls.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) + calls.currentIndex = -1 + calls._selectedCall = null } } @@ -141,8 +131,10 @@ function handleRowsInserted (_, first, last) { var call = model.data(model.index(index, 0)) if (call.isOutgoing) { - calls.currentIndex = first - calls._selectedCall = model.data(model.index(first, 0)) + calls.currentIndex = -1 + calls._selectedCall = null + + return } } } diff --git a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml index 755000086..279035356 100644 --- a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml +++ b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml @@ -25,13 +25,14 @@ ListView { // --------------------------------------------------------------------------- + onCountChanged: Logic.handleCountChanged(count) + Connections { target: model onCallRunning: Logic.handleCallRunning(index, call) onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved(parent, first, last) onRowsInserted: Logic.handleRowsInserted(parent, first, last) - onRowsRemoved: Logic.handleRowsRemoved(parent, first, last) } // --------------------------------------------------------------------------- @@ -123,8 +124,10 @@ ListView { width: parent.width onClicked: { - _selectedCall = $call - calls.currentIndex = index + if ($call.status !== CallModel.CallStatusEnded) { + _selectedCall = $call + calls.currentIndex = index + } } // ------------------------------------------------------------------------- diff --git a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js index 90b72d088..14374bd3c 100644 --- a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js +++ b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js @@ -43,7 +43,7 @@ function handleRowsAboutToBeRemoved (parent, first, last) { } } -function handleCountChanged () { +function handleCountChanged (_) { var sipAddress = timeline._selectedSipAddress if (sipAddress.length > 0) { setSelectedEntry(sipAddress) diff --git a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml index 8d01d4d96..aaf70a186 100644 --- a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml +++ b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml @@ -139,6 +139,6 @@ ColumnLayout { } } - onCountChanged: Logic.handleCountChanged() + onCountChanged: Logic.handleCountChanged(count) } }