diff --git a/linphone-desktop/resources.qrc b/linphone-desktop/resources.qrc
index 972fc80da..9719c97ea 100644
--- a/linphone-desktop/resources.qrc
+++ b/linphone-desktop/resources.qrc
@@ -327,6 +327,7 @@
ui/modules/Linphone/Styles/Timeline/TimelineStyle.qml
ui/modules/Linphone/TelKeypad/TelKeypadButton.qml
ui/modules/Linphone/TelKeypad/TelKeypad.qml
+ ui/modules/Linphone/Timeline/Timeline.js
ui/modules/Linphone/Timeline/Timeline.qml
ui/scripts/LinphoneUtils/linphone-utils.js
ui/scripts/LinphoneUtils/qmldir
diff --git a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js
new file mode 100644
index 000000000..90b72d088
--- /dev/null
+++ b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.js
@@ -0,0 +1,51 @@
+// =============================================================================
+// `Timeline.qml` Logic.
+// =============================================================================
+
+function setSelectedEntry (sipAddress) {
+ var model = timeline.model
+ var n = view.count
+
+ timeline._selectedSipAddress = sipAddress
+
+ for (var i = 0; i < n; i++) {
+ if (sipAddress === 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)
+ }
+}
diff --git a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml
index a312a201e..8d01d4d96 100644
--- a/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml
+++ b/linphone-desktop/ui/modules/Linphone/Timeline/Timeline.qml
@@ -4,7 +4,8 @@ import QtQuick.Layouts 1.3
import Common 1.0
import Linphone 1.0
import Linphone.Styles 1.0
-import Utils 1.0
+
+import 'Timeline.js' as Logic
// =============================================================================
@@ -14,9 +15,10 @@ ColumnLayout {
// ---------------------------------------------------------------------------
property alias model: view.model
-
property string _selectedSipAddress
+ property var _newInsertedItem
+
// ---------------------------------------------------------------------------
signal entrySelected (var entry)
@@ -24,21 +26,11 @@ ColumnLayout {
// ---------------------------------------------------------------------------
function setSelectedEntry (sipAddress) {
- var n = model.rowCount()
-
- for (var i = 0; i < n; i++) {
- _selectedSipAddress = sipAddress
-
- if (sipAddress === model.data(model.index(i, 0)).sipAddress) {
- view.currentIndex = i
- return
- }
- }
+ Logic.setSelectedEntry(sipAddress)
}
function resetSelectedEntry () {
- view.currentIndex = -1
- _selectedSipAddress = ''
+ Logic.resetSelectedEntry()
}
// ---------------------------------------------------------------------------
@@ -50,37 +42,8 @@ ColumnLayout {
Connections {
target: model
- // Handle if current entry was moved in timeline.
- onDataChanged: {
- var index = view.currentIndex
- if (
- index !== -1 &&
- _selectedSipAddress !== model.data(model.index(index, 0)).sipAddress
- ) {
- setSelectedEntry(_selectedSipAddress)
- }
- }
-
- // A timeline entry is removed from timeline if there is no history entry.
- onRowsAboutToBeRemoved: {
- var index = view.currentIndex
- if (index >= first && index <= last) {
- view.currentIndex = -1
- }
- }
-
- // A entry is added when history is created.
- onRowsInserted: {
- if (_selectedSipAddress.length === 0) {
- return
- }
-
- for (var i = first; i <= last; i++) {
- if (_selectedSipAddress === model.data(model.index(i, 0)).sipAddress) {
- view.currentIndex = i
- }
- }
- }
+ onDataChanged: Logic.handleDataChanged(topLeft, bottomRight, roles)
+ onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved (parent, first, last)
}
// ---------------------------------------------------------------------------
@@ -175,5 +138,7 @@ ColumnLayout {
}
}
}
+
+ onCountChanged: Logic.handleCountChanged()
}
}