Verified Commit 7b6dccab authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Adapt to Akonadi::MessageModel API changes

The model has been ported to ETM which required some
smaller API changes.
parent 70aefa48
......@@ -43,7 +43,7 @@ endif()
set(KDEPIM_VERSION "${PIM_VERSION}${KDEPIM_DEV_VERSION} (${RELEASE_SERVICE_VERSION})")
set(AKONADI_MIMELIB_VERSION "5.14.40")
set(AKONADI_MIMELIB_VERSION "5.14.41")
set(AKONADI_CONTACT_VERSION "5.14.40")
set(CALENDARUTILS_LIB_VERSION "5.14.40")
set(IDENTITYMANAGEMENT_LIB_VERSION "5.14.40")
......
......@@ -45,16 +45,14 @@
#include <KLocalizedString>
#include <KFormat>
KMSearchMessageModel::KMSearchMessageModel(QObject *parent)
: Akonadi::MessageModel(parent)
KMSearchMessageModel::KMSearchMessageModel(Akonadi::Monitor *monitor, QObject *parent)
: Akonadi::MessageModel(monitor, parent)
{
fetchScope().fetchFullPayload();
fetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::All);
monitor->itemFetchScope().fetchFullPayload();
monitor->itemFetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::All);
}
KMSearchMessageModel::~KMSearchMessageModel()
{
}
KMSearchMessageModel::~KMSearchMessageModel() = default;
static QString toolTip(const Akonadi::Item &item)
{
......@@ -124,19 +122,13 @@ static QString toolTip(const Akonadi::Item &item)
return tip;
}
int KMSearchMessageModel::columnCount(const QModelIndex &parent) const
int KMSearchMessageModel::entityColumnCount(HeaderGroup headerGroup) const
{
if (collection().isValid()
&& !collection().contentMimeTypes().contains(QLatin1String("message/rfc822"))
&& collection().contentMimeTypes() != QStringList(QStringLiteral("inode/directory"))) {
return 1;
}
if (!parent.isValid()) {
return 6; // keep in sync with the column type enum
if (headerGroup == Akonadi::EntityTreeModel::ItemListHeaders) {
return 6; // keep in sync with the column type enum
}
return 0;
return Akonadi::MessageModel::entityColumnCount(headerGroup);
}
QString KMSearchMessageModel::fullCollectionPath(Akonadi::Collection::Id id) const
......@@ -149,93 +141,31 @@ QString KMSearchMessageModel::fullCollectionPath(Akonadi::Collection::Id id) con
return path;
}
QVariant KMSearchMessageModel::data(const QModelIndex &index, int role) const
QVariant KMSearchMessageModel::entityData(const Akonadi::Item &item, int column, int role) const
{
if (!index.isValid()) {
return QVariant();
}
if (index.row() >= rowCount()) {
return QVariant();
}
if (!collection().contentMimeTypes().contains(QLatin1String("message/rfc822"))) {
if (role == Qt::DisplayRole) {
return i18nc("@label", "This model can only handle email folders. The current collection holds mimetypes: %1",
collection().contentMimeTypes().join(QLatin1Char(',')));
} else {
return QVariant();
}
}
Akonadi::Item item = itemForIndex(index);
// Handle the most common case first, before calling payload().
if ((role == Qt::DisplayRole || role == Qt::EditRole) && index.column() == Collection) {
if (item.storageCollectionId() >= 0) {
return fullCollectionPath(item.storageCollectionId());
}
return fullCollectionPath(item.parentCollection().id());
if (role == Qt::ToolTipRole) {
return toolTip(item);
}
if (!item.hasPayload<KMime::Message::Ptr>()) {
return QVariant();
}
KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
if (role == Qt::DisplayRole) {
switch (index.column()) {
case Subject:
return msg->subject()->asUnicodeString();
case Sender:
return msg->from()->asUnicodeString();
case Receiver:
return msg->to()->asUnicodeString();
case Date:
return QLocale().toString(msg->date()->dateTime());
case Size:
if (item.size() == 0) {
return i18nc("@label No size available", "-");
} else {
return KFormat().formatByteSize(item.size());
// The Collection column is first and is added by this model
if (column == Collection) {
if (role == Qt::DisplayRole || role == Qt::EditRole) {
if (item.storageCollectionId() >= 0) {
return fullCollectionPath(item.storageCollectionId());
}
default:
return QVariant();
}
} else if (role == Qt::EditRole) { // used for sorting
switch (index.column()) {
case Subject:
return msg->subject()->asUnicodeString();
case Sender:
return msg->from()->asUnicodeString();
case Receiver:
return msg->to()->asUnicodeString();
case Date:
return msg->date()->dateTime();
case Size:
return item.size();
default:
return QVariant();
return fullCollectionPath(item.parentCollection().id());
}
} else if (role == Qt::ToolTipRole) {
return toolTip(item);
return {};
} else {
// Delegate the remaining columns to the MessageModel
return Akonadi::MessageModel::entityData(item, column - 1, role);
}
return ItemModel::data(index, role);
}
QVariant KMSearchMessageModel::headerData(int section, Qt::Orientation orientation, int role) const
QVariant KMSearchMessageModel::entityHeaderData(int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup) const
{
if (collection().isValid()
&& !collection().contentMimeTypes().contains(QLatin1String("message/rfc822"))
&& collection().contentMimeTypes() != QStringList(QStringLiteral("inode/directory"))) {
return QVariant();
}
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case Collection:
return i18nc("@title:column, folder (e.g. email)", "Folder");
default:
return Akonadi::MessageModel::headerData((section - 1), orientation, role);
}
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == Collection) {
return i18nc("@title:column, folder (e.g. email)", "Folder");
}
return Akonadi::MessageModel::headerData((section - 1), orientation, role);
return Akonadi::MessageModel::entityHeaderData((section - 1), orientation, role, headerGroup);
}
......@@ -44,13 +44,13 @@ public:
Date,
Size
};
explicit KMSearchMessageModel(QObject *parent = nullptr);
explicit KMSearchMessageModel(Akonadi::Monitor *monitor, QObject *parent = nullptr);
~KMSearchMessageModel() override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
protected:
int entityColumnCount(HeaderGroup headerGroup) const override;
QVariant entityData(const Akonadi::Item &item, int column, int role = Qt::DisplayRole) const override;
QVariant entityHeaderData(int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup) const override;
private:
Q_REQUIRED_RESULT QString fullCollectionPath(Akonadi::Collection::Id id) const;
......
......@@ -26,6 +26,7 @@
#include "MailCommon/FolderRequester"
#include "kmcommands.h"
#include "kmkernel.h"
#include "kmmainwidget.h"
#include "MailCommon/MailKernel"
#include "MailCommon/SearchPatternEdit"
......@@ -50,6 +51,8 @@
#include "kmail_debug.h"
#include <QIcon>
#include <QSortFilterProxyModel>
#include <entitytreemodel.h>
#include <entitytreeview.h>
#include <kmime/kmime_message.h>
#include <KStandardAction>
#include <KStandardGuiItem>
......@@ -256,8 +259,11 @@ void SearchWindow::createSearchModel()
if (mResultModel) {
mResultModel->deleteLater();
}
mResultModel = new KMSearchMessageModel(this);
mResultModel->setCollection(mFolder);
auto monitor = new Akonadi::Monitor();
monitor->setCollectionMonitored(mFolder);
mResultModel = new KMSearchMessageModel(monitor, this);
mResultModel->setCollectionMonitored(mFolder);
monitor->setParent(mResultModel);
QSortFilterProxyModel *sortproxy = new QSortFilterProxyModel(mResultModel);
sortproxy->setDynamicSortFilter(true);
sortproxy->setSortRole(Qt::EditRole);
......@@ -724,7 +730,7 @@ Akonadi::Item::List SearchWindow::selectedMessages() const
const QModelIndexList lst = mUi.mLbxMatches->selectionModel()->selectedRows();
for (const QModelIndex &index : lst) {
const Akonadi::Item item = index.data(Akonadi::ItemModel::ItemRole).value<Akonadi::Item>();
const Akonadi::Item item = index.data(Akonadi::EntityTreeModel::ItemRole).value<Akonadi::Item>();
if (item.isValid()) {
messages.append(item);
}
......@@ -735,7 +741,7 @@ Akonadi::Item::List SearchWindow::selectedMessages() const
Akonadi::Item SearchWindow::selectedMessage() const
{
return mUi.mLbxMatches->currentIndex().data(Akonadi::ItemModel::ItemRole).value<Akonadi::Item>();
return mUi.mLbxMatches->currentIndex().data(Akonadi::EntityTreeModel::ItemRole).value<Akonadi::Item>();
}
void SearchWindow::updateContextMenuActions()
......
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