|
Nokia N97 SDK Example Applications Guide |
#include <HsWidgetExample.h>
Inheritance diagram for 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) |
| virtual | ~CHsWidgetExample () |
| void | RegisterWidgetL () |
| void | PublishWidgetL () |
| void | ChangeWidgetValuesL () |
| void | RemoveWidgetL () |
Static Public Member Functions |
|
| static CHsWidgetExample * | NewL () |
| static CHsWidgetExample * | NewLC () |
Private Member Functions |
|
| CHsWidgetExample () | |
| void | ConstructL () |
| std::string | ToStringL (const TDesC &aText) |
Private Attributes |
|
| Hs::HsWidgetPublisher * | iHsWidgetPublisher |
| std::string | templateType |
| std::string | widgetName |
| std::string | widgetId |
| TInt | iCounter |
|
|
C++ destructor. Definition at line 47 of file HsWidgetExample.cpp. References iHsWidgetPublisher. 00048 { 00049 delete iHsWidgetPublisher; 00050 }
|
|
|
C++ constructor for performing the 1st stage construction Definition at line 36 of file HsWidgetExample.cpp. Referenced by NewLC().
|
|
||||||||||||
|
Intended to handle an event that occured on a widget. This would include EActivate, EDeactivate, ESuspend, EReusume. Template is being published when the received event is EActivate or EResume
|
|
||||||||||||||||
|
If the ESelect event was triggerred by the image item it will trigger the content of the widget items to be changed. If the event is triggeted by the text item the publisher application will he sent to foreground. To be noted that if the publisher application is not running the Homescreen application will start the publisher. The subsequent events will be sent to the now running publisher application.
|
|
|
Two-phased constructor. Definition at line 70 of file HsWidgetExample.cpp. References NewLC(). Referenced by CHsWidgetAppUi::ConstructL(), and CHsWidgetAppUi::HandleCommandL(). 00071 { 00072 CHsWidgetExample* self=CHsWidgetExample::NewLC(); 00073 CleanupStack::Pop(); // self; 00074 return self; 00075 }
|
|
|
Two-phased constructor. Leaves constructed object on the cleanup stack Definition at line 57 of file HsWidgetExample.cpp. References CHsWidgetExample(). Referenced by NewL(). 00058 { 00059 CHsWidgetExample* self = new (ELeave)CHsWidgetExample(); 00060 CleanupStack::PushL(self); 00061 self->ConstructL(); 00062 return self; 00063 }
|
|
|
Register widget to the home screen so it can be added as content. New template is created and is kept by the Home Screen Publishing API. Definition at line 129 of file HsWidgetExample.cpp. References iHsWidgetPublisher, templateType, widgetId, and widgetName. Referenced by CHsWidgetAppUi::ConstructL(), and CHsWidgetAppUi::HandleCommandL(). 00130 { 00131 __LOGSTR_TOFILE("Enter CHsWidgetExample::RegisterWidgetL"); 00132 try 00133 { 00134 iHsWidgetPublisher->createHsWidget( templateType, 00135 widgetName, widgetId ); 00136 } 00137 catch( Hs::HsException& e) 00138 { 00139 //catch error from Homescreen Publishing API 00140 __LOGSTR_TOFILE1("[-] HSPAPI exception : %d", e.getReason()); 00141 User::Leave( e.getReason() ); 00142 } 00143 catch( ... ) 00144 { 00145 //catch error from other libraries 00146 __LOGSTR_TOFILE("[-] Generic exception"); 00147 User::Leave( KErrGeneral ); 00148 } 00149 __LOGSTR_TOFILE("Exit CHsWidgetExample::RegisterWidgetL"); 00150 }
|
|
|
Publish widget with actual seted items' values to the home screen. Definition at line 159 of file HsWidgetExample.cpp. References iHsWidgetPublisher, templateType, widgetId, and widgetName. Referenced by CHsWidgetAppUi::HandleCommandL(). 00160 { 00161 __LOGSTR_TOFILE("Enter CHsWidgetExample::PublishWidgetL"); 00162 try 00163 { 00164 iHsWidgetPublisher->publishHsWidget( 00165 iHsWidgetPublisher->getHsWidget( templateType, 00166 widgetName, widgetId ) ); 00167 } 00168 catch( Hs::HsException& e) 00169 { 00170 //catch error from Homescreen Publishing API 00171 __LOGSTR_TOFILE1("[-] HSPAPI exception : %d", e.getReason()); 00172 User::Leave( e.getReason() ); 00173 } 00174 catch( ... ) 00175 { 00176 //catch error from other libraries 00177 __LOGSTR_TOFILE("[-] Generic exception"); 00178 User::Leave( KErrGeneral ); 00179 } 00180 __LOGSTR_TOFILE("Exit CHsWidgetExample::PublishWidgetL"); 00181 }
|
|
|
Change items' values. They will only be commited (and updated on the home screen) once you call PublishWidgetL Definition at line 188 of file HsWidgetExample.cpp. References iCounter, iHsWidgetPublisher, templateType, ToStringL(), widgetId, and widgetName. Referenced by CHsWidgetAppUi::HandleCommandL(). 00189 { 00190 __LOGSTR_TOFILE("Enter CHsWidgetExample::ChangeWidgetValuesL"); 00191 try 00192 { 00193 HBufC* buf1 = NULL; 00194 HBufC* buf2 = NULL; 00195 if( !( iCounter % 2 ) ) 00196 { 00197 buf1 = CCoeEnv::Static()-> 00198 AllocReadResourceL( R_FILE_BEGINING ); 00199 buf2 = CCoeEnv::Static()-> 00200 AllocReadResourceL( R_TEXT_BEGINING ); 00201 } 00202 else 00203 { 00204 buf1 = CCoeEnv::Static()-> 00205 AllocReadResourceL( R_FILE_UPDATED ); 00206 buf2 = CCoeEnv::Static()-> 00207 AllocReadResourceL( R_TEXT_UPDATED ); 00208 } 00209 00210 iHsWidgetPublisher->getHsWidget( templateType, widgetName, widgetId ). 00211 setItem( image, ToStringL( *buf1 ) ); 00212 iHsWidgetPublisher->getHsWidget( templateType, widgetName, widgetId ). 00213 setItem( text, ToStringL( *buf2 ) ); 00214 00215 delete buf1; 00216 delete buf2; 00217 } 00218 catch( Hs::HsException& e) 00219 { 00220 //catch error from Homescreen Publishing API 00221 __LOGSTR_TOFILE1("HSPAPI exception : %d", e.getReason()); 00222 User::Leave( e.getReason() ); 00223 } 00224 catch( ... ) 00225 { 00226 //catch error from other libraries 00227 __LOGSTR_TOFILE("Generic exception"); 00228 User::Leave( KErrGeneral ); 00229 } 00230 iCounter++; 00231 __LOGSTR_TOFILE("Exit CHsSMWidgetExample::ChangeWidgetValuesL"); 00232 }
|
|
|
Remove widget's template from the Homescreen Publishing API. It is now not available for the home screen and it doesn't report events. Definition at line 242 of file HsWidgetExample.cpp. References iHsWidgetPublisher, templateType, widgetId, and widgetName. Referenced by CHsWidgetAppUi::HandleCommandL(). 00243 { 00244 __LOGSTR_TOFILE("Enter CHsWidgetExample::RemoveWidgetL"); 00245 try 00246 { 00247 iHsWidgetPublisher->removeHsWidget( templateType, 00248 widgetName, widgetId); 00249 } 00250 catch( Hs::HsException& e) 00251 { 00252 //catch error from Homescreen Publishing API 00253 __LOGSTR_TOFILE1("HSPAPI exception : %d", e.getReason()); 00254 User::Leave( e.getReason() ); 00255 } 00256 catch( ... ) 00257 { 00258 //catch error from other libraries 00259 __LOGSTR_TOFILE("Generic exception"); 00260 User::Leave( KErrGeneral ); 00261 } 00262 __LOGSTR_TOFILE("Exit CHsWidgetExample::RemoveWidgetL"); 00263 }
|
|
|
EPOC default constructor for performing the 2nd stage construction Definition at line 84 of file HsWidgetExample.cpp. References iHsWidgetPublisher, templateType, ToStringL(), widgetId, and widgetName. 00085 { 00086 __LOGSTR_TOFILE("Enter CHsWidgetExample::ConstructL"); 00087 00088 try 00089 { 00090 iHsWidgetPublisher = new Hs::HsWidgetPublisher( this ); 00091 } 00092 catch( Hs::HsException& e) 00093 { 00094 //catch error from Homescreen Publishing API 00095 __LOGSTR_TOFILE1("[-] HSPAPI exception : %d", e.getReason()); 00096 User::Leave( e.getReason() ); 00097 } 00098 catch( ... ) 00099 { 00100 //catch error from other libraries 00101 __LOGSTR_TOFILE("[-] Generic exception"); 00102 User::Leave( KErrGeneral ); 00103 } 00104 //converitng string from UNICODE to UTF-8 std::string 00105 HBufC* buf1 = StringLoader::LoadLC( R_TEMPLATE_TYPE ); 00106 templateType = ToStringL( *buf1 ); 00107 CleanupStack::PopAndDestroy(buf1); // delete buf1 00108 buf1 = StringLoader::LoadLC( R_WIDGET_NAME ); 00109 widgetName = ToStringL( *buf1 ); 00110 CleanupStack::PopAndDestroy(buf1); // delete buf1 00111 buf1 = StringLoader::LoadLC( R_WIDGET_ID ); 00112 widgetId = ToStringL( *buf1 ); 00113 CleanupStack::PopAndDestroy(buf1); // delete buf1 00114 00115 __LOGSTR_TOFILE("Exit CHsWidgetExample::ConstructL"); 00116 }
|
|
|
Conversion method.
Definition at line 331 of file HsWidgetExample.cpp. Referenced by ChangeWidgetValuesL(), and ConstructL(). 00332 { 00333 HBufC8* text = HBufC8::NewLC( aText.Length() + 4 /*for ending zero*/ ); 00334 TPtr8 dest( text->Des() ); 00335 CnvUtfConverter::ConvertFromUnicodeToUtf8( dest, aText ); 00336 std::string ret((const char*)dest.PtrZ()); 00337 CleanupStack::PopAndDestroy(text); // delete text 00338 return ret; 00339 }
|
|
|
The Home Screen Publisher API's main class Definition at line 128 of file HsWidgetExample.h. Referenced by ChangeWidgetValuesL(), ConstructL(), PublishWidgetL(), RegisterWidgetL(), RemoveWidgetL(), and ~CHsWidgetExample(). |
|
|
String indicating which template will be used for this widget. Definition at line 133 of file HsWidgetExample.h. Referenced by ChangeWidgetValuesL(), ConstructL(), PublishWidgetL(), RegisterWidgetL(), and RemoveWidgetL(). |
|
|
Widget's name. Will be shown to the user when he/she selects a widget to be added to the home screen. Definition at line 139 of file HsWidgetExample.h. Referenced by ChangeWidgetValuesL(), ConstructL(), PublishWidgetL(), RegisterWidgetL(), and RemoveWidgetL(). |
|
|
Unique UID identifiying a widget. Definition at line 144 of file HsWidgetExample.h. Referenced by ChangeWidgetValuesL(), ConstructL(), PublishWidgetL(), RegisterWidgetL(), and RemoveWidgetL(). |
|
|
A counter, used to display different content on its widget depending on its odd/even value Definition at line 150 of file HsWidgetExample.h. Referenced by ChangeWidgetValuesL(). |
|
© Nokia 2009 |