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