22 #include <Akonadi/Collection>
23 #include <Akonadi/Item>
24 #include <Akonadi/ItemFetchScope>
26 #include <KCalCore/FreeBusy>
27 #include <KCalCore/Event>
28 #include <KCalCore/Journal>
29 #include <KCalCore/Todo>
31 #include <KIconLoader>
36 using namespace CalendarSupport;
38 class KCalModel::Private
46 static QStringList allMimeTypes()
49 types << KCalCore::Event::eventMimeType()
50 << KCalCore::Todo::todoMimeType()
51 << KCalCore::Journal::journalMimeType()
52 << KCalCore::FreeBusy::freeBusyMimeType();
55 bool collectionMatchesMimeTypes()
const
57 Q_FOREACH (
const QString &type, allMimeTypes() ) {
58 if ( q->collection().contentMimeTypes().contains( type ) ) {
65 bool collectionIsValid()
68 !q->collection().isValid() ||
69 collectionMatchesMimeTypes() ||
70 q->collection().contentMimeTypes() == QStringList( QLatin1String(
"inode/directory" ) );
78 : ItemModel( parent ), d( new Private( this ) )
80 fetchScope().fetchFullPayload();
92 << QLatin1String(
"text/uri-list" )
98 if ( d->collectionIsValid() ) {
107 if ( d->collectionIsValid() ) {
108 return ItemModel::rowCount();
116 if ( role == ItemModel::IdRole ) {
117 return ItemModel::data( index, role );
120 if ( !index.isValid() || index.row() >=
rowCount() ) {
125 if ( !d->collectionIsValid() ) {
126 if ( role == Qt::DisplayRole ) {
127 return i18nc(
"@info",
128 "This model can only handle event, task, journal or free-busy list folders. "
129 "The current collection holds mimetypes: %1",
130 collection().contentMimeTypes().join( QLatin1String(
"," ) ) );
135 const Akonadi::Item item = itemForIndex( index );
137 if ( !item.hasPayload<KCalCore::Incidence::Ptr>() ) {
141 const KCalCore::Incidence::Ptr
incidence = item.payload<KCalCore::Incidence::Ptr>();
145 case Qt::DecorationRole:
146 if ( index.column() == 0 ) {
147 if ( incidence->type() == KCalCore::Incidence::TypeTodo ) {
148 return SmallIcon( QLatin1String(
"view-pim-tasks" ) );
149 }
else if ( incidence->type() == KCalCore::Incidence::TypeJournal ) {
150 return SmallIcon( QLatin1String(
"view-pim-journal" ) );
151 }
else if ( incidence->type() == KCalCore::Incidence::TypeEvent ) {
152 return SmallIcon( QLatin1String(
"view-calendar" ) );
154 return SmallIcon( QLatin1String(
"network-wired" ) );
158 case Qt::DisplayRole:
159 switch( index.column() ) {
161 return incidence->summary();
164 return incidence->dtStart().toString();
167 return incidence->dateTime( KCalCore::Incidence::RoleEnd ).toString();
170 return incidence->type();
186 if ( !d->collectionIsValid() ) {
190 if ( role == Qt::DisplayRole && orientation == Qt::Horizontal ) {
193 return i18nc(
"@title:column, calendar event summary",
"Summary" );
195 return i18nc(
"@title:column, calendar event start date and time",
"Start date and time" );
197 return i18nc(
"@title:column, calendar event end date and time",
"End date and time" );
199 return i18nc(
"@title:column, calendar event type",
"Type" );
205 return Akonadi::ItemModel::headerData( section, orientation, role );
virtual QStringList mimeTypes() const
Reimplemented from QAbstractItemModel.
CALENDARSUPPORT_EXPORT KCalCore::Incidence::Ptr incidence(const Akonadi::Item &item)
returns the incidence from an akonadi item, or a null pointer if the item has no such payload ...
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
KCalModel(QObject *parent=0)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const