creator/src/creator_appui.cpp
branchRCL_3
changeset 22 fad26422216a
parent 0 d6fe6244b863
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <creator.rsg>
       
    22 
       
    23 #include "creator.pan"
       
    24 #include "creator_appui.h"
       
    25 #include "creator_container.h"
       
    26 #include "creator.hrh"
       
    27 
       
    28 #include <bautils.h>
       
    29 #include <pathinfo.h> 
       
    30 #include <aknmessagequerydialog.h> 
       
    31 #include <eikmenub.h>
       
    32 #include <akntitle.h>
       
    33 #include <akncontext.h>
       
    34 #include <aknnotewrappers.h>
       
    35 #include <avkon.hrh>
       
    36 
       
    37 // delay before script running and application exiting in seconds
       
    38 // when script is run from command line
       
    39 const TInt KCommandLineDelay = 3;
       
    40 
       
    41 // ConstructL is called by the application framework
       
    42 void CCreatorAppUi::ConstructL()
       
    43     {
       
    44     BaseConstructL(EAknEnableSkin);
       
    45 
       
    46     iAppView = CCreatorAppView::NewL(ClientRect());    
       
    47 
       
    48     AddToStackL(iAppView);
       
    49 
       
    50     iEnv=CEikonEnv::Static();
       
    51 
       
    52     iEngine = CCreatorEngine::NewL(this);
       
    53  
       
    54 	iMode = ETimerModeNone;
       
    55 	iTickCount = 0;
       
    56     iTimer = CHeartbeat::NewL(0);
       
    57     
       
    58     // parse script name and random data file name from command line
       
    59     iCommandLineScriptName = HBufC::NewL(User::CommandLineLength());
       
    60     iCommandLineRandomDataFileName = HBufC::NewL(User::CommandLineLength());
       
    61     HBufC* commandLine = HBufC::NewLC(User::CommandLineLength());
       
    62     TPtr16 ptr = commandLine->Des();
       
    63     User::CommandLine(ptr);
       
    64     commandLine->Des().Trim();
       
    65     
       
    66     TInt pos = commandLine->Des().Find(_L(" "));
       
    67     if (pos != KErrNotFound)
       
    68     	{
       
    69     	iCommandLineScriptName->Des().Copy(commandLine->Des().Left(pos));
       
    70     	iCommandLineRandomDataFileName->Des().Copy(commandLine->Des().Mid(pos));
       
    71     	iCommandLineRandomDataFileName->Des().Trim();
       
    72     	}
       
    73     else
       
    74     	{
       
    75     	iCommandLineScriptName->Des().Copy(commandLine->Des());
       
    76     	iCommandLineRandomDataFileName->Des().Copy(KNullDesC);
       
    77     	}
       
    78 
       
    79     CleanupStack::PopAndDestroy(commandLine);
       
    80     
       
    81     if (iCommandLineScriptName->Des().Length() > 0)
       
    82     	{
       
    83     	iMode = ETimerModeStartScript;
       
    84     	iTimer->Start(ETwelveOClock, this);
       
    85     	}
       
    86     }
       
    87 
       
    88 
       
    89 CCreatorAppUi::CCreatorAppUi()                              
       
    90     {
       
    91     // add any construction that cannot leave here
       
    92     }
       
    93 
       
    94 
       
    95 CCreatorAppUi::~CCreatorAppUi()
       
    96     {
       
    97 
       
    98     delete iCommandLineRandomDataFileName;
       
    99     delete iCommandLineScriptName;
       
   100     
       
   101     if (iTimer)
       
   102     	{
       
   103     	iTimer->Cancel();
       
   104         delete iTimer;
       
   105         iTimer = NULL;
       
   106     	}
       
   107     
       
   108     delete iEngine;
       
   109 
       
   110 	if (iAppView)
       
   111         {
       
   112 		RemoveFromStack(iAppView);
       
   113         delete iAppView;
       
   114         iAppView = NULL;
       
   115         }
       
   116     }
       
   117 
       
   118 
       
   119 // handle any menu commands
       
   120 void CCreatorAppUi::HandleCommandL(TInt aCommand)
       
   121     {
       
   122     switch(aCommand)
       
   123         {
       
   124         // main menus, not assigned to any commands
       
   125 	    case ECmdCreateCalendarEntries:
       
   126 	    case ECmdCreateBrowserEntries:
       
   127 	    case ECmdCreateFileEntries:
       
   128 	    case ECmdCreateLogEntries:
       
   129 	    case ECmdCreateMessagingEntries:
       
   130 	    case ECmdCreateMiscEntries:
       
   131 	    case ECmdCreatePhoneBookEntries:
       
   132             {
       
   133             User::Panic (_L("Unused command"), 102);
       
   134             }
       
   135             break;
       
   136 
       
   137         // about
       
   138 	    case ECmdAboutCreator:
       
   139             {
       
   140 	        CAknMessageQueryDialog* dialog = new (ELeave) CAknMessageQueryDialog;
       
   141             dialog->ExecuteLD(R_CREATOR_ABOUT_DIALOG);
       
   142             }
       
   143             break;
       
   144 
       
   145 
       
   146         // run script
       
   147         case ECmdCreateFromFile:
       
   148             {
       
   149             iEngine->RunScriptL();
       
   150 			}
       
   151 			break;
       
   152 
       
   153         // select random data file
       
   154         case ECmdSelectRandomDataFile:
       
   155             {
       
   156             TFileName filename;
       
   157             if (iEngine->GetRandomDataFilenameL(filename))
       
   158             	{
       
   159             	iEngine->GetRandomDataFromFileL(filename);
       
   160             	}
       
   161 			}
       
   162 			break;
       
   163 
       
   164 
       
   165         // commands:
       
   166 	    case ECmdCreateCalendarEntryAppointments:
       
   167 	    case ECmdCreateCalendarEntryEvents:
       
   168 	    case ECmdCreateCalendarEntryAnniversaries:
       
   169 	    case ECmdCreateCalendarEntryToDos:
       
   170 	    case ECmdCreateCalendarEntryReminders:
       
   171         
       
   172         case ECmdCreateBrowserBookmarkEntries:
       
   173 	    case ECmdCreateBrowserBookmarkFolderEntries:
       
   174 	    case ECmdCreateBrowserSavedPageEntries:
       
   175 	    case ECmdCreateBrowserSavedPageFolderEntries:
       
   176 
       
   177 	    case ECmdCreatePhoneBookEntryContacts:
       
   178 	    case ECmdCreatePhoneBookEntryGroups:
       
   179 
       
   180    	    case ECmdCreateMiscEntryNotes:
       
   181    	    case ECmdCreateMiscEntryLandmarks:
       
   182 
       
   183 	    case ECmdCreateLogEntryMissedCalls:
       
   184 	    case ECmdCreateLogEntryReceivedCalls:
       
   185 	    case ECmdCreateLogEntryDialledNumbers:
       
   186 
       
   187 	    case ECmdCreateMiscEntryAccessPoints:
       
   188   	    case ECmdCreateMiscEntryIMPSServers:
       
   189 
       
   190 	    case ECmdCreateMessagingEntryMailboxes:
       
   191 	    case ECmdCreateMessagingEntryMessages:
       
   192 
       
   193 	    case ECmdCreateFileEntryEmptyFolder:
       
   194 	    case ECmdCreateFileEntry3GPP_70kB:
       
   195 	    case ECmdCreateFileEntryAAC_100kB:
       
   196 	    case ECmdCreateFileEntryAMR_20kB:
       
   197 	    case ECmdCreateFileEntryBMP_25kB:
       
   198 	    case ECmdCreateFileEntryDeck_1kB:
       
   199 	    case ECmdCreateFileEntryDOC_20kB:
       
   200 	    case ECmdCreateFileEntryGIF_2kB:
       
   201 	    case ECmdCreateFileEntryHTML_20kB:
       
   202 	    case ECmdCreateFileEntryJAD_1kB:
       
   203 	    case ECmdCreateFileEntryJAR_10kB:
       
   204 	    case ECmdCreateFileEntryJP2_65kB:
       
   205 	    case ECmdCreateFileEntryJPEG_200kB:
       
   206 	    case ECmdCreateFileEntryJPEG_25kB:
       
   207 	    case ECmdCreateFileEntryJPEG_500kB:
       
   208 	    case ECmdCreateFileEntryMIDI_10kB:
       
   209 	    case ECmdCreateFileEntryMP3_250kB:
       
   210 	    case ECmdCreateFileEntryMP4_200kB:
       
   211 	    case ECmdCreateFileEntryMXMF_40kB:
       
   212 	    case ECmdCreateFileEntryPNG_15kB:
       
   213 	    case ECmdCreateFileEntryPPT_40kB:
       
   214 	    case ECmdCreateFileEntryRAM_1kB:
       
   215 	    case ECmdCreateFileEntryRM_95kB:
       
   216 	    case ECmdCreateFileEntryRNG_1kB:
       
   217 	    case ECmdCreateFileEntrySVG_15kB:
       
   218 	    case ECmdCreateFileEntrySWF_15kB:
       
   219 	    case ECmdCreateFileEntryTIF_25kB:
       
   220 	    case ECmdCreateFileEntryTXT_10kB:
       
   221 	    case ECmdCreateFileEntryTXT_70kB:
       
   222 	    case ECmdCreateFileEntryVCF_1kB:
       
   223 	    case ECmdCreateFileEntryVCS_1kB:
       
   224 	    case ECmdCreateFileEntryWAV_20kB:
       
   225 	    case ECmdCreateFileEntryXLS_15kB:
       
   226 	    case ECmdCreateFileEntrySISX_10kB:
       
   227 	    case ECmdCreateFileEntryWMA_50kB:
       
   228 	    case ECmdCreateFileEntryWMV_200kB:
       
   229 	    case ECmdDeleteAllEntries:
       
   230 	    case ECmdDeleteAllCreatorEntries:
       
   231 	    case ECmdDeleteContacts:
       
   232         case ECmdDeleteCreatorContacts:
       
   233         case ECmdDeleteContactGroups:
       
   234         case ECmdDeleteCreatorContactGroups:
       
   235         case ECmdDeleteCalendarEntries:
       
   236         case ECmdDeleteCreatorCalendarEntries:
       
   237         case ECmdDeleteBrowserBookmarks:
       
   238         case ECmdDeleteCreatorBrowserBookmarks:
       
   239         case ECmdDeleteBrowserBookmarkFolders:
       
   240         case ECmdDeleteCreatorBrowserBookmarkFolders:
       
   241         case ECmdDeleteBrowserSavedPages:
       
   242         case ECmdDeleteCreatorBrowserSavedPages:
       
   243         case ECmdDeleteBrowserSavedPageFolders:
       
   244         case ECmdDeleteCreatorBrowserSavedPageFolders:
       
   245         case ECmdDeleteCreatorFiles:
       
   246         case ECmdDeleteLogs:
       
   247         case ECmdDeleteCreatorLogs:
       
   248         case ECmdDeleteMessages:
       
   249         case ECmdDeleteCreatorMessages:
       
   250         case ECmdDeleteMailboxes:
       
   251         case ECmdDeleteCreatorMailboxes:
       
   252         case ECmdDeleteIAPs:
       
   253         case ECmdDeleteCreatorIAPs:
       
   254         case ECmdDeleteIMPSs:
       
   255         case ECmdDeleteCreatorIMPSs:
       
   256         case ECmdDeleteNotes:
       
   257         case ECmdDeleteLandmarks:
       
   258         case ECmdDeleteCreatorLandmarks:
       
   259             {
       
   260             iEngine->ExecuteOptionsMenuCommandL(aCommand);
       
   261             }
       
   262             break;
       
   263 
       
   264         case ECmdDeleteEntries:
       
   265         case ECmdCreatePhoneBookEntrySubscribedContacts:
       
   266 	    case ECmdCreateMessagingEntryCBSTopics:
       
   267 	    case ECmdCreateMessagingEntrySMSMessageCenters:
       
   268 	    case ECmdCreateMessagingEntryTemplates:
       
   269 	    case ECmdCreateMiscEntryAppMenuFolders:
       
   270 	    case ECmdCreateMiscEntrySyncSettings:
       
   271         case ECmdCreateMessagingEntryDocumentsFolders:
       
   272             {
       
   273             CAknInformationNote* note = new(ELeave) CAknInformationNote;
       
   274             note->ExecuteLD(_L("Please contact S60 CO if you need this feature..."));
       
   275             }
       
   276             break;
       
   277 
       
   278 		case EEikCmdExit:
       
   279 		case EAknSoftkeyExit:
       
   280 			{
       
   281 			Exit();
       
   282 			}
       
   283             break;
       
   284 
       
   285         default:
       
   286             User::Panic (_L("Invalid command"), 101);
       
   287             break;
       
   288         }
       
   289     }
       
   290 
       
   291 
       
   292 void CCreatorAppUi::DynInitMenuPaneL( TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/ )
       
   293 	{
       
   294 	}
       
   295 
       
   296 void CCreatorAppUi::RunScriptDone()
       
   297 	{
       
   298 	if (iMode == ETimerModeStartScript)
       
   299 		{
       
   300 		iMode = ETimerModeExitAppUi;
       
   301 		iTimer->Start(ETwelveOClock, this);
       
   302 		}
       
   303 	}
       
   304 
       
   305 void CCreatorAppUi::Beat()
       
   306 	{
       
   307 	Tick();
       
   308 	}
       
   309 
       
   310 void CCreatorAppUi::Synchronize()
       
   311 	{
       
   312 	Tick();
       
   313 	}
       
   314 
       
   315 void CCreatorAppUi::Tick()
       
   316 	{
       
   317 	iTickCount++;
       
   318 	if (iTickCount > KCommandLineDelay)
       
   319 		{
       
   320 		iTimer->Cancel();
       
   321 		iTickCount = 0;
       
   322 		if (iMode == ETimerModeStartScript)
       
   323 			{
       
   324         	iEngine->GetRandomDataFromFileL(*iCommandLineRandomDataFileName);
       
   325 			TInt status = iEngine->RunScriptL(*iCommandLineScriptName);
       
   326 			if (status != KErrNone)
       
   327 				{
       
   328 				TBuf<128> noteMsg;
       
   329 				if (status == KErrNotFound)
       
   330 					{
       
   331 					_LIT(KMessage1, "Error in opening script file.");
       
   332 					noteMsg.Copy(KMessage1);
       
   333 					}
       
   334 				else if (status == KErrCorrupt)
       
   335 					{
       
   336 					_LIT(KMessage2, "Error in parsing script file.");
       
   337 					noteMsg.Copy(KMessage2);
       
   338 					}
       
   339 				else if (status == KErrCompletion)
       
   340 					{
       
   341 					_LIT(KMessage3, "Script file does not contain any elements.");
       
   342 					noteMsg.Copy(KMessage3);
       
   343 					}
       
   344 				else
       
   345 					{
       
   346 					_LIT(KMessage4, "Unknown error in opening script file.");
       
   347 					noteMsg.Copy(KMessage4);
       
   348 					}
       
   349 				CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote;
       
   350 				note->ExecuteLD(noteMsg);
       
   351 				RunScriptDone();
       
   352 				}
       
   353 			}
       
   354 		else if (iMode == ETimerModeExitAppUi)
       
   355 	    	{
       
   356 	    	iMode = ETimerModeNone;
       
   357 	    	Exit();
       
   358 	    	}
       
   359 		}
       
   360 	}