• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi/kmime

messagemodel.cpp

00001 /*
00002     Copyright (c) 2006 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "messagemodel.h"
00021 #include "messageparts.h"
00022 
00023 #include <akonadi/itemfetchscope.h>
00024 #include <akonadi/monitor.h>
00025 #include <akonadi/session.h>
00026 
00027 #include <kmime/kmime_message.h>
00028 #include <boost/shared_ptr.hpp>
00029 typedef boost::shared_ptr<KMime::Message> MessagePtr;
00030 
00031 #include <kdebug.h>
00032 #include <kglobal.h>
00033 #include <klocale.h>
00034 #include <kio/job.h>
00035 
00036 #include <QtCore/QDebug>
00037 
00038 using namespace Akonadi;
00039 
00040 class Akonadi::MessageModel::Private
00041 {
00042   public:
00043 };
00044 
00045 MessageModel::MessageModel( QObject *parent ) :
00046     ItemModel( parent ),
00047     d( new Private() )
00048 {
00049   fetchScope().fetchPayloadPart( MessagePart::Envelope );
00050 }
00051 
00052 MessageModel::~MessageModel( )
00053 {
00054   delete d;
00055 }
00056 
00057 QStringList MessageModel::mimeTypes() const
00058 {
00059   return QStringList()
00060       << QLatin1String("text/uri-list")
00061       << QLatin1String("message/rfc822");
00062 }
00063 
00064 int MessageModel::rowCount( const QModelIndex& ) const
00065 {
00066   if ( collection().isValid()
00067           && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
00068           && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
00069     return 1;
00070 
00071   return ItemModel::rowCount();
00072 }
00073 
00074 int MessageModel::columnCount( const QModelIndex & parent ) const
00075 {
00076   if ( collection().isValid()
00077           && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
00078           && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
00079     return 1;
00080 
00081   if ( !parent.isValid() )
00082     return 5; // keep in sync with the column type enum
00083 
00084   return 0;
00085 }
00086 
00087 QVariant MessageModel::data( const QModelIndex & index, int role ) const
00088 {
00089   if ( !index.isValid() )
00090     return QVariant();
00091   if ( index.row() >= rowCount() )
00092     return QVariant();
00093 
00094   if ( !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") ) ) {
00095      if ( role == Qt::DisplayRole )
00096        return i18nc( "@label", "This model can only handle email folders. The current collection holds mimetypes: %1",
00097                        collection().contentMimeTypes().join( QLatin1String(",") ) );
00098      else
00099        return QVariant();
00100   }
00101 
00102   Item item = itemForIndex( index );
00103   if ( !item.hasPayload<MessagePtr>() )
00104     return QVariant();
00105   MessagePtr msg = item.payload<MessagePtr>();
00106   if ( role == Qt::DisplayRole ) {
00107     switch ( index.column() ) {
00108       case Subject:
00109         return msg->subject()->asUnicodeString();
00110       case Sender:
00111         return msg->from()->asUnicodeString();
00112       case Receiver:
00113         return msg->to()->asUnicodeString();
00114       case Date:
00115         return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate );
00116       case Size:
00117         if ( item.size() == 0 )
00118           return i18nc( "@label No size available", "-" );
00119         else
00120           return KGlobal::locale()->formatByteSize( item.size() );
00121       default:
00122         return QVariant();
00123     }
00124   } else if ( role == Qt::EditRole ) {
00125     switch ( index.column() ) {
00126       case Subject:
00127         return msg->subject()->asUnicodeString();
00128       case Sender:
00129         return msg->from()->asUnicodeString();
00130       case Receiver:
00131         return msg->to()->asUnicodeString();
00132       case Date:
00133         return msg->date()->dateTime().dateTime();
00134       case Size:
00135         return item.size();
00136       default:
00137         return QVariant();
00138     }
00139   }
00140   return ItemModel::data( index, role );
00141 }
00142 
00143 QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const
00144 {
00145 
00146   if ( collection().isValid()
00147           && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
00148           && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
00149     return QVariant();
00150 
00151   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
00152     switch ( section ) {
00153       case Subject:
00154         return i18nc( "@title:column, message (e.g. email) subject", "Subject" );
00155       case Sender:
00156         return i18nc( "@title:column, sender of message (e.g. email)", "Sender" );
00157       case Receiver:
00158         return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" );
00159       case Date:
00160         return i18nc( "@title:column, message (e.g. email) timestamp", "Date" );
00161       case Size:
00162         return i18nc( "@title:column, message (e.g. email) size", "Size" );
00163       default:
00164         return QString();
00165     }
00166   }
00167   return ItemModel::headerData( section, orientation, role );
00168 }
00169 
00170 #include "messagemodel.moc"

akonadi/kmime

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal