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

akonadi

  • 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 
35 #include <QtCore/QDebug>
36 
37 using namespace Akonadi;
38 
39 class Akonadi::MessageModel::Private
40 {
41  public:
42 };
43 
44 MessageModel::MessageModel( QObject *parent ) :
45  ItemModel( parent ),
46  d( new Private() )
47 {
48  fetchScope().fetchPayloadPart( MessagePart::Envelope );
49 }
50 
51 MessageModel::~MessageModel( )
52 {
53  delete d;
54 }
55 
56 QStringList MessageModel::mimeTypes() const
57 {
58  return QStringList()
59  << QLatin1String("text/uri-list")
60  << QLatin1String("message/rfc822");
61 }
62 
63 int MessageModel::rowCount( const QModelIndex& ) const
64 {
65  if ( collection().isValid()
66  && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
67  && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
68  return 1;
69 
70  return ItemModel::rowCount();
71 }
72 
73 int MessageModel::columnCount( const QModelIndex & parent ) const
74 {
75  if ( collection().isValid()
76  && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
77  && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
78  return 1;
79 
80  if ( !parent.isValid() )
81  return 5; // keep in sync with the column type enum
82 
83  return 0;
84 }
85 
86 QVariant MessageModel::data( const QModelIndex & index, int role ) const
87 {
88  if ( !index.isValid() )
89  return QVariant();
90  if ( index.row() >= rowCount() )
91  return QVariant();
92 
93  if ( !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) ) {
94  if ( role == Qt::DisplayRole )
95  return i18nc( "@label", "This model can only handle email folders. The current collection holds mimetypes: %1",
96  collection().contentMimeTypes().join( QLatin1String(",") ) );
97  else
98  return QVariant();
99  }
100 
101  Item item = itemForIndex( index );
102  if ( !item.hasPayload<MessagePtr>() )
103  return QVariant();
104  MessagePtr msg = item.payload<MessagePtr>();
105  if ( role == Qt::DisplayRole ) {
106  switch ( index.column() ) {
107  case Subject:
108  return msg->subject()->asUnicodeString();
109  case Sender:
110  return msg->from()->asUnicodeString();
111  case Receiver:
112  return msg->to()->asUnicodeString();
113  case Date:
114  return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate );
115  case Size:
116  if ( item.size() == 0 )
117  return i18nc( "@label No size available", "-" );
118  else
119  return KGlobal::locale()->formatByteSize( item.size() );
120  default:
121  return QVariant();
122  }
123  } else if ( role == Qt::EditRole ) {
124  switch ( index.column() ) {
125  case Subject:
126  return msg->subject()->asUnicodeString();
127  case Sender:
128  return msg->from()->asUnicodeString();
129  case Receiver:
130  return msg->to()->asUnicodeString();
131  case Date:
132  return msg->date()->dateTime().dateTime();
133  case Size:
134  return item.size();
135  default:
136  return QVariant();
137  }
138  }
139  return ItemModel::data( index, role );
140 }
141 
142 QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const
143 {
144 
145  if ( collection().isValid()
146  && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
147  && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
148  return QVariant();
149 
150  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
151  switch ( section ) {
152  case Subject:
153  return i18nc( "@title:column, message (e.g. email) subject", "Subject" );
154  case Sender:
155  return i18nc( "@title:column, sender of message (e.g. email)", "Sender" );
156  case Receiver:
157  return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" );
158  case Date:
159  return i18nc( "@title:column, message (e.g. email) timestamp", "Date" );
160  case Size:
161  return i18nc( "@title:column, message (e.g. email) size", "Size" );
162  default:
163  return QString();
164  }
165  }
166  return ItemModel::headerData( section, orientation, role );
167 }
168 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:39 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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
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