linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js
2018-08-22 14:31:58 +02:00

60 lines
1.5 KiB
JavaScript

// =============================================================================
// `Timeline.qml` Logic.
// =============================================================================
.import Linphone 1.0 as Linphone
// =============================================================================
function setSelectedEntry (peerAddress, localAddress) {
if (localAddress !== Linphone.AccountSettingsModel.sipAddress) {
resetSelectedEntry()
return
}
var model = timeline.model
var n = view.count
timeline._selectedSipAddress = peerAddress
for (var i = 0; i < n; i++) {
if (peerAddress === model.data(model.index(i, 0)).sipAddress) {
view.currentIndex = i
return
}
}
}
function resetSelectedEntry () {
view.currentIndex = -1
timeline._selectedSipAddress = ''
}
// -----------------------------------------------------------------------------
function handleDataChanged (topLeft, bottomRight, roles) {
var index = view.currentIndex
var model = timeline.model
var sipAddress = timeline._selectedSipAddress
if (
index !== -1 &&
sipAddress !== model.data(model.index(index, 0)).sipAddress
) {
setSelectedEntry(sipAddress)
}
}
function handleRowsAboutToBeRemoved (parent, first, last) {
var index = view.currentIndex
if (index >= first && index <= last) {
view.currentIndex = -1
}
}
function handleCountChanged (_) {
var sipAddress = timeline._selectedSipAddress
if (sipAddress.length > 0) {
setSelectedEntry(sipAddress)
}
}