creator/src/engine.cpp
changeset 19 4b22a598b890
parent 17 4f2773374eff
child 23 c9bf25a20c9f
equal deleted inserted replaced
17:4f2773374eff 19:4b22a598b890
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <EIKENV.H>
    19 #include <eikenv.h>
    20 #include <S32FILE.H> 
    20 #include <s32file.h> 
    21 #include <coemain.h>
    21 #include <coemain.h>
    22 
    22 
    23 #include <datacreator.rsg>
    23 #include <datacreator.rsg>
    24 
    24 
    25 #include "mainview.h"
    25 #include "mainview.h"
    26 #include "engine.h"
    26 #include "engine.h"
    27 #include "enginewrapper.h"
    27 #include "enginewrapper.h"
    28 
    28 
    29 
    29 
    30 #include <cntdb.h>//For Math
    30 #include <cntdb.h>//For Math
       
    31 
       
    32 #include "creator_scriptentry.h"
       
    33 #include "creator_modulebase.h"
       
    34 #include "creator_browser.h"
       
    35 #include "creator_calendar.h"
       
    36 #include "creator_phonebookbase.h"
       
    37 #include "creator_note.h"
       
    38 #include "creator_log.h"
       
    39 #include "creator_connectionmethodbase.h"
       
    40 #include "creator_mailbox.h"
       
    41 //#include "creator_imps.h"
       
    42 #include "creator_message.h"
       
    43 #include "creator_landmark.h"
    31 
    44 
    32 
    45 
    33 #include "creator_traces.h"
    46 #include "creator_traces.h"
    34 #include "creator_factory.h"
    47 #include "creator_factory.h"
    35 #include "creator_scriptparser.h"
    48 #include "creator_scriptparser.h"
    36 #include "creator_file.h"
    49 #include "creator_file.h"
    37 #include "creator_cmdscriptrun.h"
    50 #include "creator_cmdscriptrun.h"
    38 
    51 #include "creator_contactsetcache.h"
    39 
    52 
    40 #include <apparc.h>
    53 #include <apparc.h>
    41 #include <eikappui.h>
    54 #include <eikappui.h>
    42 #include <eikapp.h>
    55 #include <eikapp.h>
    43 #include <bitmaptransforms.h>
    56 #include <bitmaptransforms.h>
    44 
    57 
    45 _LIT(KEDriveError, "Not available");
    58 _LIT(KEDriveError, "Not available");
    46 _LIT(KTempPathDrive, "d");
    59 _LIT(KTempPathDrive, "d");
    47 _LIT(KTempPath, ":\\Creator\\");
    60 _LIT(KTempPath, ":\\Creator\\");
    48 _LIT(KSavingText, "Saving");
    61 //_LIT(KSavingText, "Saving");
    49 _LIT(KDeletingText, "Deleting");
    62 _LIT(KDeletingText, "Deleting");
    50 const TInt KRegisterDrive = EDriveC;
    63 const TInt KRegisterDrive = EDriveC;
    51 _LIT(KRegisterFileName, "creator_created_items.dat");
    64 _LIT(KRegisterFileName, "creator_created_items.dat");
    52 _LIT(KResourceFileName, "z:\\Resource\\apps\\datacreator.RSC");
    65 _LIT(KResourceFileName, "z:\\Resource\\apps\\datacreator.RSC");
    53 
    66 
   139     delete iScaledBitmap;
   152     delete iScaledBitmap;
   140     delete iBitmap;
   153     delete iBitmap;
   141     delete iBitmapData;
   154     delete iBitmapData;
   142 	
   155 	
   143     delete iCmdScriptRun;
   156     delete iCmdScriptRun;
   144     iCmdScriptRun = NULL;	
   157     iCmdScriptRun = NULL;
       
   158     
       
   159     delete iCommandParser;
   145     }
   160     }
   146 
   161 
   147 void CCreatorEngine::CopyFileL(const TFileName& aSourceFile, const TFileName& aTargetFile, TBool aOverwrite )
   162 void CCreatorEngine::CopyFileL(const TFileName& aSourceFile, const TFileName& aTargetFile, TBool aOverwrite )
   148 	{
   163 	{
   149 	if( !aOverwrite && ConeUtils::FileExists(aTargetFile))
   164 	if( !aOverwrite && ConeUtils::FileExists(aTargetFile))
   716     TRAP(err, iAccessPoints = (CCreatorConnectionSettingsBase*)TCreatorFactory::CreateConnectionSettingsL(this));
   731     TRAP(err, iAccessPoints = (CCreatorConnectionSettingsBase*)TCreatorFactory::CreateConnectionSettingsL(this));
   717     TRAP(err, iMailboxes = CCreatorMailboxes::NewL(this));
   732     TRAP(err, iMailboxes = CCreatorMailboxes::NewL(this));
   718     TRAP(err, iFiles = CCreatorFiles::NewL(this));
   733     TRAP(err, iFiles = CCreatorFiles::NewL(this));
   719     TRAP(err, iMessages = CCreatorMessages::NewL(this));
   734     TRAP(err, iMessages = CCreatorMessages::NewL(this));
   720     TRAP(err, iLandmarks = CCreatorLandmarks::NewL(this));
   735     TRAP(err, iLandmarks = CCreatorLandmarks::NewL(this));
       
   736     ContactLinkCache::InitializeL();
   721 /*
   737 /*
   722     #ifdef __PRESENCE
   738     #ifdef __PRESENCE
   723       TRAP(err, iIMPS = CCreatorIMPS::NewL(this));
   739       TRAP(err, iIMPS = CCreatorIMPS::NewL(this));
   724     #endif 
   740     #endif 
   725 */
   741 */
   764     delete iBrowser;
   780     delete iBrowser;
   765     iBrowser = NULL;
   781     iBrowser = NULL;
   766     delete iLandmarks;
   782     delete iLandmarks;
   767     iLandmarks = NULL;
   783     iLandmarks = NULL;
   768 
   784 
       
   785     ContactLinkCache::DestroyL();
   769     // now delete the command array
   786     // now delete the command array
   770     delete iCommandArray;
   787     delete iCommandArray;
   771     iCommandArray = NULL;
   788     iCommandArray = NULL;
   772 	
   789 	
   773 	// delete parameter array
   790 	// delete parameter array
   774 	iParameterArray.ResetAndDestroy();
   791 	iParameterArray.ResetAndDestroy();
   775 	iParameterArray.Close();
   792 	iParameterArray.Close();
       
   793 	
       
   794 	if(iCommandParser)
       
   795 	    {
       
   796         delete iCommandParser;
       
   797 	    iCommandParser = NULL;
       
   798 	    }
       
   799     
   776     
   800     
   777 	// clear temp drive
   801 	// clear temp drive
   778 	CFileMan* fileMan = CFileMan::NewL( iEnv->FsSession() );
   802 	CFileMan* fileMan = CFileMan::NewL( iEnv->FsSession() );
   779 	CleanupStack::PushL( fileMan );
   803 	CleanupStack::PushL( fileMan );
   780 	fileMan->RmDir( iTempPath->Des() );
   804 	fileMan->RmDir( iTempPath->Des() );
   789 
   813 
   790     iTimer.Cancel();
   814     iTimer.Cancel();
   791     }
   815     }
   792 
   816 
   793 // ---------------------------------------------------------------------------
   817 // ---------------------------------------------------------------------------
   794 
   818 void CCreatorEngine::QueryDialogClosedL( TBool /*aPositiveAction*/, TInt /*aUserData*/ )
   795 void CCreatorEngine::RunScriptL()
   819     {
   796     {
   820     
   797     LOGSTRING("Creator: CCreatorEngine::RunScriptL");
   821     }
   798 
   822 
   799     // startup modules (also inits the command array):
   823 void CCreatorEngine::FileChosenL( TBool aSuccess, const TDesC& aFileName )
   800     StartEnginesL();
   824     {
   801 
   825     if( aSuccess )
   802     // use the command parser module to init the command array from a script file
   826         {
   803     CCommandParser* commandParser = CCommandParser::NewLC(this);
   827         // open the file for reading
   804     RFile scriptFile;
   828         RFile scriptFile;
   805     TBool ret = commandParser->OpenScriptL(scriptFile);
   829         User::LeaveIfError( scriptFile.Open( iEnv->FsSession(), aFileName, EFileRead ) );
   806     CleanupClosePushL(scriptFile);
   830         CleanupClosePushL(scriptFile);
   807     if( ret )
   831     
   808         {
   832         
   809         // wait dialog
   833         // wait dialog
   810 		/* TODO
   834         /* TODO
   811         CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC();
   835         CAknGlobalNote* waitDialog = CAknGlobalNote::NewLC();
   812         waitDialog->SetSoftkeys( R_AVKON_SOFTKEYS_CANCEL );
   836         waitDialog->SetSoftkeys( R_AVKON_SOFTKEYS_CANCEL );
   813         TInt dialogId = waitDialog->ShowNoteL( EAknGlobalWaitNote, _L("Parsing") );
   837         TInt dialogId = waitDialog->ShowNoteL( EAknGlobalWaitNote, _L("Parsing") );
   814         */
   838         */
   815         TInt parseErr( KErrNone );
   839         TInt parseErr( KErrNone );
   816         TRAPD( parserErr,
   840         CCreatorScriptParser* scriptParser = CCreatorScriptParser::NewLC(this);
   817                CCreatorScriptParser* scriptParser = CCreatorScriptParser::NewLC(this);
   841         scriptParser->ParseL(scriptFile);
   818                scriptParser->ParseL(scriptFile);
   842         parseErr = scriptParser->GetError();
   819                parseErr = scriptParser->GetError();
   843         CleanupStack::PopAndDestroy( scriptParser );
   820                CleanupStack::PopAndDestroy( scriptParser );
   844     
   821              );
   845         CleanupStack::PopAndDestroy( &scriptFile );
       
   846     
   822         //waitDialog->CancelNoteL( dialogId );
   847         //waitDialog->CancelNoteL( dialogId );
   823         //CleanupStack::PopAndDestroy( waitDialog );
   848         //CleanupStack::PopAndDestroy( waitDialog );
   824         User::LeaveIfError( parserErr );
   849     
   825         
       
   826         if(parseErr != KErrNone)
   850         if(parseErr != KErrNone)
   827             {
   851             {
   828 			
       
   829             // show error note
   852             // show error note
   830             _LIT(KErrMsg, "Parser error: %d");
   853             _LIT(KErrMsg, "Parser error: %d");
   831             TBuf<32> msgBuf;
   854             TBuf<32> msgBuf;
   832             msgBuf.Format(KErrMsg, parseErr);
   855             msgBuf.Format(KErrMsg, parseErr);
   833             iEngineWrapper->ShowNote(msgBuf);
   856             iEngineWrapper->ShowErrorMessage(msgBuf);
   834             CleanupStack::PopAndDestroy(); //commandParser   
       
   835             ShutDownEnginesL();
   857             ShutDownEnginesL();
       
   858             delete iCommandParser;
       
   859             iCommandParser = NULL;
   836             return;
   860             return;
   837             }         
   861             }         
   838         }
   862         }
   839     CleanupStack::PopAndDestroy( &scriptFile );
       
   840     CleanupStack::PopAndDestroy( commandParser );   
       
   841 
   863 
   842     // start executing commands if commands in the command array
   864     // start executing commands if commands in the command array
   843     if (CommandArrayCount() > 0)
   865     if (CommandArrayCount() > 0)
   844         {
   866         {
   845         ExecuteFirstCommandL( KSavingText );
   867         ExecuteFirstCommandL( KSavingText );
   846         }
   868         }
   847     else
   869     else
   848         {
   870         {
   849         ShutDownEnginesL();
   871         ShutDownEnginesL();
   850         }
   872         }
   851 
   873     }
       
   874 // ---------------------------------------------------------------------------
       
   875 
       
   876 void CCreatorEngine::RunScriptL()
       
   877     {
       
   878     LOGSTRING("Creator: CCreatorEngine::RunScriptL");
       
   879 
       
   880     // startup modules (also inits the command array):
       
   881     StartEnginesL();
       
   882 
       
   883     // use the command parser module to init the command array from a script file
       
   884     delete iCommandParser;
       
   885     iCommandParser = CCommandParser::NewL(this);
       
   886     TBool ret = EFalse;
       
   887     TRAPD(err, ret = iCommandParser->OpenScriptL( this ) );
       
   888     if( err != KErrNone || ret == EFalse)
       
   889         {
       
   890         ShutDownEnginesL();
       
   891         User::LeaveIfError(err);
       
   892         }
   852     }
   893     }
   853 
   894 
   854 // ---------------------------------------------------------------------------
   895 // ---------------------------------------------------------------------------
   855 
   896 
   856 TInt CCreatorEngine::RunScriptL(const TDesC& aScriptFile)
   897 TInt CCreatorEngine::RunScriptL(const TDesC& aScriptFile)
  1116                 {
  1157                 {
  1117                 // cancelled, free resources
  1158                 // cancelled, free resources
  1118                 ShutDownEnginesL();
  1159                 ShutDownEnginesL();
  1119                 }
  1160                 }
  1120             }
  1161             }
  1121         else if ( iUsedOptionsMenuModule->AskDataFromUserL( aCommand, iEntriesToBeCreated )  )
  1162         else if ( iUsedOptionsMenuModule->AskDataFromUserL( aCommand )  )
  1122             {
  1163             {
  1123             // add this command to command array
  1164             // add this command to command array
  1124             AppendToCommandArrayL( aCommand, NULL, 1 );
  1165 //            AppendToCommandArrayL( aCommand, NULL, 1 );
  1125     
  1166     
  1126             // started exucuting commands
  1167             // started exucuting commands
  1127             ExecuteFirstCommandL( KDeletingText );        
  1168 //            ExecuteFirstCommandL( KDeletingText );        
  1128             }
  1169             }
  1129         else
  1170         else
  1130             {
  1171             {
  1131             // cancelled, free resources
  1172             // cancelled, free resources
  1132             ShutDownEnginesL();
  1173             ShutDownEnginesL();
  1133             }
  1174             }
  1134         }
  1175         }
  1135 
  1176 
  1136     // ask user data, if query accepted start processing...
  1177     // ask user data, if query accepted start processing...
  1137     else if (iUsedOptionsMenuModule->AskDataFromUserL(aCommand, iEntriesToBeCreated))
  1178     else if (iUsedOptionsMenuModule->AskDataFromUserL(aCommand))
  1138         {
  1179         {
  1139         // add this command to command array
  1180         // add this command to command array
  1140         AppendToCommandArrayL(aCommand, NULL, iEntriesToBeCreated);
  1181         //AppendToCommandArrayL(aCommand, NULL, iEntriesToBeCreated);
  1141 
  1182 
  1142         // started exucuting commands
  1183         // started exucuting commands
  1143         ExecuteFirstCommandL( KSavingText );
  1184         //ExecuteFirstCommandL( KSavingText );
  1144         }
  1185         }
  1145      else
  1186      else
  1146         {
  1187         {
  1147         // cancelled, free resources
  1188         // cancelled, free resources
  1148         ShutDownEnginesL();
  1189         ShutDownEnginesL();
  1200      
  1241      
  1201     }
  1242     }
  1202 
  1243 
  1203 // ---------------------------------------------------------------------------
  1244 // ---------------------------------------------------------------------------
  1204 
  1245 
  1205 TBool CCreatorEngine::GetRandomDataFilenameL(TDes& aFilename)
  1246 TBool CCreatorEngine::GetRandomDataL()
  1206 	{
  1247 	{
       
  1248     TFileName fileName;
  1207     CCommandParser* commandParser = CCommandParser::NewLC(this);
  1249     CCommandParser* commandParser = CCommandParser::NewLC(this);
  1208 	TBool ret = commandParser->GetRandomDataFilenameL(aFilename);
  1250 	TBool ret = commandParser->GetRandomDataFilenameL(fileName);
  1209     CleanupStack::PopAndDestroy(commandParser);
  1251     CleanupStack::PopAndDestroy(commandParser);
       
  1252     if (ret)
       
  1253         {
       
  1254         ret = GetRandomDataFromFileL(fileName);
       
  1255         }
  1210     return ret;
  1256     return ret;
  1211 	}
  1257 	}
  1212 
  1258 
  1213 // ---------------------------------------------------------------------------
  1259 // ---------------------------------------------------------------------------
  1214 
  1260