• Skip to content
  • Skip to link menu
KDE 4.1 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 
00035 #include <QtCore/QDebug>
00036 
00037 using namespace Akonadi;
00038 
00039 class Akonadi::MessageModel::Private
00040 {
00041   public:
00042 };
00043 
00044 MessageModel::MessageModel( QObject *parent ) :
00045     ItemModel( parent ),
00046     d( new Private() )
00047 {
00048   fetchScope().fetchPayloadPart( MessagePart::Envelope );
00049 }
00050 
00051 MessageModel::~MessageModel( )
00052 {
00053   delete d;
00054 }
00055 
00056 int MessageModel::columnCount( const QModelIndex & parent ) const
00057 {
00058   if ( !parent.isValid() )
00059     return 5; // keep in sync with the column type enum
00060 
00061   return 0;
00062 }
00063 
00064 QVariant MessageModel::data( const QModelIndex & index, int role ) const
00065 {
00066   if ( !index.isValid() )
00067     return QVariant();
00068   if ( index.row() >= rowCount() )
00069     return QVariant();
00070   Item item = itemForIndex( index );
00071   if ( !item.hasPayload<MessagePtr>() )
00072     return QVariant();
00073   MessagePtr msg = item.payload<MessagePtr>();
00074   if ( role == Qt::DisplayRole ) {
00075     switch ( index.column() ) {
00076       case Subject:
00077         return msg->subject()->asUnicodeString();
00078       case Sender:
00079         return msg->from()->asUnicodeString();
00080       case Receiver:
00081         return msg->to()->asUnicodeString();
00082       case Date:
00083         return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate );
00084       case Size:
00085         // TODO
00086         return 0; // pass modeltest
00087       default:
00088         return QVariant();
00089     }
00090   } else if ( role == Qt::EditRole ) {
00091     switch ( index.column() ) {
00092       case Subject:
00093         return msg->subject()->asUnicodeString();
00094       case Sender:
00095         return msg->from()->asUnicodeString();
00096       case Receiver:
00097         return msg->to()->asUnicodeString();
00098       case Date:
00099         return msg->date()->dateTime().dateTime();
00100       case Size:
00101         // TODO
00102         return 0; // pass modeltest
00103       default:
00104         return QVariant();
00105     }
00106   }
00107   return ItemModel::data( index, role );
00108 }
00109 
00110 QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const
00111 {
00112   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) {
00113     switch ( section ) {
00114       case Subject:
00115         return i18nc( "@title:column, message (e.g. email) subject", "Subject" );
00116       case Sender:
00117         return i18nc( "@title:column, sender of message (e.g. email)", "Sender" );
00118       case Receiver:
00119         return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" );
00120       case Date:
00121         return i18nc( "@title:column, message (e.g. email) timestamp", "Date" );
00122       case Size:
00123         return i18nc( "@title:column, message (e.g. email) size", "Size" );
00124       default:
00125         return QString();
00126     }
00127   }
00128   return ItemModel::headerData( section, orientation, role );
00129 }
00130 
00131 #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
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
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