20#include "messagemodel.h"
21#include "messageparts.h"
23#include <akonadi/itemfetchscope.h>
24#include <akonadi/monitor.h>
25#include <akonadi/session.h>
27#include <kmime/kmime_message.h>
28#include <boost/shared_ptr.hpp>
29typedef boost::shared_ptr<KMime::Message> MessagePtr;
34#include <klocalizedstring.h>
36#include <QtCore/QDebug>
40class Akonadi::MessageModel::Private
60 << QLatin1String(
"text/uri-list")
61 << QLatin1String(
"message/rfc822");
68 && !
collection().contentMimeTypes().contains(QLatin1String(
"message/rfc822"))
69 &&
collection().contentMimeTypes() != QStringList(QLatin1String(
"inode/directory"))) {
73 return ItemModel::rowCount();
79 && !
collection().contentMimeTypes().contains(QLatin1String(
"message/rfc822"))
80 &&
collection().contentMimeTypes() != QStringList(QLatin1String(
"inode/directory"))) {
84 if (!parent.isValid()) {
93 if (!index.isValid()) {
100 if (!
collection().contentMimeTypes().contains(QLatin1String(
"message/rfc822"))) {
101 if (role == Qt::DisplayRole) {
102 return i18nc(
"@label",
"This model can only handle email folders. The current collection holds mimetypes: %1",
103 collection().contentMimeTypes().join(QLatin1String(
",")));
110 if (!item.hasPayload<MessagePtr>()) {
113 MessagePtr msg = item.payload<MessagePtr>();
114 if (role == Qt::DisplayRole) {
115 switch (index.column()) {
117 return msg->subject()->asUnicodeString();
119 return msg->from()->asUnicodeString();
121 return msg->to()->asUnicodeString();
123 return KGlobal::locale()->formatDateTime(msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate);
125 if (item.size() == 0) {
126 return i18nc(
"@label No size available",
"-");
128 return KGlobal::locale()->formatByteSize(item.size());
133 }
else if (role == Qt::EditRole) {
134 switch (index.column()) {
136 return msg->subject()->asUnicodeString();
138 return msg->from()->asUnicodeString();
140 return msg->to()->asUnicodeString();
142 return msg->date()->dateTime().dateTime();
149 return ItemModel::data(index, role);
156 && !
collection().contentMimeTypes().contains(QLatin1String(
"message/rfc822"))
157 &&
collection().contentMimeTypes() != QStringList(QLatin1String(
"inode/directory"))) {
161 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
164 return i18nc(
"@title:column, message (e.g. email) subject",
"Subject");
166 return i18nc(
"@title:column, sender of message (e.g. email)",
"Sender");
168 return i18nc(
"@title:column, receiver of message (e.g. email)",
"Receiver");
170 return i18nc(
"@title:column, message (e.g. email) timestamp",
"Date");
172 return i18nc(
"@title:column, message (e.g. email) size",
"Size");
177 return ItemModel::headerData(section, orientation, role);
void fetchPayloadPart(const QByteArray &part, bool fetch=true)
Sets which payload parts shall be fetched.
Item itemForIndex(const QModelIndex &index) const
Returns the item at the given index.
Collection collection() const
Returns the collection being displayed in the model.
ItemFetchScope & fetchScope()
Returns the item fetch scope.
virtual ~MessageModel()
Deletes the message model.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented from QAbstractItemModel.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Reimplemented from QAbstractItemModel.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented from QAbstractItemModel.
virtual QStringList mimeTypes() const
Reimplemented from QAbstractItemModel.
MessageModel(QObject *parent=0)
Creates a new message model.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented from QAbstractItemModel.
@ Receiver
Receiver column.
AKONADI_KMIME_EXPORT const char * Envelope
The part identifier for envelope parts.
FreeBusyManager::Singleton.