mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-24 07:08:07 +00:00
unstable
This commit is contained in:
parent
2a19553f02
commit
55a4e008f1
7 changed files with 122 additions and 34 deletions
|
|
@ -35,6 +35,7 @@ set(SOURCES
|
|||
src/app/DefaultTranslator.cpp
|
||||
src/app/Logger.cpp
|
||||
src/components/chat/ChatModel.cpp
|
||||
src/components/chat/ChatModelFilter.cpp
|
||||
src/components/chat/ChatProxyModel.cpp
|
||||
src/components/contacts/ContactModel.cpp
|
||||
src/components/contacts/ContactsListModel.cpp
|
||||
|
|
@ -55,6 +56,7 @@ set(HEADERS
|
|||
src/app/DefaultTranslator.hpp
|
||||
src/app/Logger.hpp
|
||||
src/components/chat/ChatModel.hpp
|
||||
src/components/chat/ChatModelFilter.hpp
|
||||
src/components/chat/ChatProxyModel.hpp
|
||||
src/components/contacts/ContactModel.hpp
|
||||
src/components/contacts/ContactsListModel.hpp
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>removeAllEntriesTitle</source>
|
||||
<translation>Suppression de l'historique</translation>
|
||||
<translation>Suppression de l'historique</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
@ -184,7 +184,7 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>endedCall</source>
|
||||
<translation>Fin d'appel</translation>
|
||||
<translation>Fin d'appel</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>missedIncomingCall</source>
|
||||
|
|
|
|||
19
tests/src/components/chat/ChatModelFilter.cpp
Normal file
19
tests/src/components/chat/ChatModelFilter.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "ChatProxyModel.hpp"
|
||||
|
||||
// ===================================================================
|
||||
|
||||
ChatModelFilter::ChatModelFilter (QObject *parent) : QSortFilterProxyModel(parent) {
|
||||
setSourceModel(&m_chat_model);
|
||||
}
|
||||
|
||||
bool ChatModelFilter::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
|
||||
if (m_entry_type_filter == ChatModel::EntryType::GenericEntry)
|
||||
return true;
|
||||
|
||||
QModelIndex index = sourceModel()->index(source_row, 0, QModelIndex());
|
||||
const QVariantMap &data = qvariant_cast<QVariantMap>(
|
||||
index.data()
|
||||
);
|
||||
|
||||
return data["type"].toInt() == m_entry_type_filter;
|
||||
}
|
||||
35
tests/src/components/chat/ChatModelFilter.hpp
Normal file
35
tests/src/components/chat/ChatModelFilter.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef CHAT_MODEL_FILTER_H_
|
||||
#define CHAT_MODEL_FILTER_H_
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "ChatModel.hpp"
|
||||
#include <QtDebug>
|
||||
|
||||
// ===================================================================
|
||||
// Fetch K filtered chat entries.
|
||||
// ===================================================================
|
||||
|
||||
class ChatModelFilter : public QSortFilterProxyModel {
|
||||
friend class ChatProxyModel;
|
||||
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
ChatModelFilter (QObject *parent = Q_NULLPTR);
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
|
||||
|
||||
private:
|
||||
void setEntryTypeFilter (ChatModel::EntryType type) {
|
||||
m_entry_type_filter = type;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
ChatModel m_chat_model;
|
||||
|
||||
ChatModel::EntryType m_entry_type_filter = ChatModel::EntryType::GenericEntry;
|
||||
};
|
||||
|
||||
#endif // CHAT_MODEL_FILTER_H_
|
||||
|
|
@ -2,25 +2,37 @@
|
|||
|
||||
// ===================================================================
|
||||
|
||||
const unsigned int ChatProxyModel::ENTRIES_CHUNK_SIZE = 25;
|
||||
|
||||
ChatProxyModel::ChatProxyModel (QObject *parent) : QSortFilterProxyModel(parent) {
|
||||
m_chat_model.setParent(this);
|
||||
setSourceModel(&m_chat_model);
|
||||
setSourceModel(&m_chat_model_filter);
|
||||
}
|
||||
|
||||
int ChatProxyModel::rowCount (const QModelIndex &parent) const {
|
||||
int size = QSortFilterProxyModel::rowCount(parent);
|
||||
return size < m_n_max_displayed_entries ? size : m_n_max_displayed_entries;
|
||||
}
|
||||
|
||||
QVariant ChatProxyModel::data (const QModelIndex &index, int role) const {
|
||||
QAbstractItemModel *model = sourceModel();
|
||||
|
||||
return model->data(
|
||||
model->index(
|
||||
mapToSource(index).row() + (model->rowCount() - rowCount()),
|
||||
0
|
||||
),
|
||||
role
|
||||
);
|
||||
}
|
||||
|
||||
void ChatProxyModel::loadMoreEntries () {
|
||||
// TODO.
|
||||
}
|
||||
|
||||
void ChatProxyModel::removeEntry (int id) {
|
||||
m_chat_model.removeEntry(
|
||||
mapToSource(index(id, 0)).row()
|
||||
QModelIndex source_index = mapToSource(index(id, 0));
|
||||
|
||||
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeEntry(
|
||||
mapToSource(source_index).row()
|
||||
);
|
||||
}
|
||||
|
||||
bool ChatProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const {
|
||||
if (m_entry_type_filter == ChatModel::EntryType::GenericEntry)
|
||||
return true;
|
||||
|
||||
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||
const QVariantMap &data = qvariant_cast<QVariantMap>(
|
||||
index.data()
|
||||
);
|
||||
|
||||
return data["type"].toInt() == m_entry_type_filter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef CHAT_PROXY_MODEL_H_
|
||||
#define CHAT_PROXY_MODEL_H_
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "ChatModel.hpp"
|
||||
#include "ChatModelFilter.hpp"
|
||||
|
||||
// ===================================================================
|
||||
// Fetch the L last filtered chat entries.
|
||||
// ===================================================================
|
||||
|
||||
class ChatProxyModel : public QSortFilterProxyModel {
|
||||
|
|
@ -23,32 +23,38 @@ signals:
|
|||
public:
|
||||
ChatProxyModel (QObject *parent = Q_NULLPTR);
|
||||
|
||||
int rowCount (const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data (const QModelIndex &index, int role) const override;
|
||||
|
||||
public slots:
|
||||
void loadMoreEntries ();
|
||||
|
||||
void setEntryTypeFilter (ChatModel::EntryType type) {
|
||||
m_chat_model_filter.setEntryTypeFilter(type);
|
||||
}
|
||||
|
||||
void removeEntry (int id);
|
||||
|
||||
void removeAllEntries () {
|
||||
m_chat_model.removeAllEntries();
|
||||
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->removeAllEntries();
|
||||
}
|
||||
|
||||
void setEntryTypeFilter (ChatModel::EntryType type) {
|
||||
m_entry_type_filter = type;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow (int source_row, const QModelIndex &source_parent) const;
|
||||
|
||||
private:
|
||||
QString getSipAddress () const {
|
||||
return m_chat_model.getSipAddress();
|
||||
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->getSipAddress();
|
||||
}
|
||||
|
||||
void setSipAddress (const QString &sip_address) {
|
||||
m_chat_model.setSipAddress(sip_address);
|
||||
static_cast<ChatModel *>(m_chat_model_filter.sourceModel())->setSipAddress(
|
||||
sip_address
|
||||
);
|
||||
}
|
||||
|
||||
ChatModel m_chat_model;
|
||||
ChatModel::EntryType m_entry_type_filter = ChatModel::EntryType::GenericEntry;
|
||||
ChatModelFilter m_chat_model_filter;
|
||||
|
||||
unsigned int m_n_max_displayed_entries = ENTRIES_CHUNK_SIZE;
|
||||
|
||||
static const unsigned int ENTRIES_CHUNK_SIZE;
|
||||
};
|
||||
|
||||
#endif // CHAT_PROXY_MODEL_H_
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@ ColumnLayout {
|
|||
ScrollableListView {
|
||||
id: chat
|
||||
|
||||
property bool _tryToLoadMoreEntries: false
|
||||
|
||||
function _loadMoreEntries () {
|
||||
if (chat.contentY > 500 || _tryToLoadMoreEntries) {
|
||||
return
|
||||
}
|
||||
|
||||
_tryToLoadMoreEntries = true
|
||||
|
||||
proxyModel.loadMoreEntries()
|
||||
}
|
||||
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
|
|
@ -164,6 +176,8 @@ ColumnLayout {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
onContentYChanged: _loadMoreEntries()
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue