sysresmonitoring/oommonitor/tsrc/oomtest/t_oomdummyapp/src/t_oomdummyappAppUi.cpp
changeset 35 13fd6fd25fe7
child 46 eea20ed08f4b
equal deleted inserted replaced
29:6a787171e1de 35:13fd6fd25fe7
       
     1 /*
       
     2 * Copyright (c) 2006-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 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <avkon.hrh>
       
    23 #include <aknmessagequerydialog.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <stringloader.h>
       
    26 #include <f32file.h>
       
    27 #include <s32file.h>
       
    28 #include <hlplch.h>
       
    29 
       
    30 #include <t_oomdummyapp_0xE6CFBA00.rsg>
       
    31 #include <oommonitorsession.h>
       
    32 
       
    33 //#include "t_oomdummyapp_0xE6CFBA00.hlp.hrh"
       
    34 #include "t_oomdummyapp.hrh"
       
    35 #include "t_oomdummyapp.pan"
       
    36 #include "t_oomdummyappApplication.h"
       
    37 #include "t_oomdummyappAppUi.h"
       
    38 #include "t_oomdummyappAppView.h"
       
    39 #include "CMsgHandler.h"
       
    40 #include "t_oomdummyappmsgs.h"
       
    41 
       
    42 _LIT( KFileName, "C:\\private\\E6CFBA00\\t_oomdummyapp.txt" );
       
    43 _LIT( KText, "OOM dummy app");
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Ct_oomdummyappAppUi::ConstructL()
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void Ct_oomdummyappAppUi::ConstructL()
       
    54 	{
       
    55 	// Initialise app UI with standard value.
       
    56 	BaseConstructL(CAknAppUi::EAknEnableSkin);
       
    57 
       
    58 	// Create view object
       
    59 	iAppView = Ct_oomdummyappAppView::NewL(ClientRect());
       
    60 
       
    61 	// Create a file to write the text to
       
    62 	TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName);
       
    63 	if ((KErrNone != err) && (KErrAlreadyExists != err))
       
    64 		{
       
    65 		return;
       
    66 		}
       
    67 
       
    68 	RFile file;
       
    69 	err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite);
       
    70 	CleanupClosePushL(file);
       
    71 	if (KErrNone != err)
       
    72 		{
       
    73 		CleanupStack::PopAndDestroy(1); // file
       
    74 		return;
       
    75 		}
       
    76 
       
    77 	RFileWriteStream outputFileStream(file);
       
    78 	CleanupClosePushL(outputFileStream);
       
    79 	outputFileStream << KText;
       
    80 
       
    81 	CleanupStack::PopAndDestroy(2); // outputFileStream, file
       
    82 
       
    83 	TRAP_IGNORE(iMsgHandler = CMsgHandler::NewL(*this)); //if not launched by test harness, the message queue won't exist
       
    84 	}
       
    85 // -----------------------------------------------------------------------------
       
    86 // Ct_oomdummyappAppUi::Ct_oomdummyappAppUi()
       
    87 // C++ default constructor can NOT contain any code, that might leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 Ct_oomdummyappAppUi::Ct_oomdummyappAppUi()
       
    91 	{
       
    92 	// No implementation required
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // Ct_oomdummyappAppUi::~Ct_oomdummyappAppUi()
       
    97 // Destructor.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 Ct_oomdummyappAppUi::~Ct_oomdummyappAppUi()
       
   101 	{
       
   102 	if (iAppView)
       
   103 		{
       
   104 		delete iAppView;
       
   105 		iAppView = NULL;
       
   106 		}
       
   107 	delete iMsgHandler;
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // Ct_oomdummyappAppUi::HandleCommandL()
       
   112 // Takes care of command handling.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void Ct_oomdummyappAppUi::HandleCommandL(TInt aCommand)
       
   116 	{
       
   117 	switch (aCommand)
       
   118 		{
       
   119 		case EEikCmdExit:
       
   120 		case EAknSoftkeyExit:
       
   121 			Exit();
       
   122 			break;
       
   123 
       
   124 		case ECommand1:
       
   125 			{
       
   126 
       
   127 			// Load a string from the resource file and display it
       
   128 			HBufC* textResource = StringLoader::LoadLC(R_COMMAND1_TEXT);
       
   129 			CAknInformationNote* informationNote;
       
   130 
       
   131 			informationNote = new (ELeave) CAknInformationNote;
       
   132 
       
   133 			// Show the information Note with
       
   134 			// textResource loaded with StringLoader.
       
   135 			informationNote->ExecuteLD(*textResource);
       
   136 
       
   137 			// Pop HBuf from CleanUpStack and Destroy it.
       
   138 			CleanupStack::PopAndDestroy(textResource);
       
   139 			}
       
   140 			break;
       
   141 		case ECommand2:
       
   142 			{
       
   143 			RFile rFile;
       
   144 
       
   145 			//Open file where the stream text is
       
   146 			User::LeaveIfError(rFile.Open(CCoeEnv::Static()->FsSession(),
       
   147 					KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
       
   148 			CleanupClosePushL(rFile);
       
   149 
       
   150 			// copy stream from file to RFileStream object
       
   151 			RFileReadStream inputFileStream(rFile);
       
   152 			CleanupClosePushL(inputFileStream);
       
   153 
       
   154 			// HBufC descriptor is created from the RFileStream object.
       
   155 			HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
       
   156 
       
   157 			CAknInformationNote* informationNote;
       
   158 
       
   159 			informationNote = new (ELeave) CAknInformationNote;
       
   160 			// Show the information Note
       
   161 			informationNote->ExecuteLD(*fileData);
       
   162 
       
   163 			// Pop loaded resources from the cleanup stack
       
   164 			CleanupStack::PopAndDestroy(3); // filedata, inputFileStream, rFile
       
   165 			}
       
   166 			break;
       
   167 		case EHelp:
       
   168 			{
       
   169 
       
   170 			CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
       
   171 			HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
       
   172 			}
       
   173 			break;
       
   174 		case EAbout:
       
   175 			{
       
   176 
       
   177 			CAknMessageQueryDialog* dlg = new (ELeave) CAknMessageQueryDialog();
       
   178 			dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
       
   179 			HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
       
   180 			dlg->QueryHeading()->SetTextL(*title);
       
   181 			CleanupStack::PopAndDestroy(); //title
       
   182 			HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
       
   183 			dlg->SetMessageTextL(*msg);
       
   184 			CleanupStack::PopAndDestroy(); //msg
       
   185 			dlg->RunLD();
       
   186 			}
       
   187 			break;
       
   188 		default:
       
   189 			Panic(Et_oomdummyappUi);
       
   190 			break;
       
   191 		}
       
   192 	}
       
   193 
       
   194 void Ct_oomdummyappAppUi::HandleHarnessCommandL(TInt aCommand)
       
   195 	{
       
   196 	switch(aCommand)
       
   197 		{
       
   198 		case 0:
       
   199 			Exit();
       
   200 			break;
       
   201 		case 1:
       
   202 			ActivateTopViewL();
       
   203 			break;
       
   204 		case KOomDummyAppSetBusy:
       
   205 			SetPriorityBusy();
       
   206 			break;
       
   207 		case KOomDummyAppSetNormalPriority:
       
   208 			SetPriorityNormal();
       
   209 			break;
       
   210 		case KOomDummyAppSetHighPriority:
       
   211 			SetPriorityHigh();
       
   212 			break;
       
   213 		}
       
   214 	}
       
   215 
       
   216 void Ct_oomdummyappAppUi::SetPriorityBusy()
       
   217 	{
       
   218 	ROomMonitorSession oomSession;
       
   219 	oomSession.Connect();
       
   220 	oomSession.SetOomPriority(ROomMonitorSession::EOomPriorityBusy);
       
   221 	oomSession.Close();
       
   222 	}
       
   223 
       
   224 void Ct_oomdummyappAppUi::SetPriorityNormal()
       
   225 	{
       
   226 	ROomMonitorSession oomSession;
       
   227 	oomSession.Connect();
       
   228 	oomSession.SetOomPriority(ROomMonitorSession::EOomPriorityNormal);
       
   229 	oomSession.Close();
       
   230 	}
       
   231 
       
   232 void Ct_oomdummyappAppUi::SetPriorityHigh()
       
   233 	{
       
   234 	ROomMonitorSession oomSession;
       
   235 	oomSession.Connect();
       
   236 	oomSession.SetOomPriority(ROomMonitorSession::EOomPriorityHigh);
       
   237 	oomSession.Close();
       
   238 	}
       
   239 
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 //  Called by the framework when the application status pane
       
   243 //  size is changed.  Passes the new client rectangle to the
       
   244 //  AppView
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void Ct_oomdummyappAppUi::HandleStatusPaneSizeChange()
       
   248 	{
       
   249 	iAppView->SetRect(ClientRect());
       
   250 	}
       
   251 
       
   252 CArrayFix<TCoeHelpContext>* Ct_oomdummyappAppUi::HelpContextL() const
       
   253 	{
       
   254 	// Note: Help will not work if the application uid3 is not in the
       
   255 	// protected range.  The default uid3 range for projects created
       
   256 	// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so that they
       
   257 	// can be self signed and installed on the device during testing.
       
   258 	// Once you get your official uid3 from Symbian Ltd. and find/replace
       
   259 	// all occurrences of uid3 in your project, the context help will
       
   260 	// work. Alternatively, a patch now exists for the versions of 
       
   261 	// HTML help compiler in SDKs and can be found here along with an FAQ:
       
   262 	// http://www3.symbian.com/faq.nsf/AllByDate/E9DF3257FD565A658025733900805EA2?OpenDocument
       
   263 	CArrayFixFlat<TCoeHelpContext>* array = new (ELeave) CArrayFixFlat<
       
   264 			TCoeHelpContext> (1);
       
   265 	CleanupStack::PushL(array);
       
   266 	//array->AppendL(TCoeHelpContext(KUidt_oomdummyappApp, KGeneral_Information));
       
   267 	CleanupStack::Pop(array);
       
   268 	return array;
       
   269 	}
       
   270 
       
   271 // End of File