akonadi
messagemodel.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
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"