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