akonadi/kcal
kcalmodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kcalmodel.h"
00021
00022 #include <akonadi/item.h>
00023 #include <akonadi/itemfetchjob.h>
00024 #include <akonadi/itemfetchscope.h>
00025
00026 #include <kcal/incidence.h>
00027 #include <kcal/event.h>
00028
00029 #include <klocale.h>
00030 #include <boost/shared_ptr.hpp>
00031
00032 #include <kiconloader.h>
00033 #include <QtGui/QPixmap>
00034
00035 typedef boost::shared_ptr<KCal::Incidence> IncidencePtr;
00036
00037 using namespace Akonadi;
00038
00039 class KCalModel::Private
00040 {
00041 public:
00042 };
00043
00044 KCalModel::KCalModel( QObject *parent )
00045 : ItemModel( parent ),
00046 d( new Private() )
00047 {
00048 fetchScope().fetchFullPayload();
00049 }
00050
00051 KCalModel::~KCalModel()
00052 {
00053 delete d;
00054 }
00055
00056 int KCalModel::columnCount( const QModelIndex& ) const
00057 {
00058 return 4;
00059 }
00060
00061 QVariant KCalModel::data( const QModelIndex &index, int role ) const
00062 {
00063 if ( role == ItemModel::IdRole )
00064 return ItemModel::data( index, role );
00065
00066 if ( !index.isValid() || index.row() >= rowCount() )
00067 return QVariant();
00068
00069 const Item item = itemForIndex( index );
00070
00071 if ( !item.hasPayload<IncidencePtr>() )
00072 return QVariant();
00073
00074 const IncidencePtr incidence = item.payload<IncidencePtr>();
00075
00076
00077 switch( role ) {
00078 case Qt::DecorationRole:
00079 if ( index.column() == 0 ) {
00080 if ( incidence->type() == "Todo" ) {
00081 return SmallIcon( QLatin1String( "view-pim-tasks" ) );
00082 } else if ( incidence->type() == "Journal" ) {
00083 return SmallIcon( QLatin1String( "view-pim-journal" ) );
00084 } else if ( incidence->type() == "Event" ) {
00085 return SmallIcon( QLatin1String( "view-pim-calendar" ) );
00086 } else {
00087 return SmallIcon( QLatin1String( "network-wired" ) );
00088 }
00089 }
00090 break;
00091 case Qt::DisplayRole:
00092 switch( index.column() ) {
00093 case Summary:
00094 return incidence->summary();
00095 break;
00096 case DateTimeStart:
00097 return incidence->dtStart().toString();
00098 break;
00099 case DateTimeEnd:
00100 return incidence->dtEnd().toString();
00101 break;
00102 case Type:
00103 return incidence->type();
00104 break;
00105 default:
00106 break;
00107 }
00108 break;
00109 default:
00110 return QVariant();
00111 break;
00112 }
00113
00114 return QVariant();
00115 }
00116
00117 QVariant KCalModel::headerData( int section, Qt::Orientation orientation, int role ) const
00118 {
00119 if ( role == Qt::DisplayRole && orientation == Qt::Horizontal ) {
00120 switch( section ) {
00121 case Summary:
00122 return i18nc( "@title:column, calendar event summary", "Summary" );
00123 case DateTimeStart:
00124 return i18nc( "@title:column, calendar event start date and time", "Start date and time" );
00125 case DateTimeEnd:
00126 return i18nc( "@title:column, calendar event end date and time", "End date and time" );
00127 case Type:
00128 return i18nc( "@title:column, calendar event type", "Type" );
00129 default:
00130 return QString();
00131 }
00132 }
00133
00134 return ItemModel::headerData( section, orientation, role );
00135 }