Nokia N97 SDK
Example Applications Guide

HsWidgetAppUi.cpp

00001 /*
00002  ============================================================================
00003  Name           : HsWidgetAppUi.cpp
00004  Author   : 
00005  Copyright   : This material, including documentation and any related computer
00006           programs, is protected by copyright controlled by Nokia Corporation.
00007  Description : CHsWidgetAppUi implementation
00008  ============================================================================
00009  */
00010 
00011 // INCLUDE FILES
00012 #include <eikmenup.h>
00013 #include <avkon.hrh>
00014 #include <aknmessagequerydialog.h>
00015 #include <aknnotewrappers.h>
00016 #include <stringloader.h>
00017 #include <f32file.h>
00018 #include <s32file.h>
00019 #include <hlplch.h>
00020 #include <apgtask.h>
00021 
00022 #include <HsWidget.rsg>
00023 
00024 #include "HsWidget.hlp.hrh"
00025 #include "HsWidget.hrh"
00026 #include "HsWidget.pan"
00027 #include "HsWidgetApplication.h"
00028 #include "HsWidgetAppUi.h"
00029 #include "HsWidgetAppView.h"
00030 #include "HsWidgetExample.h"
00031 #include "HsSMWidgetExample.h"
00032 
00033 // logging
00034 #include "logger.h" 
00035 
00036 // ============================ MEMBER FUNCTIONS ===============================
00037 
00038 
00039 // -----------------------------------------------------------------------------
00040 // CHsWidgetAppUi::ConstructL()
00041 // Symbian 2nd phase constructor can leave.
00042 // -----------------------------------------------------------------------------
00043 //
00044 void CHsWidgetAppUi::ConstructL()
00045         {
00046         __LOGSTR_TOFILE("Enter CHsWidgetAppUi::ConstructL");
00047         
00048         // Initialise app UI with standard value.
00049         BaseConstructL(CAknAppUi::EAknEnableSkin);
00050 
00051         // Create view object
00052         iAppView = CHsWidgetAppView::NewL(ClientRect() );       
00053         
00054         // if the example widget already exists when the application is started
00055         // it is possible that it was itself that lauched the
00056         // application thus we want to reconnect with it quickly
00057         // and receive its events
00058         iWidgetExample = CHsWidgetExample::NewL();
00059         iWidgetExample->RegisterWidgetL();
00060 
00061         // if the SM Widget exists when the application starts it must be due
00062         // to a phone reboot while the widget was registered
00063         iSMWidgetExample = CHsSMWidgetExample::NewL();
00064         iSMWidgetExample->RegisterWidgetL();
00065         iSMWidgetExample->RemoveWidgetL();
00066         delete iSMWidgetExample;
00067         iSMWidgetExample = NULL;
00068         
00069         __LOGSTR_TOFILE("Exit CHsWidgetAppUi::ConstructL");
00070         }
00071 // -----------------------------------------------------------------------------
00072 // CHsWidgetAppUi::CHsWidgetAppUi()
00073 // C++ default constructor can NOT contain any code, that might leave.
00074 // -----------------------------------------------------------------------------
00075 //
00076 CHsWidgetAppUi::CHsWidgetAppUi()
00077         {
00078         // No implementation required
00079         }
00080 
00081 // -----------------------------------------------------------------------------
00082 // CHsWidgetAppUi::~CHsWidgetAppUi()
00083 // Destructor.
00084 // -----------------------------------------------------------------------------
00085 //
00086 CHsWidgetAppUi::~CHsWidgetAppUi()
00087         {
00088         __LOGSTR_TOFILE("Enter CHsWidgetAppUi::~CHsWidgetAppUi");
00089         
00090         // delete the widget example
00091         // note that the widget is not unregistered
00092         // thus it will still remain at user's disposal 
00093         delete iWidgetExample;
00094         
00095 
00096         // remove and delete this widget
00097         // if already selected by the user on the homescreen
00098         // the widget will be closed
00099         if(iSMWidgetExample!=NULL)
00100                 {
00101                 iSMWidgetExample->RemoveWidgetL();
00102                 delete iSMWidgetExample;
00103                 iSMWidgetExample = NULL;
00104                 }
00105         
00106         if (iAppView)
00107                 {
00108                 delete iAppView;
00109                 iAppView = NULL;
00110                 }
00111 
00112         __LOGSTR_TOFILE("Exit CHsWidgetAppUi::~CHsWidgetAppUi");
00113         __LOGSTR_TOFILE("====================================");
00114         }
00115 
00116 // -----------------------------------------------------------------------------
00117 // CHsWidgetAppUi::HandleCommandL()
00118 // Takes care of command handling.
00119 // -----------------------------------------------------------------------------
00120 //
00121 void CHsWidgetAppUi::HandleCommandL(TInt aCommand)
00122         {
00123         __LOGSTR_TOFILE1("Enter CHsWidgetAppUi::HandleCommandL with aCommand = %d", aCommand);
00124         
00125         switch (aCommand)
00126                 {
00127                 case EEikCmdExit:
00128                 case EAknSoftkeyExit:
00129                         Exit();
00130                         break;
00131 
00132                 case EAknSoftkeyBack:
00133                         {
00134                         TApaTask task( iEikonEnv->WsSession() );
00135                         task.SetWgId(iEikonEnv->RootWin().Identifier());
00136                         task.SendToBackground();
00137                         }
00138                         break;
00139                         
00140                 case ERegisterWidget:
00141                         {
00142                         if( !iWidgetExample)
00143                                 {
00144                                 iWidgetExample = CHsWidgetExample::NewL();
00145                                 iWidgetExample->RegisterWidgetL();
00146                                 }
00147                         }
00148                         break;
00149                 case EChangeWidgetValues:
00150                         {
00151                         // set new content for the widget
00152                         iWidgetExample->ChangeWidgetValuesL();
00153                         // publish the content
00154                         iWidgetExample->PublishWidgetL();
00155                         }
00156                         break;
00157                 case ERemoveWidget:
00158                         {
00159                         iWidgetExample->RemoveWidgetL();
00160                         delete iWidgetExample;
00161                         iWidgetExample = NULL;
00162                         }
00163                         break;
00164                 case ERegisterSMWidget:
00165                         {
00166                         if(!iSMWidgetExample)
00167                                 {
00168                                 iSMWidgetExample = CHsSMWidgetExample::NewL();
00169                                 // register widget
00170                                 iSMWidgetExample->RegisterWidgetL();
00171                                 }
00172                         }                       
00173                         break;
00174                 case ERemoveSMWidget:
00175                         {
00176                         iSMWidgetExample->RemoveWidgetL();
00177                         delete iSMWidgetExample;
00178                         iSMWidgetExample = NULL;
00179                         }
00180                         break;
00181                 case EHelp:
00182                         {
00183                         CArrayFix<TCoeHelpContext>* buf =
00184                                          CCoeAppUi::AppHelpContextL();
00185                         HlpLauncher::LaunchHelpApplicationL(
00186                                                 iEikonEnv->WsSession(), buf);
00187                         }
00188                         break;
00189                 case EAbout:
00190                         {
00191                         CAknMessageQueryDialog* dlg =
00192                                          new (ELeave)CAknMessageQueryDialog();
00193                         dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
00194                         HBufC* title =
00195                                  iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
00196                         dlg->QueryHeading()->SetTextL(*title);
00197                         CleanupStack::PopAndDestroy(); //title
00198                         HBufC* msg =
00199                                  iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
00200                         dlg->SetMessageTextL(*msg);
00201                         CleanupStack::PopAndDestroy(); //msg
00202                         dlg->RunLD();
00203                         }
00204                         break;
00205                 default:
00206                         Panic(EHsWidgetUi);
00207                         break;
00208                 }
00209         
00210         __LOGSTR_TOFILE("Exit CHsWidgetAppUi::HandleCommandL");
00211         }
00212 // -----------------------------------------------------------------------------
00213 //  Called by the framework when the application status pane
00214 //  size is changed.  Passes the new client rectangle to the
00215 //  AppView
00216 // -----------------------------------------------------------------------------
00217 //
00218 void CHsWidgetAppUi::HandleStatusPaneSizeChange()
00219         {
00220         iAppView->SetRect(ClientRect() );
00221         }
00222 
00223 CArrayFix<TCoeHelpContext>* CHsWidgetAppUi::HelpContextL() const
00224         {
00225         //#warning "Please see comment about help and UID3..."
00226         // Note: Help will not work if the application uid3 is not in the
00227         // protected range.  The default uid3 range for projects created
00228         // from this template (0xE0000000 - 0xEFFFFFFF) are not in the
00229         // protected range so that they can be self signed and installed
00230         // on the device during testing.
00231         // Once you get your official uid3 from Symbian Ltd. and find/replace
00232         // all occurrences of uid3 in your project, the context help will
00233         // work.
00234         CArrayFixFlat<TCoeHelpContext>* array = 
00235                                 new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
00236         CleanupStack::PushL(array);
00237         array->AppendL(TCoeHelpContext(KUidHsWidgetApp, KGeneral_Information));
00238         CleanupStack::Pop(array);
00239         return array;
00240         }
00241 
00242 
00243 // -----------------------------------------------------------------------------
00244 // CHsWidgetAppUi::DynInitMenuPaneL
00245 // Dimm items depend on widget existing.
00246 // -----------------------------------------------------------------------------
00247 //
00248 void CHsWidgetAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
00249         {
00250         if( aResourceId != R_MENU )
00251                 {
00252                 return;
00253                 }
00254         if( iWidgetExample == NULL)
00255                 {
00256             aMenuPane->SetItemDimmed( ERegisterWidget, EFalse );
00257             aMenuPane->SetItemDimmed( EChangeWidgetValues, ETrue );
00258             aMenuPane->SetItemDimmed( ERemoveWidget, ETrue );
00259             }
00260         else
00261                 {
00262                 aMenuPane->SetItemDimmed( ERegisterWidget, ETrue );
00263             aMenuPane->SetItemDimmed( EChangeWidgetValues, EFalse );
00264             aMenuPane->SetItemDimmed( ERemoveWidget, EFalse );
00265                 }
00266         if( iSMWidgetExample == NULL)
00267                 {
00268             aMenuPane->SetItemDimmed( ERegisterSMWidget, EFalse );
00269             aMenuPane->SetItemDimmed( ERemoveSMWidget, ETrue );
00270             }
00271         else
00272                 {
00273                 aMenuPane->SetItemDimmed( ERegisterSMWidget, ETrue );
00274             aMenuPane->SetItemDimmed( ERemoveSMWidget, EFalse );
00275                 }
00276 
00277         }
00278 
00279 // -----------------------------------------------------------------------------
00280 // CHsWidgetAppUi::HandleResourceChangeL
00281 // Receive notification when system resouces change.
00282 // -----------------------------------------------------------------------------
00283 //
00284 void CHsWidgetAppUi::HandleResourceChangeL(TInt aType)
00285         {
00286         CAknAppUi::HandleResourceChangeL( aType );
00287         if(aType == KAknsMessageSkinChange)
00288                 {
00289                 __LOGSTR_TOFILE(" * CHsWidgetAppUi::HandleResourceChangeL received KAknsMessageSkinChange");
00290                 // HsSMWidgetExample depends on skin collors, must be updated
00291                 if(iSMWidgetExample != NULL)
00292                         {
00293                         iSMWidgetExample->SignalLevelChangedL(-1,-1);
00294                         }
00295                 }
00296         }
00297 
00298 // -----------------------------------------------------------------------------
00299 // CHsWidgetAppUi::ProcessCommandParametersL
00300 // Intercept and process received command parameters.
00301 // -----------------------------------------------------------------------------
00302 //
00303 TBool CHsWidgetAppUi::ProcessCommandParametersL( CApaCommandLine &aCommandLine )
00304         {
00305         __LOGSTR_TOFILE("Enter CHsWidgetAppUi::ProcessCommandParametersL");
00306 
00307         if (aCommandLine.OpaqueData().Length() > 0)
00308                 {
00309                 // Opaque data exists so application was probably started by:
00310                 //      - the user from the Menu grid
00311                 //      - the home screen application
00312                 __LOGSTR_TOFILE("Has opaque data");
00313                 }
00314         else
00315                 {
00316                 // Opaque data does not exists, app. has been autostarted ?
00317                 __LOGSTR_TOFILE("No opaque data");
00318                 }       
00319         
00320         __LOGSTR_TOFILE("Exit CHsWidgetAppUi::ProcessCommandParametersL");
00321         
00322         return CEikAppUi::ProcessCommandParametersL(aCommandLine);
00323         }
00324         
00325 // End of File

© Nokia 2009

Back to top