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

akonadi

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 & parent ) 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        // FIXME i18n when we unfreeze for 4.4
00097        return QString::fromLatin1( "This model can only handle email folders. The current collection holds mimetypes: %1").arg(
00098                        collection().contentMimeTypes().join( QLatin1String(",") ) );
00099      else
00100        return QVariant();
00101   }
00102 
00103   Item item = itemForIndex( index );
00104   if ( !item.hasPayload<MessagePtr>() )
00105     return QVariant();
00106   MessagePtr msg = item.payload<MessagePtr>();
00107   if ( role == Qt::DisplayRole ) {
00108     switch ( index.column() ) {
00109       case Subject:
00110         return msg->subject()->asUnicodeString();
00111       case Sender:
00112         return msg->from()->asUnicodeString();
00113       case Receiver:
00114         return msg->to()->asUnicodeString();
00115       case Date:
00116         return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate );
00117       case Size:
00118         if ( item.size() == 0 )
00119           return i18nc( "No size available", "-" );
00120         else
00121           return KIO::convertSize( KIO::filesize_t( item.size() ) );
00122       default:
00123         return QVariant();
00124     }
00125   } else if ( role == Qt::EditRole ) {
00126     switch ( index.column() ) {
00127       case Subject:
00128         return msg->subject()->asUnicodeString();
00129       case Sender:
00130         return msg->from()->asUnicodeString();
00131       case Receiver:
00132         return msg->to()->asUnicodeString();
00133       case Date:
00134         return msg->date()->dateTime().dateTime();
00135       case Size:
00136         return item.size();
00137       default:
00138         return QVariant();
00139     }
00140   }
00141   return ItemModel::data( index, role );
00142 }
00143 
00144 QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const
00145 {
00146 
00147   if ( collection().isValid()
00148           && !collection().contentMimeTypes().contains( QLatin1String("message/rfc822") )
00149           && collection().contentMimeTypes() != QStringList( QLatin1String("inode/directory") ) )
00150     return QVariant();
00151 
00152   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
00153     switch ( section ) {
00154       case Subject:
00155         return i18nc( "@title:column, message (e.g. email) subject", "Subject" );
00156       case Sender:
00157         return i18nc( "@title:column, sender of message (e.g. email)", "Sender" );
00158       case Receiver:
00159         return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" );
00160       case Date:
00161         return i18nc( "@title:column, message (e.g. email) timestamp", "Date" );
00162       case Size:
00163         return i18nc( "@title:column, message (e.g. email) size", "Size" );
00164       default:
00165         return QString();
00166     }
00167   }
00168   return ItemModel::headerData( section, orientation, role );
00169 }
00170 
00171 #include "messagemodel.moc"

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.8
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