03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CleanupStack::PushL(fileName);<br />

// Check it's a valid filename<br />

if(!iCoeEnv->FsSession().IsValidName(*fileName))<br />

{<br />

TryChangeFocusToL(EExampleControlIdFileName);<br />

iEikonEnv->LeaveWithInfoMsg(R_EIK_TBUF_INVALID_FILE_NAME);<br />

}<br />

// Check whether it's going to be possible to create the file<br />

for reading<br />

RFile file;<br />

User::LeaveIfError(file.Open(iCoeEnv->FsSession(), *fileName,<br />

EFileRead));<br />

file.Close();<br />

// Finished with user interaction: communicate parameters<br />

and return<br />

delete iAppUi->iFileName;<br />

iAppUi->iFileName = fileName;<br />

CleanupStack::Pop(); // fileName<br />

return ETrue;<br />

}<br />

As before, the job of OkToExitL() is to check that the user's input is sensible. This function<br />

checks:<br />

� that a filename has been specified,<br />

� that the filename is valid,<br />

� that it's going to be possible to read the file: I use RFile::Open()for this and leave if<br />

there was any error.<br />

Assuming all is well, control returns to my command handler that processes it using:<br />

void CExampleAppUi::CmdReadFileL()<br />

{<br />

...<br />

// Create a read stream on the file<br />

RFileReadStream reader;<br />

reader.PushL();<br />

// Reader on cleanup stack<br />

User::LeaveIfError(reader.Open(iCoeEnv->FsSession(),<br />

*iFileName,<br />

EFileRead));<br />

// Read the text<br />

HBufC* string = HBufC::NewL(reader, 10000);<br />

delete iText;<br />

iText = string;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!