fix(ui/modules/Linphone/Calls/Calls): handle calls correctly

This commit is contained in:
Ronan Abhamon 2017-04-27 17:33:17 +02:00
parent 63e4132d5c
commit 9d8b263218
4 changed files with 31 additions and 36 deletions

View file

@ -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
}
}
}

View file

@ -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
}
}
// -------------------------------------------------------------------------

View file

@ -43,7 +43,7 @@ function handleRowsAboutToBeRemoved (parent, first, last) {
}
}
function handleCountChanged () {
function handleCountChanged (_) {
var sipAddress = timeline._selectedSipAddress
if (sipAddress.length > 0) {
setSelectedEntry(sipAddress)

View file

@ -139,6 +139,6 @@ ColumnLayout {
}
}
onCountChanged: Logic.handleCountChanged()
onCountChanged: Logic.handleCountChanged(count)
}
}