|
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 |
|
18 |
|
19 |
|
20 #include <calenservices.h> |
|
21 #include <agendautil.h> |
|
22 #include "calendaymodel.h" |
|
23 |
|
24 |
|
25 /*! |
|
26 BC Day Model constructor |
|
27 \a date defined day for which entries will be fetched \a services is handle to |
|
28 organizer services \a parent |
|
29 */ |
|
30 CalenDayModel::CalenDayModel(const QDateTime &date, MCalenServices &services, |
|
31 QObject *parent) |
|
32 : QAbstractListModel(parent), mServices(services) |
|
33 { |
|
34 if (date.isValid()) |
|
35 { |
|
36 loadAndStoreInstances(date); |
|
37 } |
|
38 } |
|
39 |
|
40 /* |
|
41 \reimp |
|
42 */ |
|
43 int CalenDayModel::rowCount( const QModelIndex &parent ) const |
|
44 { |
|
45 Q_UNUSED( parent ) |
|
46 return mEntryList.count(); |
|
47 } |
|
48 |
|
49 /* |
|
50 \reimp |
|
51 */ |
|
52 QVariant CalenDayModel::data(const QModelIndex &index, int role) const |
|
53 { |
|
54 if (!index.isValid()) |
|
55 { |
|
56 return QVariant(); |
|
57 } |
|
58 |
|
59 if (index.row() >= mEntryList.count()) |
|
60 { |
|
61 return QVariant(); |
|
62 } |
|
63 |
|
64 if (role == CalenDayEntry) |
|
65 { |
|
66 return mEntryList.at(index.row()); |
|
67 } |
|
68 else |
|
69 { |
|
70 return QVariant(); |
|
71 } |
|
72 } |
|
73 |
|
74 /*! |
|
75 Resets model. Old events are removed. Evenets for given day are fetched. |
|
76 \a date defined day for which entries will be fetched |
|
77 */ |
|
78 void CalenDayModel::refreshModel(const QDateTime &date) |
|
79 { |
|
80 beginResetModel(); |
|
81 loadAndStoreInstances(date); |
|
82 endResetModel(); |
|
83 } |
|
84 |
|
85 |
|
86 /*! |
|
87 Fetches entries via. organizer API and stores it in member container |
|
88 */ |
|
89 void CalenDayModel::loadAndStoreInstances(const QDateTime &date) |
|
90 { |
|
91 mDateTime = date; |
|
92 //Filter flags |
|
93 AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags( |
|
94 AgendaUtil::IncludeAppointments | AgendaUtil::IncludeEvents); |
|
95 QList<AgendaEntry> list; |
|
96 // Fetch the instance list from the agenda interface |
|
97 list = mServices.agendaInterface()->createEntryIdListForDay(date, filter); |
|
98 |
|
99 mEntryList.clear(); |
|
100 |
|
101 foreach(AgendaEntry entry, list) |
|
102 { |
|
103 mEntryList.append(QVariant::fromValue(entry)); |
|
104 } |
|
105 } |
|
106 |
|
107 /*! |
|
108 Retruns date (day). Model holds events for this day. |
|
109 */ |
|
110 QDateTime CalenDayModel::modelDate() const |
|
111 { |
|
112 return mDateTime; |
|
113 } |