• Skip to content
  • Skip to link menu
KDE 4.2 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 int MessageModel::columnCount( const QModelIndex & parent ) const
00058 {
00059   if ( !parent.isValid() )
00060     return 5; // keep in sync with the column type enum
00061 
00062   return 0;
00063 }
00064 
00065 QVariant MessageModel::data( const QModelIndex & index, int role ) const
00066 {
00067   if ( !index.isValid() )
00068     return QVariant();
00069   if ( index.row() >= rowCount() )
00070     return QVariant();
00071   Item item = itemForIndex( index );
00072   if ( !item.hasPayload<MessagePtr>() )
00073     return QVariant();
00074   MessagePtr msg = item.payload<MessagePtr>();
00075   if ( role == Qt::DisplayRole ) {
00076     switch ( index.column() ) {
00077       case Subject:
00078         return msg->subject()->asUnicodeString();
00079       case Sender:
00080         return msg->from()->asUnicodeString();
00081       case Receiver:
00082         return msg->to()->asUnicodeString();
00083       case Date:
00084         return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate );
00085       case Size:
00086         if ( item.size() == 0 )
00087           return i18nc( "No size available", "-" );
00088         else
00089           return KIO::convertSize( KIO::filesize_t( item.size() ) );
00090       default:
00091         return QVariant();
00092     }
00093   } else if ( role == Qt::EditRole ) {
00094     switch ( index.column() ) {
00095       case Subject:
00096         return msg->subject()->asUnicodeString();
00097       case Sender:
00098         return msg->from()->asUnicodeString();
00099       case Receiver:
00100         return msg->to()->asUnicodeString();
00101       case Date:
00102         return msg->date()->dateTime().dateTime();
00103       case Size:
00104         return item.size();
00105       default:
00106         return QVariant();
00107     }
00108   }
00109   return ItemModel::data( index, role );
00110 }
00111 
00112 QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const
00113 {
00114   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
00115     switch ( section ) {
00116       case Subject:
00117         return i18nc( "@title:column, message (e.g. email) subject", "Subject" );
00118       case Sender:
00119         return i18nc( "@title:column, sender of message (e.g. email)", "Sender" );
00120       case Receiver:
00121         return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" );
00122       case Date:
00123         return i18nc( "@title:column, message (e.g. email) timestamp", "Date" );
00124       case Size:
00125         return i18nc( "@title:column, message (e.g. email) size", "Size" );
00126       default:
00127         return QString();
00128     }
00129   }
00130   return ItemModel::headerData( section, orientation, role );
00131 }
00132 
00133 #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
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.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