voiceui/vcommand/src/vcappui.cpp
branchRCL_3
changeset 18 cad71a31b7fc
parent 17 8ce15fced3a6
child 19 e36f3802f733
equal deleted inserted replaced
17:8ce15fced3a6 18:cad71a31b7fc
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Application UI class for vcommand app
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <hlplch.h>
       
    21 #include <featmgr.h>
       
    22 #include <akntitle.h>  // CAknTitlePane
       
    23 #include <barsread.h>  // TResourceReader
       
    24 #include <StringLoader.h>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <aknnotewrappers.h>
       
    27 
       
    28 #include <e32property.h>        // RProperty
       
    29 #include <PSVariables.h>        // Property values
       
    30 #include <ctsydomainpskeys.h>
       
    31 
       
    32 #include <vcommand.rsg>
       
    33 #include "vcappui.h"
       
    34 #include "vcmodelappuiinterface.h"
       
    35 #include "vcgenericview.h"
       
    36 #include "vcfolderview.h"
       
    37 #include "vcsettingsview.h"
       
    38 #include "vcommandconstants.h"
       
    39 #include "vcmodel.h"
       
    40 
       
    41 #include "rubydebug.h"
       
    42 
       
    43 /**
       
    44 * This is an application closer class. VCommandhandler needs to finish certain
       
    45 * operations once they are started. Since the application receives key events
       
    46 * all the time, including the ones requesting application exit, we ask the
       
    47 * system to Call() this class a bit later. From its RunL it will gracefully
       
    48 * close the application
       
    49 */
       
    50 NONSHARABLE_CLASS( CAppCloser ) : public CAsyncOneShot 
       
    51 	{
       
    52 	public:
       
    53 		CAppCloser();
       
    54 	protected:
       
    55 	    /** Is called by the system after we asked it to Call() closer
       
    56 	    */
       
    57 		virtual void RunL();
       
    58 	};
       
    59 	
       
    60 // -----------------------------------------------------------------------------
       
    61 //  Constructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CAppCloser::CAppCloser() :
       
    65 	CAsyncOneShot( CActive::EPriorityStandard )
       
    66 	{
       
    67 	}
       
    68 	
       
    69 // -----------------------------------------------------------------------------
       
    70 //  CAppCloser::RunL
       
    71 //  Will be called by the system and exits the application
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CAppCloser::RunL() 
       
    75 	{
       
    76 	if( iStatus == KErrNone ) 
       
    77 		{
       
    78 		static_cast<CVCAppUi*> ( CEikonEnv::Static()->AppUi() )->DoExitProgram();
       
    79 		}
       
    80 	else 
       
    81 		{
       
    82 		RUBY_ERROR1( "CAppCloser::RunL Unexpected iStatus [%d]", iStatus.Int() );
       
    83 		}
       
    84 	}
       
    85 
       
    86 
       
    87 // ================= MEMBER FUNCTIONS =======================
       
    88 //
       
    89 // ----------------------------------------------------------------------------
       
    90 // CVCAppUi::ConstructL()
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 void CVCAppUi::ConstructL()
       
    94     {
       
    95     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
    96     
       
    97     iCloser = new (ELeave) CAppCloser;
       
    98  
       
    99     // Sets up TLS, must be done before FeatureManager is used.
       
   100     FeatureManager::InitializeLibL();
       
   101     
       
   102     iModel = CVCModel::NewL( this );
       
   103 
       
   104     iMainView = new (ELeave) CVCGenericView( *iModel );
       
   105     iMainView->ConstructL( R_VCOMMAND_MAIN_VIEW );
       
   106     AddViewL( iMainView );      // transfer ownership to CAknViewAppUi
       
   107     
       
   108     iFolderView = new (ELeave) CVCFolderView( *iModel );
       
   109 
       
   110     iFolderView->ConstructL( R_VCOMMAND_FOLDER_VIEW );
       
   111     AddViewL( iFolderView );      // transfer ownership to CAknViewAppUi
       
   112 
       
   113 	CVCSettingsView* settingsView = new (ELeave) CVCSettingsView;
       
   114 
       
   115     CleanupStack::PushL( settingsView );
       
   116     settingsView->ConstructL();
       
   117     AddViewL( settingsView );      // transfer ownership to CAknViewAppUi
       
   118     CleanupStack::Pop( settingsView );   
       
   119 
       
   120     SetDefaultViewL( *iMainView );
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // CVCAppUi::~CVCAppUi()
       
   125 // Destructor
       
   126 // ----------------------------------------------------------------------------
       
   127 //
       
   128 CVCAppUi::~CVCAppUi() 
       
   129     {    
       
   130     delete iCloser;
       
   131     delete iModel;
       
   132 
       
   133     FeatureManager::UnInitializeLib();
       
   134     }
       
   135 
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // CVCAppUi::DynInitMenuPaneL
       
   139 // This function is called by the EIKON framework just before it displays
       
   140 // a menu pane.
       
   141 // ----------------------------------------------------------------------------
       
   142 //
       
   143 void CVCAppUi::DynInitMenuPaneL(
       
   144     TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
       
   145     {
       
   146     }
       
   147 
       
   148 
       
   149 // ----------------------------------------------------------------------------
       
   150 // CVCAppUi::HandleCommandL
       
   151 // ----------------------------------------------------------------------------
       
   152 //
       
   153 void CVCAppUi::HandleCommandL(TInt aCommand)
       
   154     {
       
   155     switch ( aCommand )
       
   156         {
       
   157         // Both exit commands should do the same thing
       
   158         case EEikCmdExit:
       
   159         case EAknSoftkeyExit:
       
   160             {
       
   161             ExitProgram();
       
   162             break;
       
   163             }
       
   164             
       
   165         case EAknCmdHelp:
       
   166             {
       
   167             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   168                                                  AppHelpContextL() );
       
   169             break;
       
   170             }
       
   171             
       
   172         default:
       
   173             {
       
   174             CAknViewAppUi::HandleCommandL( aCommand );
       
   175             break;              
       
   176             }
       
   177         }
       
   178     }
       
   179 
       
   180 
       
   181 // ----------------------------------------------------------------------------
       
   182 // CVCAppUi::ExitProgram
       
   183 // ----------------------------------------------------------------------------
       
   184 //
       
   185 void CVCAppUi::ExitProgram() 
       
   186     {
       
   187     if( iOperationInProgress ) 
       
   188         {
       
   189         iExitRequested = ETrue;
       
   190         }
       
   191     else 
       
   192         {
       
   193         DoExitProgram();
       
   194         }
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CVCAppUi::DoExitProgram
       
   199 // ----------------------------------------------------------------------------
       
   200 //    
       
   201 void CVCAppUi::DoExitProgram() 
       
   202     {
       
   203     Exit();
       
   204     }
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CVCAppUi::ExitProgramDeferred
       
   208 // ----------------------------------------------------------------------------
       
   209 //
       
   210 void CVCAppUi::ExitProgramDeferred()
       
   211     {
       
   212     iCloser->Call();
       
   213     }
       
   214     
       
   215 // ----------------------------------------------------------------------------
       
   216 // CVCAppUi::StartAtomicOperationLC
       
   217 // ----------------------------------------------------------------------------
       
   218 //  
       
   219 void CVCAppUi::StartAtomicOperationLC()
       
   220     {
       
   221     iOperationInProgress = ETrue;
       
   222     
       
   223     TCleanupItem item( CleanupEndAtomicOperation, this );
       
   224     CleanupStack::PushL( item );
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CVCAppUi::NotifyEndOfAtomicOperationL
       
   229 // ----------------------------------------------------------------------------
       
   230 //   
       
   231 void CVCAppUi::EndAtomicOperation()
       
   232     {
       
   233     iOperationInProgress = EFalse;
       
   234     if( iExitRequested ) 
       
   235         {
       
   236         RUBY_DEBUG0( "NotifyEndOfAtomicOperationL exit requested -> DoExit" );
       
   237         ExitProgramDeferred();
       
   238         
       
   239         // A function with a NotifyStartOfAtomicOperation -
       
   240         // NotifyEndOfAtomicOperation pair might be called from a function
       
   241         // with the same pair, so we make sure ExitProgramDeferred is called
       
   242         // only once in such a situation.
       
   243         iExitRequested = EFalse;
       
   244         }
       
   245     }
       
   246     
       
   247 // ----------------------------------------------------------------------------
       
   248 // CVCAppUi::CleanupEndAtomicOperation
       
   249 // ----------------------------------------------------------------------------
       
   250 //   
       
   251 void CVCAppUi::CleanupEndAtomicOperation( TAny* aService )
       
   252     {
       
   253     CVCAppUi* service = static_cast<CVCAppUi*>(aService);
       
   254     service->EndAtomicOperation();
       
   255     }
       
   256 
       
   257 
       
   258 void CVCAppUi::CreateAndPushEndAtomicCleanupItemL()
       
   259     {
       
   260     TCleanupItem item( CleanupEndAtomicOperation, this );
       
   261     CleanupStack::PushL( item );
       
   262     }
       
   263 
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CVCAppUi::SetTitleL
       
   267 // Set title pane text from a resource.
       
   268 // ----------------------------------------------------------------------------
       
   269 //
       
   270 void CVCAppUi::SetTitleL( TInt aResourceId )
       
   271     {
       
   272     CAknTitlePane* title = static_cast<CAknTitlePane*>(
       
   273         StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   274         
       
   275     TResourceReader reader;
       
   276     iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   277     title->SetFromResourceL( reader );
       
   278     CleanupStack::PopAndDestroy();  // resource reader
       
   279     }
       
   280     
       
   281 // ----------------------------------------------------------------------------
       
   282 // CVCAppUi::InvalidTextNoteL
       
   283 // ----------------------------------------------------------------------------
       
   284 //
       
   285 void CVCAppUi::ShowErrorNoteL( TInt aResourceId )
       
   286     {
       
   287     HBufC* text = StringLoader::LoadLC( aResourceId );
       
   288     CAknErrorNote* note = new( ELeave ) CAknErrorNote( ETrue );
       
   289     note->ExecuteLD( *text );
       
   290     CleanupStack::PopAndDestroy( text );
       
   291     }
       
   292 
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CVCAppUi::NameAlreadyInUseNoteL
       
   296 // ----------------------------------------------------------------------------
       
   297 //
       
   298 void CVCAppUi::NameAlreadyInUseNoteL( const TDesC& aName )
       
   299     {
       
   300     if ( aName.Length() > 0 )
       
   301         {
       
   302         // Not using the version of LoadLC where a parameter is inserted to
       
   303         // the returned string because for some reason that causes some weird
       
   304         // characters to appear when using localized strings
       
   305         TDesC* stringholder = StringLoader::LoadLC( R_QTN_VC_ERROR_IN_USE,
       
   306                                                     iEikonEnv );
       
   307         TName noteText;
       
   308         StringLoader::Format( noteText, *stringholder, -1, aName );
       
   309         CleanupStack::PopAndDestroy( stringholder );
       
   310         
       
   311         CAknNoteWrapper* note = new ( ELeave ) CAknNoteWrapper();
       
   312         note->ExecuteLD( R_VC_ALREADY_IN_USE, noteText );
       
   313         }
       
   314     }
       
   315     
       
   316     
       
   317 // ----------------------------------------------------------------------------
       
   318 // CVCSindAppUi::ShowWaitNoteL
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 void CVCAppUi::ShowWaitNoteL( const TDesC& aText )
       
   322     {
       
   323     if ( iWaitNote )
       
   324         {
       
   325         delete iWaitNote;
       
   326         iWaitNote = NULL;
       
   327         }
       
   328     iWaitNote = new(ELeave) CAknWaitDialog(
       
   329         ( reinterpret_cast<CEikDialog**>( &iWaitNote ) ), ETrue );
       
   330     iWaitNote->PrepareLC( R_VC_WAIT_NOTE );
       
   331     iWaitNote->SetTextL( aText );
       
   332     
       
   333     iWaitNote->RunLD();
       
   334     }
       
   335     
       
   336     
       
   337 // ----------------------------------------------------------------------------
       
   338 // CVCSindAppUi::ShowWaitNoteL
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 void CVCAppUi::DeleteWaitNoteL()
       
   342     {
       
   343     if (iWaitNote)
       
   344     	{
       
   345     	iWaitNote->ProcessFinishedL(); // deletes the dialog    	
       
   346     	}
       
   347     delete iWaitNote;
       
   348     iWaitNote = NULL;
       
   349     }
       
   350 
       
   351 
       
   352 // ----------------------------------------------------------------------------
       
   353 // CVCAppUi::CheckCallStateL
       
   354 // ----------------------------------------------------------------------------
       
   355 //
       
   356 TInt CVCAppUi::CheckCallStateL()
       
   357     {
       
   358     TInt callState;
       
   359     TInt err = RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState,
       
   360                                callState );
       
   361         
       
   362     User::LeaveIfError( err );
       
   363         
       
   364     return callState;
       
   365     }
       
   366 
       
   367 
       
   368 // ----------------------------------------------------------------------------
       
   369 // CVCAppUi::IsVideoCallL
       
   370 // ----------------------------------------------------------------------------
       
   371 //
       
   372 TBool CVCAppUi::IsVideoCallL() 
       
   373     { 
       
   374     TInt callType;
       
   375     TInt err =  RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallType,
       
   376                                 callType );
       
   377                                 
       
   378     User::LeaveIfError( err );
       
   379 
       
   380     return callType == EPSCTsyCallTypeH324Multimedia;
       
   381     }
       
   382 
       
   383 
       
   384 // ----------------------------------------------------------------------------
       
   385 // CVCAppUi::CallInProgressNoteL
       
   386 // ----------------------------------------------------------------------------
       
   387 //
       
   388 void CVCAppUi::CallInProgressNoteL()
       
   389     {
       
   390     HBufC* text = StringLoader::LoadLC( R_TEXT_CALL_IN_PROGRESS );
       
   391     CAknInformationNote* note = new( ELeave ) CAknInformationNote( ETrue );
       
   392     note->ExecuteLD( *text );
       
   393     CleanupStack::PopAndDestroy( text );
       
   394     }
       
   395 
       
   396 
       
   397 // ----------------------------------------------------------------------------
       
   398 // CVCAppUi::HandleResourceChangeL
       
   399 // Handle skin change event.
       
   400 // ----------------------------------------------------------------------------
       
   401 //
       
   402 void CVCAppUi::HandleResourceChangeL( TInt aType )
       
   403     {
       
   404     CAknAppUi::HandleResourceChangeL( aType );
       
   405     
       
   406     if ( aType == KEikDynamicLayoutVariantSwitch ) 
       
   407         {
       
   408         CAknView* view = View( KUidVCMainView );        
       
   409         if ( view )
       
   410             {
       
   411         	static_cast< CVCGenericView* >( view )->HandleSizeChange(); 
       
   412             }
       
   413         
       
   414         view = View( KUidVCFolderView );        
       
   415         if ( view )
       
   416             {
       
   417             static_cast< CVCGenericView* >( view )->HandleSizeChange(); 
       
   418             }
       
   419             
       
   420         view = View( KUidVCSettingsView );        
       
   421         if ( view )
       
   422             {
       
   423             static_cast< CVCSettingsView* >( view )->HandleClientRectChange();
       
   424             }
       
   425         }
       
   426     }
       
   427     
       
   428 // ----------------------------------------------------------------------------
       
   429 // CVCAppUi::CommandSetChanged
       
   430 // ----------------------------------------------------------------------------
       
   431 //
       
   432 void CVCAppUi::CommandSetChanged()
       
   433     {
       
   434     TUid focusedView = FocusedView();
       
   435     
       
   436     TRAPD( err,
       
   437         // Shouldn't all views be updated?
       
   438 /*        if( focusedView == KUidVCMainView )
       
   439             {
       
   440             iMainView->RefreshViewL();
       
   441             }
       
   442         else
       
   443             {
       
   444             iFolderView->RefreshViewL();
       
   445             }*/
       
   446         iMainView->RefreshViewL();
       
   447         iFolderView->RefreshViewL();
       
   448         );
       
   449     if( err != KErrNone )
       
   450         {
       
   451         RUBY_ERROR1( "RefreshViewL failed with [%d]", err );
       
   452         }
       
   453     }
       
   454     
       
   455 // ----------------------------------------------------------------------------
       
   456 // CVCAppUi::CommandSetChanged
       
   457 // ----------------------------------------------------------------------------
       
   458 //
       
   459 TBool CVCAppUi::IsDisplayingMenuOrDialog()
       
   460     {
       
   461     return EFalse;
       
   462     }
       
   463     
       
   464 // End of File  
       
   465