Nokia N97 SDK
Example Applications Guide

CHsWidgetExample Class Reference

#include <HsWidgetExample.h>

Inheritance diagram for CHsWidgetExample:

List of all members.

Detailed Description

CHsWidgetExample

Definition at line 31 of file HsWidgetExample.h.

Public Member Functions

virtual void handleEvent (std::string aWidgetName, IHsDataObserver::EEvent aEvent)
virtual void handleItemEvent (std::string aWidgetName, std::string aWidgetItemName, IHsDataObserver::EItemEvent aEvent)
 ~CHsWidgetExample ()
void RegisterWidget ()
void PublishWidget ()
void ChangeWidgetValuesL ()
void RemoveWidget ()

Static Public Member Functions

static CHsWidgetExampleNewL ()
static CHsWidgetExampleNewLC ()

Private Member Functions

 CHsWidgetExample ()
void ConstructL ()
std::string ToString (const TDesC &aText)

Private Attributes

Hs::HsWidgetPublisher * iHsWidgetPublisher
std::string templateType
std::string widgetName
std::string widgetId
TInt iCounter


Constructor & Destructor Documentation

CHsWidgetExample::~CHsWidgetExample  ) 
 

Destructor.

Definition at line 42 of file HsWidgetExample.cpp.

References iHsWidgetPublisher.

00043         {
00044         delete iHsWidgetPublisher;
00045         }

CHsWidgetExample::CHsWidgetExample  )  [private]
 

Constructor for performing 1st stage construction

Definition at line 31 of file HsWidgetExample.cpp.

Referenced by NewLC().

00032         {
00033         // No implementation required
00034         }


Member Function Documentation

virtual void CHsWidgetExample::handleEvent std::string  aWidgetName,
IHsDataObserver::EEvent  aEvent
[virtual]
 

Intended to handle an event that occured on a widget. This would include EActivate, EDeactivate, ESuspend, EReusume.

Parameters:
aWidgetName Name of the widget that event is envoked for.
aEvent Event type that has taken place.

virtual void CHsWidgetExample::handleItemEvent std::string  aWidgetName,
std::string  aWidgetItemName,
IHsDataObserver::EItemEvent  aEvent
[virtual]
 

Intended to handle an event that occured on a widget's item. This would include ESelection.

Parameters:
aWidgetName Name of the widget that event is envoked for.
aWidgetItemName Name of the item that event is envoked for.
aEvent Event type that has taken place

CHsWidgetExample * CHsWidgetExample::NewL  )  [static]
 

Two-phased constructor.

Definition at line 65 of file HsWidgetExample.cpp.

References NewLC().

Referenced by CHsWidgetAppUi::HandleCommandL().

00066         {
00067         CHsWidgetExample* self=CHsWidgetExample::NewLC();
00068         CleanupStack::Pop(); // self;
00069         return self;
00070         }

CHsWidgetExample * CHsWidgetExample::NewLC  )  [static]
 

Two-phased constructor.

Definition at line 52 of file HsWidgetExample.cpp.

References CHsWidgetExample().

Referenced by NewL().

00053         {
00054         CHsWidgetExample* self = new (ELeave)CHsWidgetExample();
00055         CleanupStack::PushL(self);
00056         self->ConstructL();
00057         return self;
00058         }

void CHsWidgetExample::RegisterWidget  ) 
 

Register widget to HS so it can be added as content. New template is created and is keept by HSApi.

Definition at line 110 of file HsWidgetExample.cpp.

References iHsWidgetPublisher, templateType, widgetId, and widgetName.

Referenced by CHsWidgetAppUi::HandleCommandL().

00111         {
00112         try
00113                 {
00114                 iHsWidgetPublisher->createHsWidget( templateType, widgetName, widgetId );
00115                 }
00116         catch( Hs::HsException& e)
00117                 {
00118                 //catch error from HSPApi
00119                 User::Leave( e.getReason() );
00120                 }
00121         catch( ... )
00122                 {
00123                 //catch error from other libraries
00124                 User::Leave( KErrGeneral );
00125                 }
00126         }

void CHsWidgetExample::PublishWidget  ) 
 

Publish widget with actual seted items' values to HS.

Definition at line 134 of file HsWidgetExample.cpp.

References iHsWidgetPublisher, templateType, widgetId, and widgetName.

00135         {
00136         try
00137                 {       
00138                 iHsWidgetPublisher->publishHsWidget( 
00139                         iHsWidgetPublisher->getHsWidget( templateType, widgetName,
00140                                 widgetId ) );
00141                 }
00142         catch( Hs::HsException& e)
00143                 {
00144                 //catch error from HSPApi
00145                 User::Leave( e.getReason() );
00146                 }
00147         catch( ... )
00148                 {
00149                 //catch error from other libraries
00150                 User::Leave( KErrGeneral );
00151                 }
00152         }

void CHsWidgetExample::ChangeWidgetValuesL  ) 
 

Change items' values.

Definition at line 159 of file HsWidgetExample.cpp.

References iCounter, iHsWidgetPublisher, templateType, ToString(), widgetId, and widgetName.

Referenced by CHsWidgetAppUi::HandleCommandL().

00160         {
00161         try
00162                 {
00163                 HBufC* buf1 = NULL;
00164                 HBufC* buf2 = NULL;
00165                 if( !( iCounter % 2 ) )
00166                         {
00167                         buf1 = CCoeEnv::Static()->AllocReadResourceL( R_FILE_BEGINING );
00168                         buf2 = CCoeEnv::Static()->AllocReadResourceL( R_TEXT_BEGINING );
00169                         }
00170                 else
00171                         {
00172                         buf1 = CCoeEnv::Static()->AllocReadResourceL( R_FILE_UPDATED );
00173                         buf2 = CCoeEnv::Static()->AllocReadResourceL( R_TEXT_UPDATED );
00174                         }
00175                 
00176                 iHsWidgetPublisher->getHsWidget( templateType, widgetName, widgetId ).
00177                         setItem( image, ToString( *buf1 ) );
00178                 iHsWidgetPublisher->getHsWidget( templateType, widgetName, widgetId ).
00179                         setItem( text, ToString( *buf2 ) );
00180                 
00181                 delete buf1;
00182                 delete buf2;
00183                 }
00184         catch( Hs::HsException& e)
00185                 {
00186                 //catch error from HSPApi
00187                 User::Leave( e.getReason() );
00188                 }
00189         catch( ... )
00190                 {
00191                 //catch error from other libraries
00192                 User::Leave( KErrGeneral );
00193                 }
00194         iCounter++;
00195         }

void CHsWidgetExample::RemoveWidget  ) 
 

Remove widget's template from HSApi. It is now not avaliable for HS and it doesn't support events.

Definition at line 202 of file HsWidgetExample.cpp.

References iHsWidgetPublisher, templateType, widgetId, and widgetName.

Referenced by CHsWidgetAppUi::HandleCommandL().

00203         {
00204         try
00205                 {       
00206                 iHsWidgetPublisher->removeHsWidget( templateType, widgetName, widgetId);
00207                 }
00208         catch( Hs::HsException& e)
00209                 {
00210                 //catch error from HSPApi
00211                 User::Leave( e.getReason() );
00212                 }
00213         catch( ... )
00214                 {
00215                 //catch error from other libraries
00216                 User::Leave( KErrGeneral );
00217                 }
00218         }

void CHsWidgetExample::ConstructL  )  [private]
 

EPOC default constructor for performing 2nd stage construction

Definition at line 77 of file HsWidgetExample.cpp.

References iHsWidgetPublisher, templateType, ToString(), widgetId, and widgetName.

00078         {
00079         try
00080                 {
00081                 iHsWidgetPublisher = new Hs::HsWidgetPublisher( this );
00082                 }
00083         catch( Hs::HsException& e)
00084                 {
00085                 //catch error from HSPApi
00086                 User::Leave( e.getReason() );
00087                 }
00088         catch( ... )
00089                 {
00090                 //catch error from other libraries
00091                 User::Leave( KErrGeneral );
00092                 }
00093         //converitng string from UNICODE to UTF-8 std::string
00094         HBufC* buf1 = CCoeEnv::Static()->AllocReadResourceL( R_TEMPLATE_TYPE );
00095         templateType = ToString( *buf1 );
00096         delete buf1;
00097         buf1 = CCoeEnv::Static()->AllocReadResourceL( R_WIDGET_NAME );
00098         widgetName = ToString( *buf1 );
00099         delete buf1;
00100         buf1 = CCoeEnv::Static()->AllocReadResourceL( R_WIDGET_ID );
00101         widgetId = ToString( *buf1 );
00102         delete buf1;
00103         }

std::string CHsWidgetExample::ToString const TDesC &  aText  )  [private]
 

Conversion method.

Parameters:
aText string to convert
Returns:
converted string

Definition at line 254 of file HsWidgetExample.cpp.

Referenced by ChangeWidgetValuesL(), and ConstructL().

00255     {
00256     HBufC8* text = HBufC8::NewL( aText.Length() + 4 /*for ending zero*/ );
00257     TPtr8 dest( text->Des() );
00258     CnvUtfConverter::ConvertFromUnicodeToUtf8( dest, aText );    
00259     std::string ret((const char*)dest.PtrZ());
00260     delete text;
00261     return ret;
00262     }


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top