|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <aknlists.h> |
|
21 #include <aknsskininstance.h> |
|
22 #include <data_caging_path_literals.hrh> |
|
23 |
|
24 #include "engine.h" |
|
25 #include "enginewrapper.h" |
|
26 #include "creator_traces.h" |
|
27 #include "creator_factory.h" |
|
28 |
|
29 |
|
30 |
|
31 const TInt KReadBufSize = 8192; |
|
32 |
|
33 // Creator random data file filter |
|
34 _LIT(KRandomDataFileFilter, "*.creatordataxml"); |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 |
|
38 |
|
39 CCommandParser* CCommandParser::NewL(CCreatorEngine* aEngine) |
|
40 { |
|
41 CCommandParser* self = CCommandParser::NewLC(aEngine); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 CCommandParser* CCommandParser::NewLC(CCreatorEngine* aEngine) |
|
47 { |
|
48 CCommandParser* self = new (ELeave) CCommandParser; |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aEngine); |
|
51 return self; |
|
52 } |
|
53 |
|
54 CCommandParser::CCommandParser() |
|
55 { |
|
56 } |
|
57 |
|
58 void CCommandParser::ConstructL(CCreatorEngine* aEngine) |
|
59 { |
|
60 LOGSTRING("Creator: CCommandParser::ConstructL"); |
|
61 |
|
62 iEngine = aEngine; |
|
63 |
|
64 iReadBuf = HBufC8::NewL(KReadBufSize); |
|
65 } |
|
66 |
|
67 CCommandParser::~CCommandParser() |
|
68 { |
|
69 LOGSTRING("Creator: CCommandParser::~CCommandParser"); |
|
70 |
|
71 if (iSearchArray) |
|
72 delete iSearchArray; |
|
73 |
|
74 if (iReadBuf) |
|
75 delete iReadBuf; |
|
76 } |
|
77 |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 //#if(!defined __SERIES60_30__ && !defined __SERIES60_31__) |
|
81 void CCommandParser::OpenScriptL() {} |
|
82 TBool CCommandParser::OpenScriptL(RFile& aScriptFile) |
|
83 { |
|
84 LOGSTRING("Creator: CCommandParser::OpenScriptL"); |
|
85 TBool ret = EFalse; |
|
86 |
|
87 // init the search array |
|
88 iSearchArray = new(ELeave) CDesCArrayFlat(500); |
|
89 |
|
90 // wait dialog |
|
91 // TODO |
|
92 //CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC(); |
|
93 //waitDialog->SetSoftkeys(R_AVKON_SOFTKEYS_CANCEL); |
|
94 //TInt dialogId = waitDialog->ShowNoteL(EAknGlobalWaitNote, _L("Searching")); |
|
95 |
|
96 |
|
97 // search all the .creator files from the phone |
|
98 TInt err; |
|
99 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\"))); |
|
100 |
|
101 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\system\\apps\\Creator\\"))); |
|
102 |
|
103 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\data\\"))); |
|
104 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\data\\"))); |
|
105 |
|
106 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\documents\\"))); |
|
107 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\documents\\"))); |
|
108 |
|
109 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\creator\\"))); |
|
110 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\creator\\"))); |
|
111 |
|
112 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\scripts\\"))); |
|
113 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\scripts\\"))); |
|
114 |
|
115 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\temp\\"))); |
|
116 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\temp\\"))); |
|
117 |
|
118 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\system\\temp\\"))); |
|
119 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\system\\temp\\"))); |
|
120 |
|
121 TRAP(err, FindFiles(_L("*.creatorxml"), _L("\\private\\20011383\\"))); |
|
122 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\private\\20011383\\"))); |
|
123 |
|
124 TRAP(err, FindFilesRecursiveL(_L("*.creatorxml"), _L("\\private\\1000484b\\"))); |
|
125 |
|
126 |
|
127 // remove the wait dialog |
|
128 // TODO |
|
129 //waitDialog->CancelNoteL(dialogId); |
|
130 //CleanupStack::PopAndDestroy(); //waitDialog; |
|
131 |
|
132 |
|
133 if ( iSearchArray->MdcaCount() > 0) |
|
134 { |
|
135 // create a file name array based on the iSearchArray |
|
136 CDesCArray* fileNameArray = new(ELeave) CDesCArrayFlat(iSearchArray->MdcaCount()); |
|
137 CleanupStack::PushL(fileNameArray); |
|
138 |
|
139 for (TInt i=0; i<iSearchArray->MdcaCount(); i++) |
|
140 { |
|
141 |
|
142 TParse filename; // file name parser |
|
143 filename.Set(iSearchArray->MdcaPoint(i), NULL, NULL); |
|
144 |
|
145 if ( filename.Drive()[0] == 'e' || filename.Drive()[0] == 'E') // MMC |
|
146 { |
|
147 TFileName nameMMC; |
|
148 nameMMC.Append(filename.Name()); |
|
149 nameMMC.Append(_L("\t0")); // MMC icon |
|
150 fileNameArray->AppendL(nameMMC); |
|
151 } |
|
152 else |
|
153 { |
|
154 fileNameArray->AppendL(filename.Name()); |
|
155 } |
|
156 } |
|
157 CleanupStack::Pop(fileNameArray); |
|
158 |
|
159 |
|
160 // create a popup list |
|
161 int index = 0; |
|
162 TBool result = iEngine->GetEngineWrapper()->PopupListDialog(_L("Select script"), fileNameArray, index); |
|
163 //CAknSinglePopupMenuStyleListBox* listBox = new(ELeave) CAknSinglePopupMenuStyleListBox; |
|
164 //CleanupStack::PushL(listBox); |
|
165 |
|
166 //CAknPopupList* popupList = CAknPopupList::NewL( listBox, R_AVKON_SOFTKEYS_SELECT_CANCEL, AknPopupLayouts::EMenuWindow ); |
|
167 //CleanupStack::PushL(popupList); |
|
168 //popupList->SetTitleL(_L("Select script")); |
|
169 //listBox->ConstructL( popupList, EAknListBoxSelectionList|EAknListBoxLoopScrolling ); |
|
170 //listBox->CreateScrollBarFrameL( ETrue ); |
|
171 //listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
172 //listBox->Model()->SetItemTextArray( fileNameArray ); |
|
173 //listBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); // !!! |
|
174 //listBox->HandleItemAdditionL(); |
|
175 |
|
176 |
|
177 // define MMC icon |
|
178 //MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
179 //_LIT( KFLDMemoryCardUiBitmapFile, "z:aknmemorycardui.mbm" ); |
|
180 //CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 1 ); |
|
181 //listBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
182 |
|
183 //TParse* fp = new(ELeave) TParse(); |
|
184 //fp->Set(KFLDMemoryCardUiBitmapFile, &KDC_APP_BITMAP_DIR, NULL); |
|
185 //TFileName resourceFileName( fp->FullName() ); |
|
186 //delete fp; |
|
187 |
|
188 //CGulIcon* icon = AknsUtils::CreateGulIconL( skin, KAknsIIDQgnIndiMmcAdd, |
|
189 // resourceFileName, |
|
190 // EMbmAknmemorycarduiQgn_indi_mmc_add, |
|
191 // EMbmAknmemorycarduiQgn_indi_mmc_add_mask ); |
|
192 //CleanupStack::PushL( icon ); |
|
193 //iconArray->AppendL( icon ); |
|
194 //CleanupStack::Pop( icon ); |
|
195 |
|
196 // execute dialog |
|
197 //TBool result; // = popupList->ExecuteLD(); |
|
198 //CleanupStack::Pop(); // popupList |
|
199 |
|
200 if ( result ) |
|
201 { |
|
202 // open the file for reading |
|
203 //RFile file; |
|
204 TRAPD(err, aScriptFile.Open(CEikonEnv::Static()->FsSession(), iSearchArray->MdcaPoint(index), EFileRead)); |
|
205 if( err != KErrNone) |
|
206 { |
|
207 aScriptFile.Close(); |
|
208 User::Leave(err); |
|
209 } |
|
210 ret = ETrue; |
|
211 } |
|
212 //CleanupStack::PopAndDestroy(); //listBox |
|
213 } |
|
214 else // no scripts found from the search paths |
|
215 { |
|
216 iEngine->GetEngineWrapper()->ShowNote(_L("No scripts found")); |
|
217 } |
|
218 |
|
219 delete iSearchArray; |
|
220 iSearchArray = NULL; |
|
221 return ret; |
|
222 } |
|
223 /* |
|
224 #else |
|
225 // --------------------------------------------------------------------------- |
|
226 void CCommandParser::OpenScriptL() |
|
227 { |
|
228 LOGSTRING("Creator: CCommandParser::OpenScriptL"); |
|
229 |
|
230 // init the search array |
|
231 iSearchArray = new(ELeave) CDesCArrayFlat(500); |
|
232 |
|
233 // wait dialog |
|
234 CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC(); |
|
235 waitDialog->SetSoftkeys(R_AVKON_SOFTKEYS_CANCEL); |
|
236 TInt dialogId = waitDialog->ShowNoteL(EAknGlobalWaitNote, _L("Searching")); |
|
237 |
|
238 |
|
239 // search all the .creator files from the phone |
|
240 TInt err; |
|
241 TRAP(err, FindFiles(_L("*.creator"), _L("\\"))); |
|
242 |
|
243 TRAP(err, FindFiles(_L("*.creator"), _L("\\system\\apps\\Creator\\"))); |
|
244 |
|
245 TRAP(err, FindFiles(_L("*.creator"), _L("\\data\\"))); |
|
246 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\data\\"))); |
|
247 |
|
248 TRAP(err, FindFiles(_L("*.creator"), _L("\\documents\\"))); |
|
249 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\documents\\"))); |
|
250 |
|
251 TRAP(err, FindFiles(_L("*.creator"), _L("\\creator\\"))); |
|
252 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\creator\\"))); |
|
253 |
|
254 TRAP(err, FindFiles(_L("*.creator"), _L("\\scripts\\"))); |
|
255 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\scripts\\"))); |
|
256 |
|
257 TRAP(err, FindFiles(_L("*.creator"), _L("\\temp\\"))); |
|
258 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\temp\\"))); |
|
259 |
|
260 TRAP(err, FindFiles(_L("*.creator"), _L("\\system\\temp\\"))); |
|
261 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\system\\temp\\"))); |
|
262 |
|
263 TRAP(err, FindFiles(_L("*.creator"), _L("\\private\\101FA751\\"))); |
|
264 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\private\\101FA751\\"))); |
|
265 |
|
266 TRAP(err, FindFilesRecursiveL(_L("*.creator"), _L("\\private\\1000484b\\"))); |
|
267 |
|
268 |
|
269 // remove the wait dialog |
|
270 waitDialog->CancelNoteL(dialogId); |
|
271 CleanupStack::PopAndDestroy(); //waitDialog; |
|
272 |
|
273 |
|
274 if ( iSearchArray->MdcaCount() > 0) |
|
275 { |
|
276 // create a file name array based on the iSearchArray |
|
277 CDesCArray* fileNameArray = new(ELeave) CDesCArrayFlat(iSearchArray->MdcaCount()); |
|
278 CleanupStack::PushL(fileNameArray); |
|
279 |
|
280 for (TInt i=0; i<iSearchArray->MdcaCount(); i++) |
|
281 { |
|
282 |
|
283 TParse filename; // file name parser |
|
284 filename.Set(iSearchArray->MdcaPoint(i), NULL, NULL); |
|
285 |
|
286 if ( filename.Drive()[0] == 'e' || filename.Drive()[0] == 'E') // MMC |
|
287 { |
|
288 TFileName nameMMC; |
|
289 nameMMC.Append(filename.Name()); |
|
290 nameMMC.Append(_L("\t0")); // MMC icon |
|
291 fileNameArray->AppendL(nameMMC); |
|
292 } |
|
293 else |
|
294 { |
|
295 fileNameArray->AppendL(filename.Name()); |
|
296 } |
|
297 } |
|
298 CleanupStack::Pop(fileNameArray); |
|
299 |
|
300 |
|
301 // create a popup list |
|
302 CAknSinglePopupMenuStyleListBox* listBox = new(ELeave) CAknSinglePopupMenuStyleListBox; |
|
303 CleanupStack::PushL(listBox); |
|
304 CAknPopupList* popupList = CAknPopupList::NewL( listBox, R_AVKON_SOFTKEYS_SELECT_CANCEL, AknPopupLayouts::EMenuWindow ); |
|
305 CleanupStack::PushL(popupList); |
|
306 popupList->SetTitleL(_L("Select script")); |
|
307 listBox->ConstructL( popupList, EAknListBoxSelectionList|EAknListBoxLoopScrolling ); |
|
308 listBox->CreateScrollBarFrameL( ETrue ); |
|
309 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
310 listBox->Model()->SetItemTextArray( fileNameArray ); |
|
311 listBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); // !!! |
|
312 listBox->HandleItemAdditionL(); |
|
313 |
|
314 |
|
315 // define MMC icon |
|
316 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
317 _LIT( KFLDMemoryCardUiBitmapFile, "z:aknmemorycardui.mbm" ); |
|
318 CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 1 ); |
|
319 listBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
320 |
|
321 TParse* fp = new(ELeave) TParse(); |
|
322 fp->Set(KFLDMemoryCardUiBitmapFile, &KDC_APP_BITMAP_DIR, NULL); |
|
323 TFileName resourceFileName( fp->FullName() ); |
|
324 delete fp; |
|
325 |
|
326 CGulIcon* icon = AknsUtils::CreateGulIconL( skin, KAknsIIDQgnIndiMmcAdd, |
|
327 resourceFileName, |
|
328 EMbmAknmemorycarduiQgn_indi_mmc_add, |
|
329 EMbmAknmemorycarduiQgn_indi_mmc_add_mask ); |
|
330 CleanupStack::PushL( icon ); |
|
331 iconArray->AppendL( icon ); |
|
332 CleanupStack::Pop( icon ); |
|
333 |
|
334 |
|
335 // execute dialog |
|
336 TBool result = popupList->ExecuteLD(); |
|
337 CleanupStack::Pop(); // popupList |
|
338 |
|
339 if ( result ) |
|
340 { |
|
341 // open the file for reading |
|
342 RFile file; |
|
343 User::LeaveIfError(file.Open(CEikonEnv::Static()->FsSession(), iSearchArray->MdcaPoint(listBox->CurrentItemIndex()), EFileRead)); |
|
344 while (ReadLineFromFileL(file) == KErrNone) |
|
345 { |
|
346 iReadBuf->Des().Trim(); // delete leading and trailing white space |
|
347 |
|
348 if (iReadBuf->Length() < 5) // command too short, ignoring... |
|
349 { |
|
350 //CEikonEnv::Static()->InfoMsg(_L("Corrupted line")); |
|
351 } |
|
352 |
|
353 // check it's a valid line: first char is A-Z and the line ends to ';' |
|
354 else if (iReadBuf->Des()[0] >= 'A' && iReadBuf->Des()[0] <= 'Z' && iReadBuf->Des()[iReadBuf->Length()-1] == ';') |
|
355 { |
|
356 // this line is valid -> parse the command |
|
357 ParseCommandFromDescriptorL(); |
|
358 } |
|
359 else |
|
360 { |
|
361 //CEikonEnv::Static()->InfoMsg(_L("Not a valid line")); |
|
362 } |
|
363 |
|
364 } |
|
365 |
|
366 file.Close(); |
|
367 |
|
368 // show a note if there were no valid commands in the script |
|
369 if (iEngine->CommandArrayCount() == 0) |
|
370 { |
|
371 CAknInformationNote* note = new(ELeave) CAknInformationNote; |
|
372 note->ExecuteLD(_L("No valid commands in this script")); |
|
373 } |
|
374 |
|
375 } |
|
376 |
|
377 CleanupStack::PopAndDestroy(); //listBox |
|
378 } |
|
379 |
|
380 else // no scripts found from the search paths |
|
381 { |
|
382 CAknInformationNote* note = new (ELeave) CAknInformationNote; |
|
383 note->ExecuteLD(_L("No scripts found")); |
|
384 } |
|
385 |
|
386 |
|
387 delete iSearchArray; |
|
388 iSearchArray = NULL; |
|
389 |
|
390 } |
|
391 #endif |
|
392 */ |
|
393 |
|
394 TBool CCommandParser::GetRandomDataFilenameL(TDes& aFilename) |
|
395 { |
|
396 LOGSTRING("Creator: CCommandParser::GetRandomDataFilenameL"); |
|
397 TBool ret = EFalse; |
|
398 |
|
399 // init the search array |
|
400 if (iSearchArray) |
|
401 { |
|
402 delete iSearchArray; |
|
403 iSearchArray = NULL; |
|
404 } |
|
405 iSearchArray = new(ELeave) CDesCArrayFlat(500); |
|
406 |
|
407 /* TODO: |
|
408 // wait dialog |
|
409 CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC(); |
|
410 waitDialog->SetSoftkeys(R_AVKON_SOFTKEYS_CANCEL); |
|
411 TInt dialogId = waitDialog->ShowNoteL(EAknGlobalWaitNote, _L("Searching")); |
|
412 */ |
|
413 |
|
414 |
|
415 // search all the creator random data files from the phone |
|
416 TInt err; |
|
417 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\"))); |
|
418 |
|
419 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\system\\apps\\Creator\\"))); |
|
420 |
|
421 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\data\\"))); |
|
422 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\data\\"))); |
|
423 |
|
424 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\documents\\"))); |
|
425 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\documents\\"))); |
|
426 |
|
427 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\creator\\"))); |
|
428 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\creator\\"))); |
|
429 |
|
430 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\scripts\\"))); |
|
431 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\scripts\\"))); |
|
432 |
|
433 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\temp\\"))); |
|
434 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\temp\\"))); |
|
435 |
|
436 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\system\\temp\\"))); |
|
437 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\system\\temp\\"))); |
|
438 |
|
439 TRAP(err, FindFiles(KRandomDataFileFilter, _L("\\private\\20011383\\"))); |
|
440 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\private\\20011383\\"))); |
|
441 |
|
442 TRAP(err, FindFilesRecursiveL(KRandomDataFileFilter, _L("\\private\\1000484b\\"))); |
|
443 |
|
444 |
|
445 // remove the wait dialog |
|
446 // TODO |
|
447 //waitDialog->CancelNoteL(dialogId); |
|
448 //CleanupStack::PopAndDestroy(); //waitDialog; |
|
449 |
|
450 |
|
451 if (iSearchArray->MdcaCount() > 0) |
|
452 { |
|
453 // create a file name array based on the iSearchArray |
|
454 CDesCArray* fileNameArray = new(ELeave) CDesCArrayFlat(iSearchArray->MdcaCount() + 1); |
|
455 CleanupStack::PushL(fileNameArray); |
|
456 |
|
457 for (TInt i=0; i<iSearchArray->MdcaCount(); i++) |
|
458 { |
|
459 |
|
460 TParse filename; // file name parser |
|
461 filename.Set(iSearchArray->MdcaPoint(i), NULL, NULL); |
|
462 |
|
463 if ( filename.Drive()[0] == 'e' || filename.Drive()[0] == 'E') // MMC |
|
464 { |
|
465 TFileName nameMMC; |
|
466 nameMMC.Append(filename.Name()); |
|
467 nameMMC.Append(_L("\t0")); // MMC icon |
|
468 fileNameArray->AppendL(nameMMC); |
|
469 } |
|
470 else |
|
471 { |
|
472 fileNameArray->AppendL(filename.Name()); |
|
473 } |
|
474 } |
|
475 |
|
476 // add "default" (resource file) to list |
|
477 fileNameArray->AppendL(_L("Default")); |
|
478 |
|
479 CleanupStack::Pop(fileNameArray); |
|
480 |
|
481 // create a popup list |
|
482 int index = 0; |
|
483 TBool result = iEngine->GetEngineWrapper()->PopupListDialog(_L("Select random data file"), fileNameArray, index); |
|
484 /* |
|
485 CAknSinglePopupMenuStyleListBox* listBox = new(ELeave) CAknSinglePopupMenuStyleListBox; |
|
486 CleanupStack::PushL(listBox); |
|
487 CAknPopupList* popupList = CAknPopupList::NewL( listBox, R_AVKON_SOFTKEYS_SELECT_CANCEL, AknPopupLayouts::EMenuWindow ); |
|
488 CleanupStack::PushL(popupList); |
|
489 popupList->SetTitleL(_L("Select random data file")); |
|
490 listBox->ConstructL( popupList, EAknListBoxSelectionList|EAknListBoxLoopScrolling ); |
|
491 listBox->CreateScrollBarFrameL( ETrue ); |
|
492 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
493 listBox->Model()->SetItemTextArray( fileNameArray ); |
|
494 listBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); // !!! |
|
495 listBox->HandleItemAdditionL(); |
|
496 |
|
497 |
|
498 // define MMC icon |
|
499 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
500 _LIT( KFLDMemoryCardUiBitmapFile, "z:aknmemorycardui.mbm" ); |
|
501 CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 1 ); |
|
502 listBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
503 |
|
504 TParse* fp = new(ELeave) TParse(); |
|
505 fp->Set(KFLDMemoryCardUiBitmapFile, &KDC_APP_BITMAP_DIR, NULL); |
|
506 TFileName resourceFileName( fp->FullName() ); |
|
507 delete fp; |
|
508 |
|
509 CGulIcon* icon = AknsUtils::CreateGulIconL( skin, KAknsIIDQgnIndiMmcAdd, |
|
510 resourceFileName, |
|
511 EMbmAknmemorycarduiQgn_indi_mmc_add, |
|
512 EMbmAknmemorycarduiQgn_indi_mmc_add_mask ); |
|
513 CleanupStack::PushL( icon ); |
|
514 iconArray->AppendL( icon ); |
|
515 CleanupStack::Pop( icon ); |
|
516 |
|
517 |
|
518 // execute dialog |
|
519 TBool result = popupList->ExecuteLD(); |
|
520 CleanupStack::Pop(); // popupList |
|
521 */ |
|
522 if ( result ) |
|
523 { |
|
524 if (index == (fileNameArray->Count() - 1)) |
|
525 { |
|
526 // "default" (resource file) selected |
|
527 aFilename.Copy(KNullDesC); |
|
528 } |
|
529 else |
|
530 { |
|
531 // xml file selected |
|
532 aFilename.Copy(iSearchArray->MdcaPoint(index)); |
|
533 } |
|
534 ret = ETrue; |
|
535 } |
|
536 // CleanupStack::PopAndDestroy(); //listBox |
|
537 } |
|
538 else // no random data files found from the search paths |
|
539 { |
|
540 iEngine->GetEngineWrapper()->ShowNote(_L("No random data files found")); |
|
541 } |
|
542 |
|
543 delete iSearchArray; |
|
544 iSearchArray = NULL; |
|
545 return ret; |
|
546 } |
|
547 |
|
548 TInt CCommandParser::FindFilesRecursiveL(const TDesC& aFileName, const TDesC& aPath) |
|
549 { |
|
550 return CreatorFileUtils::FindFilesRecursiveL(iSearchArray, aFileName, aPath); |
|
551 } |
|
552 TInt CreatorFileUtils::FindFilesRecursiveL(CDesCArrayFlat* aFileArray, const TDesC& aFileName, const TDesC& aPath) |
|
553 { |
|
554 TInt err = KErrNone; |
|
555 CDirScan* scan = CDirScan::NewLC(CEikonEnv::Static()->FsSession()); |
|
556 scan->SetScanDataL(aPath, KEntryAttDir, ESortNone); |
|
557 CDir* dirEntries = NULL; |
|
558 |
|
559 for(;;) |
|
560 { |
|
561 TRAP(err, scan->NextL(dirEntries)); |
|
562 if (!dirEntries || (err!=KErrNone)) |
|
563 break; |
|
564 |
|
565 for (TInt i=0; i<dirEntries->Count(); i++) |
|
566 { |
|
567 TFileName path(scan->FullPath()); |
|
568 path.Append((*dirEntries)[i].iName); |
|
569 path.Append(_L("\\")); |
|
570 FindFiles(aFileArray, aFileName, path); |
|
571 } |
|
572 delete(dirEntries); |
|
573 } |
|
574 |
|
575 CleanupStack::PopAndDestroy(scan); |
|
576 return err; |
|
577 } |
|
578 |
|
579 TInt CreatorFileUtils::FindFiles(CDesCArrayFlat* aFileArray, const TDesC& aFileName, const TDesC& aPath) |
|
580 { |
|
581 TFindFile fileFinder(CEikonEnv::Static()->FsSession()); |
|
582 CDir* fileList; |
|
583 TInt err = fileFinder.FindWildByDir(aFileName, aPath, fileList); |
|
584 |
|
585 while (err == KErrNone) |
|
586 { |
|
587 for (TInt i=0; i<fileList->Count(); i++) |
|
588 { |
|
589 TParse fullentry; |
|
590 fullentry.Set((*fileList)[i].iName, &fileFinder.File(), NULL); |
|
591 |
|
592 TRAP(err, aFileArray->AppendL(fullentry.FullName())); |
|
593 } |
|
594 |
|
595 delete fileList; |
|
596 err = fileFinder.FindWild(fileList); |
|
597 } |
|
598 return err; |
|
599 } |
|
600 // --------------------------------------------------------------------------- |
|
601 |
|
602 TInt CCommandParser::FindFiles(const TDesC& aFileName, const TDesC& aPath) |
|
603 { |
|
604 return CreatorFileUtils::FindFiles(iSearchArray, aFileName, aPath); |
|
605 } |
|
606 |
|
607 // --------------------------------------------------------------------------- |
|
608 |
|
609 TInt CCommandParser::ReadLineFromFileL(RFile& aInputFile) |
|
610 { |
|
611 LOGSTRING("Creator: CCommandParser::ReadLineFromFile"); |
|
612 |
|
613 _LIT8(KImcvCRLF, "\r\n"); |
|
614 |
|
615 TInt err = KErrNone; |
|
616 |
|
617 // Read into the buffer |
|
618 HBufC8* tempLine = HBufC8::NewLC(KReadBufSize); |
|
619 TPtr8 buffer = tempLine->Des(); |
|
620 |
|
621 // clear the targer |
|
622 iReadBuf->Des().Copy(_L("")); |
|
623 |
|
624 // Get the current file position |
|
625 TInt filePos = 0; |
|
626 aInputFile.Seek(ESeekCurrent, filePos); |
|
627 |
|
628 // Read the buffer |
|
629 err = aInputFile.Read(buffer); |
|
630 |
|
631 //end of file? |
|
632 TInt s = buffer.Length(); |
|
633 if ( s == 0) |
|
634 err = KErrEof; |
|
635 |
|
636 if (err == KErrNone) |
|
637 { |
|
638 // Copy to the lfcr and then set the file pointer to the point after that |
|
639 TInt pos = buffer.Find(KImcvCRLF); |
|
640 if ( pos != -1) |
|
641 { |
|
642 iReadBuf->Des().Justify(buffer, pos, ELeft, ' '); |
|
643 filePos += (pos+2); |
|
644 |
|
645 // Set the file pointer back to after the lfcr |
|
646 aInputFile.Seek(ESeekStart, filePos); |
|
647 } |
|
648 // Else fill the whole buffer |
|
649 else |
|
650 { |
|
651 iReadBuf->Des().Copy(buffer); |
|
652 } |
|
653 } |
|
654 |
|
655 CleanupStack::PopAndDestroy(); // tempLine |
|
656 return err; |
|
657 } |
|
658 |
|
659 // --------------------------------------------------------------------------- |
|
660 |
|
661 void CCommandParser::StrParserL(HBufC*& aDestinationBuf, TUint aToken) |
|
662 { |
|
663 // store old position |
|
664 iParserOldPosition = iParserPosition; |
|
665 |
|
666 // make sure we are not reading outside of buffer |
|
667 if (iParserPosition >= iReadBuf->Length() - 1) |
|
668 return; |
|
669 |
|
670 // read until asked token |
|
671 do |
|
672 { |
|
673 iParserPosition++; |
|
674 } |
|
675 while (iReadBuf->Des()[iParserPosition] != aToken && iParserPosition < iReadBuf->Des().Length()-1); |
|
676 |
|
677 // calculate length of the destination buffer |
|
678 TInt bufferLength = iParserPosition-iParserOldPosition-1; |
|
679 |
|
680 // reset the destination buffer |
|
681 if (aDestinationBuf) |
|
682 { |
|
683 delete aDestinationBuf; |
|
684 aDestinationBuf = NULL; |
|
685 } |
|
686 |
|
687 // allocate memory for the destination buffer |
|
688 aDestinationBuf = HBufC::NewL(bufferLength); |
|
689 |
|
690 // copy data from the read buffer to the destination buffer |
|
691 aDestinationBuf->Des().Copy(iReadBuf->Des().Mid(iParserOldPosition+1, bufferLength)); |
|
692 } |
|
693 |
|
694 // --------------------------------------------------------------------------- |
|
695 |
|
696 void CCommandParser::StrParserL(HBufC8*& aDestinationBuf, TUint aToken) |
|
697 { |
|
698 // store old position |
|
699 iParserOldPosition = iParserPosition; |
|
700 |
|
701 // make sure we are not reading outside of buffer |
|
702 if (iParserPosition >= iReadBuf->Length() - 1) |
|
703 return; |
|
704 |
|
705 // read until asked token |
|
706 do |
|
707 { |
|
708 iParserPosition++; |
|
709 } |
|
710 while (iReadBuf->Des()[iParserPosition] != aToken && iParserPosition < iReadBuf->Des().Length()-1); |
|
711 |
|
712 // calculate length of the destination buffer |
|
713 TInt bufferLength = iParserPosition-iParserOldPosition-1; |
|
714 |
|
715 // reset the destination buffer |
|
716 if (aDestinationBuf) |
|
717 { |
|
718 delete aDestinationBuf; |
|
719 aDestinationBuf = NULL; |
|
720 } |
|
721 |
|
722 // allocate memory for the destination buffer |
|
723 aDestinationBuf = HBufC8::NewL(bufferLength); |
|
724 |
|
725 // copy data from the read buffer to the destination buffer |
|
726 aDestinationBuf->Des().Copy(iReadBuf->Des().Mid(iParserOldPosition+1, bufferLength)); |
|
727 } |
|
728 |
|
729 //---------------------------------------------------------------------------- |
|
730 |
|
731 void CCommandParser::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) // from MMsvSessionObserver |
|
732 { |
|
733 } |
|
734 |
|
735 //---------------------------------------------------------------------------- |
|
736 |