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: Model manager holds models for three day views
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
63
|
18 |
// System includes
|
45
|
19 |
#include <calenservices.h>
|
|
20 |
#include <calencontext.h>
|
|
21 |
|
63
|
22 |
// User includes
|
45
|
23 |
#include "calendaymodelmanager.h"
|
|
24 |
#include "calendaymodel.h"
|
|
25 |
|
|
26 |
/*!
|
57
|
27 |
BC Model Manager constructor. Model manager use calendar context to
|
|
28 |
populate models with proper events.
|
|
29 |
\a services is handle to organizer services \a emptyModels if true created models
|
|
30 |
are not populated with events \a parent
|
45
|
31 |
*/
|
57
|
32 |
CalenDayModelManager::CalenDayModelManager(
|
|
33 |
MCalenServices &services,
|
|
34 |
bool emptyModels,
|
|
35 |
QObject *parent) :
|
|
36 |
QObject(parent), mServices(services)
|
45
|
37 |
{
|
57
|
38 |
if (emptyModels) {
|
|
39 |
mCurrentDayTime = QDateTime();
|
|
40 |
}
|
|
41 |
else {
|
|
42 |
mCurrentDayTime = mServices.Context().focusDateAndTime();
|
|
43 |
}
|
|
44 |
createAllModels();
|
45
|
45 |
}
|
|
46 |
|
|
47 |
CalenDayModelManager::~CalenDayModelManager()
|
|
48 |
{
|
57
|
49 |
// not needed now
|
45
|
50 |
}
|
|
51 |
|
|
52 |
void CalenDayModelManager::viewsScrollingFinished(CalenScrollDirection scrollTo)
|
57
|
53 |
{
|
|
54 |
if (scrollTo == ECalenScrollToNext) {
|
|
55 |
moveForward();
|
|
56 |
}
|
|
57 |
else {
|
|
58 |
moveBackward();
|
|
59 |
}
|
|
60 |
}
|
45
|
61 |
|
|
62 |
/*!
|
57
|
63 |
Reorganize models after move to previous day.
|
45
|
64 |
*/
|
|
65 |
void CalenDayModelManager::moveBackward()
|
|
66 |
{
|
57
|
67 |
mCurrentDayTime = mServices.Context().focusDateAndTime();
|
45
|
68 |
|
57
|
69 |
CalenDayModel* tmp = mModels[NextDay];
|
|
70 |
tmp->refreshModel(mCurrentDayTime.addDays(-1));
|
|
71 |
|
|
72 |
mModels[NextDay] = mModels[CurrentDay];
|
|
73 |
mModels[CurrentDay] = mModels[PreviousDay];
|
|
74 |
mModels[PreviousDay] = tmp;
|
45
|
75 |
}
|
|
76 |
|
|
77 |
/*!
|
57
|
78 |
Reorganize models after move to next day.
|
45
|
79 |
*/
|
57
|
80 |
void CalenDayModelManager::moveForward()
|
45
|
81 |
{
|
57
|
82 |
mCurrentDayTime = mServices.Context().focusDateAndTime();
|
|
83 |
|
|
84 |
CalenDayModel* tmp = mModels[PreviousDay];
|
|
85 |
tmp->refreshModel(mCurrentDayTime.addDays(1));
|
|
86 |
|
|
87 |
mModels[PreviousDay] = mModels[CurrentDay];
|
|
88 |
mModels[CurrentDay] = mModels[NextDay];
|
|
89 |
mModels[NextDay] = tmp;
|
45
|
90 |
}
|
|
91 |
|
|
92 |
/*!
|
57
|
93 |
Returns given model
|
|
94 |
/a day defines model, can be (PreviousDay, CurrentDay, NextDay) only.
|
45
|
95 |
*/
|
|
96 |
QAbstractItemModel &CalenDayModelManager::getModel(ModelDay day)
|
|
97 |
{
|
57
|
98 |
return *(mModels[day]);
|
45
|
99 |
}
|
|
100 |
|
|
101 |
/*!
|
57
|
102 |
Creates all models objects durring construction.
|
45
|
103 |
*/
|
|
104 |
void CalenDayModelManager::createAllModels()
|
|
105 |
{
|
57
|
106 |
|
|
107 |
mModels[CurrentDay] = new CalenDayModel(mCurrentDayTime, mServices, this);
|
|
108 |
|
|
109 |
QDateTime previousDayTime;
|
|
110 |
QDateTime nextDayTime;
|
|
111 |
|
|
112 |
if (mCurrentDayTime.isValid()) {
|
|
113 |
previousDayTime = mCurrentDayTime.addDays(-1);
|
|
114 |
nextDayTime = mCurrentDayTime.addDays(1);
|
|
115 |
}
|
|
116 |
|
|
117 |
mModels[PreviousDay] = new CalenDayModel(previousDayTime, mServices, this);
|
|
118 |
mModels[NextDay] = new CalenDayModel(nextDayTime, mServices, this);
|
45
|
119 |
}
|
|
120 |
|
|
121 |
/*!
|
57
|
122 |
Refetch data for all models. Context calendar is used to fill models
|
|
123 |
with correct events. Should be used for full (three days) repopulation.
|
45
|
124 |
*/
|
|
125 |
void CalenDayModelManager::refreshAllModels()
|
57
|
126 |
{
|
|
127 |
mCurrentDayTime = mServices.Context().focusDateAndTime();
|
45
|
128 |
|
57
|
129 |
mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1));
|
|
130 |
mModels[CurrentDay]->refreshModel(mCurrentDayTime);
|
|
131 |
mModels[NextDay]->refreshModel(mCurrentDayTime.addDays(1));
|
|
132 |
}
|
45
|
133 |
|
|
134 |
/*!
|
57
|
135 |
Refetch data given day model. Context calendar is used to fill model
|
|
136 |
with correct events.
|
|
137 |
/a day defines model, can be (PreviousDay, CurrentDay, NextDay) only.
|
45
|
138 |
*/
|
|
139 |
void CalenDayModelManager::refreshSingleModel(CalenDayModelManager::ModelDay day)
|
57
|
140 |
{
|
|
141 |
switch (day) {
|
|
142 |
case PreviousDay: {
|
|
143 |
mModels[PreviousDay]->refreshModel(mCurrentDayTime.addDays(-1));
|
|
144 |
}
|
|
145 |
break;
|
|
146 |
case CurrentDay: {
|
|
147 |
mModels[CurrentDay]->refreshModel(mCurrentDayTime);
|
|
148 |
}
|
|
149 |
break;
|
|
150 |
case NextDay: {
|
81
|
151 |
mModels[NextDay]->refreshModel(mCurrentDayTime.addDays(1));
|
57
|
152 |
}
|
|
153 |
break;
|
|
154 |
default:
|
|
155 |
break;
|
|
156 |
}
|
|
157 |
}
|
45
|
158 |
|
|
159 |
// End of File
|