Nokia N97 SDK
Example Applications Guide

CSIPExAppUi Class Reference

#include <SIPExAppUi.h>

Inheritance diagram for CSIPExAppUi:

MSIPExGameObserver MSIPExStateViewNotifier List of all members.

Detailed Description

Application user interface class. User interface part of the CKON application framework for the SIPEx game.

Definition at line 40 of file SIPExAppUi.h.


Public Member Functions

  CSIPExAppUi ()
void  ConstructL ()
virtual  ~CSIPExAppUi ()
TKeyResponse  HandleKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType)
void  HandleCommandL (TInt aCommand)
void  GameStateChanged (CSIPExEngine::TEngineState aState)
TBool  AcceptInvitationL (const TDesC &aFrom)
void  IMReceivedL (const TDesC8 &aFrom, const TDesC8 &aMsg)
void  ShowStatusInfoL (const TDesC &aText)
void  ShowInfoL (const TDesC &aText)
void  ShowInfoL (const TDesC8 &aText)
const CSIPExEngine::TEngineState  EngineState ()
TBool  GameViewActive ()
TBool  LogViewActive ()
TBool  IsViewActive (TUid aViewUid)
CSIPExGameContainer *  GameContainer ()
CSIPExLogContainer *  LogContainer ()

Private Attributes

CSIPExEngine *  iEngine
TBuf< KMaxSIPAddressLength >  iAddress
CSIPExEngine::TEngineState  iState
CAknNavigationControlContainer *  iNaviPane
CAknTabGroup *  iTabGroup
CAknNavigationDecorator *  iDecoratedTabGroup


Constructor & Destructor Documentation

CSIPExAppUi::CSIPExAppUi (   ) 
 

C++ default constructor. This needs to be public due to the way the framework constructs the AppUi.

Definition at line 42 of file SIPExAppUi.cpp.

00043 : iState( CSIPExEngine::EIdle )
00044     {
00045     }

CSIPExAppUi::~CSIPExAppUi (   )  [virtual]
 

Destructor.

Definition at line 100 of file SIPExAppUi.cpp.

References iDecoratedTabGroup.

00101     {
00102     delete iDecoratedTabGroup;
00103     }


Member Function Documentation

void CSIPExAppUi::ConstructL (   ) 
 

2nd phase constructor. This needs to be public due to the way the framework constructs the AppUi

Definition at line 52 of file SIPExAppUi.cpp.

References iDecoratedTabGroup, iEngine, iNaviPane, iTabGroup, CSIPExLogView::NewLC(), CSIPExGameView::NewLC(), and CSIPExEngine::SetViewNotifier().

00053     {
00054     BaseConstructL( EAknEnableSkin );
00055     
00056     // Show tabs for main views from resources
00057     CEikStatusPane* sp = StatusPane();
00058 
00059     // Fetch pointer to the default navi pane control
00060     iNaviPane = static_cast< CAknNavigationControlContainer*>( 
00061         sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
00062 
00063     // Tabgroup has been read from resource and it was pushed to the navi 
00064     // pane. Get pointer to the navigation decorator with the 
00065     // ResourceDecorator() function. 
00066     // Application owns the decorator and it has responsibility to 
00067     // delete the object.
00068     iDecoratedTabGroup = iNaviPane->ResourceDecorator();
00069     if (iDecoratedTabGroup)
00070         {
00071         iTabGroup = static_cast< CAknTabGroup* >( 
00072                 iDecoratedTabGroup->DecoratedControl() );
00073         }
00074 
00075     iEngine = 
00076         ( static_cast< CSIPExDoc* >( Document() ) )->CreateEngineL( *this );
00077     
00078     // Receive view notifications from engine. Depending on currently 
00079     // active view, request (show message etc.) is either executed or 
00080     // stored for later usage
00081     iEngine->SetViewNotifier( *this );
00082     
00083     
00084     CSIPExGameView* gameview = CSIPExGameView::NewLC( *iEngine );
00085     AddViewL( gameview ); //transfer ownership to CAknViewAppUi
00086     CleanupStack::Pop( gameview );
00087     
00088     CSIPExLogView* logview = CSIPExLogView::NewLC( *iEngine );
00089     AddViewL( logview ); //transfer ownership to CAknViewAppUi
00090     CleanupStack::Pop( logview );
00091 
00092     SetDefaultViewL( *gameview );
00093     }

TKeyResponse CSIPExAppUi::HandleKeyEventL (  const TKeyEvent &  aKeyEvent,
TEventCode  aType
) 
 

From CEikAppUi, handles key events.

Parameters:
aKeyEvent  Event to handled.
aType  Type of the key event.
Returns:
Response code (EKeyWasConsumed, EKeyWasNotConsumed).

Definition at line 110 of file SIPExAppUi.cpp.

00113     {
00114     // This would be good place for changing views according to left and right
00115     // key presses but those are reserved for game view for moving the piece
00116     return EKeyWasConsumed;
00117     }

void CSIPExAppUi::HandleCommandL (  TInt  aCommand  ) 
 

From CEikAppUi handles the user interaction.

Parameters:
aCommand  Id of the initiated command

Definition at line 125 of file SIPExAppUi.cpp.

References CSIPExEngine::DisableProfileL(), CSIPExEngine::EnableProfileL(), CSIPExEngine::EndGameL(), iAddress, iEngine, CSIPExEngine::InviteL(), CSIPExIMDialog::NewL(), CSIPExAddrQueryDlg::NewL(), and CSIPExEngine::SendInstantMsgL().

00126     {
00127     switch ( aCommand )
00128         {
00129         case EEikCmdExit:
00130             {
00131             // If game is ongoing, notify opponent, ignore errors
00132             TRAPD( err, iEngine->EndGameL() );
00133             Exit();
00134             break;
00135             }
00136 
00137         case ECmdInviteForGame:
00138             {
00139             CSIPExAddrQueryDlg* dlg = CSIPExAddrQueryDlg::NewL( iAddress );
00140             if( dlg->ExecuteLD( R_INVITE_ADDRESS_DLG ) )
00141                 {
00142                 iEngine->InviteL( iAddress );
00143                 }
00144             break;
00145             }     
00146 
00147         case ECmdEnableProfile:
00148             {
00149             iEngine->EnableProfileL();
00150             break;
00151             }
00152 
00153         case ECmdDisableProfile:
00154             {
00155             iEngine->DisableProfileL();
00156             break;
00157             }
00158 
00159         // Send instant message
00160         case ECmdSendIM:
00161             {
00162             TBuf< ESIPMaxMsgLen > msg;
00163             CSIPExIMDialog* dlg = CSIPExIMDialog::NewL( iAddress, msg );
00164             if( dlg->ExecuteLD( R_INSTANT_MESSAGE_DLG ) )
00165                 {
00166                 iEngine->SendInstantMsgL( iAddress, msg );
00167                 }
00168             break;
00169             }
00170             
00171         // Change to Game View
00172         case ECmdChangeViewToGame:
00173             {
00174             if ( iTabGroup )
00175                 {
00176                 TInt active = iTabGroup->ActiveTabIndex();
00177                 TInt count = iTabGroup->TabCount();
00178                 if ( active > 0 )
00179                     {
00180                     active--;
00181                     iTabGroup->SetActiveTabByIndex( active );
00182                     // ActivateLocalViewL() is used to change the view. 
00183                     ActivateLocalViewL( 
00184                         TUid::Uid( iTabGroup->TabIdFromIndex( active ) ) );
00185                     }
00186                 }
00187             break;
00188             }
00189             
00190         // Change to Log View
00191         case ECmdChangeViewToLog:
00192             {
00193             if ( iTabGroup )
00194                 {
00195                 TInt active = iTabGroup->ActiveTabIndex();
00196                 TInt count = iTabGroup->TabCount();
00197                 if ( (active + 1) < count )
00198                     {
00199                     active++;
00200                     iTabGroup->SetActiveTabByIndex( active );
00201                     // ActivateLocalViewL() is used to change the view. 
00202                     ActivateLocalViewL( 
00203                         TUid::Uid( iTabGroup->TabIdFromIndex( active ) ) );
00204                     }
00205                 }    
00206             break;
00207             }
00208             
00209 
00210         // End game
00211         case ECmdEndGame:
00212             {
00213             iEngine->EndGameL();
00214             break;
00215             }
00216 
00217         default:
00218             {
00219             
00220             // Do nothing, no-one will handle it
00221             // No use of leaving though, because this isn't an error - only
00222             // an unhandled command
00223             break;
00224             }
00225         }
00226     }

void CSIPExAppUi::GameStateChanged (  CSIPExEngine::TEngineState  aState  )  [virtual]
 

GameStateChanged Called when the active state of the game is changed.

Parameters:
aNewState  A new state of the game engine.

Implements MSIPExGameObserver.

Definition at line 234 of file SIPExAppUi.cpp.

References GameContainer(), GameViewActive(), and iState.

00235     {
00236     iState = aState;
00237     
00238     if ( GameViewActive() )
00239         {
00240         GameContainer()->DrawDeferred();
00241         }
00242     }

TBool CSIPExAppUi::AcceptInvitationL (  const TDesC &  aFrom  )  [virtual]
 

AcceptInvitationL Called when the invitation has arrived from SIP engine.

Parameters:
aFrom  The address of the summoner.
Returns:
ETrue if the user accepts the invitation, else EFalse.

Implements MSIPExGameObserver.

Definition at line 252 of file SIPExAppUi.cpp.

00253     {
00254     HBufC* buf = 
00255         StringLoader::LoadLC( R_SIP_EX_ACCEPT_INVITATION, aFrom, iEikonEnv );
00256     TBool retVal( EFalse );
00257 
00258     CAknQueryDialog* query = CAknQueryDialog::NewL();
00259     if( query->ExecuteLD( R_ACCEPT_INVITATION_DLG, *buf ) )
00260         {
00261         retVal = ETrue;
00262         }
00263 
00264     CleanupStack::PopAndDestroy( buf );
00265     return retVal;
00266     }

void CSIPExAppUi::IMReceivedL (  const TDesC8 &  aFrom,
const TDesC8 &  aMsg
)  [virtual]
 

IMReceived Called when the instant message has arrived from the SIP engine.

Parameters:
aFrom  The address of the sender.
aMsg  The message.

Implements MSIPExGameObserver.

Definition at line 274 of file SIPExAppUi.cpp.

References ShowInfoL().

00275     {
00276     HBufC* from = HBufC::NewLC( aFrom.Length() );
00277     from->Des().Copy( aFrom );
00278 
00279     HBufC* msg = HBufC::NewLC( aMsg.Length() );
00280     msg->Des().Copy( aMsg );
00281 
00282     CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat( 2 );
00283     CleanupStack::PushL( strings );
00284     strings->AppendL( *from );
00285     strings->AppendL( *msg );
00286     HBufC* buf = 
00287             StringLoader::LoadL( R_SIP_EX_IM_RECEIVED, *strings, iEikonEnv );
00288             
00289     CleanupStack::PopAndDestroy( strings );
00290     CleanupStack::PushL( buf );
00291     ShowInfoL( *buf );
00292     CleanupStack::PopAndDestroy( 3 );
00293     }

void CSIPExAppUi::ShowStatusInfoL (  const TDesC &  aText  )  [virtual]
 

ShowStatusInfoL Called when game status changes.

Parameters:
aText  A free format text.

Implements MSIPExStateViewNotifier.

Definition at line 299 of file SIPExAppUi.cpp.

00300     {
00301     // Show status info in title pane (could be additionally 
00302     // shown in some popup note)
00303     //
00304     TUid titlePaneUid = { EEikStatusPaneUidTitle };
00305     
00306     CEikStatusPane* statusPane = StatusPane();
00307     
00308     CEikStatusPaneBase::TPaneCapabilities subPane = 
00309                                 statusPane->PaneCapabilities( titlePaneUid );
00310     
00311     
00312     HBufC* text = StringLoader::LoadLC( R_SIP_EX_TITLE_TXT, aText, iEikonEnv );
00313     
00314     if ( subPane.IsPresent() && subPane.IsAppOwned() )
00315         {
00316         CAknTitlePane* titlePane = 
00317             static_cast< CAknTitlePane* >( statusPane->ControlL( titlePaneUid ) );
00318         
00319         titlePane->SetText( text );
00320         
00321         CleanupStack::Pop( text );
00322         }
00323     else
00324         {
00325         CleanupStack::PopAndDestroy( text );
00326         }
00327     }

void CSIPExAppUi::ShowInfoL (  const TDesC &  aText  )  [virtual]
 

ShowInfoL Called when the new info is available about engine state.

Parameters:
aText  A 16-bit free format text.

Implements MSIPExStateViewNotifier.

Definition at line 333 of file SIPExAppUi.cpp.

References GameViewActive(), LogContainer(), and CSIPExLogContainer::ShowInfoL().

Referenced by IMReceivedL().

00334     {
00335     static_cast< CSIPExDoc* >( Document() )->StoreInfoTextL( aText );
00336     if( !GameViewActive() )
00337         {
00338         LogContainer()->ShowInfoL();
00339         } 
00340     }

void CSIPExAppUi::ShowInfoL (  const TDesC8 &  aText  )  [virtual]
 

ShowInfoL Called when the new info is available about engine state.

Parameters:
aText  A 8-bit free format text.

Implements MSIPExStateViewNotifier.

Definition at line 346 of file SIPExAppUi.cpp.

References GameViewActive(), LogContainer(), and CSIPExLogContainer::ShowInfoL().

00347     {
00348     HBufC* buf = HBufC::NewLC( aText.Length() );
00349     buf->Des().Copy( aText );
00350     static_cast< CSIPExDoc* >( Document() )->StoreInfoTextL( *buf );
00351     CleanupStack::PopAndDestroy( buf );
00352     
00353     if( !GameViewActive() )
00354         {
00355         LogContainer()->ShowInfoL();
00356         } 
00357     }

const CSIPExEngine::TEngineState CSIPExAppUi::EngineState (   ) 
 

Return current state of the engine

Definition at line 363 of file SIPExAppUi.cpp.

References iState.

00364     {
00365     return iState;
00366     }

TBool CSIPExAppUi::GameViewActive (   ) 
 

Return true if currently active view is the GameView, false otherwise

Definition at line 372 of file SIPExAppUi.cpp.

References IsViewActive().

Referenced by GameStateChanged(), and ShowInfoL().

00373     {
00374     return IsViewActive( KGameViewId );
00375     }

TBool CSIPExAppUi::LogViewActive (   ) 
 

Return true if currently active view is the LogView, false otherwise

Definition at line 381 of file SIPExAppUi.cpp.

References IsViewActive().

00382     {
00383     return IsViewActive( KLogViewId );
00384     }

TBool CSIPExAppUi::IsViewActive (  TUid  aViewUid  ) 
 

Return true if currently active view is matching with aViewUid

Definition at line 390 of file SIPExAppUi.cpp.

References iTabGroup.

Referenced by GameViewActive(), and LogViewActive().

00391         {
00392         TInt active = iTabGroup->ActiveTabIndex();
00393     return ( TUid::Uid( iTabGroup->TabIdFromIndex( active ) ) == aViewUid );
00394         }

CSIPExGameContainer * CSIPExAppUi::GameContainer (   ) 
 

Return pointer to game container, ownership is not transferred

Definition at line 400 of file SIPExAppUi.cpp.

Referenced by GameStateChanged().

00401     {
00402     return static_cast< CSIPExGameView* >( View( KGameViewId ) )->Container();
00403     }

CSIPExLogContainer * CSIPExAppUi::LogContainer (   ) 
 

Return pointer to log container, ownership is not transferred

Definition at line 409 of file SIPExAppUi.cpp.

Referenced by ShowInfoL().

00410     {
00411     return static_cast< CSIPExLogView* >( View( KLogViewId ) )->Container();
00412     }


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

© Nokia 2009

Back to top