mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-04-23 01:08:30 +00:00
Add search feature in messages
This commit is contained in:
parent
479869cf22
commit
0fa9d7b136
5 changed files with 175 additions and 99 deletions
|
|
@ -57,7 +57,6 @@ protected:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
|
QModelIndex index = sourceModel()->index(sourceRow, 0, QModelIndex());
|
||||||
|
|
||||||
auto eventModel = sourceModel()->data(index);
|
auto eventModel = sourceModel()->data(index);
|
||||||
|
|
||||||
if( mEntryTypeFilter == ChatRoomModel::EntryType::CallEntry && eventModel.value<ChatCallModel*>() != nullptr)
|
if( mEntryTypeFilter == ChatRoomModel::EntryType::CallEntry && eventModel.value<ChatCallModel*>() != nullptr)
|
||||||
|
|
@ -164,8 +163,20 @@ void ChatRoomProxyModel::setEntryTypeFilter (int type) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool ChatRoomProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &) const {
|
bool ChatRoomProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const {
|
||||||
return true;
|
bool show = false;
|
||||||
|
if(mFilterText != ""){
|
||||||
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||||
|
auto eventModel = sourceModel()->data(index);
|
||||||
|
ChatMessageModel * chatModel = eventModel.value<ChatMessageModel*>();
|
||||||
|
if( chatModel){
|
||||||
|
QRegularExpression search(QRegularExpression::escape(mFilterText), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption);
|
||||||
|
show = chatModel->mContent.contains(search);
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
show = true;
|
||||||
|
|
||||||
|
return show;
|
||||||
}
|
}
|
||||||
bool ChatRoomProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
|
bool ChatRoomProxyModel::lessThan (const QModelIndex &left, const QModelIndex &right) const {
|
||||||
auto l = sourceModel()->data(left);
|
auto l = sourceModel()->data(left);
|
||||||
|
|
@ -278,6 +289,14 @@ void ChatRoomProxyModel::resetMessageCount(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatRoomProxyModel::setFilterText(const QString& text){
|
||||||
|
if( mFilterText != text){
|
||||||
|
mFilterText = text;
|
||||||
|
invalidate();
|
||||||
|
emit filterTextChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ChatRoomModel *ChatRoomProxyModel::getChatRoomModel () const{
|
ChatRoomModel *ChatRoomProxyModel::getChatRoomModel () const{
|
||||||
return mChatRoomModel.get();
|
return mChatRoomModel.get();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ class ChatRoomProxyModel : public QSortFilterProxyModel {
|
||||||
//Q_PROPERTY(bool isSecure READ getIsSecure NOTIFY isSecureChanged)
|
//Q_PROPERTY(bool isSecure READ getIsSecure NOTIFY isSecureChanged)
|
||||||
Q_PROPERTY(QString cachedText READ getCachedText)
|
Q_PROPERTY(QString cachedText READ getCachedText)
|
||||||
|
|
||||||
|
Q_PROPERTY(QString filterText MEMBER mFilterText WRITE setFilterText NOTIFY filterTextChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChatRoomProxyModel (QObject *parent = Q_NULLPTR);
|
ChatRoomProxyModel (QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
|
@ -66,6 +68,8 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void resetMessageCount();
|
Q_INVOKABLE void resetMessageCount();
|
||||||
|
|
||||||
|
Q_INVOKABLE void setFilterText(const QString& text);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void peerAddressChanged (const QString &peerAddress);
|
void peerAddressChanged (const QString &peerAddress);
|
||||||
void localAddressChanged (const QString &localAddress);
|
void localAddressChanged (const QString &localAddress);
|
||||||
|
|
@ -79,6 +83,7 @@ signals:
|
||||||
void moreEntriesLoaded (int n);
|
void moreEntriesLoaded (int n);
|
||||||
|
|
||||||
void entryTypeFilterChanged (int type);
|
void entryTypeFilterChanged (int type);
|
||||||
|
void filterTextChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
|
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
|
|
@ -121,10 +126,9 @@ private:
|
||||||
QString mLocalAddress;
|
QString mLocalAddress;
|
||||||
QString mFullPeerAddress;
|
QString mFullPeerAddress;
|
||||||
QString mFullLocalAddress;
|
QString mFullLocalAddress;
|
||||||
//int mIsSecure;
|
|
||||||
static QString gCachedText;
|
static QString gCachedText;
|
||||||
//std::shared_ptr<linphone::ChatRoom> mChatRoom;
|
|
||||||
|
|
||||||
|
QString mFilterText;
|
||||||
|
|
||||||
std::shared_ptr<ChatRoomModel> mChatRoomModel;
|
std::shared_ptr<ChatRoomModel> mChatRoomModel;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ bool TimelineProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex &sou
|
||||||
if( !show && ( (mFilterFlags & TimelineFilter::EphemeralChatRoom) == TimelineFilter::EphemeralChatRoom))
|
if( !show && ( (mFilterFlags & TimelineFilter::EphemeralChatRoom) == TimelineFilter::EphemeralChatRoom))
|
||||||
show = timeline->getChatRoomModel()->isEphemeralEnabled();
|
show = timeline->getChatRoomModel()->isEphemeralEnabled();
|
||||||
if(show && mFilterText != ""){
|
if(show && mFilterText != ""){
|
||||||
QRegularExpression search(mFilterText, QRegularExpression::CaseInsensitiveOption);
|
QRegularExpression search(QRegularExpression::escape(mFilterText), QRegularExpression::CaseInsensitiveOption | QRegularExpression::UseUnicodePropertiesOption);
|
||||||
show = timeline->getChatRoomModel()->getSubject().contains(search)
|
show = timeline->getChatRoomModel()->getSubject().contains(search)
|
||||||
|| timeline->getChatRoomModel()->getUsername().contains(search);
|
|| timeline->getChatRoomModel()->getUsername().contains(search);
|
||||||
//|| timeline->getChatRoomModel()->getFullPeerAddress().contains(search); not enough significant?
|
//|| timeline->getChatRoomModel()->getFullPeerAddress().contains(search); not enough significant?
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ Controls.TextField {
|
||||||
property QtObject textFieldStyle : TextFieldStyle.normal
|
property QtObject textFieldStyle : TextFieldStyle.normal
|
||||||
onTextFieldStyleChanged: if( !textFieldStyle) textFieldStyle = TextFieldStyle.normal
|
onTextFieldStyleChanged: if( !textFieldStyle) textFieldStyle = TextFieldStyle.normal
|
||||||
|
|
||||||
|
signal iconClicked()
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
|
|
@ -83,6 +85,10 @@ Controls.TextField {
|
||||||
|
|
||||||
iconSize: parent.contentHeight
|
iconSize: parent.contentHeight
|
||||||
visible: !parent.text
|
visible: !parent.text
|
||||||
|
MouseArea{
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: textField.iconClicked()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bottomPadding: (statusItem.visible?statusItem.height:2)
|
bottomPadding: (statusItem.visible?statusItem.height:2)
|
||||||
TextEdit{
|
TextEdit{
|
||||||
|
|
|
||||||
|
|
@ -379,6 +379,7 @@ ColumnLayout {
|
||||||
visible: SettingsModel.chatEnabled
|
visible: SettingsModel.chatEnabled
|
||||||
|
|
||||||
ExclusiveButtons {
|
ExclusiveButtons {
|
||||||
|
id: filterButtons
|
||||||
anchors {
|
anchors {
|
||||||
left: parent.left
|
left: parent.left
|
||||||
leftMargin: ConversationStyle.filters.leftMargin
|
leftMargin: ConversationStyle.filters.leftMargin
|
||||||
|
|
@ -393,6 +394,52 @@ ColumnLayout {
|
||||||
|
|
||||||
onClicked: Logic.updateChatFilter(button)
|
onClicked: Logic.updateChatFilter(button)
|
||||||
}
|
}
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// Search.
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
Icon {
|
||||||
|
id:searchButton
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.rightMargin: 20
|
||||||
|
icon: 'timeline_search'
|
||||||
|
iconSize: searchBar.contentHeight
|
||||||
|
visible: !searchView.visible
|
||||||
|
MouseArea{
|
||||||
|
anchors.fill:parent
|
||||||
|
onClicked:{
|
||||||
|
searchView.visible = !searchView.visible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rectangle{
|
||||||
|
id:searchView
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.left : filterButtons.right
|
||||||
|
anchors.rightMargin: 10
|
||||||
|
anchors.leftMargin: 10
|
||||||
|
visible:false
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id:searchBar
|
||||||
|
anchors {
|
||||||
|
fill: parent
|
||||||
|
margins: 7
|
||||||
|
}
|
||||||
|
Layout.fillWidth: true
|
||||||
|
icon: 'search'
|
||||||
|
//: 'Search in messages' : this is a placeholder when searching something in the timeline list
|
||||||
|
placeholderText: qsTr('searchMessagesPlaceholder')
|
||||||
|
|
||||||
|
onTextChanged: chatRoomProxyModel.filterText = text
|
||||||
|
onIconClicked: searchView.visible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue