Commit e038b2bb authored by Carl Schwan's avatar Carl Schwan 🚴 Committed by Claudio Cambra
Browse files

Implement search



Signed-off-by: Carl Schwan's avatarCarl Schwan <carl@carlschwan.eu>
parent 321ae468
......@@ -15,6 +15,7 @@ import "dateutils.js" as DateUtils
import "labelutils.js" as LabelUtils
import org.kde.kalendar 1.0
import org.kde.kalendar.contact 1.0
import org.kde.kalendar.mail 1.0
import org.kde.kalendar.utils 1.0
Kirigami.ApplicationWindow {
......@@ -493,6 +494,10 @@ Kirigami.ApplicationWindow {
ContactManager.filteredContacts.setFilterFixedString(searchText)
return;
}
if (mode === KalendarApplication.Mail) {
MailManager.folderModel.searchString = searchText;
return;
}
if(root.filter) {
root.filter.name = searchText;
} else {
......
......@@ -14,7 +14,7 @@
#include <QQmlEngine>
MailModel::MailModel(QObject *parent)
: QIdentityProxyModel(parent)
: QSortFilterProxyModel(parent)
{
}
......@@ -128,3 +128,42 @@ MessageStatus MailModel::copyMessageStatus(MessageStatus messageStatus)
newStatus.set(messageStatus);
return messageStatus;
}
QString MailModel::searchString() const
{
return m_searchString;
}
void MailModel::setSearchString(const QString &searchString)
{
if (searchString == m_searchString) {
return;
}
m_searchString = searchString;
invalidateFilter();
Q_EMIT searchStringChanged();
}
bool MailModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_UNUSED(sourceParent)
if (m_searchString.isEmpty()) {
return true;
}
QVariant itemVariant = sourceModel()->index(sourceRow, 0).data(Akonadi::EntityTreeModel::ItemRole);
Akonadi::Item item = itemVariant.value<Akonadi::Item>();
if (!item.hasPayload<KMime::Message::Ptr>()) {
return false;
}
const KMime::Message::Ptr mail = item.payload<KMime::Message::Ptr>();
if (mail->subject() && mail->subject()->asUnicodeString().contains(m_searchString)) {
return true;
}
if (mail->from() && mail->from()->asUnicodeString().contains(m_searchString)) {
return true;
}
return false;
}
......@@ -5,15 +5,16 @@
#pragma once
#include <Akonadi/Item>
#include <QIdentityProxyModel>
#include <QItemSelectionModel>
#include <QObject>
#include <QSortFilterProxyModel>
#include "messagestatus.h"
class MailModel : public QIdentityProxyModel
class MailModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged)
public:
enum ExtraRole {
......@@ -33,10 +34,18 @@ public:
explicit MailModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
virtual QVariant data(const QModelIndex &index, int role) const override;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
Q_INVOKABLE void updateMessageStatus(int row, MessageStatus messageStatus);
Q_INVOKABLE MessageStatus copyMessageStatus(MessageStatus messageStatus);
QString searchString() const;
void setSearchString(const QString &searchString);
Q_SIGNALS:
void searchStringChanged();
private:
Akonadi::Item itemForRow(int row) const;
QString m_searchString;
};
......@@ -25,7 +25,7 @@ import org.kde.kitemmodels 1.0 as KItemModels
labelItem.color: if (highlighted) {
return Kirigami.Theme.highlightedTextColor;
} else {
return model.status.isRead ? Kirigami.Theme.textColor : Kirigami.Theme.linkColor;
return !model.status || model.status.isRead ? Kirigami.Theme.textColor : Kirigami.Theme.linkColor;
}
onClicked: {
applicationWindow().pageStack.push(Qt.resolvedUrl('ConversationViewer.qml'), {
......
Supports Markdown
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