45
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Single day item view model
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
57
|
18 |
// System includes
|
45
|
19 |
#include <calenservices.h>
|
|
20 |
#include <agendautil.h>
|
57
|
21 |
|
|
22 |
// User includes
|
45
|
23 |
#include "calendaymodel.h"
|
|
24 |
|
|
25 |
|
|
26 |
/*!
|
57
|
27 |
BC Day Model constructor
|
|
28 |
\a date defined day for which entries will be fetched \a services is handle to
|
|
29 |
organizer services \a parent
|
45
|
30 |
*/
|
57
|
31 |
CalenDayModel::CalenDayModel(const QDateTime &date, MCalenServices &services, QObject *parent) :
|
|
32 |
QAbstractListModel(parent), mServices(services)
|
45
|
33 |
{
|
57
|
34 |
if (date.isValid()) {
|
|
35 |
loadAndStoreInstances(date);
|
|
36 |
}
|
45
|
37 |
}
|
|
38 |
|
|
39 |
/*
|
57
|
40 |
\reimp
|
45
|
41 |
*/
|
57
|
42 |
int CalenDayModel::rowCount(const QModelIndex &parent) const
|
45
|
43 |
{
|
|
44 |
Q_UNUSED( parent )
|
|
45 |
return mEntryList.count();
|
|
46 |
}
|
|
47 |
|
|
48 |
/*
|
57
|
49 |
\reimp
|
45
|
50 |
*/
|
|
51 |
QVariant CalenDayModel::data(const QModelIndex &index, int role) const
|
|
52 |
{
|
57
|
53 |
if (!index.isValid()) {
|
45
|
54 |
return QVariant();
|
57
|
55 |
}
|
45
|
56 |
|
57
|
57 |
if (index.row() >= mEntryList.count()) {
|
45
|
58 |
return QVariant();
|
57
|
59 |
}
|
45
|
60 |
|
57
|
61 |
if (role == CalenDayEntry) {
|
45
|
62 |
return mEntryList.at(index.row());
|
57
|
63 |
}
|
|
64 |
else {
|
45
|
65 |
return QVariant();
|
57
|
66 |
}
|
45
|
67 |
}
|
|
68 |
|
|
69 |
/*!
|
57
|
70 |
Resets model. Old events are removed. Evenets for given day are fetched.
|
|
71 |
\a date defined day for which entries will be fetched
|
45
|
72 |
*/
|
|
73 |
void CalenDayModel::refreshModel(const QDateTime &date)
|
|
74 |
{
|
57
|
75 |
beginResetModel();
|
|
76 |
loadAndStoreInstances(date);
|
|
77 |
endResetModel();
|
45
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
57
|
81 |
Fetches entries via. organizer API and stores it in member container
|
|
82 |
*/
|
|
83 |
void CalenDayModel::loadAndStoreInstances(const QDateTime &date)
|
|
84 |
{
|
|
85 |
mDateTime = date;
|
|
86 |
//Filter flags
|
|
87 |
AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(AgendaUtil::IncludeAppointments
|
|
88 |
| AgendaUtil::IncludeEvents);
|
|
89 |
QList<AgendaEntry> list;
|
|
90 |
// Fetch the instance list from the agenda interface
|
|
91 |
list = mServices.agendaInterface()->createEntryIdListForDay(date, filter);
|
|
92 |
|
|
93 |
mEntryList.clear();
|
|
94 |
|
|
95 |
foreach(AgendaEntry entry, list){
|
|
96 |
mEntryList.append(QVariant::fromValue(entry));
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Retruns date (day). Model holds events for this day.
|
45
|
102 |
*/
|
|
103 |
QDateTime CalenDayModel::modelDate() const
|
|
104 |
{
|
57
|
105 |
return mDateTime;
|
45
|
106 |
}
|