author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:17:03 +0300 | |
branch | RCL_3 |
changeset 31 | 97232defd20e |
parent 30 | bd7edf625bdd |
permissions | -rw-r--r-- |
30 | 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: To handle Calendar Db filed |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// system includes |
|
19 |
#include <AknPopupField.h> |
|
20 |
#include <AknQueryValueText.h> |
|
21 |
#include <AknQueryDialog.h> |
|
22 |
#include <badesca.h> |
|
23 |
#include <calentry.h> |
|
24 |
#include <centralrepository.h> |
|
25 |
#include <CalenDefaultEditorsData.rsg> |
|
26 |
#include <calsession.h> |
|
27 |
#include <calencontext.h> |
|
28 |
#include <caleninstanceid.h> // TCalenInstanceId |
|
29 |
#include <calenservices.h> |
|
30 |
#include <calcalendarinfo.h> |
|
31 |
||
32 |
// user includes |
|
33 |
#include "calendbfield.h" |
|
34 |
#include "CalenDefaultEditors.hrh" |
|
35 |
#include "calenunifiededitor.h" |
|
36 |
#include "CalendarPrivateCRKeys.h" |
|
37 |
#include "CleanupResetAndDestroy.h" |
|
38 |
#include "calendarui_debug.h" |
|
39 |
||
40 |
||
41 |
// ----------------------------------------------------------------------------- |
|
42 |
// CCalenDbField::NewL |
|
43 |
// First Phase constuctor |
|
44 |
// ----------------------------------------------------------------------------- |
|
45 |
// |
|
46 |
CCalenDbField* CCalenDbField::NewL( CCalenUnifiedEditor& aUnifiedEditor,MCalenServices& aServices ) |
|
47 |
{ |
|
48 |
TRACE_ENTRY_POINT; |
|
49 |
||
50 |
CCalenDbField* self = |
|
51 |
new( ELeave ) CCalenDbField( aUnifiedEditor, aServices ); |
|
52 |
CleanupStack::PushL( self ); |
|
53 |
self->ConstructL(); |
|
54 |
CleanupStack::Pop(); |
|
55 |
||
56 |
TRACE_EXIT_POINT; |
|
57 |
return self; |
|
58 |
} |
|
59 |
||
60 |
// ----------------------------------------------------------------------------- |
|
61 |
// CCalenDbField::CCalenDbField |
|
62 |
// C++ constructor |
|
63 |
// ----------------------------------------------------------------------------- |
|
64 |
// |
|
65 |
CCalenDbField::CCalenDbField( CCalenUnifiedEditor& aUnifiedEditor,MCalenServices& aServices ) |
|
66 |
: iUnifiedEditor( aUnifiedEditor ), |
|
67 |
iServices(&aServices) |
|
68 |
{ |
|
69 |
TRACE_ENTRY_POINT; |
|
70 |
TRACE_EXIT_POINT; |
|
71 |
} |
|
72 |
||
73 |
// ----------------------------------------------------------------------------- |
|
74 |
// CCalenDbField::ConstructL |
|
75 |
// second phase constructor |
|
76 |
// ----------------------------------------------------------------------------- |
|
77 |
// |
|
78 |
void CCalenDbField::ConstructL() |
|
79 |
{ |
|
80 |
TRACE_ENTRY_POINT; |
|
81 |
||
82 |
//Get MultipleDbInfo array |
|
83 |
RPointerArray<CCalCalendarInfo> calendarInfoList; |
|
84 |
iServices->GetAllCalendarInfoL(calendarInfoList); |
|
85 |
CleanupClosePushL( calendarInfoList ); |
|
86 |
||
87 |
iDbNamesArrayText = new ( ELeave ) CDesCArrayFlat( calendarInfoList.Count()+1 ); |
|
88 |
||
89 |
for(TInt i=0 ; i < calendarInfoList.Count();i++ ) |
|
90 |
{ |
|
91 |
HBufC* calendarName=( *calendarInfoList[i] ).NameL().AllocLC(); |
|
92 |
iDbNamesArrayText->AppendL( *calendarName ); |
|
93 |
CleanupStack::PopAndDestroy( calendarName ); |
|
94 |
} |
|
95 |
CleanupStack::PopAndDestroy( &calendarInfoList ); |
|
96 |
||
97 |
// create textarray |
|
98 |
iDbNamesArray = CAknQueryValueTextArray::NewL(); |
|
99 |
iDbNamesArray->SetArray( *iDbNamesArrayText ); |
|
100 |
||
101 |
iDbNamesTextValues = CAknQueryValueText::NewL(); |
|
102 |
iDbNamesTextValues->SetArrayL( iDbNamesArray ); |
|
103 |
||
104 |
TRACE_EXIT_POINT; |
|
105 |
} |
|
106 |
||
107 |
// ----------------------------------------------------------------------------- |
|
108 |
// CCalenDbField::~CCalenDbField |
|
109 |
// (other items were commented in a header). |
|
110 |
// ----------------------------------------------------------------------------- |
|
111 |
// |
|
112 |
CCalenDbField::~CCalenDbField() |
|
113 |
{ |
|
114 |
TRACE_ENTRY_POINT; |
|
115 |
||
116 |
if( iAsyncDBquery ) |
|
117 |
{ |
|
118 |
iAsyncDBquery->Cancel(); |
|
119 |
delete iAsyncDBquery; |
|
120 |
iAsyncDBquery = NULL; |
|
121 |
} |
|
122 |
||
123 |
delete iDbNamesArrayText; |
|
124 |
delete iDbNamesArray; |
|
125 |
delete iDbNamesTextValues; |
|
126 |
delete iCalendarFileName; |
|
127 |
||
128 |
TRACE_EXIT_POINT; |
|
129 |
} |
|
130 |
||
131 |
// ----------------------------------------------------------------------------- |
|
132 |
// CCalenDbField::InitDbFieldLayoutL |
|
133 |
// Updates fields just before the form is shown. |
|
134 |
// ----------------------------------------------------------------------------- |
|
135 |
// |
|
136 |
void CCalenDbField::InitDbFieldLayoutL() |
|
137 |
{ |
|
138 |
TRACE_ENTRY_POINT; |
|
139 |
||
140 |
CAknPopupField* pops = |
|
141 |
static_cast<CAknPopupField*>( iUnifiedEditor.Control( ECalenEditorDBName ) ); |
|
142 |
pops->SetQueryValueL( iDbNamesTextValues ); |
|
143 |
||
144 |
TRACE_EXIT_POINT; |
|
145 |
} |
|
146 |
||
147 |
// ----------------------------------------------------------------------------- |
|
148 |
// CCalenDbField::SetDataToEditorL |
|
149 |
// update data in form |
|
150 |
// ----------------------------------------------------------------------------- |
|
151 |
// |
|
152 |
void CCalenDbField::SetDataToEditorL() |
|
153 |
{ |
|
154 |
TRACE_ENTRY_POINT; |
|
155 |
//Get MultipleDbInfo array |
|
156 |
RPointerArray<CCalCalendarInfo> calendarInfoList; |
|
157 |
iServices->GetAllCalendarInfoL(calendarInfoList); |
|
158 |
CleanupClosePushL(calendarInfoList); |
|
159 |
||
160 |
TInt index = KErrNotFound; |
|
161 |
if (iUnifiedEditor.IsCreatingNewEntry()) |
|
162 |
{ |
|
163 |
TBuf<KMaxFileName> lastUsedCalendar; |
|
164 |
CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); |
|
165 |
User::LeaveIfError(cenRep->Get(KCalendarLastUsedCalendar, |
|
166 |
lastUsedCalendar)); |
|
167 |
||
168 |
HBufC* name = lastUsedCalendar.AllocLC(); |
|
169 |
index = calendarInfoList.Find(*name, |
|
170 |
CCalenDbField::CalendarInfoNameIdentifierL); |
|
171 |
||
172 |
if (KErrNotFound == index) |
|
173 |
{ |
|
174 |
User::LeaveIfError(cenRep->Set(KCalendarLastUsedCalendar, |
|
175 |
name->Des())); |
|
176 |
} |
|
177 |
||
178 |
CleanupStack::PopAndDestroy(name); |
|
179 |
CleanupStack::PopAndDestroy(cenRep); |
|
180 |
} |
|
181 |
else |
|
182 |
{ |
|
183 |
TCalCollectionId colId = iServices->Context().InstanceId().iColId; |
|
184 |
HBufC* calendarFileName= iServices->GetCalFileNameForCollectionId(colId).AllocLC(); |
|
185 |
index = calendarInfoList.Find(*calendarFileName, |
|
186 |
CCalenDbField::CalendarInfoNameIdentifierL); |
|
187 |
CleanupStack::PopAndDestroy(calendarFileName); |
|
188 |
} |
|
189 |
||
190 |
if (index != KErrNotFound) |
|
191 |
{ |
|
192 |
iDbNamesTextValues->SetCurrentValueIndex(index); |
|
193 |
} |
|
194 |
||
195 |
if (KErrNotFound == index) |
|
196 |
{ |
|
197 |
iDbNamesTextValues->SetCurrentValueIndex(0); |
|
198 |
} |
|
199 |
||
200 |
TInt pos = iDbNamesTextValues->CurrentValueIndex(); |
|
201 |
HBufC* calendarFileName = calendarInfoList[pos]->FileNameL().AllocLC(); |
|
202 |
iPreviousColId = iCurrentColId |
|
203 |
= iServices->SessionL(*calendarFileName).CollectionIdL(); |
|
204 |
CleanupStack::PopAndDestroy(calendarFileName); |
|
205 |
||
206 |
iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL( |
|
207 |
IsCalendarEdited(), iPreviousColId, iCurrentColId); |
|
208 |
||
209 |
CleanupStack::PopAndDestroy(&calendarInfoList); |
|
210 |
||
211 |
TRACE_EXIT_POINT; |
|
212 |
} |
|
213 |
||
214 |
// ----------------------------------------------------------------------------- |
|
215 |
// CCalenDbField::SetDataToEditorL |
|
216 |
// update data in form |
|
217 |
// ----------------------------------------------------------------------------- |
|
218 |
// |
|
219 |
void CCalenDbField::SetDataToEditorL(const TCalCollectionId& aColId) |
|
220 |
{ |
|
221 |
TRACE_ENTRY_POINT; |
|
222 |
//Get MultipleDbInfo array |
|
223 |
RPointerArray<CCalCalendarInfo> calendarInfoList; |
|
224 |
iServices->GetAllCalendarInfoL(calendarInfoList); |
|
225 |
CleanupClosePushL(calendarInfoList); |
|
226 |
||
227 |
TInt index = KErrNotFound; |
|
228 |
||
229 |
HBufC* calendarFileName= iServices->GetCalFileNameForCollectionId(aColId).AllocLC(); |
|
230 |
index = calendarInfoList.Find(*calendarFileName, CCalenDbField::CalendarInfoNameIdentifierL); |
|
231 |
CleanupStack::PopAndDestroy(calendarFileName); |
|
232 |
||
233 |
if (KErrNotFound == index) |
|
234 |
{ |
|
235 |
iDbNamesTextValues->SetCurrentValueIndex(0); |
|
236 |
} |
|
237 |
else |
|
238 |
{ |
|
239 |
iDbNamesTextValues->SetCurrentValueIndex(index); |
|
240 |
} |
|
241 |
iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL( |
|
242 |
IsCalendarEdited(), iPreviousColId, iCurrentColId); |
|
243 |
||
244 |
CleanupStack::PopAndDestroy(&calendarInfoList); |
|
245 |
||
246 |
TRACE_EXIT_POINT; |
|
247 |
} |
|
248 |
||
249 |
// ----------------------------------------------------------------------------- |
|
250 |
// CCalenDbField::HandleControlStateChangeL |
|
251 |
// (other items were commented in a header). |
|
252 |
// ----------------------------------------------------------------------------- |
|
253 |
// |
|
254 |
void CCalenDbField::HandleControlStateChangeL( TInt aControlId ) |
|
255 |
{ |
|
256 |
TRACE_ENTRY_POINT; |
|
257 |
||
258 |
switch(aControlId) |
|
259 |
{ |
|
260 |
case ECalenEditorDBName: |
|
261 |
{ |
|
262 |
TBool continueOnError = EFalse; |
|
263 |
ReadDataFromFormL( continueOnError ); |
|
264 |
iUnifiedEditor.EditorDataHandler().SetCalendarFieldEditedL(IsCalendarEdited() |
|
265 |
,iPreviousColId,iCurrentColId); |
|
266 |
||
31
97232defd20e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
267 |
|
97232defd20e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
268 |
if(!iAsyncDBquery) |
97232defd20e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
269 |
{ |
30 | 270 |
TCallBack callback(DoAsyncShowChangeDBQueryL,this); |
271 |
iAsyncDBquery = new(ELeave) CAsyncCallBack(callback,CActive::EPriorityStandard); |
|
31
97232defd20e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
272 |
} |
97232defd20e
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
273 |
|
30 | 274 |
iAsyncDBquery->CallBack(); |
275 |
break; |
|
276 |
} |
|
277 |
default: |
|
278 |
break; |
|
279 |
} |
|
280 |
||
281 |
TRACE_EXIT_POINT; |
|
282 |
} |
|
283 |
||
284 |
// ---------------------------------------------------------------------------- |
|
285 |
// CallBackForShowinginfonote |
|
286 |
// (other items were commented in a header). |
|
287 |
// ---------------------------------------------------------------------------- |
|
288 |
// |
|
289 |
TInt CCalenDbField::DoAsyncShowChangeDBQueryL(TAny* aThisPtr) |
|
290 |
{ |
|
291 |
TRACE_ENTRY_POINT |
|
292 |
CCalenDbField* self = static_cast<CCalenDbField*>(aThisPtr); |
|
293 |
if(self) |
|
294 |
{ |
|
295 |
self->ShowChangeDBQueryL(); |
|
296 |
} |
|
297 |
TRACE_EXIT_POINT |
|
298 |
return 0; |
|
299 |
} |
|
300 |
||
301 |
// ----------------------------------------------------------------------------- |
|
302 |
// CCalenDbField::ReadDataFromFormL |
|
303 |
// (other items were commented in a header). |
|
304 |
// ----------------------------------------------------------------------------- |
|
305 |
// |
|
306 |
void CCalenDbField::ReadDataFromFormL( TBool /*aContinueOnError*/ ) |
|
307 |
{ |
|
308 |
TRACE_ENTRY_POINT; |
|
309 |
||
310 |
RPointerArray<CCalCalendarInfo> calendarInfoList; |
|
311 |
iServices->GetAllCalendarInfoL(calendarInfoList); |
|
312 |
CleanupClosePushL( calendarInfoList ); |
|
313 |
TInt pos; |
|
314 |
if( calendarInfoList.Count() == 1 ) |
|
315 |
{ |
|
316 |
pos = 0; |
|
317 |
} |
|
318 |
else |
|
319 |
{ |
|
320 |
pos = iDbNamesTextValues->CurrentValueIndex(); |
|
321 |
} |
|
322 |
||
323 |
HBufC* calendarFileName = calendarInfoList[pos]->FileNameL().AllocLC(); |
|
324 |
iCurrentColId = iServices->SessionL(*calendarFileName).CollectionIdL(); |
|
325 |
CleanupStack::PopAndDestroy(calendarFileName); |
|
326 |
CleanupStack::PopAndDestroy( &calendarInfoList ); |
|
327 |
||
328 |
TRACE_EXIT_POINT; |
|
329 |
} |
|
330 |
||
331 |
// ----------------------------------------------------------------------------- |
|
332 |
// CCalenDbField::PrepareForFocusTransitionL |
|
333 |
// (other items were commented in a header). |
|
334 |
// ----------------------------------------------------------------------------- |
|
335 |
// |
|
336 |
void CCalenDbField::PrepareForFocusTransitionL( TInt aFocusedId ) |
|
337 |
{ |
|
338 |
TRACE_ENTRY_POINT; |
|
339 |
||
340 |
switch(aFocusedId) |
|
341 |
{ |
|
342 |
case ECalenEditorDBName: |
|
343 |
{ |
|
344 |
TBool continueOnError = EFalse; |
|
345 |
ReadDataFromFormL( continueOnError ); |
|
346 |
break; |
|
347 |
} |
|
348 |
default: |
|
349 |
break; |
|
350 |
} |
|
351 |
TRACE_EXIT_POINT; |
|
352 |
} |
|
353 |
||
354 |
// ----------------------------------------------------------------------------- |
|
355 |
// CCalenDbField::GetCalendarIndexForEntryL |
|
356 |
// (other items were commented in a header). |
|
357 |
// ----------------------------------------------------------------------------- |
|
358 |
// |
|
359 |
TInt CCalenDbField::GetCalendarIndexForEntryL() |
|
360 |
{ |
|
361 |
TRACE_ENTRY_POINT; |
|
362 |
TRACE_EXIT_POINT; |
|
363 |
return iDbNamesTextValues->CurrentValueIndex();; |
|
364 |
} |
|
365 |
||
366 |
// ----------------------------------------------------------------------------- |
|
367 |
// CCalenDbField::GetCalendarNameForEntryL |
|
368 |
// get calendar name for the entry |
|
369 |
// ----------------------------------------------------------------------------- |
|
370 |
// |
|
371 |
const TDesC& CCalenDbField::GetCalendarNameForEntryL() |
|
372 |
{ |
|
373 |
TRACE_ENTRY_POINT |
|
374 |
||
375 |
if(iCalendarFileName) |
|
376 |
{ |
|
377 |
delete iCalendarFileName; |
|
378 |
iCalendarFileName = NULL; |
|
379 |
} |
|
380 |
||
381 |
RPointerArray<CCalCalendarInfo> calendarInfoList; |
|
382 |
iServices->GetAllCalendarInfoL(calendarInfoList); |
|
383 |
CleanupClosePushL( calendarInfoList ); |
|
384 |
TInt pos = iDbNamesTextValues->CurrentValueIndex(); |
|
385 |
iCalendarFileName = calendarInfoList[pos]->FileNameL().AllocL(); |
|
386 |
CleanupStack::PopAndDestroy( &calendarInfoList ); |
|
387 |
||
388 |
TRACE_EXIT_POINT |
|
389 |
return *iCalendarFileName; |
|
390 |
} |
|
391 |
||
392 |
// ----------------------------------------------------------------------------- |
|
393 |
// CCalenDbField::GetCalendarNameForEntryL |
|
394 |
// get calendar index for the entry |
|
395 |
// ----------------------------------------------------------------------------- |
|
396 |
// |
|
397 |
TInt CCalenDbField::GetCalendarNameForEntryL(const TDesC& aCalendarFileName) |
|
398 |
{ |
|
399 |
TRACE_ENTRY_POINT |
|
400 |
__impl_prints(_L("CCalenDbField::GetCalendarNameForEntryL 2-- start")); |
|
401 |
HBufC* calendarFilename = aCalendarFileName.AllocLC(); |
|
402 |
RPointerArray<CCalCalendarInfo> calendarInfoList; |
|
403 |
iServices->GetAllCalendarInfoL(calendarInfoList); |
|
404 |
CleanupClosePushL( calendarInfoList ); |
|
405 |
__impl_prints(_L("CCalenDbField::GetCalendarNameForEntryL -- GetAllCalendarInfoL")); |
|
406 |
TInt index = calendarInfoList.Find(*calendarFilename, |
|
407 |
CCalenDbField::CalendarInfoNameIdentifierL); |
|
408 |
__impl_print(_L("CCalenDbField::GetCalendarNameForEntryL 2 -- index = %d"),index); |
|
409 |
CleanupStack::PopAndDestroy(calendarFilename); |
|
410 |
CleanupStack::PopAndDestroy( &calendarInfoList ); |
|
411 |
||
412 |
TRACE_EXIT_POINT |
|
413 |
return index; |
|
414 |
} |
|
415 |
||
416 |
// ----------------------------------------------------------------------------- |
|
417 |
// CCalenDbField::IsCalendarEdited |
|
418 |
// (other items were commented in a header). |
|
419 |
// ----------------------------------------------------------------------------- |
|
420 |
// |
|
421 |
TBool CCalenDbField::IsCalendarEdited() |
|
422 |
{ |
|
423 |
TRACE_ENTRY_POINT |
|
424 |
TRACE_EXIT_POINT |
|
425 |
return (iPreviousColId != iCurrentColId); |
|
426 |
} |
|
427 |
||
428 |
// ----------------------------------------------------------------------------- |
|
429 |
// CCalenDbField::CalendarInfoNameIdentifierL |
|
430 |
// (other items were commented in a header). |
|
431 |
// ----------------------------------------------------------------------------- |
|
432 |
// |
|
433 |
TBool CCalenDbField::CalendarInfoNameIdentifierL( const HBufC* aName, |
|
434 |
const CCalCalendarInfo& aInfoItem ) |
|
435 |
{ |
|
436 |
TRACE_ENTRY_POINT; |
|
437 |
TPtrC calendarFileName = aInfoItem.FileNameL(); |
|
438 |
TRACE_EXIT_POINT; |
|
439 |
return (!calendarFileName.CompareF(*aName)); |
|
440 |
} |
|
441 |
// ----------------------------------------------------------------------------- |
|
442 |
// CCalenDbField::ShowChangeDBQueryL |
|
443 |
// (other items were commented in a header). |
|
444 |
// ----------------------------------------------------------------------------- |
|
445 |
// |
|
446 |
void CCalenDbField::ShowChangeDBQueryL() |
|
447 |
{ |
|
448 |
||
449 |
//Check the child entries for the repeated entry |
|
450 |
//The entry which is changing the calendar having any childs |
|
451 |
//show this information note to the user. |
|
452 |
CCalEntry& originalEntry = iUnifiedEditor.EditorDataHandler().Entry(); |
|
453 |
RPointerArray<CCalEntry> childEntries; |
|
454 |
CleanupResetAndDestroyPushL(childEntries); |
|
455 |
iServices->EntryViewL(iPreviousColId)->FetchL(originalEntry.UidL(), childEntries); |
|
456 |
if(IsCalendarEdited() && (childEntries.Count() > 1)) |
|
457 |
{ |
|
458 |
TCalCollectionId currentId = iCurrentColId; |
|
459 |
SetDataToEditorL(); |
|
460 |
iUnifiedEditor.UpdateFormL(); |
|
461 |
CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
462 |
if( dlg->ExecuteLD( R_CALEN_DB_CHANGE_QUERY ) ) |
|
463 |
{ |
|
464 |
iCurrentColId = currentId; |
|
465 |
SetDataToEditorL(iCurrentColId); |
|
466 |
iUnifiedEditor.UpdateFormL(); |
|
467 |
} |
|
468 |
} |
|
469 |
CleanupStack::PopAndDestroy( &childEntries ); |
|
470 |
} |
|
471 |
// End of File |