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
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;
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
00086 return 0;
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
00102 return 0;
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"