66
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 : Implemrntation class for calenmultidbutility .
|
|
15 |
*
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
// system include.
|
|
19 |
#include <calsession.h>
|
|
20 |
#include <calentryview.h>
|
|
21 |
#include <calentry.h>
|
|
22 |
#include <CalenInterimUtils2.h>
|
|
23 |
#include <calcalendarinfo.h>
|
|
24 |
#include <calcalendariterator.h>
|
|
25 |
#include <calenmulticaluids.hrh>
|
|
26 |
#include <ErrorUI.h>
|
|
27 |
|
|
28 |
// user include.
|
|
29 |
#include "multicaluidialogmodel.h"
|
|
30 |
#include "calendarui_debug.h"
|
|
31 |
#include "CleanupResetAndDestroy.h"
|
|
32 |
|
|
33 |
const TInt KBuffLength = 24;
|
|
34 |
|
|
35 |
// ----------------------------------------------------------------------------
|
|
36 |
// CMultiCalUiDialogModel::CMultiCalUiDialogModel
|
|
37 |
// Constructor
|
|
38 |
// ----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CMultiCalUiDialogModel::CMultiCalUiDialogModel()
|
|
41 |
{
|
|
42 |
TRACE_ENTRY_POINT
|
|
43 |
TRACE_EXIT_POINT
|
|
44 |
}
|
|
45 |
|
|
46 |
// ----------------------------------------------------------------------------
|
|
47 |
// CMultiCalUiDialogModel::NewL
|
|
48 |
// First phase constructor
|
|
49 |
// ----------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
CMultiCalUiDialogModel* CMultiCalUiDialogModel::NewL()
|
|
52 |
{
|
|
53 |
TRACE_ENTRY_POINT
|
|
54 |
CMultiCalUiDialogModel* self = CMultiCalUiDialogModel::NewLC();
|
|
55 |
CleanupStack::Pop(self);
|
|
56 |
TRACE_EXIT_POINT
|
|
57 |
return self;
|
|
58 |
}
|
|
59 |
|
|
60 |
// ----------------------------------------------------------------------------
|
|
61 |
// CMultiCalUiDialogModel::NewLC
|
|
62 |
// First phase constructor
|
|
63 |
// ----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
CMultiCalUiDialogModel* CMultiCalUiDialogModel::NewLC()
|
|
66 |
{
|
|
67 |
TRACE_ENTRY_POINT
|
|
68 |
CMultiCalUiDialogModel* self = new (ELeave) CMultiCalUiDialogModel();
|
|
69 |
CleanupStack::PushL(self);
|
|
70 |
self->ConstructL();
|
|
71 |
TRACE_EXIT_POINT
|
|
72 |
return self;
|
|
73 |
}
|
|
74 |
|
|
75 |
// ----------------------------------------------------------------------------
|
|
76 |
// CMultiCalUiDialogModel::~CMultiCalUiDialogModel
|
|
77 |
// Rest of the details are commented in header.
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
CMultiCalUiDialogModel::~CMultiCalUiDialogModel()
|
|
81 |
{
|
|
82 |
TRACE_ENTRY_POINT
|
|
83 |
|
|
84 |
iCalendarInfoList.ResetAndDestroy();
|
|
85 |
|
|
86 |
if (iCalendarsSession)
|
|
87 |
{
|
|
88 |
delete iCalendarsSession;
|
|
89 |
iCalendarsSession = NULL;
|
|
90 |
}
|
|
91 |
|
|
92 |
iCalEntryViewArray.ResetAndDestroy();
|
|
93 |
|
|
94 |
iCalSessionArray.ResetAndDestroy();
|
|
95 |
|
|
96 |
iCalendarStatus.Reset();
|
|
97 |
|
|
98 |
if (iInterimUtils)
|
|
99 |
{
|
|
100 |
delete iInterimUtils;
|
|
101 |
iInterimUtils = NULL;
|
|
102 |
}
|
|
103 |
|
|
104 |
iCalEntries.Reset();
|
|
105 |
|
|
106 |
TRACE_EXIT_POINT;
|
|
107 |
}
|
|
108 |
|
|
109 |
// ----------------------------------------------------------------------------
|
|
110 |
// CMultiCalUiDialogModel::SetCalEntry
|
|
111 |
// Rest of the details are commented in header.
|
|
112 |
// ----------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
void CMultiCalUiDialogModel::SetCalEntryL(
|
|
115 |
const RPointerArray<CCalEntry>& aCalEntries)
|
|
116 |
{
|
|
117 |
TRACE_ENTRY_POINT
|
|
118 |
//We take only the pointers to entries , we dont own it
|
|
119 |
//So never do iCalEntries.ResetAndDestroy() only Reset
|
|
120 |
for (TInt i = 0; i < aCalEntries.Count(); i++)
|
|
121 |
{
|
|
122 |
iCalEntries.AppendL(aCalEntries[i]);
|
|
123 |
}
|
|
124 |
|
|
125 |
TRACE_EXIT_POINT;
|
|
126 |
}
|
|
127 |
|
|
128 |
// ----------------------------------------------------------------------------
|
|
129 |
// CMultiCalUiDialogModel::GetMultiDbInfo
|
|
130 |
// Rest of the details are commented in header.
|
|
131 |
// ----------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
RPointerArray<CCalCalendarInfo>& CMultiCalUiDialogModel::GetCalendarInfoArray()
|
|
134 |
{
|
|
135 |
TRACE_ENTRY_POINT
|
|
136 |
TRACE_EXIT_POINT;
|
|
137 |
return iCalendarInfoList;
|
|
138 |
}
|
|
139 |
|
|
140 |
// ----------------------------------------------------------------------------
|
|
141 |
// CMultiCalUiDialogModel::ConstructL
|
|
142 |
// Second phase constructor
|
|
143 |
// ----------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
void CMultiCalUiDialogModel::ConstructL()
|
|
146 |
{
|
|
147 |
TRACE_ENTRY_POINT
|
|
148 |
//iCalSessionArray takes ownership of this.
|
|
149 |
CCalSession* defaultSession = CCalSession::NewL();
|
|
150 |
|
|
151 |
TRAPD(err,GetAllCalendarInfoL(iCalendarInfoList));
|
|
152 |
|
|
153 |
//Something happened and
|
|
154 |
if(err!=KErrNone)
|
|
155 |
{
|
|
156 |
CErrorUI* errorUi = CErrorUI::NewLC();
|
|
157 |
errorUi->ShowGlobalErrorNoteL( err );
|
|
158 |
CleanupStack::PopAndDestroy( errorUi );
|
|
159 |
}
|
|
160 |
|
|
161 |
for (TInt index = 0; index < iCalendarInfoList.Count(); index++)
|
|
162 |
{
|
|
163 |
iCalendarStatus.Append(0);
|
|
164 |
|
|
165 |
if (!index) //First create the default session
|
|
166 |
{
|
|
167 |
const TPtrC name = iCalendarInfoList[index]->FileNameL();
|
|
168 |
defaultSession->OpenL(name);
|
|
169 |
iCalSessionArray.Append(defaultSession);
|
|
170 |
CCalEntryView* entryView = CCalEntryView::NewL(*defaultSession);
|
|
171 |
CleanupStack::PushL(entryView);
|
|
172 |
iCalEntryViewArray.Append(entryView);
|
|
173 |
CleanupStack::Pop(entryView);
|
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
CCalSession* session = CCalSession::NewL(*defaultSession);
|
|
178 |
CleanupStack::PushL(session);
|
|
179 |
const TPtrC name = iCalendarInfoList[index]->FileNameL();
|
|
180 |
session->OpenL(name);
|
|
181 |
CleanupStack::Pop(session);
|
|
182 |
iCalSessionArray.Append(session);
|
|
183 |
CCalEntryView* entryView = CCalEntryView::NewL(*session);
|
|
184 |
CleanupStack::PushL(entryView);
|
|
185 |
iCalEntryViewArray.Append(entryView);
|
|
186 |
CleanupStack::Pop(entryView);
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
iInterimUtils = CCalenInterimUtils2::NewL();
|
|
191 |
|
|
192 |
TRACE_EXIT_POINT;
|
|
193 |
}
|
|
194 |
|
|
195 |
// ----------------------------------------------------------------------------
|
|
196 |
// CMultiCalUiDialogModel::SetCalendarStatus
|
|
197 |
// Rest of the details are commented in header.
|
|
198 |
// ----------------------------------------------------------------------------
|
|
199 |
//
|
|
200 |
void CMultiCalUiDialogModel::SetCalendarStatus(TInt aIndex, TBool aStatus)
|
|
201 |
{
|
|
202 |
TRACE_ENTRY_POINT
|
|
203 |
__ASSERT_ALWAYS(aIndex >= 0,User::Invariant());
|
|
204 |
iCalendarStatus.Remove(aIndex);
|
|
205 |
iCalendarStatus.Insert(aStatus,aIndex);
|
|
206 |
TRACE_EXIT_POINT;
|
|
207 |
}
|
|
208 |
|
|
209 |
// ----------------------------------------------------------------------------
|
|
210 |
// CMultiCalUiDialogModel::GetCalendarStatus
|
|
211 |
// Rest of the details are commented in header.
|
|
212 |
// ----------------------------------------------------------------------------
|
|
213 |
//
|
|
214 |
TBool CMultiCalUiDialogModel::GetCalendarStatus(TInt aIndex)
|
|
215 |
{
|
|
216 |
TRACE_ENTRY_POINT
|
|
217 |
__ASSERT_ALWAYS(aIndex >= 0,User::Invariant());
|
|
218 |
TRACE_EXIT_POINT;
|
|
219 |
return iCalendarStatus[aIndex];
|
|
220 |
}
|
|
221 |
|
|
222 |
// ----------------------------------------------------------------------------
|
|
223 |
// CMultiCalUiDialogModel::MarkedCalendarsCount
|
|
224 |
// Rest of the details are commented in header.
|
|
225 |
// ----------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
TInt CMultiCalUiDialogModel::MarkedCalendarsCount()
|
|
228 |
{
|
|
229 |
TRACE_ENTRY_POINT
|
|
230 |
TInt count = NULL;
|
|
231 |
for (TInt i = 0; i < iCalendarStatus.Count(); i++)
|
|
232 |
{
|
|
233 |
if (iCalendarStatus[i])
|
|
234 |
{
|
|
235 |
count++;
|
|
236 |
}
|
|
237 |
}TRACE_EXIT_POINT;
|
|
238 |
return count;
|
|
239 |
}
|
|
240 |
|
|
241 |
// ----------------------------------------------------------------------------
|
|
242 |
// CMultiCalUiDialogModel::StoreCalEntryL
|
|
243 |
// Rest of the details are commented in header.
|
|
244 |
// ----------------------------------------------------------------------------
|
|
245 |
//
|
|
246 |
void CMultiCalUiDialogModel::StoreCalEntryL()
|
|
247 |
{
|
|
248 |
TRACE_ENTRY_POINT
|
|
249 |
//Create copy for entires.
|
|
250 |
RPointerArray<CCalEntry> copyEntries;
|
|
251 |
//Store the copy into calendars
|
|
252 |
for (TInt i = 0; i < iCalEntryViewArray.Count(); i++)
|
|
253 |
{
|
|
254 |
if (iCalendarStatus[i])
|
|
255 |
{
|
|
256 |
TInt numSuccess;
|
|
257 |
CreateCopyL(copyEntries);
|
|
258 |
iCalEntryViewArray[i]->StoreL(copyEntries, numSuccess);
|
|
259 |
copyEntries.ResetAndDestroy();
|
|
260 |
}
|
|
261 |
}
|
|
262 |
|
|
263 |
|
|
264 |
TRACE_EXIT_POINT;
|
|
265 |
}
|
|
266 |
|
|
267 |
// ----------------------------------------------------------------------------
|
|
268 |
// CMultiCalUiDialogModel::CreateCopyL
|
|
269 |
// Rest of the details are commented in header.
|
|
270 |
// ----------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
void CMultiCalUiDialogModel::CreateCopyL(
|
|
273 |
RPointerArray<CCalEntry>& aCalCopyEntries)
|
|
274 |
{
|
|
275 |
TRACE_ENTRY_POINT;
|
|
276 |
|
|
277 |
CleanupResetAndDestroyPushL(aCalCopyEntries);
|
|
278 |
for (TInt i = 0; i < iCalEntries.Count(); i++)
|
|
279 |
{
|
|
280 |
const CCalEntry* sourceEntry = iCalEntries[i];
|
|
281 |
|
|
282 |
HBufC8* guid = iInterimUtils->GlobalUidL();
|
|
283 |
CleanupStack::PushL(guid);
|
|
284 |
|
|
285 |
CCalEntry* copyEntry = CCalEntry::NewL(sourceEntry->EntryTypeL(),
|
|
286 |
guid, CCalEntry::EMethodNone, 0);
|
|
287 |
|
|
288 |
CleanupStack::Pop(guid); // ownership was passed
|
|
289 |
CleanupStack::PushL(copyEntry);
|
|
290 |
|
|
291 |
sourceEntry->DescriptionL(); // make sure entry is fully loaded
|
|
292 |
copyEntry->CopyFromL(*sourceEntry, CCalEntry::EDontCopyId);
|
|
293 |
copyEntry->DescriptionL(); // make sure entry is fully copied
|
|
294 |
|
|
295 |
aCalCopyEntries.AppendL(copyEntry);
|
|
296 |
|
|
297 |
CleanupStack::Pop(copyEntry);
|
|
298 |
}
|
|
299 |
CleanupStack::Pop(&aCalCopyEntries);
|
|
300 |
TRACE_EXIT_POINT;;
|
|
301 |
}
|
|
302 |
|
|
303 |
// ----------------------------------------------------------------------------
|
|
304 |
// CMultiCalUiDialogModel::GetAllCalendarInfoL
|
|
305 |
// Rest of the details are commented in header.
|
|
306 |
// ----------------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
void CMultiCalUiDialogModel::GetAllCalendarInfoL(RPointerArray<
|
|
309 |
CCalCalendarInfo>& aCalendarInfoList)
|
|
310 |
{
|
|
311 |
TRACE_ENTRY_POINT
|
|
312 |
|
|
313 |
if (!iCalendarsSession)
|
|
314 |
{
|
|
315 |
iCalendarsSession = CCalSession::NewL();
|
|
316 |
}
|
|
317 |
CCalCalendarIterator* calIter = CCalCalendarIterator::NewL(
|
|
318 |
*iCalendarsSession);
|
|
319 |
CleanupStack::PushL(calIter);
|
|
320 |
|
|
321 |
for( CCalCalendarInfo* calendarInfo = calIter->FirstL();
|
|
322 |
calendarInfo!=NULL;calendarInfo = calIter->NextL())
|
|
323 |
{
|
|
324 |
TBuf8<KBuffLength> keyBuff;
|
|
325 |
// Mark the meta property as SoftDeleted
|
|
326 |
keyBuff.Zero();
|
|
327 |
keyBuff.AppendNum(EMarkAsDelete);
|
|
328 |
TBool softDelete = EFalse;
|
|
329 |
TPckgC<TBool> pkgSoftDelete( softDelete );
|
|
330 |
TRAPD(err,pkgSoftDelete.Set(calendarInfo->PropertyValueL(keyBuff)));
|
|
331 |
if( KErrNone == err )
|
|
332 |
{
|
|
333 |
softDelete = pkgSoftDelete();
|
|
334 |
}
|
|
335 |
if(!softDelete)
|
|
336 |
{
|
|
337 |
aCalendarInfoList.Append(calendarInfo);
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
delete calendarInfo;
|
|
342 |
}
|
|
343 |
}
|
|
344 |
CleanupStack::PopAndDestroy(calIter);
|
|
345 |
|
|
346 |
TRACE_EXIT_POINT;
|
|
347 |
}
|
|
348 |
|
|
349 |
// end of file
|