Commit 672a22a9 authored by Christoph Vogtländer's avatar Christoph Vogtländer Committed by Sandro Knauß
Browse files

Add field "Folder" to theme content items and to message tool tip

Summary:
Add possibility to add the messages account/folder as a theme content
item. Additionally, show the path in the messages tool tip.

FEATURE: 420644
BUG: 420644
FIXED-IN: 5.15.0

Test Plan:
New tool tip:
{F8321268}

New "Folder" item in content items
{F8307551}

Message list:
{F8321283}

Reviewers: #vdg, dvratil

Reviewed By: dvratil

Subscribers: dvratil, kde-pim

Tags: #kde_pim, #kde_pim_kmail

Differential Revision: https://phabricator.kde.org/D29602
parent 1cc536fd
......@@ -551,6 +551,16 @@ void Item::setSubject(const QString &subject)
d_ptr->mSubject = subject;
}
const QString &Item::folder() const
{
return d_ptr->mFolder;
}
void Item::setFolder(const QString &folder)
{
d_ptr->mFolder = folder;
}
void MessageList::Core::Item::initialSetup(time_t date, size_t size, const QString &sender, const QString &receiver, bool useReceiver)
{
d_ptr->mDate = date;
......
......@@ -358,6 +358,16 @@ public:
* Sets the subject associated to this Item.
*/
void setSubject(const QString &subject);
/**
* Returns the folder associated to this Item.
*/
const QString &folder() const;
/**
* Sets the folder associated to this Item.
*/
void setFolder(const QString &folder);
/**
* This is meant to be called right after the constructor.
......
......@@ -242,6 +242,7 @@ public:
QString mSender; ///< The sender of the message (or group sender)
QString mReceiver; ///< The receiver of the message (or group receiver)
QString mSubject; ///< The subject of the message (or group subject)
QString mFolder; ///< The folder of the message
qint64 mItemId; ///< The Akonadi item id
qint64 mParentCollectionId; ///< The Akonadi ID of collection that this particular item comes from (can be virtual collection)
Akonadi::MessageStatus mStatus; ///< The status of the message (may be extended to groups in the future)
......
......@@ -188,6 +188,8 @@ QString Theme::ContentItem::description(Type type)
return i18n("Note Icon");
case InvitationIcon:
return i18n("Invitation Icon");
case Folder:
return i18nc("Description of Type Folder", "Folder");
default:
return i18nc("Description for an Unknown Type", "Unknown");
break;
......@@ -336,6 +338,7 @@ bool Theme::ContentItem::load(QDataStream &stream, int /*themeVersion*/)
case TagList:
case AnnotationIcon:
case InvitationIcon:
case Folder:
// ok
break;
default:
......
......@@ -212,7 +212,11 @@ public:
/**
* Whether the message is an invitation
*/
InvitationIcon = 24 | ApplicableToMessageItems | IsIcon
InvitationIcon = 24 | ApplicableToMessageItems | IsIcon,
/**
* Folder of the message
*/
Folder = 25 | DisplaysText | CanUseCustomColor | ApplicableToMessageItems
#if 0
TotalMessageCount
UnreadMessageCount
......
......@@ -865,6 +865,9 @@ void ThemeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
case Theme::ContentItem::Size:
paint_right_aligned_elided_text(item->formattedSize(), ci, painter, l, top, r, layoutDir, font);
break;
case Theme::ContentItem::Folder:
paint_right_aligned_elided_text(item->folder(), ci, painter, l, top, r, layoutDir, font);
break;
case Theme::ContentItem::GroupHeaderLabel:
if (groupHeaderItem) {
paint_right_aligned_elided_text(groupHeaderItem->label(), ci, painter, l, top, r, layoutDir, font);
......@@ -1029,6 +1032,9 @@ void ThemeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
case Theme::ContentItem::Size:
paint_left_aligned_elided_text(item->formattedSize(), ci, painter, l, top, r, layoutDir, font);
break;
case Theme::ContentItem::Folder:
paint_left_aligned_elided_text(item->folder(), ci, painter, l, top, r, layoutDir, font);
break;
case Theme::ContentItem::GroupHeaderLabel:
if (groupHeaderItem) {
paint_left_aligned_elided_text(groupHeaderItem->label(), ci, painter, l, top, r, layoutDir, font);
......@@ -1283,6 +1289,9 @@ bool ThemeDelegate::hitTest(const QPoint &viewportPoint, bool exact)
case Theme::ContentItem::Size:
compute_bounding_rect_for_right_aligned_elided_text(mHitItem->formattedSize(), ci, l, top, r, mHitContentItemRect, layoutDir, font);
break;
case Theme::ContentItem::Folder:
compute_bounding_rect_for_right_aligned_elided_text(mHitItem->folder(), ci, l, top, r, mHitContentItemRect, layoutDir, font);
break;
case Theme::ContentItem::GroupHeaderLabel:
if (groupHeaderItem) {
compute_bounding_rect_for_right_aligned_elided_text(groupHeaderItem->label(), ci, l, top, r, mHitContentItemRect, layoutDir, font);
......@@ -1428,6 +1437,9 @@ bool ThemeDelegate::hitTest(const QPoint &viewportPoint, bool exact)
case Theme::ContentItem::Size:
compute_bounding_rect_for_left_aligned_elided_text(mHitItem->formattedSize(), ci, l, top, r, mHitContentItemRect, layoutDir, font);
break;
case Theme::ContentItem::Folder:
compute_bounding_rect_for_left_aligned_elided_text(mHitItem->folder(), ci, l, top, r, mHitContentItemRect, layoutDir, font);
break;
case Theme::ContentItem::GroupHeaderLabel:
if (groupHeaderItem) {
compute_bounding_rect_for_left_aligned_elided_text(groupHeaderItem->label(), ci, l, top, r, mHitContentItemRect, layoutDir, font);
......
......@@ -2400,9 +2400,11 @@ bool View::event(QEvent *e)
if (textIsLeftToRight) {
tip += htmlCodeForStandardRow.arg(i18n("Status")).arg(status);
tip += htmlCodeForStandardRow.arg(i18n("Size")).arg(mi->formattedSize());
tip += htmlCodeForStandardRow.arg(i18n("Folder")).arg(mi->folder());
} else {
tip += htmlCodeForStandardRow.arg(status).arg(i18n("Status"));
tip += htmlCodeForStandardRow.arg(mi->formattedSize()).arg(i18n("Size"));
tip += htmlCodeForStandardRow.arg(mi->folder()).arg(i18n("Folder"));
}
if (mi->hasAnnotation()) {
......
......@@ -45,6 +45,7 @@
#include <QMimeData>
#include <QCryptographicHash>
#include <QFontDatabase>
#include <QHash>
namespace MessageList {
class Q_DECL_HIDDEN StorageModel::Private
......@@ -59,6 +60,8 @@ public:
QAbstractItemModel *mModel = nullptr;
QAbstractItemModel *mChildrenFilterModel = nullptr;
QItemSelectionModel *mSelectionModel = nullptr;
QHash<Akonadi::Collection::Id, QString> mFolderHash;
Private(StorageModel *owner)
: q(owner)
......@@ -253,6 +256,19 @@ bool StorageModel::initializeMessageItem(MessageList::Core::MessageItem *mi, int
}
mi->setSubject(subject);
auto it = d->mFolderHash.find(item.storageCollectionId());
if (it == d->mFolderHash.end()) {
QString folder;
Collection collection = collectionForId(item.storageCollectionId());
while (collection.parentCollection().isValid()) {
folder = collection.displayName() + QLatin1Char('/') + folder;
collection = collection.parentCollection();
}
folder.chop(1);
it = d->mFolderHash.insert(item.storageCollectionId(), folder);
}
mi->setFolder(it.value());
updateMessageItemData(mi, row);
......@@ -427,6 +443,7 @@ void StorageModel::Private::onSourceDataChanged(const QModelIndex &topLeft, cons
void StorageModel::Private::onSelectionChanged()
{
mFolderHash.clear();
Q_EMIT q->headerDataChanged(Qt::Horizontal, 0, q->columnCount() - 1);
}
......@@ -488,6 +505,20 @@ Collection StorageModel::parentCollectionForRow(int row) const
return col;
}
Akonadi::Collection StorageModel::collectionForId(Akonadi::Collection::Id colId) const
{
// Get ETM
QAbstractProxyModel *childrenProxy = static_cast<QAbstractProxyModel *>(d->mChildrenFilterModel);
QAbstractItemModel* etm = childrenProxy->sourceModel();
// get index in EntityTreeModel
const QModelIndex idx = EntityTreeModel::modelIndexForCollection(etm, Collection(colId));
Q_ASSERT(idx.isValid());
// get and return collection
return idx.data(EntityTreeModel::CollectionRole).value<Collection>();
}
void StorageModel::resetModelStorage()
{
beginResetModel();
......
......@@ -78,6 +78,8 @@ public:
Q_REQUIRED_RESULT Akonadi::Item itemForRow(int row) const;
Q_REQUIRED_RESULT Akonadi::Collection parentCollectionForRow(int row) const;
Q_REQUIRED_RESULT KMime::Message::Ptr messageForRow(int row) const;
Q_REQUIRED_RESULT Akonadi::Collection collectionForId(Akonadi::Collection::Id colId) const;
void resetModelStorage();
......
......@@ -205,6 +205,7 @@ ThemePreviewDelegate::ThemePreviewDelegate(QAbstractItemView *parent)
mSampleMessageItem->setSender(i18n("Sender"));
mSampleMessageItem->setReceiver(i18n("Receiver"));
mSampleMessageItem->setSubject(i18n("Very long subject very long subject very long subject very long subject very long subject very long"));
mSampleMessageItem->setFolder(i18n("Folder"));
mSampleMessageItem->setSignatureState(MessageItem::FullySigned);
mSampleMessageItem->setEncryptionState(MessageItem::FullyEncrypted);
......@@ -1362,6 +1363,11 @@ ThemeEditor::ThemeEditor(QWidget *parent)
cil->setText(Theme::ContentItem::description(cil->type()));
cil->setToolTip(Theme::ContentItem::description(cil->type()));
gblayout->addWidget(cil, 1, 2);
cil = new ThemeContentItemSourceLabel(gb, Theme::ContentItem::Folder);
cil->setText(Theme::ContentItem::description(cil->type()));
cil->setToolTip(Theme::ContentItem::description(cil->type()));
gblayout->addWidget(cil, 2, 2);
cil = new ThemeContentItemSourceLabel(gb, Theme::ContentItem::CombinedReadRepliedStateIcon);
cil->setPixmap(*dummyTheme.pixmap(Theme::IconRepliedAndForwarded));
......
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