• 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.12
  • 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& ) const
65 {
66  if ( collection().isValid()
67  && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
68  && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
69  return 1;
70 
71  return ItemModel::rowCount();
72 }
73 
74 int MessageModel::columnCount( const QModelIndex & parent ) const
75 {
76  if ( collection().isValid()
77  && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
78  && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
79  return 1;
80 
81  if ( !parent.isValid() )
82  return 5; // keep in sync with the column type enum
83 
84  return 0;
85 }
86 
87 QVariant MessageModel::data( const QModelIndex & index, int role ) const
88 {
89  if ( !index.isValid() )
90  return QVariant();
91  if ( index.row() >= rowCount() )
92  return QVariant();
93 
94  if ( !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) ) {
95  if ( role == Qt::DisplayRole )
96  return i18nc( "@label", "This model can only handle email folders. The current collection holds mimetypes: %1",
97  collection().contentMimeTypes().join( QLatin1String(",") ) );
98  else
99  return QVariant();
100  }
101 
102  Item item = itemForIndex( index );
103  if ( !item.hasPayload<MessagePtr>() )
104  return QVariant();
105  MessagePtr msg = item.payload<MessagePtr>();
106  if ( role == Qt::DisplayRole ) {
107  switch ( index.column() ) {
108  case Subject:
109  return msg->subject()->asUnicodeString();
110  case Sender:
111  return msg->from()->asUnicodeString();
112  case Receiver:
113  return msg->to()->asUnicodeString();
114  case Date:
115  return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate );
116  case Size:
117  if ( item.size() == 0 )
118  return i18nc( "@label No size available", "-" );
119  else
120  return KGlobal::locale()->formatByteSize( item.size() );
121  default:
122  return QVariant();
123  }
124  } else if ( role == Qt::EditRole ) {
125  switch ( index.column() ) {
126  case Subject:
127  return msg->subject()->asUnicodeString();
128  case Sender:
129  return msg->from()->asUnicodeString();
130  case Receiver:
131  return msg->to()->asUnicodeString();
132  case Date:
133  return msg->date()->dateTime().dateTime();
134  case Size:
135  return item.size();
136  default:
137  return QVariant();
138  }
139  }
140  return ItemModel::data( index, role );
141 }
142 
143 QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const
144 {
145 
146  if ( collection().isValid()
147  && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
148  && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
149  return QVariant();
150 
151  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
152  switch ( section ) {
153  case Subject:
154  return i18nc( "@title:column, message (e.g. email) subject", "Subject" );
155  case Sender:
156  return i18nc( "@title:column, sender of message (e.g. email)", "Sender" );
157  case Receiver:
158  return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" );
159  case Date:
160  return i18nc( "@title:column, message (e.g. email) timestamp", "Date" );
161  case Size:
162  return i18nc( "@title:column, message (e.g. email) size", "Size" );
163  default:
164  return QString();
165  }
166  }
167  return ItemModel::headerData( section, orientation, role );
168 }
169 
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
Akonadi::MessageModel::Date
Date column.
Definition: messagemodel.h:50
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:87
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:74
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:143
Akonadi::MessageModel::Sender
Sender column.
Definition: messagemodel.h:48
Akonadi::MessageModel::~MessageModel
virtual ~MessageModel()
Deletes the message model.
Definition: messagemodel.cpp:52
Akonadi::MessageModel::Size
Size column.
Definition: messagemodel.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:55 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 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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