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 &) { ...@@ -128,7 +128,7 @@ bool ChatModel::removeRow (int row, const QModelIndex &) {
bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) { bool ChatModel::removeRows (int row, int count, const QModelIndex &parent) {
int limit = row + count - 1; 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; return false;
beginRemoveRows(parent, row, limit); beginRemoveRows(parent, row, limit);
......
#include <QDebug> #include <QDebug>
#include <cmath>
#include "../../utils.hpp" #include "../../utils.hpp"
#include "../core/CoreManager.hpp" #include "../core/CoreManager.hpp"
...@@ -52,7 +54,7 @@ bool ContactsListProxyModel::filterAcceptsRow ( ...@@ -52,7 +54,7 @@ bool ContactsListProxyModel::filterAcceptsRow (
const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent); const QModelIndex &index = sourceModel()->index(source_row, 0, source_parent);
const ContactModel *contact = index.data().value<ContactModel *>(); 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 && ( return m_weights[contact] > 0 && (
!m_use_connected_filter || !m_use_connected_filter ||
......
...@@ -5,16 +5,23 @@ import Utils 1.0 ...@@ -5,16 +5,23 @@ import Utils 1.0
// ============================================================================= // =============================================================================
Item { Item {
property bool _connected: false property var handlers: ({})
function connect (emitter, signalName, handler) { function connect (emitter, signalName, handler) {
Utils.assert(!_connected, 'SmartConnect is already connected!')
emitter[signalName].connect(handler) emitter[signalName].connect(handler)
_connected = true
Component.onDestruction.connect(function () { if (!handlers[signalName]) {
emitter[signalName].disconnect(handler) 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 { ...@@ -27,9 +27,10 @@ ColumnLayout {
var n = model.rowCount() var n = model.rowCount()
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
_selectedSipAddress = sipAddress
if (sipAddress === model.data(model.index(i, 0)).sipAddress) { if (sipAddress === model.data(model.index(i, 0)).sipAddress) {
view.currentIndex = i view.currentIndex = i
_selectedSipAddress = sipAddress
return return
} }
} }
...@@ -45,7 +46,9 @@ ColumnLayout { ...@@ -45,7 +46,9 @@ ColumnLayout {
spacing: 0 spacing: 0
SmartConnect { SmartConnect {
Component.onCompleted: this.connect(model, 'dataChanged', function () { Component.onCompleted: {
// Handle if current entry was moved in timeline.
this.connect(model, 'dataChanged', function () {
var index = view.currentIndex var index = view.currentIndex
if ( if (
index !== -1 && index !== -1 &&
...@@ -54,6 +57,28 @@ ColumnLayout { ...@@ -54,6 +57,28 @@ ColumnLayout {
setSelectedEntry(_selectedSipAddress) 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