Commit c4bf90e9 authored by Laurent Montel's avatar Laurent Montel 😁

Merge remote-tracking branch 'origin/Applications/17.04'

parents a5dc872d ec5c3703
......@@ -69,7 +69,6 @@ set(kmailprivate_configureplugins_LIB_SRCS
set(kmailprivate_searchdialog_LIB_SRCS
searchdialog/kmsearchmessagemodel.cpp
searchdialog/kmsearchfilterproxymodel.cpp
searchdialog/searchpatternwarning.cpp
searchdialog/kmailsearchpatternedit.cpp
searchdialog/searchwindow.cpp
......
/*
Copyright (C) 2011-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kmsearchfilterproxymodel.h"
#include "kmsearchmessagemodel.h"
#include <QModelIndex>
#include <QDateTime>
using namespace KMail;
KMSearchFilterProxyModel::KMSearchFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
setDynamicSortFilter(true);
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
KMSearchFilterProxyModel::~KMSearchFilterProxyModel()
{
}
bool KMSearchFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
if (right.model() && left.model() && left.column() == KMSearchMessageModel::Date) {
if (sourceModel()) {
const QDateTime leftData =
sourceModel()->data(
left.sibling(left.row(), KMSearchMessageModel::DateNotTranslated)).toDateTime();
const QDateTime rightData =
sourceModel()->data(
right.sibling(right.row(), KMSearchMessageModel::DateNotTranslated)).toDateTime();
return leftData < rightData;
} else {
return false;
}
}
if (right.model() && left.model() && left.column() == KMSearchMessageModel::Size) {
if (sourceModel()) {
const qint64 leftData =
sourceModel()->data(
left.sibling(left.row(), KMSearchMessageModel::SizeNotLocalized)).toLongLong();
const qint64 rightData =
sourceModel()->data(
right.sibling(right.row(), KMSearchMessageModel::SizeNotLocalized)).toLongLong();
return leftData < rightData;
} else {
return false;
}
}
return QSortFilterProxyModel::lessThan(left, right);
}
/*
Copyright (C) 2011-2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KMSEARCHFILTERPROXYMODEL_H
#define KMSEARCHFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
class QModelIndex;
namespace KMail
{
class KMSearchFilterProxyModel : public QSortFilterProxyModel
{
public:
explicit KMSearchFilterProxyModel(QObject *parent);
~KMSearchFilterProxyModel();
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
};
}
#endif /* KMSEARCHFILTERPROXYMODEL_H */
......@@ -57,7 +57,7 @@ KMSearchMessageModel::~KMSearchMessageModel()
{
}
QString toolTip(const Akonadi::Item &item)
static QString toolTip(const Akonadi::Item &item)
{
KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
......@@ -134,12 +134,22 @@ int KMSearchMessageModel::columnCount(const QModelIndex &parent) const
}
if (!parent.isValid()) {
return 8; // keep in sync with the column type enum
return 6; // keep in sync with the column type enum
}
return 0;
}
QString KMSearchMessageModel::fullCollectionPath(Akonadi::Collection::Id id) const
{
QString path = m_collectionFullPathCache.value(id);
if (path.isEmpty()) {
path = MailCommon::Util::fullCollectionPath(Akonadi::Collection(id));
m_collectionFullPathCache.insert(id, path);
}
return path;
}
QVariant KMSearchMessageModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
......@@ -159,17 +169,21 @@ QVariant KMSearchMessageModel::data(const QModelIndex &index, int role) const
}
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 (!item.hasPayload<KMime::Message::Ptr>()) {
return QVariant();
}
KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
if (role == Qt::DisplayRole) {
switch (index.column()) {
case Collection:
if (item.storageCollectionId() >= 0) {
return MailCommon::Util::fullCollectionPath(Akonadi::Collection(item.storageCollectionId()));
}
return MailCommon::Util::fullCollectionPath(item.parentCollection());
case Subject:
return msg->subject()->asUnicodeString();
case Sender:
......@@ -184,20 +198,11 @@ QVariant KMSearchMessageModel::data(const QModelIndex &index, int role) const
} else {
return KFormat().formatByteSize(item.size());
}
case SizeNotLocalized:
return item.size();
case DateNotTranslated:
return msg->date()->dateTime();
default:
return QVariant();
}
} else if (role == Qt::EditRole) {
} else if (role == Qt::EditRole) { // used for sorting
switch (index.column()) {
case Collection:
if (item.storageCollectionId() >= 0) {
return MailCommon::Util::fullCollectionPath(Akonadi::Collection(item.storageCollectionId()));
}
return MailCommon::Util::fullCollectionPath(item.parentCollection());
case Subject:
return msg->subject()->asUnicodeString();
case Sender:
......@@ -206,11 +211,8 @@ QVariant KMSearchMessageModel::data(const QModelIndex &index, int role) const
return msg->to()->asUnicodeString();
case Date:
return msg->date()->dateTime();
case SizeNotLocalized:
case Size:
return item.size();
case DateNotTranslated:
return msg->date()->dateTime();
default:
return QVariant();
}
......
......@@ -29,6 +29,7 @@
#define KMSEARCHMESSAGEMODEL_H
#include <Akonadi/KMime/MessageModel>
#include <QHash>
class KMSearchMessageModel : public Akonadi::MessageModel
{
......@@ -41,9 +42,7 @@ public:
Sender,
Receiver,
Date,
Size,
DateNotTranslated,
SizeNotLocalized
Size
};
explicit KMSearchMessageModel(QObject *parent = nullptr);
~KMSearchMessageModel();
......@@ -53,6 +52,11 @@ public:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
private:
QString fullCollectionPath(Akonadi::Collection::Id id) const;
mutable QHash<Akonadi::Collection::Id, QString> m_collectionFullPathCache;
};
#endif
......@@ -33,7 +33,6 @@
#include "searchdescriptionattribute.h"
#include "MailCommon/FolderTreeView"
#include "kmsearchmessagemodel.h"
#include "kmsearchfilterproxymodel.h"
#include "searchpatternwarning.h"
#include "PimCommonAkonadi/SelectMultiCollectionDialog"
#include <PimCommon/PimUtil>
......@@ -51,6 +50,7 @@
#include <KActionMenu>
#include "kmail_debug.h"
#include <QIcon>
#include <QSortFilterProxyModel>
#include <KIconLoader>
#include <kmime/kmime_message.h>
#include <KStandardAction>
......@@ -270,7 +270,10 @@ void SearchWindow::createSearchModel()
}
mResultModel = new KMSearchMessageModel(this);
mResultModel->setCollection(mFolder);
KMSearchFilterProxyModel *sortproxy = new KMSearchFilterProxyModel(mResultModel);
QSortFilterProxyModel *sortproxy = new QSortFilterProxyModel(mResultModel);
sortproxy->setDynamicSortFilter(true);
sortproxy->setSortRole(Qt::EditRole);
sortproxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
sortproxy->setSourceModel(mResultModel);
mUi.mLbxMatches->setModel(sortproxy);
......
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