Commit 581eb69c authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): many changes:

  - display correctly selected chat in timeline
  - fix weight computation in `ContactsListProxyModel`
  - `SmartConnect` supports unlimited handlers
parent 67e0a4fa
......@@ -128,7 +128,7 @@ bool ChatModel::removeRow (int row, const QModelIndex &) {
bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
int limit = row + count - 1;
if (!parent.isValid() || row < 0 || count < 0 || limit >= m_entries.count())
if (row < 0 || count < 0 || limit >= m_entries.count())
return false;
beginRemoveRows(parent, row, limit);
......
#include <QDebug>
#include <cmath>
#include "../../utils.hpp"
#include "../core/CoreManager.hpp"
......@@ -52,7 +54,7 @@ bool ContactsListProxyModel::filterAcceptsRow (
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
const ContactModel *contact = index.data().value<ContactModel *>();
m_weights[contact] = static_cast<unsigned int>(computeContactWeight(*contact));
m_weights[contact] = static_cast<unsigned int>(round(computeContactWeight(*contact)));
return m_weights[contact] > 0 && (
!m_use_connected_filter ||
......
......@@ -5,16 +5,23 @@ import Utils 1.0
// =============================================================================
Item {
property bool _connected: false
property var handlers: ({})
function connect (emitter, signalName, handler) {
Utils.assert(!_connected, 'SmartConnect is already connected!')
emitter[signalName].connect(handler)
_connected = true
Component.onDestruction.connect(function () {
emitter[signalName].disconnect(handler)
})
if (!handlers[signalName]) {
handlers[signalName] = []
}
handlers[signalName].push([emitter, handler])
}
Component.onDestruction: {
for (var signalName in handlers) {
handlers[signalName].forEach(function (value) {
value[0][signalName].disconnect(value[1])
})
}
}
}
......@@ -27,9 +27,10 @@ ColumnLayout {
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
_selectedSipAddress = sipAddress
return
}
}
......@@ -45,15 +46,39 @@ ColumnLayout {
spacing: 0
SmartConnect {
Component.onCompleted: this.connect(model, 'dataChanged', function () {
var index = view.currentIndex
if (
index !== -1 &&
_selectedSipAddress !== model.data(model.index(index, 0)).sipAddress
) {
setSelectedEntry(_selectedSipAddress)
}
})
Component.onCompleted: {
// Handle if current entry was moved in timeline.
this.connect(model, 'dataChanged', function () {
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.
this.connect(model, 'rowsAboutToBeRemoved', function (_, first, last) {
var index = view.currentIndex
if (index >= first && index <= last) {
view.currentIndex = -1
}
})
// A entry is added when history is created.
this.connect(model, 'rowsInserted', function (_, first, last) {
if (_selectedSipAddress.length === 0) {
return
}
for (var i = first; i <= last; i++) {
if (_selectedSipAddress === model.data(model.index(i, 0)).sipAddress) {
view.currentIndex = i
}
}
})
}
}
// ---------------------------------------------------------------------------
......
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