Sunday, November 18, 2007

How can I reduce the size of my GCCE-produced binaries?

GCCE-build binaries are significantly larger binaries than produced with the GCC toolchain prior to Symbian OS v9, and the RVCT 2.2. toolchain from Symbian OS v9. This is because it uses, as recommend, a low level of compiler optimisation (-O1).

You can reduce this binary size for the GCCE target by specifying the REL_OPTIMISATION value to -O2 in the toolchain configuration files:
\epoc32\tools\compilation_config\gcce.mk and
\epoc32\tools\compilation-config\armv5_abiv2.mk.

Tuesday, November 06, 2007

How to add a ring tone for a specific contact stored in contacts database.

void AddRingtoneForContactL(const TDesC& aRingtone,TContactItemId aId)
{
CContactDatabase* ContactDb = CContactDatabase::OpenL();
CleanupStack::PushL(ContactDb);

CContactItem* SelItem = ContactDb->OpenContactL(aId);
CleanupStack::PushL(SelItem);

TInt RIndex = SelItem->CardFields().Find(KUidContactFieldRingTone);

if (RIndex != KErrNotFound)
{
SelItem->RemoveField(RIndex);
}

CContactItemField* contactField = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldRingTone);

contactField->TextStorage()->SetTextL(aRingtone);

contactField->SetLabelL(_L("tone"));
contactField->SetMapping(KUidContactFieldVCardMapUnknown);

contactField->SetId(2);

SelItem->AddFieldL(*contactField);
CleanupStack::Pop();//ContactField
ContactDb->CommitContactL(*SelItem);

CleanupStack::PopAndDestroy(2);//ContactDb,SelItem
}

Saturday, November 03, 2007

How to launch a message editor

         CClientMtmRegistry *cltReg = CClientMtmRegistry::NewL( *iSession );
CleanupStack::PushL( cltReg );

CBaseMtm *mtm = cltReg->NewMtmL( aEntry.iMtm );
CleanupStack::PushL( mtm );

CMtmUiRegistry *reg = CMtmUiRegistry::NewL( *iSession );
CleanupStack::PushL( reg );

CBaseMtmUi *ui = reg->NewMtmUiL( *mtm );
CleanupStack::PushL( ui );

mtm->SwitchCurrentEntryL( aEntry.Id() );
//Editor are embedded.
ui->SetPreferences( EMtmUiFlagEditorPreferEmbedded );

CMsvOperationActiveSchedulerWait *waiter = CMsvOperationActiveSchedulerWait::NewLC();

CMsvOperation* op = ui->ViewL( waiter->iStatus );

waiter->Start();

delete op;
CleanupStack::PopAndDestroy( 5, cltReg );

How to change the GCC-E optimization level to speed up your application

It is possible to change the default level of optimization used by GCC-E. This may result in code running up to three or four times as fast on the phone.

In the SDK, find the file epoc32\tools\compilation_config\GCCE.mk and edit it with a text editor.

Search for the lines:

#------------------------------------------------------------------------------------------------------------------------------
# Release Mode Options
#------------------------------------------------------------------------------------------------------------------------------

# Optimization Level in RELEASE mode
REL_OPTIMISATION=

Change the last line so that it reads:

REL_OPTIMISATION= -O2 -fno-unit-at-a-time

(You can find more information on the optimization options of GCC at http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Optimize-Options.html#Optimize-Options)

Once you have changed this file, go to your project. Type abld clean to ensure any existing object files are deleted, then build your project as usual.

Note 1: turning up the optimization level will make it more likely that your code makes assumptions which aren't honored by the compiler. If your code doesn't behave as it should, try setting back the optimization level to its initial setting.

Note 2: as explained in the GCC documentation, there are some compatibility issues with unit-at-a-time mode (enabled by -O2), hence the suggestion to disable it.

Note 3: a developer has reported getting the linker error: "undefined reference to `typeinfo for MTmTextLayoutForwarder'". This was solved by adding the following line to the mmp file: "LIBRARY form.lib tagma.lib".
Change softkeys dynamically (either right or left or both)
The article shows how Softkeys (not CBA) can be changed dynamically. Either left or right or both can be changed.
Changing right softkey
Cba()->RemoveCommandFromStack(2, EBack);
Cba()->AddCommandToStackL(2,ECancel,_L("Cancel"));
Cba()->DrawDeferred();

So instead of handling EBack in HandleCommandL ECancel will be handled.
Similarly the left softkey can be changed by
Cba()->RemoveCommandFromStack(0, ESave);
Cba()->AddCommandToStackL(0,EOk,_L("Ok"));
Cba()->DrawDeferred();

Note
•Header File - #include
•Link against - eikcoctl.lib
How to know which defined in your environment.
You can use "abld build -v" to see which macros are actually defined in your environment.
stats counter