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