Creating a S60 UI to an existing Open C component
Article Metadata
Contents |
Introduction
This article discusses how to create and what kind of options there are when creating a S60 user interface to an existing Open C component. Two ported desktop console applications Potrace and MkBitmap are used as an example.Porting a desktop console application Potrace to S60 using Open C
Creating application skeleton
The easiest way to start creating the UI is using the application wizard which comes with Carbide.C++. This example evaluates to usage of the free Carbide.C++ version 1.2 Express.
The type of the application is S60 3rd Ed. GUI Application
The Application UID 0xA0002AD9 has been requested from Symbian http://licensing.symbian.org/. The tool gives a warning because a real UID is used instead of a test UID.
The directory structure for the application
Adding interface to Open C component
The application wizard basically creates a copy the HelloWorldBasic application. The class names and UID are the only different things.
Original function
// -----------------------------------------------------------------------------
// COpenCUIExampleAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void COpenCUIExampleAppUi::HandleCommandL( TInt aCommand )
{
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ECommand1:
{
// Load a string from the resource file and display it
HBufC* textResource = StringLoader::LoadLC( R_COMMAND1_TEXT );
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note with
// textResource loaded with StringLoader.
informationNote->ExecuteLD( *textResource );
// Pop HBuf from CleanUpStack and Destroy it.
CleanupStack::PopAndDestroy( textResource );
}
break;
case ECommand2:
{
RFs fsSession;
RFile rFile;
// Connects a client process to the fileserver
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
//Open file where the stream text is
User::LeaveIfError(rFile.Open(fsSession,KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
CleanupClosePushL(rFile);
// copy stream from file to RFileStream object
RFileReadStream inputFileStream(rFile);
CleanupClosePushL(inputFileStream);
// HBufC descriptor is created from the RFileStream object.
HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( *fileData);
// Pop loaded resources from the cleanup stack
CleanupStack::PopAndDestroy(4); // filedata, inputFileStream, rFile, fsSession
fsSession.Close();
}
break;
case EHelp:
{
CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
}
break;
case EAbout:
{
CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
dlg->QueryHeading()->SetTextL(*title);
CleanupStack::PopAndDestroy(); //title
HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
dlg->SetMessageTextL(*msg);
CleanupStack::PopAndDestroy(); //msg
dlg->RunLD();
}
break;
default:
Panic( EOpenCUIExampleUi );
break;
}
}





(no comments yet)