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