|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <cntdb.h>//For Math |
|
21 |
|
22 #include "creator_model.h" |
|
23 #include "creator_traces.h" |
|
24 #include "creator_factory.h" |
|
25 #include "creator_scriptparser.h" |
|
26 #include "creator_appui.h" |
|
27 #include "creator_app.h" // KUidCreatorApp |
|
28 #include "creator_file.h" |
|
29 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
30 #include "creator_contactsetcache.h" |
|
31 #endif |
|
32 |
|
33 #include <apparc.h> |
|
34 #include <eikappui.h> |
|
35 #include <eikapp.h> |
|
36 #include <bitmaptransforms.h> |
|
37 |
|
38 _LIT(KTempPathDrive, "d"); |
|
39 _LIT(KTempPath, ":\\Creator\\"); |
|
40 _LIT(KSavingText, "Saving"); |
|
41 _LIT(KDeletingText, "Deleting"); |
|
42 const TInt KRegisterDrive = EDriveC; |
|
43 _LIT(KRegisterFileName, "creator_created_items.dat"); |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 |
|
48 CCreatorEngine* CCreatorEngine::NewL(CCreatorAppUi* aAppUi) |
|
49 { |
|
50 LOGSTRING("Creator: CCreatorEngine::NewL"); |
|
51 CCreatorEngine* self = new(ELeave) CCreatorEngine; |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(aAppUi); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 |
|
60 CCreatorEngine::CCreatorEngine() |
|
61 : |
|
62 CActive(0) |
|
63 {} |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 |
|
67 void CCreatorEngine::ConstructL(CCreatorAppUi* aAppUi) |
|
68 { |
|
69 LOGSTRING("Creator: CCreatorEngine::ConstructL"); |
|
70 |
|
71 iEnv = CEikonEnv::Static(); |
|
72 User::LeaveIfError(iTimer.CreateLocal()); |
|
73 |
|
74 iAppUi = aAppUi; |
|
75 |
|
76 // these are needed by the random data generator |
|
77 TTime now; |
|
78 now.HomeTime(); |
|
79 iSeed=now.Int64(); |
|
80 |
|
81 iTempPath = HBufC::NewL(KTempPathDrive().Length() + KTempPath().Length()); |
|
82 iTempPath->Des().Copy(KTempPathDrive); |
|
83 iTempPath->Des().Append(KTempPath); |
|
84 |
|
85 GetRandomDataFromFileL(KNullDesC); |
|
86 |
|
87 CActiveScheduler::Add(this); |
|
88 |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 |
|
93 CCreatorEngine::~CCreatorEngine() |
|
94 { |
|
95 LOGSTRING("Creator: CCreatorEngine::~CCreatorEngine"); |
|
96 |
|
97 Cancel(); |
|
98 |
|
99 for( TInt i = 0; i < iStringArrays.Count(); ++i ) |
|
100 { |
|
101 delete iStringArrays[i].iArrayPtr; |
|
102 } |
|
103 iStringArrays.Close(); |
|
104 iAllocatedFilePaths.ResetAndDestroy(); |
|
105 iAllocatedFilePaths.Close(); |
|
106 iTimer.Close(); |
|
107 |
|
108 delete iPictureFileArray; |
|
109 delete iSoundFileArray; |
|
110 delete iTempPath; |
|
111 delete iFrameImageData; |
|
112 delete iEncoder; |
|
113 delete iScaler; |
|
114 delete iDecoder; |
|
115 delete iScaledBitmap; |
|
116 delete iBitmap; |
|
117 delete iBitmapData; |
|
118 } |
|
119 |
|
120 void CCreatorEngine::CopyFileL(const TFileName& aSourceFile, const TFileName& aTargetFile, TBool aOverwrite ) |
|
121 { |
|
122 if( !aOverwrite && ConeUtils::FileExists(aTargetFile)) |
|
123 { |
|
124 // File already exists |
|
125 return; |
|
126 } |
|
127 |
|
128 // Make sure that the path exists. Creates the directory if it does not exist already: |
|
129 ConeUtils::EnsurePathExistsL(aTargetFile); |
|
130 User::LeaveIfError(BaflUtils::CopyFile(CEikonEnv::Static()->FsSession(), aSourceFile, aTargetFile)); |
|
131 } |
|
132 // --------------------------------------------------------------------------- |
|
133 |
|
134 void CCreatorEngine::ExecuteFirstCommandL(const TDesC& aText) |
|
135 { |
|
136 LOGSTRING("Creator: CCreatorEngine::ExecuteFirstCommand"); |
|
137 |
|
138 // init the progress bar |
|
139 iProgressDialog = new(ELeave)CAknProgressDialog((reinterpret_cast<CEikDialog**>(&iProgressDialog)), ETrue); |
|
140 iProgressDialog->SetCallback(this); |
|
141 iProgressDialog->PrepareLC(R_PROGRESS_NOTE); |
|
142 iProgressDialog->SetCurrentLabelL( EAknCtNote, aText ); |
|
143 iProgressInfo = iProgressDialog->GetProgressInfoL(); |
|
144 iProgressInfo->SetFinalValue( CommandArrayCount() ); |
|
145 iProgressDialog->RunLD(); |
|
146 iProgressDialog->MakeVisible( ETrue ); |
|
147 |
|
148 iFailedCommands = 0; |
|
149 |
|
150 // starts executing commands |
|
151 ExecuteCommand(); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 |
|
156 void CCreatorEngine::ExecuteCommand() |
|
157 { |
|
158 LOGSTRING("Creator: CCreatorEngine::ExecuteCommand"); |
|
159 |
|
160 // make sure the engine isn't active, should never happen |
|
161 __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("IsActive"), 500)); |
|
162 |
|
163 // execute a command after a very short delay (75ms) |
|
164 iTimer.After(iStatus, 75); |
|
165 SetActive(); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 |
|
170 void CCreatorEngine::RunL() |
|
171 { |
|
172 LOGSTRING("Creator: CCreatorEngine::RunL"); |
|
173 LOGSTRING2("Creator: CCreatorEngine::RunL iCommandId=%d", iCommandArray->At(iCurrentEntry).iCommandId); |
|
174 |
|
175 if ( iUserCancelled ) return; |
|
176 |
|
177 if (!iCommandArray->At(iCurrentEntry).iParameters) |
|
178 { |
|
179 LOGSTRING("Creator: CCreatorEngine::RunL - iParameters==NULL !"); |
|
180 } |
|
181 |
|
182 // launch a command |
|
183 |
|
184 TCreatorIds cmd = (TCreatorIds)iCommandArray->At(iCurrentEntry).iCommandId; |
|
185 switch( cmd ) |
|
186 { |
|
187 case ECmdCreateBrowserBookmarkEntries: { iBrowser->CreateBookmarkEntryL(reinterpret_cast<CBrowserParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
188 case ECmdCreateBrowserBookmarkFolderEntries: { iBrowser->CreateBookmarkFolderEntryL(reinterpret_cast<CBrowserParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
189 case ECmdCreateBrowserSavedPageEntries: { iBrowser->CreateSavedDeckEntryL(reinterpret_cast<CBrowserParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
190 case ECmdCreateBrowserSavedPageFolderEntries: { iBrowser->CreateSavedDeckFolderEntryL(reinterpret_cast<CBrowserParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
191 |
|
192 case ECmdCreateCalendarEntryAppointments: { iCalendar->CreateAppointmentEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
193 case ECmdCreateCalendarEntryEvents: { iCalendar->CreateEventEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
194 case ECmdCreateCalendarEntryAnniversaries: { iCalendar->CreateAnniversaryEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
195 case ECmdCreateCalendarEntryToDos: { iCalendar->CreateTodoEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
196 case ECmdCreateCalendarEntryReminders: { iCalendar->CreateReminderEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
197 |
|
198 |
|
199 case ECmdCreatePhoneBookEntryContacts: { iPhonebook->CreateContactEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
200 case ECmdCreatePhoneBookEntryGroups: { iPhonebook->CreateGroupEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
201 case ECmdCreatePhoneBookEntrySubscribedContacts: { iPhonebook->CreateSubscribedContactEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
202 |
|
203 case ECmdCreateMiscEntryNotes: { iNotepad->CreateNoteEntryL(reinterpret_cast<CNotepadParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
204 |
|
205 case ECmdCreateLogEntryMissedCalls: { iLogs->CreateMissedCallEntryL(reinterpret_cast<CLogsParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
206 case ECmdCreateLogEntryReceivedCalls: { iLogs->CreateReceivedCallEntryL(reinterpret_cast<CLogsParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
207 case ECmdCreateLogEntryDialledNumbers: { iLogs->CreateDialledNumberEntryL(reinterpret_cast<CLogsParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
208 |
|
209 case ECmdCreateMiscEntryAccessPoints: { iAccessPoints->CreateConnectionSettingsEntryL(iCommandArray->At(iCurrentEntry).iParameters); } break; |
|
210 case ECmdDeleteIAPs: { iAccessPoints->DeleteAllL(); } break; |
|
211 case ECmdDeleteCreatorIAPs: { iAccessPoints->DeleteAllCreatedByCreatorL(); } break; |
|
212 |
|
213 case ECmdCreateMiscEntryLandmarks: { iLandmarks->CreateLandmarkEntryL(reinterpret_cast<CLandmarkParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
214 |
|
215 case ECmdCreateMessagingEntryMailboxes: { iMailboxes->CreateMailboxEntryL(reinterpret_cast<CMailboxesParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
216 |
|
217 #ifdef __PRESENCE |
|
218 case ECmdCreateMiscEntryIMPSServers: { iIMPS->CreateIMPSServerEntryL(reinterpret_cast<CIMPSParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
219 #endif |
|
220 |
|
221 case ECmdCreateMessagingEntryMessages: { iMessages->CreateMessageEntryL(reinterpret_cast<CMessagesParameters*>(iCommandArray->At(iCurrentEntry).iParameters), ETrue); } break; |
|
222 case ECmdCreateMessagingEntryMessagesViaScript: { iMessages->CreateMessageEntryL(reinterpret_cast<CMessagesParameters*>(iCommandArray->At(iCurrentEntry).iParameters)); } break; |
|
223 |
|
224 case ECmdCreateRandomEntrySMSInbox: |
|
225 case ECmdCreateRandomEntrySMSDrafts: |
|
226 case ECmdCreateRandomEntrySMSOutbox: |
|
227 case ECmdCreateRandomEntrySMSSent: |
|
228 case ECmdCreateRandomEntryMMSInbox: |
|
229 case ECmdCreateRandomEntryMMSDrafts: |
|
230 case ECmdCreateRandomEntryMMSOutbox: |
|
231 case ECmdCreateRandomEntryMMSSent: |
|
232 case ECmdCreateRandomEntryAMSInbox: |
|
233 case ECmdCreateRandomEntryAMSDrafts: |
|
234 case ECmdCreateRandomEntryAMSOutbox: |
|
235 case ECmdCreateRandomEntryAMSSent: |
|
236 case ECmdCreateRandomEntryEmailInbox: |
|
237 case ECmdCreateRandomEntryEmailDrafts: |
|
238 case ECmdCreateRandomEntryEmailOutbox: |
|
239 case ECmdCreateRandomEntryEmailSent: |
|
240 case ECmdCreateRandomEntryBIOInbox: |
|
241 case ECmdCreateRandomEntryBIODrafts: |
|
242 case ECmdCreateRandomEntryBIOOutbox: |
|
243 case ECmdCreateRandomEntryBIOSent: |
|
244 case ECmdCreateRandomEntryIRInbox: |
|
245 case ECmdCreateRandomEntryIRDrafts: |
|
246 case ECmdCreateRandomEntryIROutbox: |
|
247 case ECmdCreateRandomEntryIRSent: |
|
248 case ECmdCreateRandomEntryBTInbox: |
|
249 case ECmdCreateRandomEntryBTDrafts: |
|
250 case ECmdCreateRandomEntryBTOutbox: |
|
251 case ECmdCreateRandomEntryBTSent: |
|
252 { iMessages->CreateRandomMessageEntryL(iCommandArray->At(iCurrentEntry).iCommandId); } break; |
|
253 |
|
254 case ECmdCreateFileEntryEmptyFolder: |
|
255 case ECmdCreateFileEntry3GPP_70kB: |
|
256 case ECmdCreateFileEntryAAC_100kB: |
|
257 case ECmdCreateFileEntryAMR_20kB: |
|
258 case ECmdCreateFileEntryBMP_25kB: |
|
259 case ECmdCreateFileEntryDeck_1kB: |
|
260 case ECmdCreateFileEntryDOC_20kB: |
|
261 case ECmdCreateFileEntryGIF_2kB: |
|
262 case ECmdCreateFileEntryHTML_20kB: |
|
263 case ECmdCreateFileEntryJAD_1kB: |
|
264 case ECmdCreateFileEntryJAR_10kB: |
|
265 case ECmdCreateFileEntryJP2_65kB: |
|
266 case ECmdCreateFileEntryJPEG_200kB: |
|
267 case ECmdCreateFileEntryJPEG_25kB: |
|
268 case ECmdCreateFileEntryJPEG_500kB: |
|
269 case ECmdCreateFileEntryMIDI_10kB: |
|
270 case ECmdCreateFileEntryMP3_250kB: |
|
271 case ECmdCreateFileEntryMP4_200kB: |
|
272 case ECmdCreateFileEntryMXMF_40kB: |
|
273 case ECmdCreateFileEntryPNG_15kB: |
|
274 case ECmdCreateFileEntryPPT_40kB: |
|
275 case ECmdCreateFileEntryRAM_1kB: |
|
276 case ECmdCreateFileEntryRM_95kB: |
|
277 case ECmdCreateFileEntryRNG_1kB: |
|
278 case ECmdCreateFileEntrySVG_15kB: |
|
279 case ECmdCreateFileEntrySWF_15kB: |
|
280 case ECmdCreateFileEntryTIF_25kB: |
|
281 case ECmdCreateFileEntryTXT_10kB: |
|
282 case ECmdCreateFileEntryTXT_70kB: |
|
283 case ECmdCreateFileEntryVCF_1kB: |
|
284 case ECmdCreateFileEntryVCS_1kB: |
|
285 case ECmdCreateFileEntryWAV_20kB: |
|
286 case ECmdCreateFileEntryXLS_15kB: |
|
287 case ECmdCreateFileEntrySISX_10kB: |
|
288 case ECmdCreateFileEntryWMA_50kB: |
|
289 case ECmdCreateFileEntryWMV_200kB: |
|
290 { iFiles->CreateFileEntryL( reinterpret_cast<CFilesParameters*>(iCommandArray->At(iCurrentEntry).iParameters), iCommandArray->At(iCurrentEntry).iCommandId ); } break; |
|
291 case ECmdDeleteContacts: |
|
292 { |
|
293 iPhonebook->DeleteAllL(); |
|
294 break; |
|
295 } |
|
296 case ECmdDeleteContactGroups: |
|
297 { |
|
298 iPhonebook->DeleteAllGroupsL(); |
|
299 break; |
|
300 } |
|
301 case ECmdDeleteCreatorContacts: |
|
302 { |
|
303 iPhonebook->DeleteAllCreatedByCreatorL(); |
|
304 break; |
|
305 } |
|
306 case ECmdDeleteCreatorContactGroups: |
|
307 { |
|
308 iPhonebook->DeleteAllGroupsCreatedByCreatorL(); |
|
309 break; |
|
310 } |
|
311 case ECmdDeleteCalendarEntries: |
|
312 { |
|
313 iCalendar->DeleteAllL(); |
|
314 break; |
|
315 } |
|
316 case ECmdDeleteCreatorCalendarEntries: |
|
317 { |
|
318 iCalendar->DeleteAllCreatedByCreatorL(); |
|
319 break; |
|
320 } |
|
321 case ECmdDeleteLogs: |
|
322 { |
|
323 iLogs->DeleteAllL(); |
|
324 break; |
|
325 } |
|
326 case ECmdDeleteCreatorLogs: |
|
327 { |
|
328 iLogs->DeleteAllCreatedByCreatorL(); |
|
329 break; |
|
330 } |
|
331 case ECmdDeleteMessages: |
|
332 { |
|
333 iMessages->DeleteAllL(); |
|
334 break; |
|
335 } |
|
336 case ECmdDeleteCreatorMessages: |
|
337 { |
|
338 iMessages->DeleteAllCreatedByCreatorL(); |
|
339 break; |
|
340 } |
|
341 case ECmdDeleteLandmarks: |
|
342 { |
|
343 iLandmarks->DeleteAllL(); |
|
344 break; |
|
345 } |
|
346 case ECmdDeleteCreatorLandmarks: |
|
347 { |
|
348 iLandmarks->DeleteAllCreatedByCreatorL(); |
|
349 break; |
|
350 } |
|
351 case ECmdDeleteMailboxes: |
|
352 { |
|
353 iMailboxes->DeleteAllL(); |
|
354 break; |
|
355 } |
|
356 case ECmdDeleteCreatorMailboxes: |
|
357 { |
|
358 iMailboxes->DeleteAllCreatedByCreatorL(); |
|
359 break; |
|
360 } |
|
361 case ECmdDeleteNotes: |
|
362 { |
|
363 iNotepad->DeleteAllL(); |
|
364 break; |
|
365 } |
|
366 case ECmdDeleteIMPSs: |
|
367 { |
|
368 iIMPS->DeleteAllL(); |
|
369 break; |
|
370 } |
|
371 case ECmdDeleteCreatorIMPSs: |
|
372 { |
|
373 iIMPS->DeleteAllCreatedByCreatorL(); |
|
374 break; |
|
375 } |
|
376 case ECmdDeleteBrowserBookmarks: |
|
377 { |
|
378 iBrowser->DeleteAllBookmarksL(); |
|
379 break; |
|
380 } |
|
381 case ECmdDeleteCreatorBrowserBookmarks: |
|
382 { |
|
383 iBrowser->DeleteAllBookmarksCreatedByCreatorL(); |
|
384 break; |
|
385 } |
|
386 case ECmdDeleteBrowserBookmarkFolders: |
|
387 { |
|
388 iBrowser->DeleteAllBookmarkFoldersL(); |
|
389 break; |
|
390 } |
|
391 case ECmdDeleteCreatorBrowserBookmarkFolders: |
|
392 { |
|
393 iBrowser->DeleteAllBookmarkFoldersCreatedByCreatorL(); |
|
394 break; |
|
395 } |
|
396 case ECmdDeleteBrowserSavedPages: |
|
397 { |
|
398 iBrowser->DeleteAllSavedPagesL(); |
|
399 break; |
|
400 } |
|
401 case ECmdDeleteCreatorBrowserSavedPages: |
|
402 { |
|
403 iBrowser->DeleteAllSavedPagesCreatedByCreatorL(); |
|
404 break; |
|
405 } |
|
406 case ECmdDeleteBrowserSavedPageFolders: |
|
407 { |
|
408 iBrowser->DeleteAllSavedPageFoldersL(); |
|
409 break; |
|
410 } |
|
411 case ECmdDeleteCreatorBrowserSavedPageFolders: |
|
412 { |
|
413 iBrowser->DeleteAllSavedPageFoldersCreatedByCreatorL(); |
|
414 break; |
|
415 } |
|
416 case ECmdDeleteCreatorFiles: |
|
417 { |
|
418 iFiles->DeleteAllCreatedByCreatorL(); |
|
419 break; |
|
420 } |
|
421 default: |
|
422 User::Panic (_L("ExecuteOptionsMenuCommandL"), 205); |
|
423 break; |
|
424 } |
|
425 |
|
426 TRAP_IGNORE( CheckForMoreCommandsL() ); |
|
427 |
|
428 } |
|
429 |
|
430 CDesCArrayFlat* CCreatorEngine::PictureFilesL() |
|
431 { |
|
432 if( iPictureFileArray == 0 ) |
|
433 { |
|
434 _LIT(KImageFile, "JPEG*.jpg"); |
|
435 _LIT(KImageFileDir, "C:\\Data\\"); |
|
436 _LIT(KImageFileDir2, "Z:\\Data\\"); |
|
437 iPictureFileArray = new (ELeave) CDesCArrayFlat(8); |
|
438 TInt err = CreatorFileUtils::FindFilesRecursiveL(iPictureFileArray, KImageFile, KImageFileDir); |
|
439 if( iPictureFileArray->Count() == 0 ) |
|
440 { |
|
441 err = CreatorFileUtils::FindFilesRecursiveL(iPictureFileArray, KImageFile, KImageFileDir2); |
|
442 } |
|
443 } |
|
444 return iPictureFileArray; |
|
445 } |
|
446 |
|
447 CDesCArrayFlat* CCreatorEngine::SoundFilesL() |
|
448 { |
|
449 if( iSoundFileArray == 0 ) |
|
450 { |
|
451 _LIT(KSoundFile, "*.aac"); |
|
452 _LIT(KSoundFileDir, "Z:\\data\\Sounds\\"); |
|
453 iSoundFileArray = new (ELeave) CDesCArrayFlat(8); |
|
454 TInt err = CreatorFileUtils::FindFilesRecursiveL(iSoundFileArray, KSoundFile, KSoundFileDir); |
|
455 } |
|
456 return iSoundFileArray; |
|
457 } |
|
458 // --------------------------------------------------------------------------- |
|
459 |
|
460 TInt CCreatorEngine::RunError(TInt aError) |
|
461 { |
|
462 LOGSTRING2("Creator: CCreatorEngine::RunError %d", aError); |
|
463 |
|
464 iFailedCommands++; |
|
465 |
|
466 _LIT(KMessage, "Command error %d"); |
|
467 TBuf<128> noteMsg; |
|
468 noteMsg.Format(KMessage, aError); |
|
469 iEnv->InfoMsg(noteMsg); |
|
470 |
|
471 TRAP_IGNORE( CheckForMoreCommandsL() ); |
|
472 |
|
473 return KErrNone; |
|
474 } |
|
475 |
|
476 // --------------------------------------------------------------------------- |
|
477 |
|
478 void CCreatorEngine::CheckForMoreCommandsL() |
|
479 { |
|
480 LOGSTRING("Creator: CCreatorEngine::CheckForMoreCommandsL"); |
|
481 if ( iUserCancelled ) return; |
|
482 // update the progress bar |
|
483 iProgressInfo->IncrementAndDraw(1); |
|
484 |
|
485 // check if we have more commands to be executed |
|
486 if (iCurrentEntry >= CommandArrayCount() - 1) |
|
487 { |
|
488 LOGSTRING("Creator: CCreatorEngine::CheckForMoreCommandsL all done"); |
|
489 |
|
490 // all done, free resources and show a note |
|
491 ShutDownEnginesL(); |
|
492 |
|
493 iProgressDialog->ProcessFinishedL(); |
|
494 |
|
495 if (iFailedCommands == 0) |
|
496 { |
|
497 _LIT(KMessage, "Done"); |
|
498 |
|
499 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote; |
|
500 note->ExecuteLD(KMessage); |
|
501 } |
|
502 else |
|
503 { |
|
504 _LIT(KMessage, "Done, %d commands failed"); |
|
505 TBuf<128> noteMsg; |
|
506 noteMsg.Format(KMessage, iFailedCommands); |
|
507 |
|
508 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote; |
|
509 note->ExecuteLD(noteMsg); |
|
510 } |
|
511 |
|
512 iAppUi->RunScriptDone(); |
|
513 |
|
514 } |
|
515 else |
|
516 { |
|
517 // maintain requests |
|
518 iCurrentEntry++; |
|
519 |
|
520 LOGSTRING2("Creator: CCreatorEngine::CheckForMoreCommandsL iCurrentEntry=%d", iCurrentEntry); |
|
521 |
|
522 ExecuteCommand(); |
|
523 } |
|
524 } |
|
525 |
|
526 // --------------------------------------------------------------------------- |
|
527 |
|
528 // This callback function is called when cancel button of the progress bar was pressed |
|
529 void CCreatorEngine::DialogDismissedL(TInt aButtonId) |
|
530 { |
|
531 LOGSTRING("Creator: CCreatorEngine::DialogDismissedL"); |
|
532 |
|
533 // check if cancel button was pressed |
|
534 if (aButtonId == EAknSoftkeyCancel) |
|
535 { |
|
536 iUserCancelled = ETrue; |
|
537 // cancel the active object, command executer |
|
538 Cancel(); |
|
539 |
|
540 // delete parameters from the command array, otherwise there might be memory leaks |
|
541 for (TInt i=iCurrentEntry; i<CommandArrayCount(); i++) |
|
542 { |
|
543 if ( iCommandArray->At(i).iParameters ) |
|
544 delete iCommandArray->At(i).iParameters; |
|
545 iCommandArray->At(i).iParameters = NULL; |
|
546 } |
|
547 |
|
548 if ( iPhonebook && iPhonebook->IsActive() ) |
|
549 { |
|
550 // virtual phonebook is known to require asynchronous |
|
551 // cancelling of operation |
|
552 iPhonebook->CancelOperation(); |
|
553 } |
|
554 else if ( iDecoder ) |
|
555 { |
|
556 iDecoder->Cancel(); |
|
557 // CancelComplete() will be called from GenerateSourceImageFileL |
|
558 } |
|
559 else if ( iScaler ) |
|
560 { |
|
561 iScaler->Cancel(); |
|
562 // CancelComplete() will be called from GenerateSourceImageFileL |
|
563 } |
|
564 else if ( iEncoder ) |
|
565 { |
|
566 iEncoder->Cancel(); |
|
567 // CancelComplete() will be called from GenerateSourceImageFileL |
|
568 } |
|
569 else |
|
570 { |
|
571 // free resources and show a note |
|
572 ShutDownEnginesL(); |
|
573 |
|
574 CAknInformationNote* note = new (ELeave) CAknInformationNote; |
|
575 note->ExecuteLD(_L("Cancelled")); |
|
576 } |
|
577 } |
|
578 } |
|
579 |
|
580 // --------------------------------------------------------------------------- |
|
581 |
|
582 void CCreatorEngine::StartEnginesL() |
|
583 { |
|
584 LOGSTRING("Creator: CCreatorEngine::StartEnginesL"); |
|
585 |
|
586 // reset user cancel flag |
|
587 iUserCancelled = EFalse; |
|
588 |
|
589 // start from the beginning |
|
590 iCurrentEntry = 0; |
|
591 |
|
592 // we'll retrieve a correct number for this later |
|
593 iEntriesToBeCreated = 0; |
|
594 |
|
595 // init the command array |
|
596 __ASSERT_ALWAYS(!iCommandArray, User::Panic(_L("iCommandArray"), 701)); |
|
597 iCommandArray = new(ELeave) CCommandArray(10000); |
|
598 |
|
599 // init all modules here |
|
600 TInt err(KErrNone); |
|
601 TRAP(err, iBrowser = CCreatorBrowser::NewL(this)); |
|
602 TRAP(err, iCalendar = CCreatorInterimCalendar::NewL(this)); |
|
603 TRAP(err, iPhonebook = (CCreatorPhonebookBase*)TCreatorFactory::CreatePhoneBookL(this)); |
|
604 TRAP(err, iNotepad = CCreatorNotepad::NewL(this)); |
|
605 TRAP(err, iLogs = CCreatorLogs::NewL(this)); |
|
606 TRAP(err, iAccessPoints = (CCreatorConnectionSettingsBase*)TCreatorFactory::CreateConnectionSettingsL(this)); |
|
607 TRAP(err, iMailboxes = CCreatorMailboxes::NewL(this)); |
|
608 TRAP(err, iFiles = CCreatorFiles::NewL(this)); |
|
609 TRAP(err, iMessages = CCreatorMessages::NewL(this)); |
|
610 TRAP(err, iLandmarks = CCreatorLandmarks::NewL(this)); |
|
611 |
|
612 #ifdef __PRESENCE |
|
613 TRAP(err, iIMPS = CCreatorIMPS::NewL(this)); |
|
614 #endif |
|
615 |
|
616 |
|
617 |
|
618 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
619 // Initialize contact-set cache: |
|
620 ContactLinkCache::InitializeL(); |
|
621 #endif |
|
622 // ... |
|
623 // ... |
|
624 // ... |
|
625 |
|
626 } |
|
627 // --------------------------------------------------------------------------- |
|
628 |
|
629 void CCreatorEngine::ShutDownEnginesL() |
|
630 { |
|
631 LOGSTRING("Creator: CCreatorEngine::ShutDownEnginesL"); |
|
632 |
|
633 |
|
634 // delete all modules here and free resources which aren't anymore needed |
|
635 |
|
636 |
|
637 #ifdef __PRESENCE |
|
638 delete iIMPS; |
|
639 iIMPS = NULL; |
|
640 #endif |
|
641 |
|
642 delete iMessages; |
|
643 iMessages = NULL; |
|
644 delete iFiles; |
|
645 iFiles = NULL; |
|
646 delete iMailboxes; |
|
647 iMailboxes = NULL; |
|
648 delete iAccessPoints; |
|
649 iAccessPoints = NULL; |
|
650 delete iLogs; |
|
651 iLogs = NULL; |
|
652 delete iNotepad; |
|
653 iNotepad = NULL; |
|
654 delete iPhonebook; |
|
655 iPhonebook = NULL; |
|
656 delete iCalendar; |
|
657 iCalendar = NULL; |
|
658 delete iBrowser; |
|
659 iBrowser = NULL; |
|
660 delete iLandmarks; |
|
661 iLandmarks = NULL; |
|
662 |
|
663 // ... |
|
664 // ... |
|
665 // ... |
|
666 |
|
667 |
|
668 // now delete the command array |
|
669 delete iCommandArray; |
|
670 iCommandArray = NULL; |
|
671 |
|
672 |
|
673 iParameterArray.ResetAndDestroy(); |
|
674 iParameterArray.Close(); |
|
675 |
|
676 |
|
677 // clear temp drive |
|
678 CFileMan* fileMan = CFileMan::NewL( iEnv->FsSession() ); |
|
679 CleanupStack::PushL( fileMan ); |
|
680 fileMan->RmDir( iTempPath->Des() ); |
|
681 CleanupStack::PopAndDestroy(); //fileMan |
|
682 |
|
683 #if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
684 // Cleanup the contact-set cache: |
|
685 ContactLinkCache::DestroyL(); |
|
686 #endif |
|
687 |
|
688 } |
|
689 |
|
690 // --------------------------------------------------------------------------- |
|
691 |
|
692 void CCreatorEngine::DoCancel() |
|
693 { |
|
694 LOGSTRING("Creator: CCreatorEngine::DoCancel"); |
|
695 |
|
696 iTimer.Cancel(); |
|
697 } |
|
698 |
|
699 // --------------------------------------------------------------------------- |
|
700 |
|
701 void CCreatorEngine::RunScriptL() |
|
702 { |
|
703 LOGSTRING("Creator: CCreatorEngine::RunScriptL"); |
|
704 |
|
705 // startup modules (also inits the command array): |
|
706 StartEnginesL(); |
|
707 |
|
708 // use the command parser module to init the command array from a script file |
|
709 CCommandParser* commandParser = CCommandParser::NewLC(this); |
|
710 RFile scriptFile; |
|
711 TBool ret = commandParser->OpenScriptL(scriptFile); |
|
712 CleanupClosePushL(scriptFile); |
|
713 if( ret ) |
|
714 { |
|
715 // wait dialog |
|
716 CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC(); |
|
717 waitDialog->SetSoftkeys( R_AVKON_SOFTKEYS_CANCEL ); |
|
718 TInt dialogId = waitDialog->ShowNoteL( EAknGlobalWaitNote, _L("Parsing") ); |
|
719 |
|
720 TInt parseErr( KErrNone ); |
|
721 TRAPD( parserErr, |
|
722 CCreatorScriptParser* scriptParser = CCreatorScriptParser::NewLC(this); |
|
723 scriptParser->ParseL(scriptFile); |
|
724 parseErr = scriptParser->GetError(); |
|
725 CleanupStack::PopAndDestroy( scriptParser ); |
|
726 ); |
|
727 waitDialog->CancelNoteL( dialogId ); |
|
728 CleanupStack::PopAndDestroy( waitDialog ); |
|
729 User::LeaveIfError( parserErr ); |
|
730 |
|
731 if(parseErr != KErrNone) |
|
732 { |
|
733 // show error note |
|
734 CAknErrorNote* note = new (ELeave) CAknErrorNote; |
|
735 _LIT(KErrMsg, "Parser error: %d"); |
|
736 TBuf<32> msgBuf; |
|
737 msgBuf.Format(KErrMsg, parseErr); |
|
738 note->ExecuteLD(msgBuf); |
|
739 CleanupStack::PopAndDestroy(); //commandParser |
|
740 ShutDownEnginesL(); |
|
741 return; |
|
742 } |
|
743 } |
|
744 CleanupStack::PopAndDestroy( &scriptFile ); |
|
745 CleanupStack::PopAndDestroy( commandParser ); |
|
746 |
|
747 // start executing commands if commands in the command array |
|
748 if (CommandArrayCount() > 0) |
|
749 { |
|
750 ExecuteFirstCommandL( KSavingText ); |
|
751 } |
|
752 else |
|
753 { |
|
754 ShutDownEnginesL(); |
|
755 } |
|
756 |
|
757 } |
|
758 /* |
|
759 void CCreatorEngine::RunScriptL() |
|
760 { |
|
761 LOGSTRING("Creator: CCreatorEngine::RunScriptL"); |
|
762 |
|
763 // startup modules (also inits the command array): |
|
764 StartEnginesL(); |
|
765 |
|
766 // use the command parser module to init the command array from a script file |
|
767 CCommandParser* commandParser = CCommandParser::NewLC(this); |
|
768 commandParser->OpenScriptL(); |
|
769 |
|
770 CleanupStack::PopAndDestroy(); //commandExecuter |
|
771 |
|
772 // start executing commands if commands in the command array |
|
773 if (CommandArrayCount() > 0) |
|
774 { |
|
775 ExecuteFirstCommandL(KSavingText); |
|
776 } |
|
777 else |
|
778 { |
|
779 ShutDownEnginesL(); |
|
780 } |
|
781 |
|
782 } |
|
783 |
|
784 */ |
|
785 |
|
786 // --------------------------------------------------------------------------- |
|
787 |
|
788 TInt CCreatorEngine::RunScriptL(const TDesC& aScriptFile) |
|
789 { |
|
790 LOGSTRING("Creator: CCreatorEngine::RunScriptL"); |
|
791 |
|
792 // startup modules (also inits the command array): |
|
793 StartEnginesL(); |
|
794 |
|
795 RFile scriptFile; |
|
796 if (scriptFile.Open(CEikonEnv::Static()->FsSession(), aScriptFile, EFileRead) != KErrNone) |
|
797 { |
|
798 ShutDownEnginesL(); |
|
799 return KErrNotFound; // file error |
|
800 } |
|
801 |
|
802 CleanupClosePushL(scriptFile); |
|
803 CCreatorScriptParser* scriptParser = CCreatorScriptParser::NewLC(this); |
|
804 scriptParser->ParseL(scriptFile); |
|
805 TInt err = scriptParser->GetError(); |
|
806 CleanupStack::PopAndDestroy(); //scriptParser |
|
807 CleanupStack::Pop(); // scriptFile |
|
808 scriptFile.Close(); |
|
809 |
|
810 if (err != KErrNone) |
|
811 { |
|
812 ShutDownEnginesL(); |
|
813 return KErrCorrupt; // parser error |
|
814 } |
|
815 |
|
816 // start executing commands if commands in the command array |
|
817 if (CommandArrayCount() > 0) |
|
818 { |
|
819 ExecuteFirstCommandL( KSavingText ); |
|
820 return KErrNone; // executing commands is started |
|
821 } |
|
822 else |
|
823 { |
|
824 ShutDownEnginesL(); |
|
825 return KErrCompletion; // nothing to do |
|
826 } |
|
827 } |
|
828 |
|
829 // --------------------------------------------------------------------------- |
|
830 |
|
831 void CCreatorEngine::ExecuteOptionsMenuCommandL(TInt aCommand) |
|
832 { |
|
833 LOGSTRING("Creator: CCreatorEngine::ExecuteOptionsMenuCommandL"); |
|
834 |
|
835 // startup modules (also inits the command array): |
|
836 StartEnginesL(); |
|
837 |
|
838 // set the home module |
|
839 switch(aCommand) |
|
840 { |
|
841 case ECmdCreateBrowserBookmarkEntries: |
|
842 case ECmdCreateBrowserBookmarkFolderEntries: |
|
843 case ECmdCreateBrowserSavedPageEntries: |
|
844 case ECmdCreateBrowserSavedPageFolderEntries: |
|
845 case ECmdDeleteBrowserBookmarks: |
|
846 case ECmdDeleteBrowserBookmarkFolders: |
|
847 case ECmdDeleteBrowserSavedPages: |
|
848 case ECmdDeleteBrowserSavedPageFolders: |
|
849 case ECmdDeleteCreatorBrowserBookmarks: |
|
850 case ECmdDeleteCreatorBrowserBookmarkFolders: |
|
851 case ECmdDeleteCreatorBrowserSavedPages: |
|
852 case ECmdDeleteCreatorBrowserSavedPageFolders: |
|
853 { |
|
854 iUsedOptionsMenuModule = iBrowser; |
|
855 } |
|
856 break; |
|
857 |
|
858 case ECmdCreateCalendarEntryAppointments: |
|
859 case ECmdCreateCalendarEntryEvents: |
|
860 case ECmdCreateCalendarEntryAnniversaries: |
|
861 case ECmdCreateCalendarEntryToDos: |
|
862 case ECmdCreateCalendarEntryReminders: |
|
863 case ECmdDeleteCalendarEntries: |
|
864 case ECmdDeleteCreatorCalendarEntries: |
|
865 { |
|
866 iUsedOptionsMenuModule = iCalendar; |
|
867 } |
|
868 break; |
|
869 |
|
870 case ECmdCreatePhoneBookEntryContacts: |
|
871 case ECmdCreatePhoneBookEntryGroups: |
|
872 case ECmdCreatePhoneBookEntrySubscribedContacts: |
|
873 case ECmdDeleteContacts: |
|
874 case ECmdDeleteCreatorContacts: |
|
875 case ECmdDeleteContactGroups: |
|
876 case ECmdDeleteCreatorContactGroups: |
|
877 { |
|
878 iUsedOptionsMenuModule = iPhonebook; |
|
879 } |
|
880 break; |
|
881 |
|
882 case ECmdCreateMiscEntryNotes: |
|
883 case ECmdDeleteNotes: |
|
884 { |
|
885 iUsedOptionsMenuModule = iNotepad; |
|
886 } |
|
887 break; |
|
888 |
|
889 case ECmdCreateLogEntryMissedCalls: |
|
890 case ECmdCreateLogEntryReceivedCalls: |
|
891 case ECmdCreateLogEntryDialledNumbers: |
|
892 case ECmdDeleteLogs: |
|
893 case ECmdDeleteCreatorLogs: |
|
894 { |
|
895 iUsedOptionsMenuModule = iLogs; |
|
896 } |
|
897 break; |
|
898 |
|
899 case ECmdCreateMiscEntryAccessPoints: |
|
900 case ECmdDeleteIAPs: |
|
901 case ECmdDeleteCreatorIAPs: |
|
902 { |
|
903 iUsedOptionsMenuModule = iAccessPoints; |
|
904 } |
|
905 break; |
|
906 |
|
907 case ECmdCreateMessagingEntryMailboxes: |
|
908 case ECmdDeleteMailboxes: |
|
909 case ECmdDeleteCreatorMailboxes: |
|
910 { |
|
911 iUsedOptionsMenuModule = iMailboxes; |
|
912 } |
|
913 break; |
|
914 |
|
915 #ifdef __PRESENCE |
|
916 case ECmdCreateMiscEntryIMPSServers: |
|
917 case ECmdDeleteIMPSs: |
|
918 case ECmdDeleteCreatorIMPSs: |
|
919 { |
|
920 iUsedOptionsMenuModule = iIMPS; |
|
921 } |
|
922 break; |
|
923 #endif |
|
924 |
|
925 case ECmdCreateFileEntryEmptyFolder: |
|
926 case ECmdCreateFileEntry3GPP_70kB: |
|
927 case ECmdCreateFileEntryAAC_100kB: |
|
928 case ECmdCreateFileEntryAMR_20kB: |
|
929 case ECmdCreateFileEntryBMP_25kB: |
|
930 case ECmdCreateFileEntryDeck_1kB: |
|
931 case ECmdCreateFileEntryDOC_20kB: |
|
932 case ECmdCreateFileEntryGIF_2kB: |
|
933 case ECmdCreateFileEntryHTML_20kB: |
|
934 case ECmdCreateFileEntryJAD_1kB: |
|
935 case ECmdCreateFileEntryJAR_10kB: |
|
936 case ECmdCreateFileEntryJP2_65kB: |
|
937 case ECmdCreateFileEntryJPEG_200kB: |
|
938 case ECmdCreateFileEntryJPEG_25kB: |
|
939 case ECmdCreateFileEntryJPEG_500kB: |
|
940 case ECmdCreateFileEntryMIDI_10kB: |
|
941 case ECmdCreateFileEntryMP3_250kB: |
|
942 case ECmdCreateFileEntryMP4_200kB: |
|
943 case ECmdCreateFileEntryMXMF_40kB: |
|
944 case ECmdCreateFileEntryPNG_15kB: |
|
945 case ECmdCreateFileEntryPPT_40kB: |
|
946 case ECmdCreateFileEntryRAM_1kB: |
|
947 case ECmdCreateFileEntryRM_95kB: |
|
948 case ECmdCreateFileEntryRNG_1kB: |
|
949 case ECmdCreateFileEntrySVG_15kB: |
|
950 case ECmdCreateFileEntrySWF_15kB: |
|
951 case ECmdCreateFileEntryTIF_25kB: |
|
952 case ECmdCreateFileEntryTXT_10kB: |
|
953 case ECmdCreateFileEntryTXT_70kB: |
|
954 case ECmdCreateFileEntryVCF_1kB: |
|
955 case ECmdCreateFileEntryVCS_1kB: |
|
956 case ECmdCreateFileEntryWAV_20kB: |
|
957 case ECmdCreateFileEntryXLS_15kB: |
|
958 case ECmdCreateFileEntrySISX_10kB: |
|
959 case ECmdCreateFileEntryWMA_50kB: |
|
960 case ECmdCreateFileEntryWMV_200kB: |
|
961 case ECmdDeleteCreatorFiles: |
|
962 |
|
963 { |
|
964 iUsedOptionsMenuModule = iFiles; |
|
965 } |
|
966 break; |
|
967 |
|
968 |
|
969 case ECmdCreateMessagingEntryMessages: |
|
970 case ECmdDeleteMessages: |
|
971 case ECmdDeleteCreatorMessages: |
|
972 { |
|
973 iUsedOptionsMenuModule = iMessages; |
|
974 } |
|
975 break; |
|
976 |
|
977 case ECmdCreateMiscEntryLandmarks: |
|
978 case ECmdDeleteLandmarks: |
|
979 case ECmdDeleteCreatorLandmarks: |
|
980 { |
|
981 iUsedOptionsMenuModule = iLandmarks; |
|
982 } |
|
983 break; |
|
984 case ECmdDeleteAllEntries: |
|
985 case ECmdDeleteAllCreatorEntries: |
|
986 { |
|
987 break; |
|
988 } |
|
989 default: |
|
990 User::Panic (_L("ExecuteOptionsMenuCommandL"), 201); |
|
991 break; |
|
992 } |
|
993 |
|
994 |
|
995 //If it's a delete command, asking do you really want to delete |
|
996 if( IsDeleteCommand( aCommand ) ) |
|
997 { |
|
998 if ( aCommand == ECmdDeleteAllEntries ) |
|
999 { |
|
1000 if ( YesNoQueryDialogL( _L("Delete all entries?") ) ) |
|
1001 { |
|
1002 AppendToCommandArrayL( ECmdDeleteContacts, NULL, 1 ); |
|
1003 AppendToCommandArrayL( ECmdDeleteContactGroups, NULL, 1 ); |
|
1004 AppendToCommandArrayL( ECmdDeleteCalendarEntries, NULL, 1 ); |
|
1005 AppendToCommandArrayL( ECmdDeleteBrowserBookmarks, NULL, 1 ); |
|
1006 AppendToCommandArrayL( ECmdDeleteBrowserBookmarkFolders, NULL, 1 ); |
|
1007 AppendToCommandArrayL( ECmdDeleteBrowserSavedPages, NULL, 1 ); |
|
1008 AppendToCommandArrayL( ECmdDeleteBrowserSavedPageFolders, NULL, 1 ); |
|
1009 AppendToCommandArrayL( ECmdDeleteLogs, NULL, 1 ); |
|
1010 AppendToCommandArrayL( ECmdDeleteMessages, NULL, 1 ); |
|
1011 AppendToCommandArrayL( ECmdDeleteIAPs, NULL, 1 ); |
|
1012 AppendToCommandArrayL( ECmdDeleteIMPSs, NULL, 1 ); |
|
1013 AppendToCommandArrayL( ECmdDeleteNotes, NULL, 1 ); |
|
1014 AppendToCommandArrayL( ECmdDeleteLandmarks, NULL, 1 ); |
|
1015 AppendToCommandArrayL( ECmdDeleteCreatorFiles, NULL, 1 ); |
|
1016 |
|
1017 // started exucuting delete commands |
|
1018 ExecuteFirstCommandL( KDeletingText ); |
|
1019 } |
|
1020 else |
|
1021 { |
|
1022 // cancelled, free resources |
|
1023 ShutDownEnginesL(); |
|
1024 } |
|
1025 } |
|
1026 else if ( aCommand == ECmdDeleteAllCreatorEntries ) |
|
1027 { |
|
1028 if ( YesNoQueryDialogL( _L("Delete all entries created with Creator?") ) ) |
|
1029 { |
|
1030 AppendToCommandArrayL( ECmdDeleteCreatorContacts, NULL, 1 ); |
|
1031 AppendToCommandArrayL( ECmdDeleteCreatorContactGroups, NULL, 1 ); |
|
1032 AppendToCommandArrayL( ECmdDeleteCreatorCalendarEntries, NULL, 1 ); |
|
1033 AppendToCommandArrayL( ECmdDeleteCreatorBrowserBookmarks, NULL, 1 ); |
|
1034 AppendToCommandArrayL( ECmdDeleteCreatorBrowserBookmarkFolders, NULL, 1 ); |
|
1035 AppendToCommandArrayL( ECmdDeleteCreatorBrowserSavedPages, NULL, 1 ); |
|
1036 AppendToCommandArrayL( ECmdDeleteCreatorBrowserSavedPageFolders, NULL, 1 ); |
|
1037 AppendToCommandArrayL( ECmdDeleteCreatorFiles, NULL, 1 ); |
|
1038 AppendToCommandArrayL( ECmdDeleteCreatorLogs, NULL, 1 ); |
|
1039 AppendToCommandArrayL( ECmdDeleteCreatorMessages, NULL, 1 ); |
|
1040 AppendToCommandArrayL( ECmdDeleteCreatorIAPs, NULL, 1 ); |
|
1041 AppendToCommandArrayL( ECmdDeleteCreatorIMPSs, NULL, 1 ); |
|
1042 AppendToCommandArrayL( ECmdDeleteCreatorLandmarks, NULL, 1 ); |
|
1043 |
|
1044 // started exucuting delete commands |
|
1045 ExecuteFirstCommandL( KDeletingText ); |
|
1046 } |
|
1047 else |
|
1048 { |
|
1049 // cancelled, free resources |
|
1050 ShutDownEnginesL(); |
|
1051 } |
|
1052 } |
|
1053 else if ( iUsedOptionsMenuModule->AskDataFromUserL( aCommand, iEntriesToBeCreated ) ) |
|
1054 { |
|
1055 // add this command to command array |
|
1056 AppendToCommandArrayL( aCommand, NULL, 1 ); |
|
1057 |
|
1058 // started exucuting commands |
|
1059 ExecuteFirstCommandL( KDeletingText ); |
|
1060 } |
|
1061 else |
|
1062 { |
|
1063 // cancelled, free resources |
|
1064 ShutDownEnginesL(); |
|
1065 } |
|
1066 } |
|
1067 |
|
1068 // ask user data, if query accepted start processing... |
|
1069 else if (iUsedOptionsMenuModule->AskDataFromUserL(aCommand, iEntriesToBeCreated)) |
|
1070 { |
|
1071 // add this command to command array |
|
1072 AppendToCommandArrayL(aCommand, NULL, iEntriesToBeCreated); |
|
1073 |
|
1074 // started exucuting commands |
|
1075 ExecuteFirstCommandL( KSavingText ); |
|
1076 } |
|
1077 else |
|
1078 { |
|
1079 // cancelled, free resources |
|
1080 ShutDownEnginesL(); |
|
1081 } |
|
1082 } |
|
1083 |
|
1084 |
|
1085 |
|
1086 TBool CCreatorEngine::IsDeleteCommand(TInt aCommand) |
|
1087 { |
|
1088 LOGSTRING("Creator: CCreatorEngine::IsDeleteCommand"); |
|
1089 |
|
1090 switch(aCommand) |
|
1091 { |
|
1092 //Add supported delete command here |
|
1093 case ECmdDeleteAllEntries: |
|
1094 case ECmdDeleteAllCreatorEntries: |
|
1095 case ECmdDeleteEntries: |
|
1096 case ECmdDeleteContacts: |
|
1097 case ECmdDeleteCreatorContacts: |
|
1098 case ECmdDeleteContactGroups: |
|
1099 case ECmdDeleteCreatorContactGroups: |
|
1100 case ECmdDeleteCalendarEntries: |
|
1101 case ECmdDeleteCreatorCalendarEntries: |
|
1102 case ECmdDeleteBrowserBookmarks: |
|
1103 case ECmdDeleteCreatorBrowserBookmarks: |
|
1104 case ECmdDeleteBrowserBookmarkFolders: |
|
1105 case ECmdDeleteCreatorBrowserBookmarkFolders: |
|
1106 case ECmdDeleteBrowserSavedPages: |
|
1107 case ECmdDeleteCreatorBrowserSavedPages: |
|
1108 case ECmdDeleteBrowserSavedPageFolders: |
|
1109 case ECmdDeleteCreatorBrowserSavedPageFolders: |
|
1110 case ECmdDeleteCreatorFiles: |
|
1111 case ECmdDeleteLogs: |
|
1112 case ECmdDeleteCreatorLogs: |
|
1113 case ECmdDeleteMessages: |
|
1114 case ECmdDeleteCreatorMessages: |
|
1115 case ECmdDeleteMailboxes: |
|
1116 case ECmdDeleteCreatorMailboxes: |
|
1117 case ECmdDeleteIAPs: |
|
1118 case ECmdDeleteCreatorIAPs: |
|
1119 case ECmdDeleteIMPSs: |
|
1120 case ECmdDeleteCreatorIMPSs: |
|
1121 case ECmdDeleteNotes: |
|
1122 case ECmdDeleteLandmarks: |
|
1123 case ECmdDeleteCreatorLandmarks: |
|
1124 { |
|
1125 return ETrue; |
|
1126 } |
|
1127 default: |
|
1128 { |
|
1129 return EFalse; |
|
1130 } |
|
1131 } |
|
1132 |
|
1133 } |
|
1134 |
|
1135 // --------------------------------------------------------------------------- |
|
1136 |
|
1137 TBool CCreatorEngine::GetRandomDataFilenameL(TDes& aFilename) |
|
1138 { |
|
1139 CCommandParser* commandParser = CCommandParser::NewLC(this); |
|
1140 TBool ret = commandParser->GetRandomDataFilenameL(aFilename); |
|
1141 CleanupStack::PopAndDestroy(commandParser); |
|
1142 return ret; |
|
1143 } |
|
1144 |
|
1145 // --------------------------------------------------------------------------- |
|
1146 |
|
1147 TBool CCreatorEngine::GetRandomDataFromFileL(const TDesC& aFilename) |
|
1148 { |
|
1149 // wait dialog |
|
1150 CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC(); |
|
1151 waitDialog->SetSoftkeys(R_AVKON_SOFTKEYS_CANCEL); |
|
1152 TInt dialogId = waitDialog->ShowNoteL(EAknGlobalWaitNote, _L("Reading random data")); |
|
1153 |
|
1154 for (TInt i = 0; i < iStringArrays.Count(); ++i) |
|
1155 { |
|
1156 delete iStringArrays[i].iArrayPtr; |
|
1157 } |
|
1158 iStringArrays.Reset(); |
|
1159 |
|
1160 TBool errorDetected = EFalse; |
|
1161 |
|
1162 // NOTE: These must be exactly in same order as in enumeration: |
|
1163 |
|
1164 if (ReadRandomDataL(EFirstName, R_DATA_FIRSTNAMES, aFilename, CCreatorRandomDataParser::EFirstName) != KErrNone) |
|
1165 { |
|
1166 errorDetected = ETrue; |
|
1167 } |
|
1168 if (ReadRandomDataL(ESurname, R_DATA_SURNAMES, aFilename, CCreatorRandomDataParser::ESurname) != KErrNone) |
|
1169 { |
|
1170 errorDetected = ETrue; |
|
1171 } |
|
1172 if (ReadRandomDataL(ECompany, R_DATA_COMPANIES, aFilename, CCreatorRandomDataParser::ECompany) != KErrNone) |
|
1173 { |
|
1174 errorDetected = ETrue; |
|
1175 } |
|
1176 if (ReadRandomDataL(EAddress, R_DATA_ADDRESSES, aFilename, CCreatorRandomDataParser::EAddress) != KErrNone) |
|
1177 { |
|
1178 errorDetected = ETrue; |
|
1179 } |
|
1180 if (ReadRandomDataL(EJobTitle, R_DATA_JOBTITLES, aFilename, CCreatorRandomDataParser::EJobTitle) != KErrNone) |
|
1181 { |
|
1182 errorDetected = ETrue; |
|
1183 } |
|
1184 if (ReadRandomDataL(EPhoneNumber, R_DATA_PHONENUMBERS, aFilename, CCreatorRandomDataParser::EPhoneNumber) != KErrNone) |
|
1185 { |
|
1186 errorDetected = ETrue; |
|
1187 } |
|
1188 if (ReadRandomDataL(EGroupName, R_DATA_GROUPNAMES, aFilename, CCreatorRandomDataParser::EGroupName) != KErrNone) |
|
1189 { |
|
1190 errorDetected = ETrue; |
|
1191 } |
|
1192 if (ReadRandomDataL(EMeetingReason, R_DATA_MEETINGREASONS, aFilename, CCreatorRandomDataParser::EMeetingReason) != KErrNone) |
|
1193 { |
|
1194 errorDetected = ETrue; |
|
1195 } |
|
1196 if (ReadRandomDataL(EMeetingPlace, R_DATA_MEETINGPLACES, aFilename, CCreatorRandomDataParser::EMeetingPlace) != KErrNone) |
|
1197 { |
|
1198 errorDetected = ETrue; |
|
1199 } |
|
1200 if (ReadRandomDataL(EMemoText, R_DATA_MEMOS, aFilename, CCreatorRandomDataParser::EMemoText) != KErrNone) |
|
1201 { |
|
1202 errorDetected = ETrue; |
|
1203 } |
|
1204 if (ReadRandomDataL(EAnniversaryReason, R_DATA_ANNIVERSARIES, aFilename, CCreatorRandomDataParser::EAnniversaryReason) != KErrNone) |
|
1205 { |
|
1206 errorDetected = ETrue; |
|
1207 } |
|
1208 if (ReadRandomDataL(EToDoText, R_DATA_TODOS, aFilename, CCreatorRandomDataParser::EToDoText) != KErrNone) |
|
1209 { |
|
1210 errorDetected = ETrue; |
|
1211 } |
|
1212 if (ReadRandomDataL(EReminderText, R_DATA_REMINDERS, aFilename, CCreatorRandomDataParser::EReminderText) != KErrNone) |
|
1213 { |
|
1214 errorDetected = ETrue; |
|
1215 } |
|
1216 if (ReadRandomDataL(EMessageSubject, R_DATA_MESSAGESUBJECTS, aFilename, CCreatorRandomDataParser::EMessageSubject) != KErrNone) |
|
1217 { |
|
1218 errorDetected = ETrue; |
|
1219 } |
|
1220 if (ReadRandomDataL(EMessageText, R_DATA_MESSAGETEXTS, aFilename, CCreatorRandomDataParser::EMessageText) != KErrNone) |
|
1221 { |
|
1222 errorDetected = ETrue; |
|
1223 } |
|
1224 if (ReadRandomDataL(ECity, R_DATA_CITIES, aFilename, CCreatorRandomDataParser::ECity) != KErrNone) |
|
1225 { |
|
1226 errorDetected = ETrue; |
|
1227 } |
|
1228 if (ReadRandomDataL(ECountry, R_DATA_COUNTRIES, aFilename, CCreatorRandomDataParser::ECountry) != KErrNone) |
|
1229 { |
|
1230 errorDetected = ETrue; |
|
1231 } |
|
1232 if (ReadRandomDataL(EPostcode, R_DATA_POSTCODES, aFilename, CCreatorRandomDataParser::EPostcode) != KErrNone) |
|
1233 { |
|
1234 errorDetected = ETrue; |
|
1235 } |
|
1236 if (ReadRandomDataL(EState, R_DATA_STATES, aFilename, CCreatorRandomDataParser::EState) != KErrNone) |
|
1237 { |
|
1238 errorDetected = ETrue; |
|
1239 } |
|
1240 if (ReadRandomDataL(EPobox, R_DATA_POBOXES, aFilename, CCreatorRandomDataParser::EPobox) != KErrNone) |
|
1241 { |
|
1242 errorDetected = ETrue; |
|
1243 } |
|
1244 if (ReadRandomDataL(EPrefix, R_DATA_PREFIXES, aFilename, CCreatorRandomDataParser::EPrefix) != KErrNone) |
|
1245 { |
|
1246 errorDetected = ETrue; |
|
1247 } |
|
1248 if (ReadRandomDataL(ESuffix, R_DATA_SUFFIXES, aFilename, CCreatorRandomDataParser::ESuffix) != KErrNone) |
|
1249 { |
|
1250 errorDetected = ETrue; |
|
1251 } |
|
1252 if (ReadRandomDataL(ELandmarkName, R_DATA_LANDMARK_NAMES, aFilename, CCreatorRandomDataParser::ELandmarkName) != KErrNone) |
|
1253 { |
|
1254 errorDetected = ETrue; |
|
1255 } |
|
1256 if (ReadRandomDataL(ELandmarkDescription, R_DATA_LANDMARK_DESCRIPTIONS, aFilename, CCreatorRandomDataParser::ELandmarkDescription) != KErrNone) |
|
1257 { |
|
1258 errorDetected = ETrue; |
|
1259 } |
|
1260 |
|
1261 // remove the wait dialog |
|
1262 waitDialog->CancelNoteL(dialogId); |
|
1263 CleanupStack::PopAndDestroy(waitDialog); |
|
1264 |
|
1265 if (errorDetected) |
|
1266 { |
|
1267 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote; |
|
1268 note->ExecuteLD(_L("Error in reading random data.")); |
|
1269 } |
|
1270 |
|
1271 return !errorDetected; |
|
1272 } |
|
1273 |
|
1274 // --------------------------------------------------------------------------- |
|
1275 |
|
1276 TInt CCreatorEngine::ReadRandomDataL(const TRandomStringType aRandomStringType, |
|
1277 const TInt aResourceId, |
|
1278 const TDesC& aFilename, |
|
1279 const CCreatorRandomDataParser::TRandomDataType aRandomDataType) |
|
1280 { |
|
1281 TInt error = KErrNone; |
|
1282 if (aFilename == KNullDesC) |
|
1283 { |
|
1284 iStringArrays.AppendL(TStringArrayPtr(aRandomStringType, iEnv->ReadDesCArrayResourceL(aResourceId))); |
|
1285 } |
|
1286 else |
|
1287 { |
|
1288 CCreatorRandomDataParser* dataParser = CCreatorRandomDataParser::NewLC(); |
|
1289 CDesCArrayFlat* array = NULL; |
|
1290 |
|
1291 TRAP(error, array = dataParser->ParseL(aFilename, aRandomDataType)); |
|
1292 if (error == KErrNone) |
|
1293 { |
|
1294 error = dataParser->GetError(); |
|
1295 } |
|
1296 if ((error == KErrNone) && (array->MdcaCount() > 0)) |
|
1297 { |
|
1298 iStringArrays.AppendL(TStringArrayPtr(aRandomStringType, array)); |
|
1299 } |
|
1300 else |
|
1301 { |
|
1302 if (array) |
|
1303 { |
|
1304 array->Reset(); |
|
1305 delete array; |
|
1306 } |
|
1307 iStringArrays.AppendL(TStringArrayPtr(aRandomStringType, iEnv->ReadDesCArrayResourceL(aResourceId))); |
|
1308 } |
|
1309 CleanupStack::PopAndDestroy(dataParser); |
|
1310 } |
|
1311 return error; |
|
1312 } |
|
1313 |
|
1314 // --------------------------------------------------------------------------- |
|
1315 |
|
1316 void CCreatorEngine::AppendToCommandArrayL(TInt aCommand, CCreatorModuleBaseParameters* aParameters, TInt aNumberOfEntries) |
|
1317 { |
|
1318 LOGSTRING("Creator: CCreatorEngine::AppendToCommandArrayL"); |
|
1319 iParameterArray.AppendL(aParameters); |
|
1320 |
|
1321 for (TInt i=0; i<aNumberOfEntries; i++) |
|
1322 iCommandArray->AppendL( TCommand(aCommand, aParameters) ); |
|
1323 } |
|
1324 |
|
1325 // --------------------------------------------------------------------------- |
|
1326 |
|
1327 TInt CCreatorEngine::CommandArrayCount() |
|
1328 { |
|
1329 TInt count(0); |
|
1330 |
|
1331 if (iCommandArray) |
|
1332 count = iCommandArray->Count(); |
|
1333 |
|
1334 LOGSTRING2("Creator: CCreatorEngine::CommandArrayCount returns %d", count); |
|
1335 |
|
1336 return count; |
|
1337 } |
|
1338 |
|
1339 // --------------------------------------------------------------------------- |
|
1340 |
|
1341 //returs fileid by its name, eg. 1 in |
|
1342 TInt CCreatorEngine::GetAttachmentIdL( const TDesC& aAttachmentIdStr ) const |
|
1343 { |
|
1344 TInt mapCount = sizeof(FileMap) / sizeof(FileMapping); |
|
1345 |
|
1346 for( TInt i = 0; i < mapCount; ++i ) |
|
1347 { |
|
1348 if( FileMap[i].FileName() == aAttachmentIdStr ) |
|
1349 return FileMap[i].FileId(); |
|
1350 } |
|
1351 LOGSTRING2("CCreatorEngine::GetAttachmentIdL: Unknown attachment file id: %s", &aAttachmentIdStr); |
|
1352 User::Leave(KErrGeneral); |
|
1353 return KErrNotFound; // Not reached, but disables a compiler warning |
|
1354 } |
|
1355 |
|
1356 // --------------------------------------------------------------------------- |
|
1357 |
|
1358 // returns a random string from the resource files |
|
1359 TPtrC CCreatorEngine::TestDataPathL (enum TTestDataPath aTestDataPath ) |
|
1360 { |
|
1361 LOGSTRING("Creator: CCreatorEngine::TestDataPathL"); |
|
1362 |
|
1363 TFileName filePath; |
|
1364 |
|
1365 switch (aTestDataPath ) |
|
1366 { |
|
1367 case ESavedDeck_1kB: |
|
1368 { |
|
1369 filePath.Copy (_L("Deck-1kB.saveddeck") ); |
|
1370 } |
|
1371 break; |
|
1372 |
|
1373 case EJPEG_25kB: |
|
1374 { |
|
1375 filePath.Copy (_L("JPEG-25kB.jpg") ); |
|
1376 } |
|
1377 break; |
|
1378 |
|
1379 case EJPEG_200kB: |
|
1380 { |
|
1381 filePath.Copy (_L("JPEG-200kB.jpg") ); |
|
1382 } |
|
1383 break; |
|
1384 |
|
1385 case EJPEG_500kB: |
|
1386 { |
|
1387 filePath.Copy (_L("JPEG-500kB.jpg") ); |
|
1388 } |
|
1389 break; |
|
1390 |
|
1391 case EPNG_15kB: |
|
1392 { |
|
1393 filePath.Copy (_L("PNG-15kB.png") ); |
|
1394 } |
|
1395 break; |
|
1396 |
|
1397 case EGIF_2kB: |
|
1398 { |
|
1399 filePath.Copy (_L("GIF-2kB.gif") ); |
|
1400 } |
|
1401 break; |
|
1402 |
|
1403 case ERNG_1kB: |
|
1404 { |
|
1405 filePath.Copy (_L("RNG-1kB.rng") ); |
|
1406 } |
|
1407 break; |
|
1408 |
|
1409 case EMIDI_10kB: |
|
1410 { |
|
1411 filePath.Copy (_L("MIDI-10kB.mid") ); |
|
1412 } |
|
1413 break; |
|
1414 |
|
1415 case EWAVE_20kB: |
|
1416 { |
|
1417 filePath.Copy (_L("WAV-20kB.wav") ); |
|
1418 } |
|
1419 break; |
|
1420 |
|
1421 case EAMR_20kB: |
|
1422 { |
|
1423 filePath.Copy (_L("AMR-20kB.amr") ); |
|
1424 } |
|
1425 break; |
|
1426 |
|
1427 case EExcel_15kB: |
|
1428 { |
|
1429 filePath.Copy (_L("XLS-15kB.xls") ); |
|
1430 } |
|
1431 break; |
|
1432 |
|
1433 case EWord_20kB: |
|
1434 { |
|
1435 filePath.Copy (_L("DOC-20kB.doc") ); |
|
1436 } |
|
1437 break; |
|
1438 |
|
1439 case EPowerPoint_40kB: |
|
1440 { |
|
1441 filePath.Copy (_L("PPT-40kB.ppt") ); |
|
1442 } |
|
1443 break; |
|
1444 |
|
1445 case EText_10kB: |
|
1446 { |
|
1447 filePath.Copy (_L("TXT-10kB.txt") ); |
|
1448 } |
|
1449 break; |
|
1450 |
|
1451 case EText_70kB: |
|
1452 { |
|
1453 filePath.Copy (_L("TXT-70kB.txt") ); |
|
1454 } |
|
1455 break; |
|
1456 |
|
1457 case E3GPP_70kB: |
|
1458 { |
|
1459 filePath.Copy (_L("3GPP-70kB.3gpp") ); |
|
1460 } |
|
1461 break; |
|
1462 |
|
1463 case EMP3_250kB: |
|
1464 { |
|
1465 filePath.Copy (_L("MP3-250kB.mp3") ); |
|
1466 } |
|
1467 break; |
|
1468 |
|
1469 case EAAC_100kB: |
|
1470 { |
|
1471 filePath.Copy (_L("AAC-100kB.aac") ); |
|
1472 } |
|
1473 break; |
|
1474 |
|
1475 case ERM_95kB: |
|
1476 { |
|
1477 filePath.Copy (_L("RM-95kB.rm") ); |
|
1478 } |
|
1479 break; |
|
1480 |
|
1481 case EBMP_25kB: |
|
1482 { |
|
1483 filePath.Copy (_L("BMP-25kB.bmp") ); |
|
1484 } |
|
1485 break; |
|
1486 case EHTML_20kB: |
|
1487 { |
|
1488 filePath.Copy (_L("HTML-20kB.html") ); |
|
1489 } |
|
1490 break; |
|
1491 case EJAD_1kB: |
|
1492 { |
|
1493 filePath.Copy (_L("JAD-1kB.jad") ); |
|
1494 } |
|
1495 break; |
|
1496 case EJAR_10kB: |
|
1497 { |
|
1498 filePath.Copy (_L("JAR-10kB.jar") ); |
|
1499 } |
|
1500 break; |
|
1501 case EJP2_65kB: |
|
1502 { |
|
1503 filePath.Copy (_L("JP2-65kB.jp2") ); |
|
1504 } |
|
1505 break; |
|
1506 case EMP4_200kB: |
|
1507 { |
|
1508 filePath.Copy (_L("MP4-200kB.mp4") ); |
|
1509 } |
|
1510 break; |
|
1511 case EMXMF_40kB: |
|
1512 { |
|
1513 filePath.Copy (_L("MXMF-40kB.mxmf") ); |
|
1514 } |
|
1515 break; |
|
1516 case ERAM_1kB: |
|
1517 { |
|
1518 filePath.Copy (_L("RAM-1kB.ram") ); |
|
1519 } |
|
1520 break; |
|
1521 case ESVG_15kB: |
|
1522 { |
|
1523 filePath.Copy (_L("SVG-15kB.svg") ); |
|
1524 } |
|
1525 break; |
|
1526 case ESWF_15kB: |
|
1527 { |
|
1528 filePath.Copy (_L("SWF-15kB.swf") ); |
|
1529 } |
|
1530 break; |
|
1531 case ETIF_25kB: |
|
1532 { |
|
1533 filePath.Copy (_L("TIF-25kB.tif") ); |
|
1534 } |
|
1535 break; |
|
1536 case EVCF_1kB: |
|
1537 { |
|
1538 filePath.Copy (_L("VCF-1kB.vcf") ); |
|
1539 } |
|
1540 break; |
|
1541 case EVCS_1kB: |
|
1542 { |
|
1543 filePath.Copy (_L("VCS-1kB.vcs") ); |
|
1544 } |
|
1545 break; |
|
1546 case ESISX_10kB: |
|
1547 { |
|
1548 filePath.Copy (_L("SISX-10kB.sisx") ); |
|
1549 } |
|
1550 break; |
|
1551 case EWMA_50kB: |
|
1552 { |
|
1553 filePath.Copy (_L("WMA-50kB.wma") ); |
|
1554 } |
|
1555 break; |
|
1556 case EWMV_200kB: |
|
1557 { |
|
1558 filePath.Copy (_L("WMV-200kB.wmv") ); |
|
1559 } |
|
1560 break; |
|
1561 |
|
1562 default: |
|
1563 User::Panic (_L("Test data"), 401 ); |
|
1564 break; |
|
1565 } |
|
1566 |
|
1567 TFileName fullTargetPath; |
|
1568 fullTargetPath.Copy( iTempPath->Des() ); |
|
1569 fullTargetPath.Append( filePath ); |
|
1570 if (ConeUtils::FileExists(fullTargetPath)) |
|
1571 { |
|
1572 // No need to copy, if the file already exists. |
|
1573 LOGSTRING2("Creator: CCreatorEngine::TestDataPathL %S already exists", &fullTargetPath); |
|
1574 return fullTargetPath; |
|
1575 } |
|
1576 |
|
1577 // Define the path where the testdata can be retrieved |
|
1578 // get the data from the private directory in secure platform |
|
1579 TFileName fullAppPath = iEnv->EikAppUi()->Application()->AppFullName(); |
|
1580 TChar driveLetter = fullAppPath[0]; |
|
1581 TInt driveNumber; |
|
1582 |
|
1583 iEnv->FsSession().CharToDrive(driveLetter, driveNumber); |
|
1584 iEnv->FsSession().SetSessionToPrivate( driveNumber ); // "\\private\\20011383\\" |
|
1585 |
|
1586 |
|
1587 // check the file exists |
|
1588 if (!ConeUtils::FileExists(filePath)) |
|
1589 { |
|
1590 LOGSTRING2("Creator: CCreatorEngine::TestDataPathL %S not found", &filePath); |
|
1591 |
|
1592 TInt generatingError( KErrNone ); |
|
1593 |
|
1594 // The file could be on C drive |
|
1595 iEnv->FsSession().SetSessionToPrivate( KRegisterDrive ); |
|
1596 |
|
1597 if ( !ConeUtils::FileExists( filePath ) ) |
|
1598 { |
|
1599 // The file is not on C drive, see if we can generate it |
|
1600 |
|
1601 // Make sure that the private path of this app in c-drive exists |
|
1602 iEnv->FsSession().CreatePrivatePath( KRegisterDrive ); |
|
1603 |
|
1604 TFileName privatePath; |
|
1605 iEnv->FsSession().PrivatePath( privatePath ); |
|
1606 privatePath.Append( filePath ); |
|
1607 TChar privateDriveChar; |
|
1608 iEnv->FsSession().DriveToChar( KRegisterDrive, privateDriveChar ); |
|
1609 TFileName fullPrivatePath; // full path of a file to be generated |
|
1610 fullPrivatePath.Append( privateDriveChar ); |
|
1611 fullPrivatePath.Append( ':' ); |
|
1612 fullPrivatePath.Append( privatePath ); |
|
1613 |
|
1614 switch ( aTestDataPath ) |
|
1615 { |
|
1616 case EJPEG_25kB: |
|
1617 case EJPEG_200kB: |
|
1618 case EJPEG_500kB: |
|
1619 case EBMP_25kB: |
|
1620 case EGIF_2kB: |
|
1621 { |
|
1622 TRAP( generatingError, GenerateSourceImageFileL( aTestDataPath, fullPrivatePath ) ); |
|
1623 // GenerateSourceImageFileL calls TestDataPathL -> private session points to z |
|
1624 // change it back to KRegisterDrive, because generated source file is there |
|
1625 // and we need to copy it at the end of this function. |
|
1626 iEnv->FsSession().SetSessionToPrivate( KRegisterDrive ); |
|
1627 break; |
|
1628 } |
|
1629 case EText_10kB: |
|
1630 { |
|
1631 TRAP( generatingError, GenereteSourceTextFileL( fullPrivatePath, 10000 ) ); |
|
1632 // GenerateSourceImageFileL calls TestDataPathL -> private session points to z |
|
1633 // change it back to KRegisterDrive, because generated source file is there |
|
1634 // and we need to copy it at the end of this function. |
|
1635 iEnv->FsSession().SetSessionToPrivate( KRegisterDrive ); |
|
1636 break; |
|
1637 } |
|
1638 case EText_70kB: |
|
1639 { |
|
1640 TRAP( generatingError, GenereteSourceTextFileL( fullPrivatePath, 70000 ) ); |
|
1641 break; |
|
1642 } |
|
1643 default: |
|
1644 { |
|
1645 generatingError = KErrNotSupported; |
|
1646 break; |
|
1647 } |
|
1648 } |
|
1649 } |
|
1650 |
|
1651 if ( iUserCancelled ) |
|
1652 { |
|
1653 LOGSTRING("Creator: CCreatorEngine::TestDataPathL iUserCancelled" ); |
|
1654 User::Leave( KErrCancel ); |
|
1655 } |
|
1656 |
|
1657 if ( generatingError ) |
|
1658 { |
|
1659 // Generating the file failed |
|
1660 |
|
1661 // cancel the dialog |
|
1662 iProgressDialog->ProcessFinishedL(); |
|
1663 DialogDismissedL(EAknSoftkeyBack); |
|
1664 |
|
1665 // show error note |
|
1666 CAknErrorNote* note = new (ELeave) CAknErrorNote; |
|
1667 note->ExecuteLD(_L("Test data missing")); |
|
1668 |
|
1669 User::Leave(KErrPathNotFound); |
|
1670 } |
|
1671 } |
|
1672 |
|
1673 // now copy the data to D-drive to make the file public |
|
1674 iEnv->FsSession().MkDirAll( iTempPath->Des() ); |
|
1675 TInt copyErr = BaflUtils::CopyFile(iEnv->FsSession(), filePath, fullTargetPath); |
|
1676 LOGSTRING4("Creator: CCreatorEngine::TestDataPathL copy %S to %S returns=%d", &filePath, &fullTargetPath, copyErr); |
|
1677 |
|
1678 // make sure that the file won't have a read only attribute |
|
1679 TEntry fileEntry; |
|
1680 iEnv->FsSession().Entry(fullTargetPath, fileEntry); |
|
1681 iEnv->FsSession().SetEntry(fullTargetPath, fileEntry.iModified, NULL, KEntryAttReadOnly); |
|
1682 |
|
1683 filePath = fullTargetPath; // change the reference to the temp path |
|
1684 return filePath; |
|
1685 } |
|
1686 |
|
1687 // --------------------------------------------------------------------------- |
|
1688 |
|
1689 // a generic query which can be used by the modules |
|
1690 TBool CCreatorEngine::EntriesQueryDialogL(TInt& aNumberOfEntries, const TDesC& aPrompt, TBool aAcceptsZero) |
|
1691 { |
|
1692 LOGSTRING("Creator: CCreatorEngine::EntriesQueryDialogL"); |
|
1693 |
|
1694 CAknNumberQueryDialog* dialog = CAknNumberQueryDialog::NewL(aNumberOfEntries, CAknQueryDialog::ENoTone); |
|
1695 dialog->SetMinimumAndMaximum (1, 99999); |
|
1696 |
|
1697 if(dialog->ExecuteLD(R_ENTRY_QUERY, aPrompt)) |
|
1698 { |
|
1699 if (aAcceptsZero) |
|
1700 { |
|
1701 if (aNumberOfEntries>=0) |
|
1702 return ETrue; |
|
1703 else |
|
1704 return EFalse; |
|
1705 } |
|
1706 else |
|
1707 { |
|
1708 if (aNumberOfEntries>0) |
|
1709 return ETrue; |
|
1710 else |
|
1711 return EFalse; |
|
1712 } |
|
1713 } |
|
1714 else |
|
1715 return EFalse; // cancelled |
|
1716 |
|
1717 |
|
1718 } |
|
1719 |
|
1720 // --------------------------------------------------------------------------- |
|
1721 |
|
1722 // a generic query which can be used by the modules |
|
1723 TBool CCreatorEngine::TimeQueryDialogL(TTime& aTime, TInt aResourceId) |
|
1724 { |
|
1725 LOGSTRING("Creator: CCreatorEngine::TimeQueryDialogL"); |
|
1726 |
|
1727 CAknTimeQueryDialog* dialog = CAknTimeQueryDialog::NewL(aTime, CAknQueryDialog::ENoTone); |
|
1728 return dialog->ExecuteLD(aResourceId); |
|
1729 } |
|
1730 |
|
1731 // --------------------------------------------------------------------------- |
|
1732 |
|
1733 // a generic YES NO query which can be used by the modules |
|
1734 TBool CCreatorEngine::YesNoQueryDialogL(const TDesC& aPrompt) |
|
1735 { |
|
1736 LOGSTRING("Creator: CCreatorEngine::YesNoQueryDialogL"); |
|
1737 |
|
1738 CAknQueryDialog* dialog = CAknQueryDialog::NewL( ); |
|
1739 |
|
1740 TInt yes = dialog->ExecuteLD(R_YES_NO_DIALOG, aPrompt); |
|
1741 |
|
1742 return (TBool)yes; |
|
1743 |
|
1744 } |
|
1745 |
|
1746 // --------------------------------------------------------------------------- |
|
1747 |
|
1748 |
|
1749 |
|
1750 // a method to return a default Internet Access Point |
|
1751 TUint32 CCreatorEngine::GetDefaultIAPL() |
|
1752 { |
|
1753 LOGSTRING("Creator: CCreatorEngine::GetDefaultIAPL"); |
|
1754 |
|
1755 TUint32 lIAPid = 1; // Default value |
|
1756 |
|
1757 CCommsDatabase* cDatabase = CCommsDatabase::NewL(); |
|
1758 CleanupStack::PushL(cDatabase); |
|
1759 |
|
1760 CCommsDbTableView* tableView = cDatabase->OpenTableLC(TPtrC(IAP)); |
|
1761 |
|
1762 TInt errorCode = tableView->GotoFirstRecord(); |
|
1763 |
|
1764 if ( errorCode == KErrNone ) |
|
1765 { |
|
1766 TUint32 iValue; |
|
1767 tableView->ReadUintL(TPtrC(COMMDB_ID),iValue); |
|
1768 lIAPid = iValue; |
|
1769 } |
|
1770 |
|
1771 CleanupStack::PopAndDestroy(2); // cDatabase,tableView |
|
1772 |
|
1773 return lIAPid; |
|
1774 } |
|
1775 |
|
1776 // --------------------------------------------------------------------------- |
|
1777 |
|
1778 TUint32 CCreatorEngine::AccessPointNameToIdL(const TDesC& aAPName, TBool aAnyIfNotFound ) |
|
1779 { |
|
1780 LOGSTRING("Creator: CCreatorEngine::AccessPointNameToIdL"); |
|
1781 // Accespoint impl moved from engine to accespoint implementations for supporting 3.0-3.1 and 3.2-> |
|
1782 return iAccessPoints->AccessPointNameToIdL(aAPName, aAnyIfNotFound ); |
|
1783 } |
|
1784 |
|
1785 static CCreatorEngine::TTestDataPath SoundFiles[] = { |
|
1786 CCreatorEngine::EMIDI_10kB, |
|
1787 CCreatorEngine::EWAVE_20kB, |
|
1788 CCreatorEngine::EMP3_250kB, |
|
1789 CCreatorEngine::EAAC_100kB |
|
1790 }; |
|
1791 |
|
1792 static CCreatorEngine::TTestDataPath PictureFiles[] = |
|
1793 { |
|
1794 CCreatorEngine::EJPEG_25kB, |
|
1795 CCreatorEngine::EJPEG_200kB, |
|
1796 CCreatorEngine::EJPEG_500kB, |
|
1797 CCreatorEngine::EPNG_15kB, |
|
1798 CCreatorEngine::EGIF_2kB |
|
1799 }; |
|
1800 |
|
1801 TPtrC CCreatorEngine::CreateSoundFileL(TTestDataPath aId) |
|
1802 { |
|
1803 TPtrC tempPath(TestDataPathL(aId)); |
|
1804 // Copy file to permanent location: |
|
1805 TParse parser; |
|
1806 parser.Set(tempPath, NULL, NULL); |
|
1807 TPtrC fileName(parser.NameAndExt()); |
|
1808 HBufC* fullTargetPath = HBufC::NewLC( KMaxFileName ); |
|
1809 fullTargetPath->Des().Copy( PathInfo::PhoneMemoryRootPath() ); |
|
1810 fullTargetPath->Des().Append( PathInfo::DigitalSoundsPath() ); |
|
1811 |
|
1812 fullTargetPath->Des().Append(fileName); |
|
1813 CopyFileL(tempPath, *fullTargetPath); |
|
1814 iAllocatedFilePaths.AppendL(fullTargetPath); |
|
1815 CleanupStack::Pop(); // fullTargetPath |
|
1816 return fullTargetPath->Des(); |
|
1817 } |
|
1818 TPtrC CCreatorEngine::CreateRandomSoundFileL() |
|
1819 { |
|
1820 TInt numOfFiles = sizeof(SoundFiles) / sizeof(TTestDataPath); |
|
1821 return CreateSoundFileL(SoundFiles[RandomNumber(0, numOfFiles-1)]); |
|
1822 } |
|
1823 TPtrC CCreatorEngine::RandomSoundFileL() |
|
1824 { |
|
1825 TInt numOfFiles = sizeof(SoundFiles) / sizeof(TTestDataPath); |
|
1826 return TestDataPathL(SoundFiles[RandomNumber(0, numOfFiles-1)]); |
|
1827 } |
|
1828 |
|
1829 TPtrC CCreatorEngine::RandomPictureFileL() |
|
1830 { |
|
1831 TInt numOfFiles = sizeof(PictureFiles) / sizeof(TTestDataPath); |
|
1832 return TestDataPathL(PictureFiles[RandomNumber(0, numOfFiles-1)]); |
|
1833 } |
|
1834 // --------------------------------------------------------------------------- |
|
1835 |
|
1836 // returns a random string from the resource files |
|
1837 TPtrC CCreatorEngine::RandomString(enum TRandomStringType aRandomStringType) |
|
1838 { |
|
1839 LOGSTRING("Creator: CCreatorEngine::RandomString"); |
|
1840 |
|
1841 // Let's see if the array is OK and the string arrays are in correct order: |
|
1842 if( ((TInt) aRandomStringType) < iStringArrays.Count() && |
|
1843 iStringArrays[aRandomStringType].iStringType == aRandomStringType) |
|
1844 { |
|
1845 TInt rand = (TInt) (iStringArrays[aRandomStringType].iArrayPtr->Count() * Math::FRand(iSeed)); |
|
1846 return (*iStringArrays[aRandomStringType].iArrayPtr)[rand]; |
|
1847 } |
|
1848 |
|
1849 // Now let's loop the arrays and try to find one with the type: |
|
1850 for( TInt i = 0; i < iStringArrays.Count(); ++i ) |
|
1851 { |
|
1852 if( iStringArrays[i].iStringType == aRandomStringType ) |
|
1853 { |
|
1854 TInt rand = (TInt) (iStringArrays[i].iArrayPtr->Count() * Math::FRand(iSeed)); |
|
1855 return (*iStringArrays[i].iArrayPtr)[rand]; |
|
1856 } |
|
1857 } |
|
1858 |
|
1859 User::Panic (_L("Random string"), 402); |
|
1860 return NULL; |
|
1861 } |
|
1862 |
|
1863 // --------------------------------------------------------------------------- |
|
1864 |
|
1865 // returns a random number |
|
1866 TInt CCreatorEngine::RandomNumber(TInt aRange) |
|
1867 { |
|
1868 LOGSTRING2("Creator: CCreatorEngine::RandomNumber aRange=%d", aRange); |
|
1869 |
|
1870 return (TInt) (aRange*Math::FRand(iSeed)); |
|
1871 } |
|
1872 |
|
1873 // --------------------------------------------------------------------------- |
|
1874 |
|
1875 // returns a random number |
|
1876 TInt CCreatorEngine::RandomNumber(TInt aMin, TInt aMax) |
|
1877 { |
|
1878 LOGSTRING3("Creator: CCreatorEngine::RandomNumber aMin=%d aMax=%d", aMin, aMax); |
|
1879 |
|
1880 TInt range = (aMax > aMin ? aMax - aMin : aMin - aMax) + 1; |
|
1881 TInt random = (TInt) (range*Math::FRand(iSeed)); |
|
1882 |
|
1883 random = (random % range) + aMin; |
|
1884 |
|
1885 if (random > aMax) |
|
1886 random = aMax; |
|
1887 else if (random < aMin) |
|
1888 random = aMin; |
|
1889 |
|
1890 return random; |
|
1891 } |
|
1892 |
|
1893 TTime CCreatorEngine::RandomTime(TTime baseTime, TRandomDateType type, TInt aMinHours, TInt aMaxHours, TInt aMinMinutes, TInt aMaxMinutes ) |
|
1894 { |
|
1895 TInt randomHours = RandomNumber(aMinHours, aMaxHours); |
|
1896 TInt randomMinutes = RandomNumber(aMinMinutes, aMaxMinutes); |
|
1897 |
|
1898 switch( type ) |
|
1899 { |
|
1900 case EDatePast: |
|
1901 return (baseTime - TTimeIntervalHours(randomHours)) - TTimeIntervalMinutes(randomMinutes); |
|
1902 case EDateFuture: |
|
1903 return (baseTime + TTimeIntervalHours(randomHours)) + TTimeIntervalMinutes(randomMinutes); |
|
1904 default: |
|
1905 break; |
|
1906 } |
|
1907 return baseTime; |
|
1908 } |
|
1909 |
|
1910 TTime CCreatorEngine::RandomDate(TTime baseTime, TRandomDateType type, TInt aMinDays, TInt aMaxDays) |
|
1911 { |
|
1912 TInt random = RandomNumber(aMinDays, aMaxDays); |
|
1913 |
|
1914 switch( type ) |
|
1915 { |
|
1916 case EDatePast: |
|
1917 return baseTime - TTimeIntervalDays(random); |
|
1918 case EDateFuture: |
|
1919 return baseTime + TTimeIntervalDays(random); |
|
1920 default: |
|
1921 break; |
|
1922 } |
|
1923 |
|
1924 return baseTime; |
|
1925 } |
|
1926 |
|
1927 TTime CCreatorEngine::RandomDate(TRandomDateType type, TInt aMinDays, TInt aMaxDays) |
|
1928 { |
|
1929 TTime time; |
|
1930 // Set to current time: |
|
1931 time.HomeTime(); |
|
1932 return RandomDate(time, type, aMinDays, aMaxDays); |
|
1933 } |
|
1934 |
|
1935 HBufC* CCreatorEngine::CreateEmailAddressLC() |
|
1936 { |
|
1937 _LIT(KCountry, "com"); |
|
1938 return CreateEmailAddressLC(RandomString(EFirstName), RandomString(ESurname), RandomString(ECompany), KCountry); |
|
1939 } |
|
1940 |
|
1941 HBufC* CCreatorEngine::CreateHTTPUrlLC() |
|
1942 { |
|
1943 _LIT(KProtocol, "http://"); |
|
1944 _LIT(KPrefix, "www"); |
|
1945 _LIT(KCountry, "com"); |
|
1946 return CreateUrlLC(KProtocol, KPrefix, RandomString(ECompany), KCountry); |
|
1947 } |
|
1948 |
|
1949 HBufC* CCreatorEngine::CreateRandomStringLC(TInt aStrLen) |
|
1950 { |
|
1951 TInt minAscii = 65; |
|
1952 TInt maxAscii = 90; |
|
1953 HBufC* str = HBufC::NewL(aStrLen); |
|
1954 CleanupStack::PushL(str); |
|
1955 for( TInt i = 0; i < aStrLen; ++i ) |
|
1956 { |
|
1957 TInt random = RandomNumber(minAscii, maxAscii); |
|
1958 TChar randomChar = TChar((TUint) random); |
|
1959 str->Des().Append(randomChar); |
|
1960 } |
|
1961 return str; |
|
1962 } |
|
1963 |
|
1964 HBufC* CCreatorEngine::CreateEmailAddressLC( |
|
1965 const TDesC& firstname, |
|
1966 const TDesC& lastname, |
|
1967 const TDesC& domain, |
|
1968 const TDesC& country ) const |
|
1969 { |
|
1970 HBufC* email = HBufC::New(firstname.Length() + lastname.Length() + domain.Length() + country.Length() + 3); |
|
1971 CleanupStack::PushL(email); |
|
1972 _LIT(KEmailAddr, "%S.%S@%S.%S"); |
|
1973 email->Des().Format(KEmailAddr, &firstname, &lastname, &domain, &country); |
|
1974 return email; |
|
1975 } |
|
1976 |
|
1977 HBufC* CCreatorEngine::CreateUrlLC( |
|
1978 const TDesC& protocol, |
|
1979 const TDesC& prefix, |
|
1980 const TDesC& domain, |
|
1981 const TDesC& country) const |
|
1982 { |
|
1983 HBufC* url = HBufC::New(protocol.Size() + prefix.Size() + domain.Size() + country.Size() + 2); |
|
1984 CleanupStack::PushL(url); |
|
1985 _LIT(KUrl, "%S%S.%S.%S"); |
|
1986 url->Des().Format(KUrl, &protocol, &prefix, &domain, &country); |
|
1987 return url; |
|
1988 } |
|
1989 // --------------------------------------------------------------------------- |
|
1990 |
|
1991 void CCreatorEngine::SetDefaultPathForFileCommandL(TInt aCommand, TFileName& aPath) |
|
1992 { |
|
1993 aPath.Copy( PathInfo::PhoneMemoryRootPath() ); |
|
1994 switch (aCommand) |
|
1995 { |
|
1996 case ECmdCreateFileEntryJPEG_25kB: |
|
1997 case ECmdCreateFileEntryJPEG_200kB: |
|
1998 case ECmdCreateFileEntryJPEG_500kB: |
|
1999 case ECmdCreateFileEntryPNG_15kB: |
|
2000 case ECmdCreateFileEntryGIF_2kB: |
|
2001 case ECmdCreateFileEntryBMP_25kB: |
|
2002 case ECmdCreateFileEntrySVG_15kB: |
|
2003 case ECmdCreateFileEntryTIF_25kB: |
|
2004 case ECmdCreateFileEntryJP2_65kB: |
|
2005 |
|
2006 { aPath.Append( PathInfo::ImagesPath() ); break; } |
|
2007 |
|
2008 case ECmdCreateFileEntryRNG_1kB: |
|
2009 { aPath.Append( PathInfo::SimpleSoundsPath() ); break; } |
|
2010 |
|
2011 case ECmdCreateFileEntryMIDI_10kB: |
|
2012 case ECmdCreateFileEntryWAV_20kB: |
|
2013 case ECmdCreateFileEntryAMR_20kB: |
|
2014 case ECmdCreateFileEntryMP3_250kB: |
|
2015 case ECmdCreateFileEntryAAC_100kB: |
|
2016 case ECmdCreateFileEntryWMA_50kB: |
|
2017 { aPath.Append( PathInfo::DigitalSoundsPath() ); break; } |
|
2018 |
|
2019 case ECmdCreateFileEntry3GPP_70kB: |
|
2020 case ECmdCreateFileEntryRM_95kB: |
|
2021 case ECmdCreateFileEntryMP4_200kB: |
|
2022 case ECmdCreateFileEntryWMV_200kB: |
|
2023 |
|
2024 { aPath.Append( PathInfo::VideosPath() ); break; } |
|
2025 |
|
2026 case ECmdCreateFileEntryEmptyFolder: |
|
2027 { aPath.Append( _L("MyFolder\\") ); break; } |
|
2028 |
|
2029 default: |
|
2030 { aPath.Append( PathInfo::OthersPath() ); break; } |
|
2031 |
|
2032 } |
|
2033 } |
|
2034 |
|
2035 |
|
2036 // --------------------------------------------------------------------------- |
|
2037 |
|
2038 void CCreatorEngine::CancelComplete() |
|
2039 { |
|
2040 LOGSTRING("Creator: CCreatorEngine::CancelComplete"); |
|
2041 // free resources and show a note |
|
2042 TRAP_IGNORE( ShutDownEnginesL() ); |
|
2043 |
|
2044 TRAP_IGNORE( |
|
2045 CAknInformationNote* note = new (ELeave) CAknInformationNote; |
|
2046 note->ExecuteLD(_L("Cancelled")); |
|
2047 ); |
|
2048 } |
|
2049 |
|
2050 // --------------------------------------------------------------------------- |
|
2051 |
|
2052 TCommand::TCommand(TInt aCommandId, CCreatorModuleBaseParameters* aParameters) |
|
2053 { |
|
2054 iCommandId = aCommandId; |
|
2055 iParameters = aParameters; |
|
2056 } |
|
2057 |
|
2058 // --------------------------------------------------------------------------- |
|
2059 |
|
2060 TCommand::~TCommand() |
|
2061 { |
|
2062 } |
|
2063 |
|
2064 // --------------------------------------------------------------------------- |
|
2065 |
|
2066 CAsyncWaiter* CAsyncWaiter::NewL(TInt aPriority) |
|
2067 { |
|
2068 CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority); |
|
2069 return self; |
|
2070 } |
|
2071 |
|
2072 CAsyncWaiter* CAsyncWaiter::NewLC(TInt aPriority) |
|
2073 { |
|
2074 CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority); |
|
2075 CleanupStack::PushL(self); |
|
2076 return self; |
|
2077 } |
|
2078 |
|
2079 CAsyncWaiter::CAsyncWaiter(TInt aPriority) : CActive(aPriority) |
|
2080 { |
|
2081 CActiveScheduler::Add(this); |
|
2082 } |
|
2083 |
|
2084 CAsyncWaiter::~CAsyncWaiter() |
|
2085 { |
|
2086 Cancel(); |
|
2087 } |
|
2088 |
|
2089 void CAsyncWaiter::StartAndWait() |
|
2090 { |
|
2091 LOGSTRING("Creator: CAsyncWaiter::StartAndWait"); |
|
2092 |
|
2093 iStatus = KRequestPending; |
|
2094 SetActive(); |
|
2095 iWait.Start(); |
|
2096 } |
|
2097 |
|
2098 TInt CAsyncWaiter::Result() const |
|
2099 { |
|
2100 return iError; |
|
2101 } |
|
2102 |
|
2103 void CAsyncWaiter::RunL() |
|
2104 { |
|
2105 LOGSTRING("Creator: CAsyncWaiter::RunL"); |
|
2106 |
|
2107 iError = iStatus.Int(); |
|
2108 CAknEnv::StopSchedulerWaitWithBusyMessage( iWait ); |
|
2109 } |
|
2110 |
|
2111 void CAsyncWaiter::DoCancel() |
|
2112 { |
|
2113 LOGSTRING("Creator: CAsyncWaiter::DoCancel"); |
|
2114 |
|
2115 iError = KErrCancel; |
|
2116 if( iStatus == KRequestPending ) |
|
2117 { |
|
2118 TRequestStatus* s=&iStatus; |
|
2119 User::RequestComplete( s, KErrCancel ); |
|
2120 } |
|
2121 |
|
2122 CAknEnv::StopSchedulerWaitWithBusyMessage( iWait ); |
|
2123 } |
|
2124 |
|
2125 FileMapping::FileMapping( const TDesC& aAttName, TInt aAttId, TInt aCommandId ) |
|
2126 : |
|
2127 iFileName(aAttName), |
|
2128 iFileId(aAttId), |
|
2129 iCommandId(aCommandId) |
|
2130 {} |
|
2131 |
|
2132 const TDesC& FileMapping::FileName() const |
|
2133 { |
|
2134 return iFileName; |
|
2135 } |
|
2136 |
|
2137 TInt FileMapping::FileId() const |
|
2138 { |
|
2139 return iFileId; |
|
2140 } |
|
2141 |
|
2142 TInt FileMapping::CommandId() const |
|
2143 { |
|
2144 return iCommandId; |
|
2145 } |
|
2146 |
|
2147 // --------------------------------------------------------------------------- |
|
2148 CDictionaryFileStore* CCreatorEngine::FileStoreLC() |
|
2149 { |
|
2150 LOGSTRING("Creator: CCreatorEngine::FileStoreLC"); |
|
2151 CDictionaryFileStore* store; |
|
2152 |
|
2153 // make sure that the private path of this app in c-drive exists |
|
2154 CEikonEnv::Static()->FsSession().CreatePrivatePath( KRegisterDrive ); // c:\\private\\20011383\\ |
|
2155 |
|
2156 // handle register always in the private directory |
|
2157 User::LeaveIfError( CEikonEnv::Static()->FsSession().SetSessionToPrivate( KRegisterDrive ) ); |
|
2158 store = CDictionaryFileStore::OpenLC( CEikonEnv::Static()->FsSession(), KRegisterFileName, KUidCreatorApp ); |
|
2159 return store; |
|
2160 } |
|
2161 |
|
2162 // --------------------------------------------------------------------------- |
|
2163 void CCreatorEngine::ReadEntryIdsFromStoreL( RArray<TInt>& aEntryIds, const TUid aModuleUid ) |
|
2164 { |
|
2165 LOGSTRING("Creator: CCreatorEngine::ReadEntryIdsFromStoreL"); |
|
2166 CDictionaryFileStore* store = FileStoreLC(); |
|
2167 User::LeaveIfNull( store ); |
|
2168 if ( store->IsPresentL( aModuleUid ) ) |
|
2169 { |
|
2170 RDictionaryReadStream in; |
|
2171 in.OpenLC( *store, aModuleUid ); |
|
2172 TFileName fullPath; |
|
2173 TInt err( KErrNone ); |
|
2174 TInt id( KErrNotFound ); |
|
2175 while ( !err ) |
|
2176 { |
|
2177 TRAP( err, id = in.ReadInt32L() ); // will leave with KErrEof |
|
2178 if ( !err ) |
|
2179 { |
|
2180 aEntryIds.Append( id ); |
|
2181 } |
|
2182 } |
|
2183 CleanupStack::PopAndDestroy( &in ); |
|
2184 } |
|
2185 CleanupStack::PopAndDestroy( store ); |
|
2186 } |
|
2187 |
|
2188 // --------------------------------------------------------------------------- |
|
2189 void CCreatorEngine::WriteEntryIdsToStoreL( RArray<TInt>& aEntryIds, const TUid aModuleUid ) |
|
2190 { |
|
2191 LOGSTRING("Creator: CCreatorEngine::WriteEntryIdsToStoreL"); |
|
2192 CDictionaryFileStore* store = FileStoreLC(); |
|
2193 User::LeaveIfNull( store ); |
|
2194 |
|
2195 // backup previous ids from store |
|
2196 // otherwise they would be overwritten when calling out.WriteL |
|
2197 RArray<TInt> previousIds; |
|
2198 CleanupClosePushL( previousIds ); |
|
2199 |
|
2200 if ( store->IsPresentL( aModuleUid ) ) |
|
2201 { |
|
2202 RDictionaryReadStream in; |
|
2203 in.OpenLC( *store, aModuleUid ); |
|
2204 TInt err( KErrNone ); |
|
2205 TInt id( KErrNotFound ); |
|
2206 while ( !err ) |
|
2207 { |
|
2208 TRAP( err, id = in.ReadInt32L() ); // will leave with KErrEof |
|
2209 if ( !err ) |
|
2210 { |
|
2211 previousIds.Append( id ); |
|
2212 } |
|
2213 } |
|
2214 CleanupStack::PopAndDestroy( &in ); |
|
2215 } |
|
2216 |
|
2217 RDictionaryWriteStream out; |
|
2218 out.AssignLC( *store, aModuleUid ); |
|
2219 |
|
2220 // restore previous ids to store |
|
2221 for ( TInt i = 0; i < previousIds.Count(); i++ ) |
|
2222 { |
|
2223 out.WriteInt32L( previousIds[i] ); |
|
2224 } |
|
2225 |
|
2226 // write new ids to store |
|
2227 for ( TInt i = 0; i < aEntryIds.Count(); i++ ) |
|
2228 { |
|
2229 out.WriteInt32L( aEntryIds[i] ); |
|
2230 } |
|
2231 |
|
2232 out.CommitL(); |
|
2233 CleanupStack::PopAndDestroy( &out ); |
|
2234 |
|
2235 store->CommitL(); |
|
2236 CleanupStack::PopAndDestroy( &previousIds ); |
|
2237 CleanupStack::PopAndDestroy( store ); |
|
2238 } |
|
2239 |
|
2240 // --------------------------------------------------------------------------- |
|
2241 void CCreatorEngine::ReadEntryIdsFromStoreL( RArray<TUint32>& aEntryIds, const TUid aModuleUid ) |
|
2242 { |
|
2243 LOGSTRING("Creator: CCreatorEngine::ReadEntryIdsFromStoreL"); |
|
2244 CDictionaryFileStore* store = FileStoreLC(); |
|
2245 User::LeaveIfNull( store ); |
|
2246 if ( store->IsPresentL( aModuleUid ) ) |
|
2247 { |
|
2248 RDictionaryReadStream in; |
|
2249 in.OpenLC( *store, aModuleUid ); |
|
2250 TFileName fullPath; |
|
2251 TInt err( KErrNone ); |
|
2252 TUint32 id( KErrNone ); |
|
2253 while ( !err ) |
|
2254 { |
|
2255 TRAP( err, id = in.ReadUint32L() ); // will leave with KErrEof |
|
2256 if ( !err ) |
|
2257 { |
|
2258 aEntryIds.Append( id ); |
|
2259 } |
|
2260 } |
|
2261 CleanupStack::PopAndDestroy( &in ); |
|
2262 } |
|
2263 CleanupStack::PopAndDestroy( store ); |
|
2264 } |
|
2265 |
|
2266 // --------------------------------------------------------------------------- |
|
2267 void CCreatorEngine::WriteEntryIdsToStoreL( RArray<TUint32>& aEntryIds, const TUid aModuleUid ) |
|
2268 { |
|
2269 LOGSTRING("Creator: CCreatorEngine::WriteEntryIdsToStoreL"); |
|
2270 CDictionaryFileStore* store = FileStoreLC(); |
|
2271 User::LeaveIfNull( store ); |
|
2272 |
|
2273 // backup previous ids from store |
|
2274 // otherwise they would be overwritten when calling out.WriteL |
|
2275 RArray<TUint32> previousIds; |
|
2276 CleanupClosePushL( previousIds ); |
|
2277 |
|
2278 if ( store->IsPresentL( aModuleUid ) ) |
|
2279 { |
|
2280 RDictionaryReadStream in; |
|
2281 in.OpenLC( *store, aModuleUid ); |
|
2282 TInt err( KErrNone ); |
|
2283 TUint32 id( KErrNone ); |
|
2284 while ( !err ) |
|
2285 { |
|
2286 TRAP( err, id = in.ReadUint32L() ); // will leave with KErrEof |
|
2287 if ( !err ) |
|
2288 { |
|
2289 previousIds.Append( id ); |
|
2290 } |
|
2291 } |
|
2292 CleanupStack::PopAndDestroy( &in ); |
|
2293 } |
|
2294 |
|
2295 RDictionaryWriteStream out; |
|
2296 out.AssignLC( *store, aModuleUid ); |
|
2297 |
|
2298 // restore previous ids to store |
|
2299 for ( TInt i = 0; i < previousIds.Count(); i++ ) |
|
2300 { |
|
2301 out.WriteUint32L( previousIds[i] ); |
|
2302 } |
|
2303 |
|
2304 // write new ids to store |
|
2305 for ( TInt i = 0; i < aEntryIds.Count(); i++ ) |
|
2306 { |
|
2307 out.WriteUint32L( aEntryIds[i] ); |
|
2308 } |
|
2309 |
|
2310 out.CommitL(); |
|
2311 CleanupStack::PopAndDestroy( &out ); |
|
2312 |
|
2313 store->CommitL(); |
|
2314 CleanupStack::PopAndDestroy( &previousIds ); |
|
2315 CleanupStack::PopAndDestroy( store ); |
|
2316 } |
|
2317 |
|
2318 // --------------------------------------------------------------------------- |
|
2319 void CCreatorEngine::RemoveStoreL( const TUid aModuleUid ) |
|
2320 { |
|
2321 LOGSTRING("Creator: CCreatorEngine::RemoveStoreL"); |
|
2322 CDictionaryFileStore* store = FileStoreLC(); |
|
2323 User::LeaveIfNull( store ); |
|
2324 if ( store->IsPresentL( aModuleUid ) ) |
|
2325 { |
|
2326 // entries of this module should be deleted by now, |
|
2327 // remove the Creator internal registry for this module |
|
2328 store->Remove( aModuleUid ); |
|
2329 store->CommitL(); |
|
2330 } |
|
2331 CleanupStack::PopAndDestroy( store ); |
|
2332 } |
|
2333 |
|
2334 //---------------------------------------------------------------------------- |
|
2335 void CCreatorEngine::GenerateSourceImageFileL( |
|
2336 const CCreatorEngine::TTestDataPath aFileType, |
|
2337 const TDesC& aFileName ) |
|
2338 { |
|
2339 LOGSTRING("Creator: CCreatorEngine::GenerateSourceImageFileL"); |
|
2340 |
|
2341 // Peek file size |
|
2342 RFile file; |
|
2343 TInt fileSize( 0 ); |
|
2344 // Using png file as the source file |
|
2345 TFileName fileName = TestDataPathL( CCreatorEngine::EPNG_15kB ); |
|
2346 User::LeaveIfError( file.Open( iEnv->FsSession(), |
|
2347 fileName, |
|
2348 EFileRead | EFileShareAny ) ); |
|
2349 CleanupClosePushL( file ); |
|
2350 User::LeaveIfError( file.Size( fileSize ) ); |
|
2351 CleanupStack::PopAndDestroy( &file ); |
|
2352 |
|
2353 // Using heap variables, because bitmaps |
|
2354 // may reserve large amount of memory. |
|
2355 |
|
2356 // Read data from the file |
|
2357 RFileReadStream ws; |
|
2358 User::LeaveIfError( ws.Open( iEnv->FsSession(), |
|
2359 fileName, |
|
2360 EFileStream | EFileRead | EFileShareAny ) ); |
|
2361 CleanupClosePushL( ws ); |
|
2362 delete iBitmapData; |
|
2363 iBitmapData = NULL; |
|
2364 iBitmapData = HBufC8::NewL( fileSize ); |
|
2365 TPtr8 dataPtr = iBitmapData->Des(); |
|
2366 ws.ReadL( dataPtr, fileSize ); |
|
2367 CleanupStack::PopAndDestroy( &ws ); |
|
2368 |
|
2369 // Create decoder for the data |
|
2370 delete iDecoder; |
|
2371 iDecoder = NULL; |
|
2372 iDecoder = CImageDecoder::DataNewL( iEnv->FsSession(), dataPtr ); |
|
2373 iFrameinfo = iDecoder->FrameInfo(); |
|
2374 |
|
2375 // Create bitmap handle for the source image |
|
2376 iBitmap = new (ELeave) CFbsBitmap(); |
|
2377 User::LeaveIfError( iBitmap->Create( iFrameinfo.iFrameCoordsInPixels.Size(), EColor16M ) ); |
|
2378 |
|
2379 // Convert the data from the file into bitmap format (inmemory) |
|
2380 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
2381 iDecoder->Convert( &waiter->iStatus, *iBitmap ); |
|
2382 waiter->StartAndWait(); |
|
2383 delete iDecoder; |
|
2384 iDecoder = NULL; |
|
2385 delete iBitmapData; |
|
2386 iBitmapData = NULL; |
|
2387 if ( iUserCancelled ) |
|
2388 { |
|
2389 CancelComplete(); |
|
2390 User::Leave( KErrCancel ); |
|
2391 } |
|
2392 User::LeaveIfError( waiter->Result() ); |
|
2393 |
|
2394 // Define the target dimensions and image quality |
|
2395 // so that the generated file size will match required size. |
|
2396 // Quality and scaling factors are defined experimentally. |
|
2397 delete iScaler; |
|
2398 iScaler = NULL; |
|
2399 iScaler = CBitmapScaler::NewL(); |
|
2400 iScaledBitmap = new (ELeave) CFbsBitmap(); |
|
2401 // use original size as base |
|
2402 TSize scaledSize( iFrameinfo.iFrameCoordsInPixels.Size() ); |
|
2403 delete iFrameImageData; |
|
2404 iFrameImageData = NULL; |
|
2405 iFrameImageData = CFrameImageData::NewL(); |
|
2406 TBuf8<64> mimeType; |
|
2407 TJpegImageData* jpegImageData( NULL ); |
|
2408 TBmpImageData* bmpImageData( NULL ); |
|
2409 switch ( aFileType ) |
|
2410 { |
|
2411 case CCreatorEngine::EJPEG_25kB: |
|
2412 // QualityFactor = 93 and size factor = 2 -> 25kB jpeg file |
|
2413 mimeType.Copy( _L8("image/jpeg") ); |
|
2414 jpegImageData = new (ELeave) TJpegImageData; |
|
2415 // Set some format specific data |
|
2416 jpegImageData->iSampleScheme = TJpegImageData::EColor444; |
|
2417 jpegImageData->iQualityFactor = 93; // 0..100 |
|
2418 // ownership passed to iFrameImageData after AppendImageData |
|
2419 User::LeaveIfError( iFrameImageData->AppendImageData( jpegImageData ) ); |
|
2420 scaledSize.iHeight *= 2; |
|
2421 scaledSize.iWidth *= 2; |
|
2422 break; |
|
2423 case CCreatorEngine::EJPEG_200kB: |
|
2424 { |
|
2425 mimeType.Copy( _L8("image/jpeg") ); |
|
2426 jpegImageData = new (ELeave) TJpegImageData; |
|
2427 // Set some format specific data |
|
2428 jpegImageData->iSampleScheme = TJpegImageData::EColor444; |
|
2429 #ifdef __WINS__ |
|
2430 // QualityFactor = 95 and size factor = 7 -> 196kB jpeg file |
|
2431 jpegImageData->iQualityFactor = 95; // 0..100 |
|
2432 scaledSize.iHeight *= 7; |
|
2433 scaledSize.iWidth *= 7; |
|
2434 #else |
|
2435 // In hw the image compression seems to work |
|
2436 // more efficiently. Need to set greater values. |
|
2437 jpegImageData->iQualityFactor = 100; // 0..100 |
|
2438 scaledSize.iHeight *= 7; |
|
2439 scaledSize.iWidth *= 7; |
|
2440 // 100, 7, 7 -> 213kB |
|
2441 #endif |
|
2442 // ownership passed to iFrameImageData after AppendImageData |
|
2443 User::LeaveIfError( iFrameImageData->AppendImageData( jpegImageData ) ); |
|
2444 break; |
|
2445 } |
|
2446 case CCreatorEngine::EJPEG_500kB: |
|
2447 { |
|
2448 mimeType.Copy( _L8("image/jpeg") ); |
|
2449 jpegImageData = new (ELeave) TJpegImageData; |
|
2450 // Set some format specific data |
|
2451 jpegImageData->iSampleScheme = TJpegImageData::EColor444; |
|
2452 #ifdef __WINS__ |
|
2453 // QualityFactor = 99 and size factor = 8 -> 514kB jpeg file |
|
2454 jpegImageData->iQualityFactor = 99; // 0..100 |
|
2455 scaledSize.iHeight *= 8; |
|
2456 scaledSize.iWidth *= 8; |
|
2457 #else |
|
2458 // In hw the image compression seems to work |
|
2459 // more efficiently. Need to set greater values. |
|
2460 jpegImageData->iQualityFactor = 100; // 0..100 |
|
2461 scaledSize.iHeight *= 13; |
|
2462 scaledSize.iWidth *= 13; |
|
2463 // 100, 13, 13 -> 535kB |
|
2464 #endif |
|
2465 // ownership passed to iFrameImageData after AppendImageData |
|
2466 User::LeaveIfError( iFrameImageData->AppendImageData( jpegImageData ) ); |
|
2467 break; |
|
2468 } |
|
2469 case CCreatorEngine::EBMP_25kB: |
|
2470 { |
|
2471 // bit depyh 8 and 11/10 size factor -> 25kB bmp |
|
2472 mimeType.Copy( _L8("image/bmp") ); |
|
2473 bmpImageData = new (ELeave) TBmpImageData; |
|
2474 bmpImageData->iBitsPerPixel = 8; |
|
2475 // ownership passed to iFrameImageData after AppendImageData |
|
2476 User::LeaveIfError( iFrameImageData->AppendImageData( bmpImageData ) ); |
|
2477 scaledSize.iHeight *= 11; |
|
2478 scaledSize.iWidth *= 11; |
|
2479 scaledSize.iHeight /= 10; |
|
2480 scaledSize.iWidth /= 10; |
|
2481 break; |
|
2482 } |
|
2483 case CCreatorEngine::EGIF_2kB: |
|
2484 { |
|
2485 // size factor 1/2 -> 2560B gif |
|
2486 mimeType.Copy( _L8("image/gif") ); |
|
2487 // GIF encoder is not configurable, only the size matters here |
|
2488 scaledSize.iHeight /= 2; |
|
2489 scaledSize.iWidth /= 2; |
|
2490 break; |
|
2491 } |
|
2492 default: break; |
|
2493 } |
|
2494 |
|
2495 // Scale to reach target size |
|
2496 User::LeaveIfError( iScaledBitmap->Create( scaledSize, EColor16M ) ); |
|
2497 iScaler->Scale( &waiter->iStatus, *iBitmap, *iScaledBitmap ); |
|
2498 waiter->StartAndWait(); |
|
2499 delete iBitmap; |
|
2500 iBitmap = NULL; |
|
2501 delete iScaler; |
|
2502 iScaler = NULL; |
|
2503 if ( iUserCancelled ) |
|
2504 { |
|
2505 CancelComplete(); |
|
2506 User::Leave( KErrCancel ); |
|
2507 } |
|
2508 User::LeaveIfError( waiter->Result() ); |
|
2509 |
|
2510 // Encode to target format |
|
2511 delete iEncoder; |
|
2512 iEncoder = NULL; |
|
2513 // Creating CImageEncoder opens the target file |
|
2514 iEncoder = CImageEncoder::FileNewL( iEnv->FsSession(), aFileName, mimeType ); |
|
2515 |
|
2516 // Do the conversion to target format, this will write to the file |
|
2517 iEncoder->Convert( &waiter->iStatus, *iScaledBitmap, iFrameImageData ); |
|
2518 waiter->StartAndWait(); |
|
2519 delete iEncoder; |
|
2520 iEncoder = NULL; |
|
2521 delete iFrameImageData; |
|
2522 iFrameImageData = NULL; |
|
2523 delete iScaledBitmap; |
|
2524 iScaledBitmap = NULL; |
|
2525 if ( iUserCancelled ) |
|
2526 { |
|
2527 CancelComplete(); |
|
2528 User::Leave( KErrCancel ); |
|
2529 } |
|
2530 User::LeaveIfError( waiter->Result() ); |
|
2531 CleanupStack::PopAndDestroy( waiter ); |
|
2532 } |
|
2533 |
|
2534 //---------------------------------------------------------------------------- |
|
2535 void CCreatorEngine::GenereteSourceTextFileL( const TDesC& aFileName, TInt aSize ) |
|
2536 { |
|
2537 LOGSTRING("Creator: CCreatorEngine::GenereteSourceTextFileL"); |
|
2538 RFile txtFile; |
|
2539 _LIT8( KTestContent, "Testing... "); |
|
2540 _LIT8( KTestContentCRLF, "\r\n"); |
|
2541 txtFile.Create( iEnv->FsSession(), |
|
2542 aFileName, |
|
2543 EFileStreamText | EFileWrite | EFileShareAny ); |
|
2544 CleanupClosePushL( txtFile ); |
|
2545 for ( TInt i = 1; i*KTestContent().Length() < aSize; i++ ) |
|
2546 { |
|
2547 User::LeaveIfError( txtFile.Write( KTestContent ) ); |
|
2548 if ( !( i % 10 ) ) // linefeed for every 10th |
|
2549 { |
|
2550 User::LeaveIfError( txtFile.Write( KTestContentCRLF ) ); |
|
2551 } |
|
2552 } |
|
2553 CleanupStack::PopAndDestroy( &txtFile ); |
|
2554 } |