• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi/kmime

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
  • kmime
messagemodel.cpp
1 /*
2  Copyright (c) 2006 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "messagemodel.h"
21 #include "messageparts.h"
22 
23 #include <akonadi/itemfetchscope.h>
24 #include <akonadi/monitor.h>
25 #include <akonadi/session.h>
26 
27 #include <kmime/kmime_message.h>
28 #include <boost/shared_ptr.hpp>
29 typedef boost::shared_ptr<KMime::Message> MessagePtr;
30 
31 #include <kdebug.h>
32 #include <kglobal.h>
33 #include <klocale.h>
34 #include <klocalizedstring.h>
35 
36 #include <QtCore/QDebug>
37 
38 using namespace Akonadi;
39 
40 class Akonadi::MessageModel::Private
41 {
42 public:
43 };
44 
45 MessageModel::MessageModel(QObject *parent)
46  : ItemModel(parent)
47  , d(new Private())
48 {
49  fetchScope().fetchPayloadPart(MessagePart::Envelope);
50 }
51 
52 MessageModel::~MessageModel()
53 {
54  delete d;
55 }
56 
57 QStringList MessageModel::mimeTypes() const
58 {
59  return QStringList()
60  << QLatin1String("text/uri-list")
61  << QLatin1String("message/rfc822");
62 }
63 
64 int MessageModel::rowCount(const QModelIndex &parent) const
65 {
66  Q_UNUSED(parent);
67  if (collection().isValid()
68  && !collection().contentMimeTypes().contains(QLatin1String("message/rfc822"))
69  && collection().contentMimeTypes() != QStringList(QLatin1String("inode/directory"))) {
70  return 1;
71  }
72 
73  return ItemModel::rowCount();
74 }
75 
76 int MessageModel::columnCount(const QModelIndex &parent) const
77 {
78  if (collection().isValid()
79  && !collection().contentMimeTypes().contains(QLatin1String("message/rfc822"))
80  && collection().contentMimeTypes() != QStringList(QLatin1String("inode/directory"))) {
81  return 1;
82  }
83 
84  if (!parent.isValid()) {
85  return 5; // keep in sync with the column type enum
86  }
87 
88  return 0;
89 }
90 
91 QVariant MessageModel::data(const QModelIndex &index, int role) const
92 {
93  if (!index.isValid()) {
94  return QVariant();
95  }
96  if (index.row() >= rowCount()) {
97  return QVariant();
98  }
99 
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(",")));
104  } else {
105  return QVariant();
106  }
107  }
108 
109  Item item = itemForIndex(index);
110  if (!item.hasPayload<MessagePtr>()) {
111  return QVariant();
112  }
113  MessagePtr msg = item.payload<MessagePtr>();
114  if (role == Qt::DisplayRole) {
115  switch (index.column()) {
116  case Subject:
117  return msg->subject()->asUnicodeString();
118  case Sender:
119  return msg->from()->asUnicodeString();
120  case Receiver:
121  return msg->to()->asUnicodeString();
122  case Date:
123  return KGlobal::locale()->formatDateTime(msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate);
124  case Size:
125  if (item.size() == 0) {
126  return i18nc("@label No size available", "-");
127  } else {
128  return KGlobal::locale()->formatByteSize(item.size());
129  }
130  default:
131  return QVariant();
132  }
133  } else if (role == Qt::EditRole) {
134  switch (index.column()) {
135  case Subject:
136  return msg->subject()->asUnicodeString();
137  case Sender:
138  return msg->from()->asUnicodeString();
139  case Receiver:
140  return msg->to()->asUnicodeString();
141  case Date:
142  return msg->date()->dateTime().dateTime();
143  case Size:
144  return item.size();
145  default:
146  return QVariant();
147  }
148  }
149  return ItemModel::data(index, role);
150 }
151 
152 QVariant MessageModel::headerData(int section, Qt::Orientation orientation, int role) const
153 {
154 
155  if (collection().isValid()
156  && !collection().contentMimeTypes().contains(QLatin1String("message/rfc822"))
157  && collection().contentMimeTypes() != QStringList(QLatin1String("inode/directory"))) {
158  return QVariant();
159  }
160 
161  if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
162  switch (section) {
163  case Subject:
164  return i18nc("@title:column, message (e.g. email) subject", "Subject");
165  case Sender:
166  return i18nc("@title:column, sender of message (e.g. email)", "Sender");
167  case Receiver:
168  return i18nc("@title:column, receiver of message (e.g. email)", "Receiver");
169  case Date:
170  return i18nc("@title:column, message (e.g. email) timestamp", "Date");
171  case Size:
172  return i18nc("@title:column, message (e.g. email) size", "Size");
173  default:
174  return QString();
175  }
176  }
177  return ItemModel::headerData(section, orientation, role);
178 }
QModelIndex
Akonadi::MessageModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented from QAbstractItemModel.
Definition: messagemodel.cpp:64
Akonadi::MessagePart::Envelope
AKONADI_KMIME_EXPORT const char * Envelope
The part identifier for envelope parts.
Definition: messageparts.cpp:23
Akonadi::MessageModel::mimeTypes
virtual QStringList mimeTypes() const
Reimplemented from QAbstractItemModel.
Definition: messagemodel.cpp:57
QModelIndex::isValid
bool isValid() const
QObject
QModelIndex::row
int row() const
Akonadi::MessageModel::Date
Date column.
Definition: messagemodel.h:50
QString
QStringList
Akonadi::MessageModel::Receiver
Receiver column.
Definition: messagemodel.h:49
Akonadi::MessageModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Reimplemented from QAbstractItemModel.
Definition: messagemodel.cpp:91
Akonadi::MessageModel::MessageModel
MessageModel(QObject *parent=0)
Creates a new message model.
Definition: messagemodel.cpp:45
Akonadi::MessageModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Reimplemented from QAbstractItemModel.
Definition: messagemodel.cpp:76
Akonadi::MessageModel::Subject
Subject column.
Definition: messagemodel.h:47
Akonadi::MessageModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Reimplemented from QAbstractItemModel.
Definition: messagemodel.cpp:152
QLatin1String
Akonadi::MessageModel::Sender
Sender column.
Definition: messagemodel.h:48
QModelIndex::column
int column() const
Akonadi::MessageModel::~MessageModel
virtual ~MessageModel()
Deletes the message model.
Definition: messagemodel.cpp:52
Akonadi::MessageModel::Size
Size column.
Definition: messagemodel.h:51
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/kmime

Skip menu "akonadi/kmime"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal