2 Copyright (c) 2008 Bruno Virlet <bvirlet@kdemail.net>
3 2009 KDAB; Author: Frank Osterfeld <osterfeld@kde.org>
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "calendarmodel.h"
24 #include <Akonadi/ChangeRecorder>
25 #include <Akonadi/ItemFetchScope>
28 #include <KIconLoader>
33 using namespace CalendarSupport
;
35 class CalendarModel::Private
38 explicit Private( CalendarModel
*qq
)
44 CalendarModel
*const q
;
47 CalendarModel::CalendarModel( Akonadi::ChangeRecorder
*monitor
, QObject
*parent
)
48 : EntityTreeModel( monitor
, parent
),
49 d( new Private( this ) )
51 monitor
->itemFetchScope().fetchAllAttributes( true );
54 CalendarModel::~CalendarModel()
59 static KDateTime
primaryDateForIncidence( const Akonadi::Item
&item
)
61 if ( const KCalCore::Todo::Ptr t
= CalendarSupport::todo( item
) ) {
62 return t
->hasDueDate() ? t
->dtDue() : KDateTime();
65 if ( const KCalCore::Event::Ptr e
= CalendarSupport::event( item
) ) {
66 return ( !e
->recurs() && !e
->isMultiDay() ) ? e
->dtStart() : KDateTime();
69 if ( const KCalCore::Journal::Ptr j
= CalendarSupport::journal( item
) ) {
76 QVariant
CalendarModel::entityData( const Akonadi::Item
&item
, int column
, int role
) const
78 const KCalCore::Incidence::Ptr incidence
= CalendarSupport::incidence( item
);
84 case Qt::DecorationRole
:
85 if ( column
!= Summary
) {
88 if ( incidence
->type() == KCalCore::IncidenceBase::TypeTodo
) {
89 return SmallIcon( QLatin1String( "view-pim-tasks" ) );
91 if ( incidence
->type() == KCalCore::IncidenceBase::TypeJournal
) {
92 return SmallIcon( QLatin1String( "view-pim-journal" ) );
94 if ( incidence
->type() == KCalCore::IncidenceBase::TypeEvent
) {
95 return SmallIcon( QLatin1String( "view-calendar" ) );
97 return SmallIcon( QLatin1String( "network-wired" ) );
102 return incidence
->summary();
105 return incidence
->dtStart().toString();
108 return incidence
->dateTime( KCalCore::Incidence::RoleEndTimeZone
).toString();
111 if ( KCalCore::Todo::Ptr todo
= CalendarSupport::todo( item
) ) {
112 return todo
->dtDue().toString();
118 if ( KCalCore::Todo::Ptr todo
= CalendarSupport::todo( item
) ) {
119 return todo
->priority();
124 case PercentComplete
:
125 if ( KCalCore::Todo::Ptr todo
= CalendarSupport::todo( item
) ) {
126 return todo
->percentComplete();
132 return primaryDateForIncidence( item
).toString();
136 return incidence
->type();
144 return incidence
->summary();
147 return incidence
->dtStart().toUtc().dateTime();
150 return incidence
->dateTime( KCalCore::Incidence::RoleEndTimeZone
).toUtc().dateTime();
153 if ( KCalCore::Todo::Ptr todo
= CalendarSupport::todo( item
) ) {
154 return todo
->dtDue().toUtc().dateTime();
160 return primaryDateForIncidence( item
).toUtc().dateTime();
163 if ( KCalCore::Todo::Ptr todo
= CalendarSupport::todo( item
) ) {
164 return todo
->priority();
169 case PercentComplete
:
170 if ( KCalCore::Todo::Ptr todo
= CalendarSupport::todo( item
) ) {
171 return todo
->percentComplete();
177 return incidence
->type();
186 return incidence
->recurs();
195 QVariant
CalendarModel::entityData( const Akonadi::Collection
&collection
,
196 int column
, int role
) const
198 return EntityTreeModel::entityData( collection
, column
, role
);
201 int CalendarModel::entityColumnCount( EntityTreeModel::HeaderGroup headerSet
) const
203 if ( headerSet
== EntityTreeModel::ItemListHeaders
) {
204 return ItemColumnCount
;
206 return CollectionColumnCount
;
210 QVariant
CalendarModel::entityHeaderData( int section
, Qt::Orientation orientation
,
211 int role
, EntityTreeModel::HeaderGroup headerSet
) const
213 if ( role
!= Qt::DisplayRole
|| orientation
!= Qt::Horizontal
) {
217 if ( headerSet
== EntityTreeModel::ItemListHeaders
) {
220 return i18nc( "@title:column calendar event summary", "Summary" );
222 return i18nc( "@title:column calendar event start date and time", "Start Date and Time" );
224 return i18nc( "@title:column calendar event end date and time", "End Date and Time" );
226 return i18nc( "@title:column calendar event type", "Type" );
228 return i18nc( "@title:column todo item due date and time", "Due Date and Time" );
230 return i18nc( "@title:column todo item priority", "Priority" );
231 case PercentComplete
:
232 return i18nc( "@title:column todo item completion in percent", "Complete" );
238 if ( headerSet
== EntityTreeModel::CollectionTreeHeaders
) {
240 case CollectionTitle
:
241 return i18nc( "@title:column calendar title", "Calendar" );