fmradio/fmradio/src/fmradioappui.cpp
branchRCL_3
changeset 19 cce62ebc198e
parent 18 1a6714c53019
child 20 93c594350b9a
equal deleted inserted replaced
18:1a6714c53019 19:cce62ebc198e
     1 /*
       
     2 * Copyright (c) 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:  FM Radio App UI implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include <featmgr.h>
       
    21 #if defined  __SERIES60_HELP || defined FF_S60_HELPS_IN_USE
       
    22 #include <hlplch.h>
       
    23 #include "radio.hlp.hrh"
       
    24 #endif
       
    25 #include <akntoolbar.h>
       
    26 #include <StringLoader.h>
       
    27 #include <eikmenup.h>
       
    28 #include <avkon.hrh>
       
    29 #include <aknlistquerydialog.h> 
       
    30 #include <AknQueryDialog.h>
       
    31 #include <AknGlobalNote.h>
       
    32 #include <fmradio.rsg>
       
    33 #include <fmradiocommandlineparams.h>
       
    34 #include <alf/alfenv.h>
       
    35 #include <AknVolumePopup.h>
       
    36 #include <fmradiointernalpskeys.h>
       
    37 #include <fmradiouids.h> 
       
    38 #include <iaupdate.h>
       
    39 #include <iaupdateparameters.h>
       
    40 #include <iaupdateresult.h>
       
    41 #include <e32property.h>
       
    42 #include <apgwgnam.h>
       
    43 #include <centralrepository.h>
       
    44 #include <settingsinternalcrkeys.h>
       
    45 #include <activeidle2domainpskeys.h>
       
    46 #include <akntoolbarextension.h>
       
    47 
       
    48 #include "fmradiobacksteppingservicewrapper.h"
       
    49 #include "fmradiodocument.h"
       
    50 #include "fmradioengine.h"
       
    51 #include "fmradiovariant.hrh"
       
    52 #include "fmradiomainview.h"
       
    53 #include "fmradiochannellistview.h"
       
    54 #include "fmradiocontroleventobserverimpl.h"
       
    55 #include "fmradioscanlocalstationsview.h"
       
    56 #include "fmradio.hrh"
       
    57 #include "fmradioengine.hrh"
       
    58 #include "fmradioappui.h"
       
    59 #include "fmradiordsreceiver.h"
       
    60 #include "fmradioapp.h"
       
    61 #include "fmradiopubsub.h"
       
    62 #include "debug.h"
       
    63 
       
    64 // Application Uid for Active Idle app
       
    65 #ifdef __ACTIVE_IDLE
       
    66 const TUid KFMRadioUidIdleApp = { 0x101FD64C };
       
    67 #else
       
    68 const TUid KFMRadioUidIdleApp = KPSUidActiveIdle2; // use this one instead because the "aisystemuids.hrh" is not export
       
    69 #endif
       
    70 // CONSTANTS 
       
    71 
       
    72 // ---------------------------------------------------------------------------------
       
    73 // CFMInformationNote::CFMInformationNote
       
    74 // ---------------------------------------------------------------------------------
       
    75 CFMInformationNote::CFMInformationNote( MInformationNoteInterface& aObserver ) :
       
    76     CAknInformationNote ( EFalse ),
       
    77     iDialogObserver( aObserver )
       
    78     {
       
    79     
       
    80     }
       
    81 // ---------------------------------------------------------------------------------
       
    82 // CFMInformationNote::~CFMInformationNote
       
    83 // ---------------------------------------------------------------------------------
       
    84 //
       
    85 CFMInformationNote::~CFMInformationNote()
       
    86     {
       
    87     iDialogObserver.DialogTerminated();
       
    88     }
       
    89 // ================= MEMBER FUNCTIONS =======================
       
    90 
       
    91 // ---------------------------------------------------------------------------------
       
    92 // C++ default constructor can NOT contain any code, that
       
    93 // might leave.
       
    94 // ---------------------------------------------------------------------------------
       
    95 //
       
    96 CFMRadioAppUi::CFMRadioAppUi() :
       
    97     iStartUp( ETrue ),
       
    98     iStartupWizardHandled( EFalse ),
       
    99     iStartupWizardRunning( EFalse ),
       
   100     iTuneFromWizardActivated( EFalse ),
       
   101     iInfoNoteOn( EFalse ),
       
   102     iPendingViewId( KNullUid ),
       
   103     iRegionChanged( EFalse )
       
   104     {
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------------
       
   108 // CFMRadioAppUi::ConstructL
       
   109 // 2nd phase constructor. Instanciates all member objects
       
   110 // ---------------------------------------------------------------------------------
       
   111 //
       
   112 void CFMRadioAppUi::ConstructL()
       
   113     {
       
   114     FTRACE( FPrint( _L("CFMRadioAppUi::ConstructL()") ) );
       
   115     
       
   116     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
   117     
       
   118     FeatureManager::InitializeLibL();
       
   119     iFeatureManagerInitialized = ETrue;
       
   120 
       
   121     // initialise local variation key with all features disabled.
       
   122     iFMRadioVariationFlags = 0;
       
   123     iAudioResourceAvailable = ETrue;
       
   124     iAlreadyClean = EFalse;
       
   125 
       
   126     iRadioEngine = CRadioEngine::NewL( *this ); // Construct a radio engine object
       
   127     
       
   128     // Fill channels array from engine
       
   129     GetChannelsArrayL();
       
   130     
       
   131     if ( iRadioEngine->IsInCall() ) 
       
   132         {
       
   133         iCurrentRadioState = EFMRadioStateOffForPhoneCall;
       
   134         }
       
   135     
       
   136     iBsWrapper = CFMRadioBackSteppingServiceWrapper::NewL( TUid::Uid( KUidFMRadioApplication ) );
       
   137     AddViewActivationObserverL( iBsWrapper );    
       
   138 
       
   139     iMainView = CFMRadioMainView::NewL( iRadioEngine, *iAlfEnv, *this  );
       
   140     AddViewL( iMainView );      // transfer ownership to CAknViewAppUi
       
   141     iChannelListView = CFMRadioChannelListView::NewL( iRadioEngine, *this );
       
   142     AddViewL( iChannelListView );     // transfer ownership to CAknViewAppUi
       
   143     iScanLocalStationsView = CFMRadioScanLocalStationsView::NewL( *iRadioEngine, *this );
       
   144     AddViewL( iScanLocalStationsView ); // transfer ownership to CAknViewAppUi
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CFMRadioAppUi::SecondaryConstructL()
       
   149 // All leaving function calls are made here, so that nothing is left on the stack if the ConstructL leaves
       
   150 // The reason for this behaviour is that the UI framework doesn't handle leaves from the AppUi correctly.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CFMRadioAppUi::SecondaryConstructL()
       
   154     {
       
   155     FTRACE( FPrint( _L("CFMRadioAppUi::SecondaryConstructL()") ) );
       
   156     
       
   157     iLayoutChangeObserver = iMainView;
       
   158 
       
   159     iRadioEngine->PubSubL().PublishPresetCountL( iChannels.Count() );
       
   160     
       
   161     // Create vertical volume popup for speaker and headset
       
   162     iIhfVolumePopupControl = CAknVolumePopup::NewL( NULL, ETrue );
       
   163     iIhfVolumePopupControl->SetRange( KFMRadioMinVolumeLevel, KFMRadioMaxVolumeLevel );
       
   164     iIhfVolumePopupControl->SetStepSize( KFMRadioVolumeStepSize );
       
   165     // Set observer for control events
       
   166     iIhfVolumePopupControl->SetObserver( this );
       
   167     
       
   168     iHeadsetVolumePopupControl = CAknVolumePopup::NewL( NULL, ETrue );
       
   169     iHeadsetVolumePopupControl->SetRange( KFMRadioMinVolumeLevel, KFMRadioMaxVolumeLevel );
       
   170     iHeadsetVolumePopupControl->SetStepSize( KFMRadioVolumeStepSize );
       
   171     iHeadsetVolumePopupControl->SetObserver( this );
       
   172     
       
   173     iActiveVolumePopupControl = iHeadsetVolumePopupControl; //initialize it to Headset
       
   174 
       
   175     // Create and set our observer for control events.
       
   176     iControlEventObserver = CFMRadioControlEventObserverImpl::NewL( *this );
       
   177     iRadioEngine->PubSubL().SetControlEventObserver( iControlEventObserver );
       
   178 
       
   179     // For monitoring side volume key events
       
   180     iSvkEvents = CFMRadioSvkEvents::NewL(*this);
       
   181 
       
   182     iRadioEngine->PubSubL().PublishApplicationRunningStateL( EFMRadioPSApplicationRunning );
       
   183 
       
   184     UpdateLandscapeInformation();	
       
   185 
       
   186     // Create alfred environment
       
   187     iAlfEnv = CAlfEnv::NewL();
       
   188 
       
   189     // Create alfred display
       
   190     TRect rect;
       
   191     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);	
       
   192     if( !IsLandscapeOrientation() )
       
   193         {
       
   194         TRect toolBarRect = iMainView->Toolbar()->Rect();
       
   195         rect.SetHeight( rect.Height() - toolBarRect.Height() );	
       
   196         }
       
   197     iAlfEnv->NewDisplayL( rect, CAlfEnv::ENewDisplayAsCoeControl );
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CFMRadioAppUi::HandleTunerReadyCallback
       
   202 // Tuner is initialized and ready.
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CFMRadioAppUi::HandleTunerReadyCallback()
       
   206     {
       
   207     iRadioEngine->InitializeRadio();
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CFMRadioAppUi::~CFMRadioAppUi
       
   212 // Destructor
       
   213 // Frees reserved resources
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 CFMRadioAppUi::~CFMRadioAppUi()
       
   217     {
       
   218     if ( iRadioEngine )
       
   219         {
       
   220         TRAP_IGNORE(
       
   221             iRadioEngine->PubSubL().PublishApplicationRunningStateL( EFMRadioPSApplicationClosing ) )
       
   222         }
       
   223 
       
   224     FTRACE( FPrint( _L("CFMRadioAppUi::~CFMRadioAppUi()") ) );
       
   225     if ( iAlreadyClean == EFalse )
       
   226         {
       
   227         Cleanup();
       
   228         }
       
   229 
       
   230     if ( iFeatureManagerInitialized )
       
   231         {
       
   232         FeatureManager::UnInitializeLib();
       
   233         }
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CFMRadioAppUi::Cleanup()
       
   238 // Perform object cleanup. This would normally be performed in the destructor,
       
   239 // but since it can also be called from SecondaryConstructL it was moved into
       
   240 // a seperate function.
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 void CFMRadioAppUi::Cleanup()
       
   244     {
       
   245     FTRACE( FPrint( _L("CFMRadioAppUi::Cleanup()") ) );
       
   246 
       
   247     delete iIhfVolumePopupControl;
       
   248     iIhfVolumePopupControl = NULL;
       
   249     delete iHeadsetVolumePopupControl;
       
   250     iHeadsetVolumePopupControl = NULL;
       
   251 
       
   252     if (iRadioEngine)
       
   253         {
       
   254         delete iRadioEngine;
       
   255         iRadioEngine = NULL;
       
   256         }
       
   257     if (iSvkEvents)
       
   258         {
       
   259         delete iSvkEvents;
       
   260         }
       
   261     if (iGlobalOfflineQuery)
       
   262         {
       
   263         delete iGlobalOfflineQuery;
       
   264         }
       
   265     if (iLocalActivateOfflineQuery)
       
   266         {
       
   267         delete iLocalActivateOfflineQuery;
       
   268         }
       
   269     if (iLocalContinueOfflineQuery)
       
   270         {
       
   271         delete iLocalContinueOfflineQuery;
       
   272         }
       
   273     delete iControlEventObserver;
       
   274     delete iAlfEnv;
       
   275     
       
   276     iAlreadyClean = ETrue;
       
   277     
       
   278     if ( iConnectHeadsetGlobalNote )
       
   279         {
       
   280         delete iConnectHeadsetGlobalNote;
       
   281         iConnectHeadsetGlobalNote = NULL;
       
   282         }
       
   283     if ( iConnectHeadsetQuery )
       
   284         {
       
   285         delete iConnectHeadsetQuery;
       
   286         iConnectHeadsetQuery = NULL;
       
   287         }
       
   288 
       
   289      iChannels.ResetAndDestroy();
       
   290      iChannels.Close();
       
   291         
       
   292     if ( iUpdate )
       
   293         {
       
   294         delete iUpdate;
       
   295         iUpdate = NULL;
       
   296         }
       
   297     if ( iParameters )
       
   298         {
       
   299         delete iParameters;
       
   300         iParameters = NULL;
       
   301         }
       
   302     if ( iSettingsRepository )
       
   303         {
       
   304         delete iSettingsRepository;
       
   305         iSettingsRepository = NULL;
       
   306         }
       
   307     if ( iBsWrapper )
       
   308         {
       
   309         RemoveViewActivationObserver( iBsWrapper );
       
   310         }
       
   311     delete iBsWrapper;
       
   312     iBsWrapper = NULL;
       
   313     
       
   314     delete iStartupForegroundCallback;
       
   315     iStartupForegroundCallback = NULL;
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CFMRadioAppUi::HandleCommandL
       
   320 // Interprets view's menu-,softkey and other commands and acts
       
   321 // accordingly by calling the appropriate command handler
       
   322 // function for further action.
       
   323 // ---------------------------------------------------------------------------
       
   324 //
       
   325 void CFMRadioAppUi::HandleCommandL( TInt aCommand )
       
   326     {
       
   327     FTRACE( FPrint( _L("CFMRadioAppUi::HandleCommandL state=%d command=%d "), iCurrentRadioState, aCommand) );
       
   328     if ( iCurrentRadioState == EFMRadioStateOn )
       
   329         {
       
   330         switch ( aCommand )
       
   331             {
       
   332             case EFMRadioCmdChannelList:
       
   333                 ActivateLocalViewL( iChannelListView->Id() );
       
   334                 break;
       
   335             case EFMRadioCmdSeekUp:
       
   336                 ScanUpL();
       
   337                 break;
       
   338             case EFMRadioCmdSeekDown:
       
   339                 ScanDownL();
       
   340                 break;
       
   341             case EFMRadioCmdSaveChannel:
       
   342                 SaveChannelToLastIntoListL();
       
   343                 break;
       
   344             case EFMRadioCmdScanLocalStations:
       
   345                 ActivateLocalViewL( iScanLocalStationsView->Id() );
       
   346                 break;
       
   347             case EFMRadioCmdScanLocalStationsScan:
       
   348                 // continue scanning
       
   349                 StartLocalStationsSeekL();
       
   350                 break;
       
   351             case EFMRadioCmdListenCh:
       
   352                 if ( iChannels.Count() > 0 )
       
   353                     {
       
   354                     PlayChannel( iChannelListView->CurrentlySelectedChannel() );
       
   355                     }
       
   356                 break;
       
   357             case EFMRadioCmdRename:
       
   358                 RenameCurrentChannelL();
       
   359                 break;
       
   360             case EFMRadioCmdActivateIhf:
       
   361                 SetAudioOutput( CRadioEngine::EFMRadioOutputIHF );
       
   362                 break;
       
   363             case EFMRadioCmdDeactivateIhf:
       
   364                 SetAudioOutput( CRadioEngine::EFMRadioOutputHeadset );
       
   365                 break;
       
   366             case EFMRadioCmdEnableRdsAfSearch:
       
   367                 iRadioEngine->SetRdsAfSearchEnable( ETrue );
       
   368                 break;
       
   369             case EFMRadioCmdDisableRdsAfSearch:
       
   370                 iRadioEngine->SetRdsAfSearchEnable( EFalse );
       
   371                 break;
       
   372             case EFMRadioCmdUpdateVolume:
       
   373                 UpdateVolume( EDirectionNone );
       
   374                 break;
       
   375             case EFMRadioCmdNextChannel:
       
   376                 {
       
   377                 TInt channelCount = iChannels.Count();
       
   378                 if ( channelCount >= 1 )
       
   379                     {
       
   380                     iMainView->SetStationChangeType( EFMRadioStationChangeNext );
       
   381                     PlayChannel( iChannelListView->NextChannel() );
       
   382                     }
       
   383                 else
       
   384                     {
       
   385                     if ( AknLayoutUtils::PenEnabled() )
       
   386                         {
       
   387                         DisplayInformationNoteL( R_QTN_FMRADIO_USE_LONG_TAP );
       
   388                         }
       
   389                     }
       
   390                 break;
       
   391                 }
       
   392             case EFMRadioCmdPrevChannel:
       
   393                 {
       
   394                 TInt channelCount = iChannels.Count();
       
   395                 if ( channelCount >= 1 )
       
   396                     {
       
   397                     iMainView->SetStationChangeType( EFMRadioStationChangePrevious );
       
   398                     PlayChannel( iChannelListView->PreviousChannel() );
       
   399                     }
       
   400                 else
       
   401                     {
       
   402                     if ( AknLayoutUtils::PenEnabled() )
       
   403                         {
       
   404                         DisplayInformationNoteL( R_QTN_FMRADIO_USE_LONG_TAP );
       
   405                         }
       
   406                     }
       
   407                 break;
       
   408             	}
       
   409             case EFMRadioCmdMuteOn:
       
   410             	iRadioEngine->SetMuteOn( ETrue );
       
   411             	break;
       
   412             case EFMRadioCmdMuteOff:
       
   413             	iRadioEngine->SetMuteOn( EFalse );
       
   414             	break;
       
   415             case EFMRadioCmdMute:
       
   416             	HandleMuteCommand();
       
   417             	break;	
       
   418             case EAknCmdHelp:
       
   419             case EFMRadioCmdHelp:
       
   420                 {
       
   421 #if defined __SERIES60_HELP || defined FF_S60_HELPS_IN_USE
       
   422                 if ( ActiveView() == KFMRadioMainViewId )
       
   423                     {
       
   424                     HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), GetCurrentHelpContextL() );
       
   425                     }
       
   426                 else
       
   427                     {
       
   428                     CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
       
   429                     HlpLauncher::LaunchHelpApplicationL( iCoeEnv->WsSession(), buf );
       
   430                     }
       
   431 #endif
       
   432                 }
       
   433                 break;
       
   434             default:
       
   435                 break;
       
   436             }
       
   437         }
       
   438     else if ( iCurrentRadioState == EFMRadioStateBusySeek ||
       
   439              iCurrentRadioState == EFMRadioStateBusyScanLocalStations )
       
   440         {
       
   441         switch ( aCommand )
       
   442             {
       
   443             case EFMRadioCmdStopTuning:
       
   444             case EAknSoftkeyCancel:
       
   445                 CancelSeek();
       
   446                 break;
       
   447             default:
       
   448                 break;
       
   449             }
       
   450         }
       
   451     switch ( aCommand )
       
   452         {
       
   453         case EFMRadioCmdScanLocalStationsViewActive:
       
   454             iLayoutChangeObserver = iScanLocalStationsView;
       
   455             break;
       
   456         case EFMRadioCmdChannelListViewActive:
       
   457             iLayoutChangeObserver = iChannelListView;
       
   458             break;
       
   459         case EFMRadioCmdMainViewActive:
       
   460             iLayoutChangeObserver = iMainView;
       
   461             break;
       
   462         case EAknSoftkeyExit:
       
   463         case EEikCmdExit:
       
   464         case EAknCmdExit:
       
   465             Exit();
       
   466             break;
       
   467         default:
       
   468             break;
       
   469         }
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // CFMRadioAppUi::ActiveView
       
   474 // ---------------------------------------------------------------------------
       
   475 //
       
   476 TUid CFMRadioAppUi::ActiveView() const
       
   477     {
       
   478     return iView ? iView->Id() : KNullUid;
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // CFMRadioAppUi::RadioEngine
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 CRadioEngine* CFMRadioAppUi::RadioEngine()
       
   486     {
       
   487     return iRadioEngine;
       
   488     }
       
   489 
       
   490 // ---------------------------------------------------------------------------
       
   491 // CFMRadioAppUi::Document
       
   492 // ---------------------------------------------------------------------------
       
   493 //
       
   494 CFMRadioDocument* CFMRadioAppUi::Document() const
       
   495     {
       
   496     return static_cast<CFMRadioDocument*>( CEikAppUi::Document() );
       
   497     }
       
   498 
       
   499 // ---------------------------------------------------------------------------
       
   500 // CFMRadioAppUi::BackSteppingWrapper
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 CFMRadioBackSteppingServiceWrapper& CFMRadioAppUi::BackSteppingWrapper() const
       
   504     {
       
   505     return *iBsWrapper;
       
   506     }
       
   507 
       
   508 // ---------------------------------------------------------------------------
       
   509 // CFMRadioAppUi::TurnRadioOn
       
   510 // Turn the fm radio hardware on
       
   511 // ---------------------------------------------------------------------------
       
   512 //
       
   513 void CFMRadioAppUi::TurnRadioOn()
       
   514     {
       
   515     FTRACE(FPrint(_L("CFMRadioAppUi::TurnRadioOn()")));
       
   516     if ( !iRadioEngine->IsRadioOn() )
       
   517         {
       
   518         // Force the mute state only if it wasn't already forced
       
   519         if ( iMuteStatusBeforeRadioInit == EFMUninitialized )
       
   520             {
       
   521             if ( iRadioEngine->IsMuteOn() )
       
   522                 {
       
   523                 FTRACE(FPrint(_L("CFMRadioAppUi::iMuteStatusBeforeRadioInit = ETrue;()")));
       
   524                 iMuteStatusBeforeRadioInit = EFMMuted;	
       
   525                 }
       
   526             else
       
   527                 {
       
   528                 FTRACE(FPrint(_L("CFMRadioAppUi::iMuteStatusBeforeRadioInit = EFalse;()")));
       
   529                 iMuteStatusBeforeRadioInit = EFMUnmuted;
       
   530                 }
       
   531             }
       
   532         iCurrentRadioState = EFMRadioStateBusyRadioOn;
       
   533         // use mute here so we have no audio until tune event
       
   534         iRadioEngine->SetMuteOn( ETrue );
       
   535         iRadioEngine->RadioOn();
       
   536         }
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // CFMRadioAppUi::PlayChannel
       
   541 // Tune the radio hardware to the frequency saved at the specified channel
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 void CFMRadioAppUi::PlayChannel( TInt aIndex )
       
   545     {
       
   546     FTRACE( FPrint( _L("CFMRadioAppUi::PlayChannel(%d)"), aIndex ) );
       
   547     if ( aIndex >= KMinNumberOfChannelListItems &&
       
   548          aIndex < KMaxNumberOfChannelListItems )
       
   549         {
       
   550         // Activate the channel by index
       
   551         TRAP_IGNORE( iRadioEngine->TunePresetL( aIndex ) )
       
   552         iMainView->PrepareViewForChannelChange();
       
   553 
       
   554         // Update channel list
       
   555         iChannelListView->SetNowPlayingChannel( aIndex );
       
   556         iChannelListView->SetLastListenedChannel( aIndex );
       
   557         }
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // CFMRadioAppUi::EraseCurrentChannelL
       
   562 // Delete channel from the channel list
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 TBool CFMRadioAppUi::EraseChannelL( TInt aIndex )
       
   566     {
       
   567     FTRACE( FPrint( _L("CFMRadioAppUi::EraseCurrentChannelL()") ) );
       
   568 
       
   569     TBool accepted = ConfirmChannelListDeleteL( aIndex );
       
   570     
       
   571     if ( accepted )
       
   572         {        
       
   573         UpdateChannelsL( EDeleteChannel, aIndex, 0 ); 
       
   574         UpdateChannelsL( EStoreAllToRepository, 0, 0 );
       
   575         }
       
   576     return accepted;
       
   577     }
       
   578 
       
   579 // ---------------------------------------------------------------------------
       
   580 // CFMRadioAppUi::RenameCurrentChannelL
       
   581 // Rename the currently selected channel
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void CFMRadioAppUi::RenameCurrentChannelL()
       
   585     {
       
   586     FTRACE( FPrint( _L("CFMRadioAppUi::RenameCurrentChannelL()") ) );
       
   587     
       
   588     TInt channelIndex = KErrNotFound;
       
   589     if ( ActiveView() == KFMRadioChannelListViewId )
       
   590         {
       
   591         channelIndex = iChannelListView->CurrentlySelectedChannel();
       
   592         }
       
   593     else
       
   594         {
       
   595         channelIndex = iRadioEngine->GetPresetIndex();
       
   596         }
       
   597     // Display the text query
       
   598     CRadioEngine::TStationName channelName = iChannels[ channelIndex ]->PresetName();
       
   599    
       
   600     CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog( channelName, CAknQueryDialog::ENoTone );
       
   601     
       
   602     if ( dlg->ExecuteLD( R_FMRADIO_RENAME_QUERY ) )
       
   603         {
       
   604         FTRACE(FPrint(_L("CFMRadioAppUi::RenameCurrentChannelL()")));
       
   605         
       
   606         iChannels[channelIndex]->SetPresetNameL( channelName );
       
   607         
       
   608         iChannelListView->UpdateChannelListContentL( channelIndex,
       
   609                         iChannels[ channelIndex ]->PresetName(),
       
   610                         iChannels[ channelIndex ]->PresetFrequency() );
       
   611         
       
   612         UpdateChannelsL( EStoreIndexToRepository, channelIndex, 0 );
       
   613         
       
   614         iMainView->SetStationChangeType( EFMRadioStationChangeNone );
       
   615         // A channel can also be renamed from the main view
       
   616         iMainView->DisplayChannelL( channelIndex );
       
   617         // show default logo for a while
       
   618         // so that animation is stopped and it has the right channel name
       
   619         // after restart
       
   620         iMainView->ShowDefaultLogo();
       
   621         }
       
   622     }
       
   623 
       
   624 // ---------------------------------------------------------------------------
       
   625 // CFMRadioAppUi::SaveChannelToLastIntoListL
       
   626 // Display listbox menu to allow user to specify a channel
       
   627 // to save currently tuned frequency to.
       
   628 // ---------------------------------------------------------------------------
       
   629 //
       
   630 void CFMRadioAppUi::SaveChannelToLastIntoListL()
       
   631     {
       
   632     FTRACE( FPrint( _L("CFMRadioAppUi::SaveChannelToLastIntoListL()") ) );
       
   633     SaveChannelL( iChannels.Count() + 1 );
       
   634     }
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // CFMRadioAppUi::SaveChannel
       
   638 // Save currently tuned frequency to the currently selected channel
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 void CFMRadioAppUi::SaveChannelL( TInt aIndex )
       
   642     {
       
   643     FTRACE( FPrint( _L("CFMRadioAppUi::SaveChannelL(%d)"), aIndex ) );
       
   644 
       
   645     TBool continueWithSave = ETrue;
       
   646     // check if channel list is full
       
   647     if ( aIndex == KMaxNumberOfChannelListItems + 1 )
       
   648         {
       
   649         CAknQueryDialog* query = CAknQueryDialog::NewL();
       
   650         if ( query->ExecuteLD( R_FMRADIO_REPLACE_EXISTING_CHANNELS_QUERY ) )
       
   651             {
       
   652             UpdateChannelsL( ERemoveAllFromRepository, 0, 0  );
       
   653             }
       
   654         else
       
   655             {
       
   656             continueWithSave = EFalse;
       
   657             }
       
   658         }
       
   659 
       
   660     if ( continueWithSave )
       
   661         {
       
   662         CFMRadioRdsReceiverBase& receiver = iRadioEngine->RdsReceiver();
       
   663         CFMRadioRdsReceiverBase::TFMRadioProgrammeSeviceType type = 
       
   664                 receiver.ProgrammeServiceNameType();
       
   665         const TDesC& channelName = type == CFMRadioRdsReceiverBase::EFMRadioPSNameStatic ?
       
   666                 receiver.ProgrammeService() : KNullDesC;
       
   667         
       
   668         CFMRadioPreset* preset = CFMRadioPreset::NewL();
       
   669         CleanupStack::PushL( preset );
       
   670         preset->SetPresetNameL( channelName );
       
   671         preset->SetPresetFrequency( iRadioEngine->GetTunedFrequency() );
       
   672                 
       
   673         const TDesC& webUrl = receiver.RtPlusProgramUrl();
       
   674         if ( webUrl.Length() )
       
   675             {
       
   676             preset->SetPresetUrlL( webUrl );
       
   677             }        
       
   678         iChannels.AppendL( preset );
       
   679         CleanupStack::Pop( preset ); 
       
   680         
       
   681         UpdateChannelsL( EStoreAllToRepository, 0, 0 );
       
   682         
       
   683         iMainView->SetStationChangeType( EFMRadioStationChangeNone );
       
   684         PlayChannel( iChannels.Count() - 1 );
       
   685         }
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // CFMRadioAppUi::ConfirmChannelListDeleteL
       
   690 // Display confirmation dialog for channel deletion
       
   691 // ---------------------------------------------------------------------------
       
   692 //
       
   693 TBool CFMRadioAppUi::ConfirmChannelListDeleteL( TInt aIndex )
       
   694     {
       
   695     FTRACE( FPrint( _L("CFMRadioAppUi::ConfirmChannelListActionL( %d )"), aIndex ) );
       
   696     TInt accepted = EFalse; // Operation accepted or discarded
       
   697     TInt stringResourceId = 0; // Resource id of the prompt text
       
   698     TInt queryResourceId = R_FMRADIO_ERASE_CH_CONFIRMATION_QUERY;  // Resource id of the used query dialog
       
   699 
       
   700     RBuf channelData;
       
   701     channelData.CleanupClosePushL();
       
   702     
       
   703     if ( iChannels[ aIndex ]->PresetName().Length() )
       
   704         {
       
   705         stringResourceId = R_QTN_FMRADIO_QUERY_DELETE;
       
   706         channelData.CreateL( iChannels[ aIndex ]->PresetName() );
       
   707         }
       
   708     else
       
   709         {
       
   710         stringResourceId = R_QTN_FMRADIO_QUERY_DELETE_MHZ;
       
   711         TInt maxDecimalPlaces = iRadioEngine->DecimalCount();
       
   712         TInt channelfreq = iChannels[ aIndex ]->PresetFrequency();
       
   713         TReal realFrequency = static_cast<TReal>( channelfreq / static_cast<TReal>( KHzConversionFactor ));
       
   714         
       
   715         channelData.CreateL( KFrequencyMaxLength );
       
   716         
       
   717         TRealFormat format( KFrequencyMaxLength, maxDecimalPlaces );
       
   718         channelData.Num( realFrequency, format );
       
   719         AknTextUtils::LanguageSpecificNumberConversion( channelData );
       
   720         }
       
   721     // Excecute a confirmation query with string and query resource id
       
   722     HBufC* prompt = StringLoader::LoadLC( stringResourceId, channelData, iCoeEnv );
       
   723     CAknQueryDialog* queryDlg = CAknQueryDialog::NewL();
       
   724     accepted = queryDlg->ExecuteLD( queryResourceId, *prompt );
       
   725     CleanupStack::PopAndDestroy( prompt );
       
   726     CleanupStack::PopAndDestroy( &channelData );
       
   727     return accepted;
       
   728     }
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // CFMRadioAppUi::ScanUpL
       
   732 // 
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 void CFMRadioAppUi::ScanUpL()
       
   736     {
       
   737     FTRACE( FPrint( _L("CFMRadioAppUi::ScanUpL()") ) );
       
   738     // Frequency is always 0 when asking engine for automatical tuning. Frequency
       
   739     // parameter is then ignored by engine when automatical tuning (seek) is requested.
       
   740     iCurrentRadioState = EFMRadioStateBusySeek;
       
   741 
       
   742     if ( iMainView->IsForeground() )
       
   743         {
       
   744         iMainView->SetStationChangeType( EFMRadioStationChangeScanUp );
       
   745         iMainView->SeekL(); // Show seek wait note
       
   746         }
       
   747     iRadioEngine->ScanUp();
       
   748     }
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // CFMRadioAppUi::ScanDownL
       
   752 // 
       
   753 // ---------------------------------------------------------------------------
       
   754 //
       
   755 void CFMRadioAppUi::ScanDownL()
       
   756     {
       
   757     FTRACE( FPrint( _L("CFMRadioAppUi::ScanDownL()") ) );
       
   758     // Frequency is always 0 when asking engine for automatical tuning. Frequency
       
   759     // parameter is then ignored by engine when automatical tuning (seek) is requested.
       
   760     iCurrentRadioState = EFMRadioStateBusySeek;
       
   761     
       
   762     if ( iMainView->IsForeground() )
       
   763         {
       
   764         iMainView->SetStationChangeType( EFMRadioStationChangeScanDown );
       
   765         iMainView->SeekL(); // Show seek wait note
       
   766         }
       
   767     iRadioEngine->ScanDown();
       
   768     }
       
   769 
       
   770 // ---------------------------------------------------------------------------
       
   771 // CFMRadioAppUi::TuneL
       
   772 // 
       
   773 // ---------------------------------------------------------------------------
       
   774 //
       
   775 void CFMRadioAppUi::TuneL( TInt aFrequency )
       
   776     {
       
   777     FTRACE( FPrint( _L("CFMRadioAppUi::TuneL(%d)"), aFrequency ) );
       
   778     // Frequency is always 0 when asking engine for automatical tuning. Frequency
       
   779     // parameter is then ignored by engine when automatical tuning (seek) is requested.
       
   780     iCurrentRadioState = EFMRadioStateBusySeek;
       
   781     if (iMainView->IsForeground())
       
   782         {
       
   783         iMainView->SeekL(); // Show seek wait note
       
   784         }
       
   785     iRadioEngine->Tune(aFrequency);
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // CFMRadioAppUi::UpdateVolume
       
   790 // Update the radio volume
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 void CFMRadioAppUi::UpdateVolume( CFMRadioAppUi::TFMRadioDirections aDirection )
       
   794     {
       
   795     FTRACE( FPrint( _L("CFMRadioAppUi::UpdateVolume(%d)"), UpdateVolume ) );
       
   796 
       
   797     if ( !iRadioEngine->IsInCall() )
       
   798         {
       
   799         TInt volumeControlLevel = iRadioEngine->GetVolume();
       
   800 
       
   801         TInt newVol = 0;
       
   802         if ( aDirection == EDirectionDown )
       
   803             {
       
   804             TRAP_IGNORE( ShowVolumePopupL(); )
       
   805             newVol = volumeControlLevel - 1;
       
   806             
       
   807             if ( newVol > KFMRadioMinVolumeLevel )
       
   808                 {
       
   809                 iRadioEngine->SetVolume( newVol );
       
   810                 }
       
   811             else
       
   812                 {
       
   813                 iRadioEngine->SetMuteOn( ETrue );
       
   814                 iRadioEngine->SetVolume( newVol );
       
   815                 iActiveVolumePopupControl->SetValue( KFMRadioMinVolumeLevel );
       
   816                 }
       
   817             }
       
   818         else if ( aDirection == EDirectionUp )
       
   819             {
       
   820             TRAP_IGNORE( ShowVolumePopupL(); )
       
   821             if ( iRadioEngine->IsMuteOn() )
       
   822                 {
       
   823                 iRadioEngine->SetMuteOn( EFalse );
       
   824                 }
       
   825             newVol = volumeControlLevel + 1;
       
   826             
       
   827             if ( newVol <= KFMRadioMaxVolumeLevel )
       
   828                 {
       
   829                 iRadioEngine->SetVolume( newVol );
       
   830                 }
       
   831             else
       
   832                 {
       
   833                 iActiveVolumePopupControl->SetValue( KFMRadioMaxVolumeLevel );
       
   834                 }
       
   835             }
       
   836         else if ( aDirection == EDirectionNone )
       
   837             {
       
   838             //we just wish to update the UI's volume control
       
   839             HandleVolumeChangedCallback();
       
   840             }
       
   841         }
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------------------------
       
   845 // CFMRadioAppUi::SetAudioOutput
       
   846 // Set the audio output of the radio.
       
   847 // ---------------------------------------------------------------------------
       
   848 //
       
   849 void CFMRadioAppUi::SetAudioOutput(
       
   850     CRadioEngine::TFMRadioAudioOutput aAudioOutput )
       
   851     {
       
   852     iRadioEngine->SetAudioOutput( aAudioOutput );
       
   853     }
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CFMRadioAppUi::CancelSeek
       
   857 // Cancel outstanding seek request.
       
   858 // ---------------------------------------------------------------------------
       
   859 //
       
   860 void CFMRadioAppUi::CancelSeek()
       
   861     {
       
   862     FTRACE( FPrint( _L("CFMRadioAppUi::CancelSeek()") ) );
       
   863     if ( iCurrentRadioState == EFMRadioStateBusySeek )
       
   864         {
       
   865         iRadioEngine->CancelScan(); // Seek request to engine
       
   866         }
       
   867     HandleStopSeekCallback();
       
   868     }
       
   869 
       
   870 // ---------------------------------------------------------------------------
       
   871 // CFMRadioAppUi::DisplayErrorNoteL
       
   872 // Displays an error note with the text contained in the passed in reference
       
   873 // ---------------------------------------------------------------------------
       
   874 //
       
   875 void CFMRadioAppUi::DisplayErrorNoteL( TInt aErrorNote )
       
   876     {
       
   877     // Show headset missing note
       
   878     CAknErrorNote* errorNote = new ( ELeave ) CAknErrorNote( ETrue );
       
   879     HBufC* noteText = StringLoader::LoadLC( aErrorNote, iCoeEnv );
       
   880     errorNote->ExecuteLD( *noteText );
       
   881     CleanupStack::PopAndDestroy( noteText );
       
   882     }
       
   883 
       
   884 // ---------------------------------------------------------------------------
       
   885 // CFMRadioAppUi::DisplayInformationNoteL
       
   886 // Displays an information note
       
   887 // ---------------------------------------------------------------------------
       
   888 //
       
   889 void CFMRadioAppUi::DisplayInformationNoteL( TInt aInfoNote )
       
   890     {
       
   891     if ( !iInfoNoteOn && IsForeground() )
       
   892         {
       
   893         CFMInformationNote* infonote = new ( ELeave ) CFMInformationNote( *this );
       
   894         HBufC* noteText = StringLoader::LoadLC( aInfoNote, iCoeEnv );
       
   895         iInfoNoteOn = ETrue;
       
   896         infonote->ExecuteLD( *noteText );
       
   897         CleanupStack::PopAndDestroy( noteText );
       
   898         }
       
   899     }
       
   900 
       
   901 // ---------------------------------------------------------------------------
       
   902 // CFMRadioAppUi::ExitApplication
       
   903 // Shutdown the application.
       
   904 // ---------------------------------------------------------------------------
       
   905 //
       
   906 void CFMRadioAppUi::ExitApplication()
       
   907     {
       
   908     FTRACE( FPrint( _L("CFMRadioAppUi::ExitApplication() - Start") ) );
       
   909     //this method is called twice. First will trigger the RadioOff command
       
   910     if ( iCurrentRadioState == EFMRadioStateOff ||
       
   911          iCurrentRadioState == EFMRadioStateOffForPhoneCall ||
       
   912          iCurrentRadioState == EFMRadioStateOffBeforePhoneCall )
       
   913         {
       
   914         //once we receive a radio off complete event we finish shutting down.
       
   915         FTRACE( FPrint( _L("CFMRadioAppUi::ExitApplication() - calling exit") ) );
       
   916         Exit();
       
   917         }
       
   918     else
       
   919         {
       
   920         if ( iCurrentRadioState != EFMRadioStateExiting )
       
   921             {
       
   922             iCurrentRadioState = EFMRadioStateExiting;
       
   923             FTRACE( FPrint( _L("CFMRadioAppUi::ExitApplication() - turning off, and starting timer") ) );
       
   924             iRadioEngine->RadioOff(); // Shutdown radio
       
   925             }
       
   926         }
       
   927     }
       
   928 
       
   929 // ---------------------------------------------------------------------------
       
   930 // From class CCoeAppUi
       
   931 // CFMRadioAppUi::HandleForegroundEventL
       
   932 // Application has gone to foreground/background.
       
   933 // ---------------------------------------------------------------------------
       
   934 //
       
   935 void CFMRadioAppUi::HandleForegroundEventL( TBool aForeground )
       
   936     {
       
   937     FTRACE( FPrint( _L("CFMRadioAppUi::HandleForegroundEventL(%d)"), aForeground ) );
       
   938     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
   939     
       
   940     if ( aForeground )
       
   941         {
       
   942         if ( iStartUp )
       
   943             {
       
   944             iStartUp = EFalse;
       
   945             // Rest of startup processing may show a waiting dialog. It cannot be 
       
   946             // done while processing a foreground event. So a call back is used.
       
   947             iStartupForegroundCallback = new( ELeave ) CAsyncCallBack( 
       
   948                 TCallBack( StaticStartupForegroundCallback, this ), CActive::EPriorityStandard );
       
   949             iStartupForegroundCallback->CallBack();
       
   950             }
       
   951         else
       
   952             {
       
   953             // Restores all resources that were released with a call to Release().
       
   954             // After this the Hitchcock user interface should be in the same state
       
   955             // in terms of resources as it was prior to the Release() call.
       
   956             iAlfEnv->RestoreL();
       
   957             
       
   958             // Check if offline profile is activated after/when playing e.g. music player.
       
   959             // In that case we didn't show the offline query as global, so we need
       
   960             // to show it now.
       
   961             if ( IsOfflineProfileActivatedWhenRadioAudioDisabled() )
       
   962                 {
       
   963                 // Do not re-show the offline query if user hasn't yet answered to it.
       
   964                 if ( !iShowingLocalOfflineContinueQuery )
       
   965                     {
       
   966                     iRadioEngine->RadioOff();
       
   967                     TInt res(0);
       
   968                     iShowingLocalOfflineContinueQuery = ETrue;
       
   969                                                                                     
       
   970                     iOfflineQueryDialogActivated = ETrue;
       
   971                     
       
   972                     if ( !iLocalContinueOfflineQuery )
       
   973                         {
       
   974                         iLocalContinueOfflineQuery = CAknQueryDialog::NewL();
       
   975                         }
       
   976                                         
       
   977                     res = iLocalContinueOfflineQuery->ExecuteLD( R_FMRADIO_CONTINUE_IN_OFFLINE_QUERY );
       
   978                     
       
   979                     iLocalContinueOfflineQuery = NULL;
       
   980                     iOfflineQueryDialogActivated = EFalse;
       
   981                     iShowingLocalOfflineContinueQuery = EFalse;
       
   982                                                             
       
   983                     if ( res )
       
   984                         {
       
   985                         iOfflineProfileActivatedWhenRadioAudioDisabled = EFalse;
       
   986                         iRadioEngine->RadioOn();
       
   987                         HandlePendingViewActivationL();
       
   988                         }
       
   989                     else
       
   990                         {
       
   991                         Exit();
       
   992                         }
       
   993                     }
       
   994                 }
       
   995             TryToResumeAudioL();
       
   996             }  
       
   997         }
       
   998     else 
       
   999         {
       
  1000         // Releases as many resources of the Hitchcock as possible. 
       
  1001         iAlfEnv->Release();
       
  1002         }
       
  1003     }
       
  1004 
       
  1005 // ---------------------------------------------------------------------------
       
  1006 // CFMRadioAppUi::HandleRadioEngineCallBack
       
  1007 // Notification from Radio Engine informing the UI when requests have
       
  1008 // completed or certain events have occured that needs to be handled.
       
  1009 // ---------------------------------------------------------------------------
       
  1010 //
       
  1011 void CFMRadioAppUi::HandleRadioEngineCallBack(
       
  1012     MRadioEngineStateChangeCallback::TFMRadioNotifyEvent aEventCode,
       
  1013     TInt aErrorCode )
       
  1014     {
       
  1015     FTRACE( FPrint( _L("CFMRadioAppUi::HandleRadioEngineCallBack - event %d error code: %d"), aEventCode, aErrorCode ) );
       
  1016     TInt err = KErrNone;
       
  1017     if ( aErrorCode == KErrNone )
       
  1018         {
       
  1019         switch ( aEventCode )
       
  1020             {
       
  1021             case EFMRadioEventTunerReady:
       
  1022                 HandleTunerReadyCallback();
       
  1023                 break;
       
  1024             case EFMRadioEventRadioOn:
       
  1025                 {
       
  1026                 iCurrentRadioState = EFMRadioStateOn;
       
  1027                 TRAPD( err, HandleStartupWizardL() );
       
  1028                 iStartupWizardHandled = ETrue;
       
  1029                 const TUid activeViewTuid = ActiveView();
       
  1030                 
       
  1031                 if ( activeViewTuid == KFMRadioChannelListViewId )
       
  1032                     {
       
  1033                     CAknToolbar* toolbar = iChannelListView->Toolbar();
       
  1034                     if ( toolbar )
       
  1035                         {
       
  1036                         iChannelListView->UpdateToolbar();
       
  1037                         toolbar->DrawDeferred();
       
  1038                         }
       
  1039                     }
       
  1040                 if( !IsStartupWizardRunning() || err != KErrNone )
       
  1041                     {
       
  1042                     //we use method because the behaviour we require is the same.
       
  1043                     if ( !iTuneFromWizardActivated && iMuteStatusBeforeRadioInit != EFMUninitialized )
       
  1044                         {
       
  1045                         TBool mute = EFalse; 
       
  1046                         if ( iMuteStatusBeforeRadioInit == EFMMuted )
       
  1047                             {
       
  1048                             mute = ETrue;
       
  1049                             }
       
  1050                         iRadioEngine->SetMuteOn( mute );
       
  1051                         iMuteStatusBeforeRadioInit = EFMUninitialized;
       
  1052                         }
       
  1053                     HandleStopSeekCallback(); 
       
  1054                     }
       
  1055                 }
       
  1056                 break;
       
  1057             case EFMRadioEventRadioOff:
       
  1058                 iCurrentRadioState = EFMRadioStateOff;
       
  1059                 
       
  1060                 if ( !iOfflineQueryDialogActivated )
       
  1061                     {
       
  1062                     ExitApplication();
       
  1063                     }
       
  1064                 
       
  1065                 break;
       
  1066             case EFMRadioEventFMRadioInitialized:
       
  1067                 TRAP( err, HandleInitializedCallbackL() );
       
  1068                 break;
       
  1069             case EFMRadioEventTune:
       
  1070                 if ( iTuneFromWizardActivated )
       
  1071                     {
       
  1072                     iTuneFromWizardActivated = EFalse;
       
  1073                     iRadioEngine->SetMuteOn( EFalse );
       
  1074                     iMuteStatusBeforeRadioInit = EFMUninitialized;
       
  1075                     }
       
  1076                 if ( IsStartupWizardHandled() )
       
  1077                     {
       
  1078                     HandleStopSeekCallback();
       
  1079                     }
       
  1080                 break;
       
  1081             case EFMRadioEventSetMuteState:
       
  1082                 HandleSetMuteStateCallback();
       
  1083                 break;
       
  1084             case EFMRadioEventVolumeUpdated:
       
  1085                 HandleVolumeChangedCallback();
       
  1086                 break;
       
  1087             case EFMRadioEventSetAudioOutput:
       
  1088                 HandleAudioOutputSetCallback();
       
  1089                 break;
       
  1090             case EFMRadioEventButtonPressed:
       
  1091                 iMainView->SetStationChangeType( EFMRadioStationChangeNext );
       
  1092                 PlayChannel( iChannelListView->NextChannel() );
       
  1093                 break;
       
  1094             case EFMRadioEventHeadsetDisconnected:
       
  1095                 HandleHeadsetDisconnectedCallback();
       
  1096                 break;
       
  1097             case EFMRadioEventHeadsetReconnected:
       
  1098                 HandleHeadsetReconnectedCallback();
       
  1099                 break;
       
  1100             case EFMRadioEventAudioResourceLost:
       
  1101             	iAudioLost = ETrue;
       
  1102                 TRAP( err, HandleAudioResourceNotAvailableL(aErrorCode) );
       
  1103                 break;
       
  1104             case EFMRadioEventAudioResourcePaused:
       
  1105                 TRAP( err, HandleAudioResourceNotAvailableL(aErrorCode) );
       
  1106                 break;                
       
  1107             case EFMRadioEventAudioResourceAvailable:
       
  1108                 TRAP( err, HandleAudioResourceAvailableL() );
       
  1109                 break;
       
  1110             case EFMRadioEventCallStarted:
       
  1111                 if ( iCurrentRadioState != EFMRadioStateOff && 
       
  1112                      iCurrentRadioState != EFMRadioStateOffBeforePhoneCall )
       
  1113                     {
       
  1114                     iCurrentRadioState = EFMRadioStateOffForPhoneCall;
       
  1115                     }
       
  1116                 else
       
  1117                     {
       
  1118                     iCurrentRadioState = EFMRadioStateOffBeforePhoneCall;
       
  1119                     }
       
  1120                 FadeViewsAndShowExit( ETrue );
       
  1121                 break;
       
  1122             case EFMRadioEventCallEnded:
       
  1123                 {
       
  1124                 if ( iAudioLost )
       
  1125                     {
       
  1126                     TRAP_IGNORE( TryToResumeAudioL() );
       
  1127                     iCurrentRadioState = EFMRadioStateOff;
       
  1128                     }
       
  1129                 else if ( iCurrentRadioState == EFMRadioStateOffForPhoneCall )
       
  1130                     {
       
  1131                     TurnRadioOn();
       
  1132                     }
       
  1133                 else
       
  1134                     {
       
  1135                     // Do nothing.
       
  1136                     }
       
  1137                 FadeViewsAndShowExit( EFalse );
       
  1138                 break;
       
  1139                 }
       
  1140             case EFMRadioEventStandbyMode:
       
  1141                 ExitApplication();
       
  1142                 break;
       
  1143             case EFMRadioEventFlightModeEnabled:
       
  1144                 TRAP( err, HandleFlightModeEnabledCallbackL() );
       
  1145                 break;
       
  1146             case EFMRadioEventFlightModeDisabled:
       
  1147                 HandleFlightModeDisabledCallback();
       
  1148                 break;
       
  1149             case EFMRadioEventFMTransmitterOn:
       
  1150                 TRAP_IGNORE( HandleFMTransmitterOnCallbackL() );
       
  1151                 break;
       
  1152             case EFMRadioEventFreqRangeChanged:
       
  1153                 HandleFreqRangeChangedCallback();
       
  1154                 break;
       
  1155             case EFMRadioEventScanLocalStationsCanceled:
       
  1156                 {
       
  1157                 HandleStopSeekCallback();
       
  1158                 SetStartupWizardRunning( EFalse );
       
  1159                 break;	
       
  1160                 }
       
  1161             default:
       
  1162                 break;
       
  1163             }
       
  1164         }
       
  1165     else
       
  1166         {
       
  1167         switch ( aEventCode )
       
  1168             {
       
  1169             case EFMRadioEventAudioResourceLost:
       
  1170             	iAudioLost = ETrue;
       
  1171                 TRAP( err, HandleAudioResourceNotAvailableL( aErrorCode ) );
       
  1172                 break;
       
  1173             case EFMRadioEventAudioResourcePaused:
       
  1174                 TRAP( err, HandleAudioResourceNotAvailableL( aErrorCode ) );
       
  1175                 break;
       
  1176             case EFMRadioEventTune:
       
  1177                 if ( iTuneFromWizardActivated )
       
  1178                     {
       
  1179                     iTuneFromWizardActivated = EFalse;
       
  1180                     iRadioEngine->SetMuteOn( EFalse );
       
  1181                     iMuteStatusBeforeRadioInit = EFMUninitialized;
       
  1182                     }
       
  1183 
       
  1184                 if ( aErrorCode == KFmRadioErrAntennaNotConnected )
       
  1185                     {
       
  1186                     iScanLocalStationsView->SetScanCanceled(EFMRadioCancelScanByHeadsetDisconnect);
       
  1187                     }
       
  1188 
       
  1189                 HandleStopSeekCallback();
       
  1190                 break;
       
  1191             case EFMRadioEventCallStarted:
       
  1192                 {
       
  1193                 FTRACE( FPrint( _L("CFMRadioAppUi::HandleRadioEngineCallBack() error -> EFMRadioEventCallStarted  ") ) );            		            	
       
  1194                 if ( iCurrentRadioState != EFMRadioStateOff && 
       
  1195                      iCurrentRadioState != EFMRadioStateOffBeforePhoneCall )
       
  1196                     {
       
  1197                     iCurrentRadioState = EFMRadioStateOffForPhoneCall;
       
  1198                     }
       
  1199                 else
       
  1200                     {
       
  1201                     iCurrentRadioState = EFMRadioStateOffBeforePhoneCall;
       
  1202                     }
       
  1203                 FadeViewsAndShowExit( ETrue );
       
  1204                 break;
       
  1205                 }
       
  1206             default:
       
  1207                 FTRACE( FPrint( _L("CFMRadioAppUi::HandleRadioEngineCallBack() failed to process event.") ) );
       
  1208                 break;
       
  1209             }
       
  1210         }
       
  1211     FTRACE( FPrint( _L("END CFMRadioAppUi::HandleRadioEngineCallBack()") ) );
       
  1212     }
       
  1213 
       
  1214 // ---------------------------------------------------------------------------
       
  1215 // CFMRadioAppUi::HandleVolumeChangedCallback
       
  1216 // Processes "volume changed" callback
       
  1217 // ---------------------------------------------------------------------------
       
  1218 //
       
  1219 void CFMRadioAppUi::HandleVolumeChangedCallback()
       
  1220     {
       
  1221     FTRACE( FPrint( _L("CFMRadioAppUi::HandleVolumeChangedCallback()  Start") ) );
       
  1222     if ( !iRadioEngine->IsMuteOn() )
       
  1223         {
       
  1224         TInt newVolume = iRadioEngine->GetVolume();  // current volume
       
  1225         FTRACE( FPrint( _L("CFMRadioAppUi::HandleVolumeChangedCallback() - volume now %d "), newVolume ) );
       
  1226         iActiveVolumePopupControl->SetValue( newVolume );
       
  1227         }
       
  1228     else
       
  1229         {
       
  1230         iActiveVolumePopupControl->SetValue( KFMRadioMinVolumeLevel );	
       
  1231         }
       
  1232     }
       
  1233 
       
  1234 // ---------------------------------------------------------------------------
       
  1235 // CFMRadioAppUi::HandleInitializedCallbackL
       
  1236 // The initialization of the radio is completed, the radio can be turned on if
       
  1237 // not in call.
       
  1238 // ---------------------------------------------------------------------------
       
  1239 //
       
  1240 void CFMRadioAppUi::HandleInitializedCallbackL()
       
  1241     {
       
  1242     FTRACE( FPrint( _L("CFMRadioAppUi::HandleInitializedCallbackL()  Start") ) );
       
  1243     if( iCurrentRadioState != EFMRadioStateOffForPhoneCall && 
       
  1244         iCurrentRadioState != EFMRadioStateOffBeforePhoneCall )
       
  1245         {
       
  1246         TurnRadioOn();
       
  1247         if ( iRadioEngine->GetAudioOutput() == CRadioEngine::EFMRadioOutputIHF )
       
  1248             {
       
  1249             iActiveVolumePopupControl = iIhfVolumePopupControl;
       
  1250             }
       
  1251         else
       
  1252             {
       
  1253             iActiveVolumePopupControl = iHeadsetVolumePopupControl;
       
  1254             }
       
  1255         HandleVolumeChangedCallback();    
       
  1256         }
       
  1257     }
       
  1258 // ---------------------------------------------------------------------------
       
  1259 // CFMRadioAppUi::FadeViewsAndShowExit
       
  1260 // fade and show exit for all views
       
  1261 // ---------------------------------------------------------------------------
       
  1262 //
       
  1263 
       
  1264 void CFMRadioAppUi::FadeViewsAndShowExit( TBool aState )
       
  1265     {
       
  1266     FTRACE( FPrint( _L("CFMRadioAppUi::FadeViewsAndShowExit( Tbool %d )"), aState ) );
       
  1267     iMainView->FadeAndShowExit( aState );
       
  1268     iChannelListView->FadeAndShowExit( aState );
       
  1269     iScanLocalStationsView->FadeAndShowExit( aState );
       
  1270     }
       
  1271 
       
  1272 // ---------------------------------------------------------------------------
       
  1273 // CFMRadioAppUi::HandleAudioResourceAvailableL
       
  1274 // When audio resource is available, we would resume the radio.
       
  1275 // ---------------------------------------------------------------------------
       
  1276 //
       
  1277 void CFMRadioAppUi::HandleAudioResourceAvailableL()
       
  1278     {
       
  1279     FTRACE( FPrint( _L("CFMRadioAppUi::HandleAudioResourceAvailableL") ) );
       
  1280 
       
  1281     iAudioResourceAvailable = ETrue;
       
  1282 
       
  1283     if ( !IsOfflineProfileActivatedWhenRadioAudioDisabled() &&
       
  1284         !( iGlobalOfflineQuery && iGlobalOfflineQuery->IsActive() ) )
       
  1285         {
       
  1286         if ( ( ( iFMRadioVariationFlags & KFMRadioInternalAntennaSupported) ||
       
  1287             iRadioEngine->IsHeadsetConnected() ) && !iAudioLost && !iRadioEngine->IsInCall() )
       
  1288             {
       
  1289             TurnRadioOn();   
       
  1290             }
       
  1291         else if ( iAudioLost &&
       
  1292                  iRadioEngine->IsHeadsetConnected() )
       
  1293             {
       
  1294             TryToResumeAudioL();
       
  1295             }
       
  1296         }
       
  1297     }
       
  1298 
       
  1299 // ---------------------------------------------------------------------------
       
  1300 // CFMRadioAppUi::HandleAudioResourceNotAvailableL
       
  1301 // Handles the cases when the radio is interrupted due to:
       
  1302 // 1. Call setup/in progress
       
  1303 // 2. Higher priority audio
       
  1304 // ---------------------------------------------------------------------------
       
  1305 
       
  1306 void CFMRadioAppUi::HandleAudioResourceNotAvailableL( TInt FDEBUGVAR(aError) )
       
  1307     {
       
  1308     FTRACE( FPrint( _L("CFMRadioAppUi::HandleAudioResourceNotAvailableL()  error code: %d"),
       
  1309     aError ) );
       
  1310 
       
  1311     SetStartupWizardRunning( EFalse );
       
  1312     iAudioResourceAvailable = EFalse;
       
  1313     
       
  1314     if ( iCurrentRadioState != EFMRadioStateOffForPhoneCall &&
       
  1315             iCurrentRadioState != EFMRadioStateOffBeforePhoneCall )
       
  1316         {
       
  1317         iCurrentRadioState = EFMRadioStateOff;
       
  1318         }
       
  1319     }
       
  1320 
       
  1321 // ---------------------------------------------------------------------------
       
  1322 // CFMRadioAppUi::HandleHeadsetDisconnectedCallback
       
  1323 // Take actions when the headset is disconnected.
       
  1324 // ---------------------------------------------------------------------------
       
  1325 //
       
  1326 void CFMRadioAppUi::HandleHeadsetDisconnectedCallback()
       
  1327     {
       
  1328     FTRACE( FPrint( _L("CFMRadioAppUi::HandleHeadsetDisconnectedCallback" ) ) );
       
  1329 
       
  1330     if ( iFMRadioVariationFlags & KFMRadioInternalAntennaSupported )
       
  1331         {
       
  1332         SetAudioOutput( CRadioEngine::EFMRadioOutputIHF );
       
  1333         }
       
  1334     else
       
  1335         {
       
  1336         // radio is already turned off, and if it was tuning it was canceled
       
  1337         iCurrentRadioState = EFMRadioStateOff;
       
  1338         TRAP_IGNORE( ShowConnectHeadsetDialogL() );
       
  1339         }
       
  1340     }
       
  1341 
       
  1342 // ---------------------------------------------------------------------------
       
  1343 // CFMRadioAppUi::HandleHeadsetReconnectedCallback
       
  1344 // Take actions when the headset is reconnected.
       
  1345 // ---------------------------------------------------------------------------
       
  1346 //
       
  1347 void CFMRadioAppUi::HandleHeadsetReconnectedCallback()
       
  1348     {
       
  1349     FTRACE( FPrint( _L("CFMRadioAppUi::HandleHeadsetReconnectedCallback()") ) );
       
  1350     if ( iConnectHeadsetQuery )
       
  1351         {
       
  1352         delete iConnectHeadsetQuery;
       
  1353         iConnectHeadsetQuery = NULL;	
       
  1354         }
       
  1355     
       
  1356     //compare bitmask to see if feature supported
       
  1357     if ( !(iFMRadioVariationFlags & KFMRadioInternalAntennaSupported) &&
       
  1358             iCurrentRadioState != EFMRadioStateOffForPhoneCall && 
       
  1359             iCurrentRadioState != EFMRadioStateOffBeforePhoneCall )
       
  1360         {        
       
  1361         if ( !iRadioEngine->IsRadioOn() && !iRadioEngine->IsInCall() )
       
  1362             {
       
  1363             FTRACE( FPrint( _L("CFMRadioAppUi::HandleHeadsetReconnectedCallback() - Turn radio on") ) );
       
  1364             TurnRadioOn();
       
  1365             } 
       
  1366         // active offline query controls radio on/off
       
  1367         else if ( iAudioLost )
       
  1368             {
       
  1369             FTRACE( FPrint( _L("CFMRadioAppUi::HandleHeadsetReconnectedCallback() - Try to resume") ) );
       
  1370             TRAP_IGNORE( TryToResumeAudioL() );	
       
  1371             }
       
  1372         else if ( ( iGlobalOfflineQuery && !iGlobalOfflineQuery->IsActive() ) ||
       
  1373               !iGlobalOfflineQuery )
       
  1374             {
       
  1375             FTRACE( FPrint( _L("CFMRadioAppUi::HandleHeadsetReconnectedCallback() - Offline query") ) );
       
  1376             iRadioEngine->InitializeRadio();
       
  1377             }
       
  1378         HandleVolumeChangedCallback();
       
  1379         }
       
  1380     }
       
  1381 
       
  1382 // ---------------------------------------------------------------------------
       
  1383 // CFMRadioAppUi::HandleManualTuneFailedCallback
       
  1384 // Processes "manual tune failed" callback
       
  1385 // ---------------------------------------------------------------------------
       
  1386 //
       
  1387 void CFMRadioAppUi::HandleManualTuneFailedCallback()
       
  1388     {
       
  1389     HandleStopSeekCallback();
       
  1390     }
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // CFMRadioAppUi::HandleVolumeUpdateFailedCallback
       
  1394 // Processes "volume update failed" callback
       
  1395 // ---------------------------------------------------------------------------
       
  1396 //
       
  1397 void CFMRadioAppUi::HandleVolumeUpdateFailedCallback()
       
  1398     {
       
  1399     HandleVolumeChangedCallback();
       
  1400     }
       
  1401 
       
  1402 // ---------------------------------------------------------------------------
       
  1403 // CFMRadioAppUi::HandleMuteCallback
       
  1404 // Processes "radio volume muted" callback
       
  1405 // ---------------------------------------------------------------------------
       
  1406 //
       
  1407 void CFMRadioAppUi::HandleSetMuteStateCallback()
       
  1408     {
       
  1409     FTRACE( FPrint( _L("CFMRadioAppUi::HandleSetMuteStateCallback()")) );
       
  1410     HandleVolumeChangedCallback();
       
  1411     }
       
  1412 
       
  1413 // ---------------------------------------------------------------------------
       
  1414 // CFMRadioAppUi::HandleStopSeekCallback
       
  1415 // Processes "seek operation completed" callback
       
  1416 // ---------------------------------------------------------------------------
       
  1417 //
       
  1418 void CFMRadioAppUi::HandleStopSeekCallback()
       
  1419     {
       
  1420     FTRACE( FPrint( _L("CFMRadioAppUi::HandleStopSeekCallback() state %d "), iCurrentRadioState) );
       
  1421     
       
  1422     if ( iCurrentRadioState == EFMRadioStateBusyManualTune ||
       
  1423          iCurrentRadioState == EFMRadioStateBusySeek ||
       
  1424          iCurrentRadioState == EFMRadioStateBusyScanLocalStations )
       
  1425         {
       
  1426         iCurrentRadioState = EFMRadioStateOn; // Update state
       
  1427         }
       
  1428 
       
  1429     const TUid activeViewTuid = ActiveView();
       
  1430     
       
  1431     if ( activeViewTuid == KFMRadioMainViewId )
       
  1432         {
       
  1433         TRAP_IGNORE( iMainView->StopSeekL() )
       
  1434         }
       
  1435     else if ( activeViewTuid == KFMRadioChannelListViewId )
       
  1436         {
       
  1437         TRAP_IGNORE( iChannelListView->StopSeekL() )
       
  1438         }
       
  1439     else if ( activeViewTuid == KFMRadioScanLocalStationsViewId )
       
  1440         {
       
  1441         TRAP_IGNORE( iScanLocalStationsView->StopSeekL() )
       
  1442         }
       
  1443     else
       
  1444         {
       
  1445         // nop
       
  1446         }
       
  1447     FTRACE( FPrint( _L("end CFMRadioAppUi::HandleStopSeekCallback") ) );
       
  1448     }
       
  1449 
       
  1450 // ---------------------------------------------------------------------------
       
  1451 // CFMRadioAppUi::HandleAudioOutputSetCallback
       
  1452 // Processes "set audio output completed" callback
       
  1453 // ---------------------------------------------------------------------------
       
  1454 //
       
  1455 void CFMRadioAppUi::HandleAudioOutputSetCallback()
       
  1456     {
       
  1457     FTRACE( FPrint( _L("CFMRadioAppUi::HandleAudioOutputSetCallback()")) );
       
  1458     if ( iRadioEngine->GetAudioOutput() == CRadioEngine::EFMRadioOutputIHF )
       
  1459         {
       
  1460         iActiveVolumePopupControl = iIhfVolumePopupControl;
       
  1461         }
       
  1462     else
       
  1463         {
       
  1464         iActiveVolumePopupControl = iHeadsetVolumePopupControl;
       
  1465         }
       
  1466     // restore volume for current output
       
  1467     TInt volumeLevel = iRadioEngine->GetVolume();
       
  1468     iRadioEngine->SetVolume( volumeLevel );
       
  1469     
       
  1470     if ( iCurrentRadioState != EFMRadioStateBusyScanLocalStations )
       
  1471         {
       
  1472         iRadioEngine->SetMuteOn( EFalse );
       
  1473         }
       
  1474     
       
  1475     TUid view = ActiveView();
       
  1476     
       
  1477     if ( view == KFMRadioScanLocalStationsViewId )
       
  1478         {
       
  1479         iScanLocalStationsView->UpdateToolbar();
       
  1480         }
       
  1481     else if ( view == KFMRadioChannelListViewId )
       
  1482         {
       
  1483         iChannelListView->UpdateToolbar();
       
  1484         }
       
  1485     else if ( view == KFMRadioMainViewId )
       
  1486         {
       
  1487         CAknView* mainView = View( KFMRadioMainViewId );
       
  1488         if ( mainView )
       
  1489             {
       
  1490             // force update for toolbar extension view
       
  1491             mainView->Toolbar()->ToolbarExtension()->SetShown( EFalse );
       
  1492             }
       
  1493         }
       
  1494     else
       
  1495         {
       
  1496         // NOP
       
  1497         }
       
  1498 
       
  1499     // So the views can dynamically change the option menu
       
  1500     StopDisplayingMenuBar(); // force update for menu bar
       
  1501     // Force UI update
       
  1502     HandleVolumeChangedCallback();
       
  1503     }
       
  1504 
       
  1505 // --------------------------------------------------------------------------------
       
  1506 // CFMRadioAppUi::HandleWsEventL
       
  1507 // --------------------------------------------------------------------------------
       
  1508 //
       
  1509 void CFMRadioAppUi::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* aDestination )
       
  1510     {
       
  1511     FTRACE( FPrint( _L("CFMRadioAppUi::HandleWsEventL - event %d "), aEvent.Type() ) );
       
  1512     switch ( aEvent.Type() )
       
  1513         {
       
  1514         case KAknUidValueEndKeyCloseEvent:
       
  1515             {
       
  1516             if ( IsForeground() )
       
  1517                 {
       
  1518                 const TUid KPhoneAppUid = {0x100058B3}; // hardcoded value for phone app uid
       
  1519                 TApaTaskList taskList( iEikonEnv->WsSession() );
       
  1520                 TApaTask phoneTask = taskList.FindApp( KPhoneAppUid );
       
  1521                 
       
  1522                 if ( phoneTask.Exists() )
       
  1523                     {
       
  1524                     // Bring phone to foreground
       
  1525                     phoneTask.BringToForeground();
       
  1526                     }
       
  1527                 else
       
  1528                     {
       
  1529                     // Phone app should always be there, but this is a backup 
       
  1530                     // plan, just set radio to background
       
  1531                     TApaTask task( iEikonEnv->WsSession() );
       
  1532                     task.SetWgId( iEikonEnv->RootWin().Identifier() );
       
  1533                     task.SendToBackground();
       
  1534                     }
       
  1535                 }
       
  1536             break;
       
  1537             }
       
  1538         case EEventFocusLost:
       
  1539             {
       
  1540             // being sent to background, cancel any seek expect local stations scan
       
  1541             if ( iCurrentRadioState == EFMRadioStateBusySeek )
       
  1542                 {
       
  1543                 iRadioEngine->CancelScan();
       
  1544                 HandleStopSeekCallback();
       
  1545                 }
       
  1546             CAknViewAppUi::HandleWsEventL( aEvent, aDestination );
       
  1547             break;
       
  1548             }
       
  1549         case EEventFocusGained:
       
  1550             // override default behavior of unfading the ui
       
  1551             // can be taken out when auto resume is implemented
       
  1552             CAknViewAppUi::HandleWsEventL(aEvent, aDestination);
       
  1553             if (iMainView)
       
  1554                 {
       
  1555                 iMainView->UpdateDisplayForFocusGained();
       
  1556                 }
       
  1557             if (iChannelListView)
       
  1558                 {
       
  1559                 iChannelListView->UpdateDisplayForFocusGained();
       
  1560                 }
       
  1561             if (iScanLocalStationsView)
       
  1562                 {
       
  1563                 iScanLocalStationsView->UpdateDisplayForFocusGained();
       
  1564                 }
       
  1565             break;
       
  1566         default:
       
  1567             CAknViewAppUi::HandleWsEventL(aEvent, aDestination);
       
  1568             break;
       
  1569         }
       
  1570     }
       
  1571 
       
  1572 // ----------------------------------------------------------------------------------------------------
       
  1573 // CFMRadioAppUi::FMRadioSvkChangeVolumeL
       
  1574 // Handles the change in the Volume that is needed as per the Side Volume Key
       
  1575 // events.
       
  1576 // ----------------------------------------------------------------------------------------------------
       
  1577 //
       
  1578 void CFMRadioAppUi::FMRadioSvkChangeVolumeL( TInt aVolumeChange )
       
  1579     {  
       
  1580     FTRACE( FPrint( _L("CFMRadioAppUi::FMRadioSvkRemoveVolumeL() aVolumeChange : %d"), aVolumeChange ) );
       
  1581     
       
  1582     TBool headsetConnected = iRadioEngine->IsHeadsetConnected();
       
  1583     
       
  1584     if ( iCurrentRadioState != EFMRadioStateBusyScanLocalStations && IsStartupWizardHandled() &&
       
  1585         headsetConnected )
       
  1586         {
       
  1587         if ( aVolumeChange > 0 ) // up direction
       
  1588             {
       
  1589             UpdateVolume( EDirectionUp );
       
  1590             }
       
  1591         else // down direction
       
  1592             {
       
  1593             UpdateVolume( EDirectionDown );
       
  1594             }
       
  1595         }
       
  1596     }
       
  1597 
       
  1598 // ----------------------------------------------------------------------------------------------------
       
  1599 // CFMRadioAppUi::FMRadioSvkRemoveVolumeL
       
  1600 // Handles the remove Volume option that is needed depending on the duration of the
       
  1601 // Side Volume Key press
       
  1602 // ----------------------------------------------------------------------------------------------------
       
  1603 //
       
  1604 void CFMRadioAppUi::FMRadioSvkRemoveVolumeL()
       
  1605    {
       
  1606    FTRACE( FPrint( _L("CFMRadioAppUi::FMRadioSvkRemoveVolumeL( )") ) );
       
  1607    }
       
  1608 
       
  1609 // ----------------------------------------------------------------------------------------------------
       
  1610 // CFMRadioAppUi::FMRadioHeadsetEvent
       
  1611 // Handles the Headset button pressed
       
  1612 // ----------------------------------------------------------------------------------------------------
       
  1613 
       
  1614 void CFMRadioAppUi::FMRadioHeadsetEvent( TAccessoryEvent aEvent )
       
  1615     {
       
  1616     FTRACE( FPrint( _L("CFMRadioAppUi::FMRadioHeadsetEvent event: %d "), aEvent ) );
       
  1617     switch ( aEvent )
       
  1618         {
       
  1619         case EForward:
       
  1620             {
       
  1621             if ( ActiveView() == KFMRadioScanLocalStationsViewId &&
       
  1622                     iCurrentRadioState != EFMRadioStateBusyScanLocalStations )
       
  1623                 {
       
  1624                 // change channels in scan local stations view
       
  1625                 TRAP_IGNORE( iScanLocalStationsView->HandleScanListRemConEventL( aEvent ) )
       
  1626                 }
       
  1627             else
       
  1628                 {
       
  1629                 TRAP_IGNORE( HandleCommandL( EFMRadioCmdNextChannel ) )
       
  1630                 }
       
  1631             break;
       
  1632             }
       
  1633         case ERewind:
       
  1634             {
       
  1635             if ( ActiveView() == KFMRadioScanLocalStationsViewId &&
       
  1636                     iCurrentRadioState != EFMRadioStateBusyScanLocalStations )
       
  1637                 {
       
  1638                 TRAP_IGNORE( iScanLocalStationsView->HandleScanListRemConEventL( aEvent ) )
       
  1639                 }
       
  1640             else
       
  1641                 {
       
  1642                 TRAP_IGNORE( HandleCommandL( EFMRadioCmdPrevChannel ) )
       
  1643                 }
       
  1644             break;
       
  1645             }
       
  1646         case EStop:
       
  1647             {
       
  1648             if ( iCurrentRadioState != EFMRadioStateBusyScanLocalStations && IsStartupWizardHandled() )
       
  1649                 {
       
  1650                 iRadioEngine->SetMuteOn( ETrue );
       
  1651                 }
       
  1652             break;
       
  1653             }
       
  1654         case EPausePlay:
       
  1655             {
       
  1656             if ( iCurrentRadioState != EFMRadioStateBusyScanLocalStations && IsStartupWizardHandled() )
       
  1657                 {
       
  1658                 HandleMuteCommand();
       
  1659                 }
       
  1660             break;
       
  1661             }
       
  1662         default:
       
  1663             break;
       
  1664         }
       
  1665     }
       
  1666 
       
  1667 // ----------------------------------------------------------------------------------------------------
       
  1668 // CFMRadioAppUi::HandleResourceChangeL
       
  1669 // ----------------------------------------------------------------------------------------------------
       
  1670 //
       
  1671 void CFMRadioAppUi::HandleResourceChangeL( TInt aType )
       
  1672     {
       
  1673     FTRACE( FPrint( _L("CFMRadioAppUi::HandleResourceChangeL type: %d "), aType ) );
       
  1674     CAknViewAppUi::HandleResourceChangeL( aType );
       
  1675     
       
  1676     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  1677         {
       
  1678         UpdateLandscapeInformation();
       
  1679         iLayoutChangeObserver->LayoutChangedL( aType );
       
  1680         }
       
  1681     else if ( aType == KAknsMessageSkinChange )
       
  1682         {
       
  1683         iLayoutChangeObserver->LayoutChangedL( aType );
       
  1684         }
       
  1685     }
       
  1686 
       
  1687 // ----------------------------------------------------------------------------------------------------
       
  1688 // Handles MCoeControl events
       
  1689 // ----------------------------------------------------------------------------------------------------
       
  1690 void CFMRadioAppUi::HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType )
       
  1691     {
       
  1692     FTRACE( FPrint( _L("CFMRadioAppUi::HandleControlEventL - aEventID = %d"), aEventType) );
       
  1693     if ( (aEventType == EEventStateChanged) &&
       
  1694          ( aControl == iActiveVolumePopupControl ) )
       
  1695         {
       
  1696         TInt volumeControlLevel = iActiveVolumePopupControl->Value();
       
  1697         
       
  1698         if ( iRadioEngine->IsMuteOn() && volumeControlLevel == 1 )
       
  1699             {
       
  1700             // Volume has been muted and volume is changed from
       
  1701             // popup. Restore volume to the previous level.
       
  1702             volumeControlLevel = iRadioEngine->GetVolume();
       
  1703             volumeControlLevel++;
       
  1704             if ( volumeControlLevel > KFMRadioMaxVolumeLevel )
       
  1705                 {
       
  1706                 volumeControlLevel = KFMRadioMaxVolumeLevel;
       
  1707                 }
       
  1708             iActiveVolumePopupControl->SetValue( volumeControlLevel );
       
  1709             }
       
  1710             
       
  1711         // Set mute
       
  1712         if ( volumeControlLevel == KFMRadioMinVolumeLevel )
       
  1713             {
       
  1714             // Mute status could change from toolbar, svk or pointer event
       
  1715             if ( !iRadioEngine->IsMuteOn() )
       
  1716                 {
       
  1717                 iRadioEngine->SetMuteOn( ETrue );
       
  1718                 }
       
  1719             }
       
  1720         else
       
  1721             {
       
  1722             iRadioEngine->SetMuteOn( EFalse );	
       
  1723             }
       
  1724 
       
  1725         // Make sure volume level is in range
       
  1726         if ( volumeControlLevel < KFMRadioMinVolumeLevel )
       
  1727             {
       
  1728             volumeControlLevel = KFMRadioMinVolumeLevel;
       
  1729             }
       
  1730         else if ( volumeControlLevel > KFMRadioMaxVolumeLevel )
       
  1731             {
       
  1732             volumeControlLevel = KFMRadioMaxVolumeLevel;
       
  1733             }
       
  1734 
       
  1735         // Set volume. If volume is muted we dont want to set it to iRadioEngine
       
  1736         if ( !iRadioEngine->IsMuteOn() )
       
  1737             {
       
  1738             iRadioEngine->SetVolume( volumeControlLevel );
       
  1739             }
       
  1740         }
       
  1741     }
       
  1742 
       
  1743 // ----------------------------------------------------------------------------------------------------
       
  1744 // DialogTerminated
       
  1745 // ----------------------------------------------------------------------------------------------------
       
  1746 void CFMRadioAppUi::DialogTerminated()
       
  1747     {
       
  1748     iInfoNoteOn = EFalse;
       
  1749     }
       
  1750 
       
  1751 // ---------------------------------------------------------------------------
       
  1752 // CFMRadioAppUi::UpdateLandscapeInformation
       
  1753 // ---------------------------------------------------------------------------
       
  1754 //    
       
  1755 void CFMRadioAppUi::UpdateLandscapeInformation()
       
  1756     {
       
  1757     TSize screenSize;
       
  1758     
       
  1759     AknLayoutUtils::LayoutMetricsSize( AknLayoutUtils::EScreen, screenSize );
       
  1760         
       
  1761     // Is it portrait or landscape, compare height and width, since we can't 
       
  1762     // be sure if EGraphicsOrientationNormal is portrait or landscape
       
  1763     if ( screenSize.iHeight < screenSize.iWidth )
       
  1764         {
       
  1765         iLandscape = ETrue;    
       
  1766         }
       
  1767     else
       
  1768         {
       
  1769         iLandscape = EFalse;
       
  1770         }
       
  1771     }
       
  1772 // ---------------------------------------------------------------------------
       
  1773 // CFMRadioAppUi::UpdateChannelsL
       
  1774 // ---------------------------------------------------------------------------
       
  1775 //    
       
  1776 void CFMRadioAppUi::UpdateChannelsL( TMoveoperations aOperation,
       
  1777         TInt aIndex, TInt aMovedToNewIndex )
       
  1778     {
       
  1779     FTRACE( FPrint( _L("CFMRadioAppUi::UpdateChannelsL(%d, %d, %d)"), aOperation, aIndex, aMovedToNewIndex ) );
       
  1780     
       
  1781     // Move channel operation moves channel from aIndex to aMovedToNewIndex value
       
  1782     if ( EMoveChannels == aOperation )
       
  1783         {
       
  1784         CFMRadioPreset* channelInfo  = iChannels[ aIndex ];
       
  1785         iChannels.Remove( aIndex );
       
  1786         CleanupStack::PushL( channelInfo );
       
  1787         iChannels.InsertL( channelInfo, aMovedToNewIndex );
       
  1788         CleanupStack::Pop( channelInfo);
       
  1789         }
       
  1790     // Delete channel deletes channel from list 
       
  1791     else if ( EDeleteChannel == aOperation )
       
  1792         {
       
  1793         const CFMRadioPreset* channelinfo  = iChannels[ aIndex ];
       
  1794         iChannels.Remove( aIndex );
       
  1795         delete channelinfo;
       
  1796         
       
  1797         for ( TInt index = 0; index < iChannels.Count(); index++ )
       
  1798             {
       
  1799             iRadioEngine->SetPresetNameFrequencyL( 
       
  1800                     index,
       
  1801                     iChannels[ index ]->PresetName(),
       
  1802                     iChannels[ index ]->PresetFrequency() );
       
  1803             
       
  1804             iRadioEngine->SaveUrlToPresetL( index, iChannels[ index ]->PresetUrl() );
       
  1805             }
       
  1806         iRadioEngine->DeletePresetL( iChannels.Count() );
       
  1807         }
       
  1808 
       
  1809     // Store all channels to repository
       
  1810     else if ( EStoreAllToRepository == aOperation )
       
  1811         {
       
  1812         for ( TInt index = 0; index < iChannels.Count(); index++ )
       
  1813             {
       
  1814             iRadioEngine->SetPresetNameFrequencyL( 
       
  1815                     index, 
       
  1816                     iChannels[ index ]->PresetName(), 
       
  1817                     iChannels[ index ]->PresetFrequency() );
       
  1818             
       
  1819             iRadioEngine->SaveUrlToPresetL( index, iChannels[ index ]->PresetUrl() );
       
  1820             }
       
  1821         }
       
  1822 
       
  1823     // Store specified index to repository and same index 
       
  1824     else if ( EStoreIndexToRepository == aOperation )
       
  1825         {
       
  1826         iRadioEngine->SetPresetNameFrequencyL( 
       
  1827              aIndex, 
       
  1828              iChannels[ aIndex ]->PresetName(), 
       
  1829              iChannels[ aIndex ]->PresetFrequency() );
       
  1830         
       
  1831         iRadioEngine->SaveUrlToPresetL( aIndex, iChannels[ aIndex ]->PresetUrl() );
       
  1832         }
       
  1833     else if ( ERemoveAllFromRepository == aOperation )
       
  1834         {
       
  1835         iRadioEngine->DeletePresetL( -1 ); // reset all presets
       
  1836         iChannels.ResetAndDestroy();
       
  1837         }
       
  1838     
       
  1839     iRadioEngine->PubSubL().PublishPresetCountL( iChannels.Count() );
       
  1840     }
       
  1841 
       
  1842 // ---------------------------------------------------------------------------
       
  1843 // CFMRadioAppUi::AddChannelToListL
       
  1844 // ---------------------------------------------------------------------------
       
  1845 // 
       
  1846 void CFMRadioAppUi::AddChannelToListL( const TDesC& aChannelName, TInt aChannelFreq )
       
  1847     {
       
  1848     FTRACE( FPrint( _L("CFMRadioAppUi::AddChannelToListL(%S, %d)"), &aChannelName, aChannelFreq ) );
       
  1849     CFMRadioPreset* preset = CFMRadioPreset::NewL();
       
  1850     CleanupStack::PushL( preset );
       
  1851     preset->SetPresetNameL( aChannelName );
       
  1852     preset->SetPresetFrequency( aChannelFreq );
       
  1853     iChannels.AppendL( preset );
       
  1854     CleanupStack::Pop( preset );
       
  1855     }
       
  1856 
       
  1857 // ---------------------------------------------------------------------------
       
  1858 // CFMRadioAppUi::IsLandscapeOrientation
       
  1859 // ---------------------------------------------------------------------------
       
  1860 //
       
  1861 TBool CFMRadioAppUi::IsLandscapeOrientation() const
       
  1862     {
       
  1863     return iLandscape;
       
  1864     }
       
  1865 
       
  1866 // ---------------------------------------------------------------------------
       
  1867 // CFMRadioAppUi::ChooseLayoutResource
       
  1868 // ---------------------------------------------------------------------------
       
  1869 //
       
  1870 TInt CFMRadioAppUi::ChooseLayoutResource( TInt aNormalPortraitRes, 
       
  1871         TInt aMirroredPortraitRes, TInt aNormalLandscapeRes, 
       
  1872         TInt aMirroredLandscapeRes ) const
       
  1873     {
       
  1874     TInt resId = 0;
       
  1875     
       
  1876     if ( IsLandscapeOrientation() )
       
  1877         {
       
  1878         if ( AknLayoutUtils::LayoutMirrored() )
       
  1879             {
       
  1880             resId = aMirroredLandscapeRes;
       
  1881             }
       
  1882         else
       
  1883             {
       
  1884             resId = aNormalLandscapeRes;
       
  1885             }
       
  1886         }
       
  1887     else
       
  1888         {
       
  1889         if ( AknLayoutUtils::LayoutMirrored() )
       
  1890             {
       
  1891             resId = aMirroredPortraitRes;
       
  1892             }
       
  1893         else
       
  1894             {
       
  1895             resId = aNormalPortraitRes;
       
  1896             }
       
  1897         }
       
  1898     return resId;
       
  1899     }
       
  1900 
       
  1901 // ---------------------------------------------------------------------------
       
  1902 // CFMRadioAppUi::IsLayoutMirrored
       
  1903 // ---------------------------------------------------------------------------
       
  1904 //
       
  1905 TBool CFMRadioAppUi::IsLayoutMirrored() const
       
  1906     {
       
  1907     return AknLayoutUtils::LayoutMirrored();
       
  1908     }
       
  1909     
       
  1910 // ---------------------------------------------------------------------------
       
  1911 // CFMRadioAppUi::HandleFlightModeEnabledCallbackL
       
  1912 // Displays continue offline query.
       
  1913 // ---------------------------------------------------------------------------
       
  1914 //
       
  1915 void CFMRadioAppUi::HandleFlightModeEnabledCallbackL()
       
  1916     {
       
  1917     FTRACE( FPrint( _L("CFMRadioAppUi::HandleFlightModeEnabledCallbackL" ) ) );
       
  1918 
       
  1919     // If off-line profile is activated when no other app
       
  1920     // (that would disable auto resume) is playing (or has played)
       
  1921     // audio, a global confirmation query is displayed.
       
  1922     if ( iAudioResourceAvailable )
       
  1923         {
       
  1924         iRadioEngine->RadioOff();
       
  1925         
       
  1926         if ( !iGlobalOfflineQuery )
       
  1927             {
       
  1928             iGlobalOfflineQuery = CFMRadioGlobalConfirmationQuery::NewL( this );                                
       
  1929             }
       
  1930         
       
  1931         HBufC* text = StringLoader::LoadLC( R_QTN_FMRADIO_QUERY_OFFLINE_USE, iCoeEnv );
       
  1932         
       
  1933         iOfflineQueryDialogActivated = ETrue;
       
  1934         iGlobalOfflineQuery->ShowQueryL( *text, R_AVKON_SOFTKEYS_YES_NO, R_QGN_NOTE_QUERY_ANIM ); 
       
  1935         
       
  1936         CleanupStack::PopAndDestroy( text );
       
  1937         }
       
  1938             
       
  1939     // Do the next when offline query wasn't already on the screen.
       
  1940     // That could happen when user changes profiles without
       
  1941     // answering to the query.
       
  1942     else if (!iGlobalOfflineQuery || !iGlobalOfflineQuery->IsActive())
       
  1943         {
       
  1944         iOfflineProfileActivatedWhenRadioAudioDisabled = ETrue;
       
  1945         }
       
  1946     }
       
  1947 
       
  1948 // ---------------------------------------------------------------------------
       
  1949 // CFMRadioAppUi::HandleFlightModeDisabledCallback
       
  1950 // Close query dialog.
       
  1951 // ---------------------------------------------------------------------------
       
  1952 //
       
  1953 void CFMRadioAppUi::HandleFlightModeDisabledCallback()
       
  1954     {
       
  1955     FTRACE( FPrint( _L("CFMRadioAppUi::HandleFlightModeDisabledCallback" ) ) );
       
  1956     iOfflineProfileActivatedWhenRadioAudioDisabled = EFalse;
       
  1957     
       
  1958     // Close continue offline query
       
  1959     if ( iLocalContinueOfflineQuery && iLocalContinueOfflineQuery->IsVisible() )
       
  1960         {
       
  1961         TRAP_IGNORE( iLocalContinueOfflineQuery->DismissQueryL() );
       
  1962         }
       
  1963     // Close activate offline query
       
  1964     if ( iLocalActivateOfflineQuery && iLocalActivateOfflineQuery->IsVisible() )
       
  1965         {
       
  1966         TRAP_IGNORE( iLocalActivateOfflineQuery->DismissQueryL() );
       
  1967         }
       
  1968     }
       
  1969 
       
  1970 // ---------------------------------------------------------------------------
       
  1971 // CFMRadioAppUi::StaticStartupForegroundCallback
       
  1972 // takes care of some delayed initialisation
       
  1973 // ---------------------------------------------------------------------------
       
  1974 //
       
  1975 TInt CFMRadioAppUi::StaticStartupForegroundCallback( TAny* aSelfPtr )
       
  1976     {
       
  1977     CFMRadioAppUi* self = reinterpret_cast<CFMRadioAppUi*>( aSelfPtr );
       
  1978     if ( self )
       
  1979         {
       
  1980         delete self->iStartupForegroundCallback;
       
  1981         self->iStartupForegroundCallback = NULL;
       
  1982 
       
  1983         TRAPD( err, self->HandleStartupForegroundEventL() )
       
  1984         if ( err )
       
  1985             {
       
  1986             // Shutdown the application
       
  1987             CEikonEnv* eikonEnv = CEikonEnv::Static();
       
  1988             TApaTask task( eikonEnv->WsSession() );
       
  1989             task.SetWgId( eikonEnv->RootWin().Identifier() );
       
  1990             task.EndTask();
       
  1991             }
       
  1992         }
       
  1993     
       
  1994     return KErrNone;
       
  1995     }
       
  1996 
       
  1997 // ---------------------------------------------------------------------------
       
  1998 // CFMRadioAppUi::HandleStartupForegroundEventL
       
  1999 // Note that leaving from this fuction will cause exit of
       
  2000 // FM Radio (on purpose)!
       
  2001 // ---------------------------------------------------------------------------
       
  2002 //
       
  2003 void CFMRadioAppUi::HandleStartupForegroundEventL()
       
  2004     {
       
  2005     FTRACE( FPrint( _L("CFMRadioAppUi::HandleStartupForegroundEventL" ) ) );
       
  2006     HandleOfflineModeAtStartUpL();
       
  2007     TFMRadioRegionSetting region = HandleRegionsAtStartUpL();
       
  2008     iRadioEngine->SetRegionIdL( region );
       
  2009     HandlePendingViewActivationL();
       
  2010     iRadioEngine->RequestTunerControl();
       
  2011     }
       
  2012 
       
  2013 // ---------------------------------------------------------------------------
       
  2014 // CFMRadioAppUi::HandleOfflineModeAtStartUpL
       
  2015 // Handles offline mode at startup.
       
  2016 // ---------------------------------------------------------------------------
       
  2017 //	
       
  2018 void CFMRadioAppUi::HandleOfflineModeAtStartUpL()
       
  2019     {
       
  2020     FTRACE( FPrint( _L("CFMRadioAppUi::HandleOfflineModeAtStartUpL" ) ) );
       
  2021     if ( iRadioEngine->IsOfflineProfileL() )
       
  2022         {
       
  2023         iOfflineQueryDialogActivated = ETrue;
       
  2024         
       
  2025         if ( AknLayoutUtils::PenEnabled() )
       
  2026             {
       
  2027             // We must hide toolbar, otherwise query dialog softkeys doesn't work 
       
  2028             ShowToolbar( EFalse );
       
  2029             }
       
  2030         
       
  2031         iLocalActivateOfflineQuery = CAknQueryDialog::NewL();
       
  2032         TInt result = iLocalActivateOfflineQuery->ExecuteLD( R_FMRADIO_ACTIVATE_IN_OFFLINE_QUERY );
       
  2033         iLocalActivateOfflineQuery = NULL;
       
  2034         
       
  2035         iOfflineQueryDialogActivated = EFalse;
       
  2036        
       
  2037         if ( result )
       
  2038             {
       
  2039             if ( AknLayoutUtils::PenEnabled() )
       
  2040                 {
       
  2041                 ShowToolbar( ETrue );
       
  2042                 }
       
  2043             }
       
  2044         else
       
  2045             {
       
  2046             Exit();
       
  2047             }
       
  2048         }
       
  2049     }
       
  2050 
       
  2051 // ---------------------------------------------------------------------------
       
  2052 // CFMRadioAppUi::ShowToolbar
       
  2053 // Sets toolbar visibility. This function is used to hide toolbar component
       
  2054 // while query dialog is shown.
       
  2055 // ---------------------------------------------------------------------------
       
  2056 //
       
  2057 void CFMRadioAppUi::ShowToolbar( TBool aVisible )
       
  2058     {
       
  2059     FTRACE( FPrint( _L("CFMRadioAppUi::ShowToolbar(%d)"), aVisible ) );
       
  2060     if ( iLayoutChangeObserver == iMainView )
       
  2061         {
       
  2062         iMainView->ShowToolbar( aVisible );	
       
  2063         }
       
  2064     else if ( iLayoutChangeObserver == iScanLocalStationsView )
       
  2065         {
       
  2066         iScanLocalStationsView->ShowToolbar( aVisible );
       
  2067         }
       
  2068     }
       
  2069 
       
  2070 // ---------------------------------------------------------------------------
       
  2071 // CFMRadioAppUi::IsOfflineProfileActivatedWhenRadioAudioDisabled
       
  2072 // ---------------------------------------------------------------------------
       
  2073 //
       
  2074 TBool CFMRadioAppUi::IsOfflineProfileActivatedWhenRadioAudioDisabled() const
       
  2075     {
       
  2076     return iOfflineProfileActivatedWhenRadioAudioDisabled;
       
  2077     }
       
  2078 
       
  2079 // ---------------------------------------------------------------------------
       
  2080 // CFMRadioAppUi::HandleFMTransmitterOnCallback
       
  2081 // Displays note about transmitter being activated and
       
  2082 // fade the UI.
       
  2083 // ---------------------------------------------------------------------------
       
  2084 //
       
  2085 void CFMRadioAppUi::HandleFMTransmitterOnCallbackL()
       
  2086     {
       
  2087     FTRACE( FPrint( _L("CFMRadioAppUi::HandleFMTransmitterOnCallbackL()") ) );
       
  2088     iCurrentRadioState = EFMRadioStateOff;
       
  2089     
       
  2090     CAknGlobalNote* fmTransmitterGlobalNote = CAknGlobalNote::NewLC();
       
  2091     
       
  2092     if ( IsStartupWizardHandled() )
       
  2093         {
       
  2094         // Wizard is allready handled so this callback is not coming
       
  2095         // in startup phase
       
  2096         HBufC* closeAppText = StringLoader::LoadLC( R_QTN_FMRADIO_NOTE_FMTX_CLOSE_APPLICATION, iCoeEnv  );
       
  2097         fmTransmitterGlobalNote->ShowNoteL( EAknGlobalInformationNote, *closeAppText );
       
  2098         CleanupStack::PopAndDestroy( closeAppText );
       
  2099         }
       
  2100     else
       
  2101         {
       
  2102         HBufC* unableToStartText = StringLoader::LoadLC( R_QTN_FMRADIO_NOTE_FMTX_UNABLE_TO_START, iCoeEnv );
       
  2103         fmTransmitterGlobalNote->ShowNoteL( EAknGlobalInformationNote, *unableToStartText );
       
  2104         CleanupStack::PopAndDestroy( unableToStartText );
       
  2105         }
       
  2106     CleanupStack::PopAndDestroy( fmTransmitterGlobalNote );
       
  2107     // check if we have any dialogs open and close them manually
       
  2108     if ( IsDisplayingDialog() )
       
  2109         {
       
  2110         TKeyEvent key;
       
  2111         key.iRepeats = 0;
       
  2112         key.iCode = EKeyEscape;
       
  2113         key.iModifiers = 0;
       
  2114         
       
  2115         iCoeEnv->SimulateKeyEventL( key, EEventKey );
       
  2116         // in case there is still dialog on the screen 
       
  2117         if ( IsDisplayingDialog() )
       
  2118             {
       
  2119             iCoeEnv->SimulateKeyEventL( key, EEventKey );
       
  2120             }
       
  2121         }
       
  2122     // Shutdown the application
       
  2123     TApaTask task( iCoeEnv->WsSession() );
       
  2124     task.SetWgId( iCoeEnv->RootWin().Identifier() );
       
  2125     task.EndTask();
       
  2126     }
       
  2127 
       
  2128 // ---------------------------------------------------------------------------
       
  2129 // CFMRadioAppUi::HandleFreqRangeChangedCallback
       
  2130 // Frequency range changed.
       
  2131 // Current handling is to exit the application since
       
  2132 // the UI specification doesn't specify how this should
       
  2133 // be handled.
       
  2134 // ---------------------------------------------------------------------------
       
  2135 //
       
  2136 void CFMRadioAppUi::HandleFreqRangeChangedCallback()
       
  2137     {
       
  2138     FTRACE( FPrint( _L("CFMRadioAppUi::HandleFreqRangeChangedCallback()") ) );
       
  2139     iCurrentRadioState = EFMRadioStateOff;
       
  2140     Exit();
       
  2141     } 
       
  2142 // ---------------------------------------------------------------------------
       
  2143 // CFMRadioAppUi::HandleMuteCommand
       
  2144 // Handles mute keypress from main view
       
  2145 // ---------------------------------------------------------------------------
       
  2146 //
       
  2147 void CFMRadioAppUi::HandleMuteCommand()
       
  2148     {
       
  2149     FTRACE( FPrint( _L("CFMRadioAppUi::HandleMuteCommand" ) ) );
       
  2150     if ( iRadioEngine->IsMuteOn() )
       
  2151         {
       
  2152         iRadioEngine->SetMuteOn( EFalse );
       
  2153         }
       
  2154     else
       
  2155         {
       
  2156         iRadioEngine->SetMuteOn( ETrue );
       
  2157         }
       
  2158     }
       
  2159 
       
  2160 // ---------------------------------------------------------------------------
       
  2161 // CFMRadioAppUi::HandleRegionsAtStartUpL
       
  2162 // get region automatically from network or manually by user choice if network
       
  2163 // is not available
       
  2164 // ---------------------------------------------------------------------------
       
  2165 //
       
  2166 TFMRadioRegionSetting CFMRadioAppUi::HandleRegionsAtStartUpL()
       
  2167     {
       
  2168     FTRACE( FPrint( _L("CFMRadioAppUi::HandleRegionsAtStartUpL()")) );
       
  2169     TFMRadioRegionSetting region = iRadioEngine->GetRegionL();
       
  2170     
       
  2171     if ( region == EFMRadioRegionNone )
       
  2172         {
       
  2173         ShowToolbar( EFalse );
       
  2174         TInt index = 0;
       
  2175         
       
  2176         CDesCArraySeg* regionList = new( ELeave ) CDesCArraySeg( KDefaultRegionArrayGranularity );
       
  2177         CleanupStack::PushL( regionList );
       
  2178         
       
  2179         iRadioEngine->FillListWithRegionDataL( *regionList );
       
  2180         
       
  2181         CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &index );
       
  2182         
       
  2183         dlg->PrepareLC( R_FMRADIO_SELECT_REGION_QUERY );
       
  2184         CTextListBoxModel* model = 
       
  2185         static_cast<CAknListQueryControl*>( dlg->ListControl() )->listbox()->Model();
       
  2186         model->SetItemTextArray( regionList );
       
  2187         model->SetOwnershipType( ELbmDoesNotOwnItemArray ); // Array won't be deleted here
       
  2188             	
       
  2189         TInt ret = dlg->RunLD();
       
  2190         CleanupStack::PopAndDestroy( regionList );
       
  2191         
       
  2192         if ( ret != EAknSoftkeyExit )
       
  2193             {
       
  2194             // We should have a proper region selected by user
       
  2195             region = iRadioEngine->RegionIdAtIndex( index );
       
  2196             }
       
  2197         
       
  2198         if ( region == EFMRadioRegionNone )
       
  2199             {
       
  2200             Exit();// This will eventually exit FMRadio.
       
  2201             }
       
  2202         else
       
  2203             {
       
  2204             HBufC* bandSetText = StringLoader::LoadLC( R_QTN_FMRADIO_CONF_FREQ_BAND_SET_MANUAL, iCoeEnv );
       
  2205             CAknInformationNote* note = new( ELeave ) CAknInformationNote( ETrue );
       
  2206             note->ExecuteLD( *bandSetText );
       
  2207             CleanupStack::PopAndDestroy( bandSetText );
       
  2208             if ( AknLayoutUtils::PenEnabled() )
       
  2209                 {
       
  2210                 ShowToolbar( ETrue );
       
  2211                 }
       
  2212             }
       
  2213         }
       
  2214     else
       
  2215         {
       
  2216         // Region is known        
       
  2217         if ( region != iRadioEngine->RegionId() )
       
  2218             {
       
  2219             TInt previousRegion = iRadioEngine->RegionId();
       
  2220             
       
  2221            if ( previousRegion != EFMRadioRegionNone )
       
  2222                 {
       
  2223                 // Show note only if the region has changed from a concrete 
       
  2224                 // one to another concrete one. EFMRadioRegionNone is not 
       
  2225                 // a concrete one (first startup case) -- don't show note.
       
  2226                 iRegionChanged = ETrue;
       
  2227                 HBufC* bandSetText = StringLoader::LoadLC( R_QTN_FMRADIO_CONF_FREQ_BAND_SET_AUTOM, iCoeEnv );
       
  2228                 CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );			    
       
  2229                 note->ExecuteLD( *bandSetText );
       
  2230                 CleanupStack::PopAndDestroy( bandSetText );
       
  2231                 }
       
  2232             }
       
  2233         }
       
  2234     return region;
       
  2235     }
       
  2236 
       
  2237 // ---------------------------------------------------------------------------
       
  2238 // From class MFMRadioGlobalConfirmationQueryObserver. Callback function 
       
  2239 // that is called when global confirmation query is dismissed.
       
  2240 // CFMRadioAppUi::GlobalConfirmationQueryDismissedL
       
  2241 // ---------------------------------------------------------------------------
       
  2242 //
       
  2243 void CFMRadioAppUi::GlobalConfirmationQueryDismissedL(TInt aSoftKey)
       
  2244     {
       
  2245     FTRACE( FPrint( _L("CFMRadioAppUi::GlobalConfirmationQueryDismissedL()")) );
       
  2246     iOfflineQueryDialogActivated = EFalse;
       
  2247     
       
  2248     if ( aSoftKey == EAknSoftkeyYes )
       
  2249         {
       
  2250         iOfflineProfileActivatedWhenRadioAudioDisabled = EFalse;
       
  2251         iRadioEngine->RadioOn();
       
  2252         HandlePendingViewActivationL();
       
  2253         }    
       
  2254     else
       
  2255         {
       
  2256         // Shutdown the application
       
  2257         TApaTask task( iCoeEnv->WsSession() );
       
  2258         task.SetWgId( iCoeEnv->RootWin().Identifier() );
       
  2259         task.EndTask();
       
  2260         }
       
  2261     }
       
  2262 
       
  2263 // ---------------------------------------------------------------------------
       
  2264 // CFMRadioAppUi::NumberOfChannelsStored
       
  2265 // return number of channels saved to the presets
       
  2266 // ---------------------------------------------------------------------------
       
  2267 //    
       
  2268 TInt CFMRadioAppUi::NumberOfChannelsStored() const
       
  2269     {
       
  2270     FTRACE( FPrint( _L("CFMRadioAppUi::NumberOfChannelsStored()")) );
       
  2271     return iChannels.Count();
       
  2272     }
       
  2273 
       
  2274 // ---------------------------------------------------------------------------
       
  2275 // CFMRadioAppUi::HandleStartupWizard
       
  2276 // Determine if "Scan all channels" in scan local stations view should be started.
       
  2277 // ---------------------------------------------------------------------------
       
  2278 // 
       
  2279 void CFMRadioAppUi::HandleStartupWizardL()
       
  2280     {
       
  2281     FTRACE( FPrint( _L("CFMRadioAppUi::HandleStartupWizardL()")) );
       
  2282     if ( !IsStartupWizardHandled() || iRegionChanged )
       
  2283         {
       
  2284         // Call to iRadioEngine->UpdatedStartupCount()
       
  2285         // increases startup count by one and returns amount of app startups.
       
  2286         TInt startupCount = iRadioEngine->UpdatedStartupCount();
       
  2287         if ( startupCount <= KMaxStartupTimesToAskSaveWizard &&
       
  2288                 NumberOfChannelsStored() == 0 )
       
  2289             {
       
  2290             SetStartupWizardRunning( ETrue );
       
  2291             ActivateLocalViewL( iScanLocalStationsView->Id() );
       
  2292             }
       
  2293         else if ( iRegionChanged ) //force rescan
       
  2294             {
       
  2295             iRegionChanged = EFalse;
       
  2296             UpdateChannelsL( ERemoveAllFromRepository, 0, 0 );
       
  2297             SetStartupWizardRunning( ETrue );
       
  2298             ActivateLocalViewL( iScanLocalStationsView->Id() );
       
  2299             }
       
  2300         else // check IAD update here
       
  2301             {
       
  2302             HandleIADUpdateCheckL();
       
  2303             }
       
  2304         }
       
  2305     }
       
  2306 
       
  2307 // --------------------------------------------------------------------------
       
  2308 // CFMRadioAppUi::IsStartupWizardRunning
       
  2309 // Return startup scanning wizard status.
       
  2310 // ---------------------------------------------------------------------------
       
  2311 // 	
       
  2312 TBool CFMRadioAppUi::IsStartupWizardRunning() const
       
  2313     {
       
  2314     return iStartupWizardRunning;
       
  2315     }
       
  2316 
       
  2317 // ---------------------------------------------------------------------------
       
  2318 // CFMRadioAppUi::SetStartupWizardRunning
       
  2319 // Set startup scanning wizard status.
       
  2320 // ---------------------------------------------------------------------------
       
  2321 // 
       
  2322 void CFMRadioAppUi::SetStartupWizardRunning( const TBool aRunningState )
       
  2323     {
       
  2324     FTRACE( FPrint( _L("CFMRadioAppUi::SetStartupWizardRunning() - state = %d"), aRunningState) );
       
  2325     iStartupWizardRunning = aRunningState;	
       
  2326     }
       
  2327 
       
  2328 // ---------------------------------------------------------------------------
       
  2329 // CFMRadioAppUi::StartLocalStationsSeekL
       
  2330 // Start local stations scan
       
  2331 // ---------------------------------------------------------------------------
       
  2332 // 
       
  2333 void CFMRadioAppUi::StartLocalStationsSeekL()
       
  2334     {
       
  2335     FTRACE( FPrint( _L("CFMRadioAppUi::StartLocalStationsSeekL()")) );
       
  2336     iCurrentRadioState = EFMRadioStateBusyScanLocalStations;
       
  2337     iRadioEngine->ScanUp();
       
  2338     }
       
  2339 
       
  2340 // ---------------------------------------------------------------------------
       
  2341 // CFMRadioAppUi::TryToResumeAudioL
       
  2342 // Show Audio Preempted query
       
  2343 // ---------------------------------------------------------------------------
       
  2344 // 
       
  2345 void CFMRadioAppUi::TryToResumeAudioL()
       
  2346     {
       
  2347     FTRACE( FPrint( _L("CFMRadioAppUi::TryToResumeAudioL" ) ) );
       
  2348     TFMRadioRegionSetting region = iRadioEngine->GetRegionL();
       
  2349     if ( iAudioLost && 
       
  2350          IsForeground() &&
       
  2351          !iOfflineQueryDialogActivated && 
       
  2352          region != EFMRadioRegionNone )
       
  2353         {
       
  2354         iAudioLost = EFalse;
       
  2355         TurnRadioOn();
       
  2356         }
       
  2357     }
       
  2358     
       
  2359 // ---------------------------------------------------------------------------
       
  2360 // CFMRadioAppUi::ShowConnectHeadsetDialogL
       
  2361 // Show connect headset query with only exit softkey
       
  2362 // ---------------------------------------------------------------------------
       
  2363 // 	
       
  2364 void CFMRadioAppUi::ShowConnectHeadsetDialogL()
       
  2365     {
       
  2366     FTRACE( FPrint( _L("CFMRadioAppUi::ShowConnectHeadsetDialogL" ) ) );
       
  2367     if ( !iConnectHeadsetQuery && !iConnectHeadsetGlobalNote )
       
  2368         {
       
  2369         HBufC* noteTxt = StringLoader::LoadLC( R_QTN_FMRADIO_ERROR_CON_HEADSET, iCoeEnv  );
       
  2370         
       
  2371         // if radio is in background, show also global note	
       
  2372         if ( !IsForeground() )
       
  2373             {
       
  2374             iConnectHeadsetGlobalNote = CAknGlobalNote::NewL();
       
  2375             iConnectHeadsetGlobalNote->ShowNoteL( EAknGlobalInformationNote, *noteTxt );
       
  2376             delete iConnectHeadsetGlobalNote;
       
  2377             iConnectHeadsetGlobalNote = NULL;
       
  2378             }
       
  2379         
       
  2380         iConnectHeadsetQuery = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );									
       
  2381         TInt ret = iConnectHeadsetQuery->ExecuteLD( R_FMRADIO_CONNECT_HEADSET_NOTE, *noteTxt );
       
  2382             
       
  2383         CleanupStack::PopAndDestroy( noteTxt );
       
  2384         FTRACE( FPrint( _L("CFMRadioAppUi::ShowConnectHeadsetDialogL() return value from dialog: %d"), ret ) );
       
  2385         if ( iConnectHeadsetQuery )
       
  2386             {
       
  2387             iConnectHeadsetQuery = NULL;
       
  2388             if ( ret == EAknSoftkeyExit || ret == EAknSoftkeyOk )
       
  2389                 {
       
  2390                 TApaTask task( iCoeEnv->WsSession() );
       
  2391                 task.SetWgId( iCoeEnv->RootWin().Identifier() );
       
  2392                 task.EndTask();
       
  2393                 }
       
  2394             else
       
  2395                 {
       
  2396                 HandlePendingViewActivationL();
       
  2397                 }
       
  2398             }
       
  2399         }
       
  2400     }
       
  2401 
       
  2402 // ---------------------------------------------------------------------------
       
  2403 // CFMRadioAppUi::ShowVolumePopupL
       
  2404 // Show currently active volume popup
       
  2405 // ---------------------------------------------------------------------------
       
  2406 // 
       
  2407 void CFMRadioAppUi::ShowVolumePopupL()
       
  2408     {
       
  2409     FTRACE( FPrint( _L("CFMRadioAppUi::ShowVolumePopupL" ) ) );
       
  2410     if ( !iRadioEngine->IsInCall() )
       
  2411         {
       
  2412         if ( iActiveVolumePopupControl )
       
  2413             {
       
  2414             if ( IsForeground() || ( IsActiveIdleEnabled() && IsIdleAppForeground() ) )
       
  2415                 {
       
  2416                 iActiveVolumePopupControl->ShowVolumePopupL();
       
  2417                 }
       
  2418             }
       
  2419         }
       
  2420     }
       
  2421 
       
  2422 // ---------------------------------------------------------------------------
       
  2423 // CFMRadioAppUi::GetCurrentHelpContext
       
  2424 // get help context based on currently active view
       
  2425 // ---------------------------------------------------------------------------
       
  2426 //	
       
  2427 CArrayFix<TCoeHelpContext>* CFMRadioAppUi::GetCurrentHelpContextL() const
       
  2428     {
       
  2429     FTRACE( FPrint( _L("CFMRadioAppUi::GetCurrentHelpContextL" ) ) );
       
  2430 #if defined __SERIES60_HELP || defined FF_S60_HELPS_IN_USE
       
  2431     // currently main container and manual tuning container are derived from CBase
       
  2432     // so lets create help array manually for them
       
  2433         CArrayFixFlat<TCoeHelpContext>* helpArray = new( ELeave )
       
  2434         CArrayFixFlat<TCoeHelpContext>( 1 );
       
  2435         CleanupStack::PushL( helpArray );
       
  2436         helpArray->AppendL( TCoeHelpContext( TUid::Uid( KUidFMRadioApplication ), KFMRADIO_HLP_MAIN ) );
       
  2437         CleanupStack::Pop( helpArray );
       
  2438         return helpArray;
       
  2439 #else
       
  2440     return AppHelpContextL();
       
  2441 #endif
       
  2442 }
       
  2443 
       
  2444 // ---------------------------------------------------------------------------
       
  2445 // CFMRadioChannelListView::GetChannelsArrayL
       
  2446 // Get channels array list from radio engine
       
  2447 // ---------------------------------------------------------------------------
       
  2448 //
       
  2449 void CFMRadioAppUi::GetChannelsArrayL()
       
  2450     {
       
  2451     FTRACE( FPrint( _L("CFMRadioChannelListView::GetChannelsArrayL  Start") ) );
       
  2452     
       
  2453     // Note: KMaxNumberOfChannelListItems can be setted to any supported max value
       
  2454     for ( TInt index = 0; index < KMaxNumberOfChannelListItems; index++ )
       
  2455         {
       
  2456         TBuf<KPresetNameLength> chName;
       
  2457         TInt chFrequency;
       
  2458         
       
  2459         iRadioEngine->GetPresetNameAndFrequencyL( index,
       
  2460                                                   chName, 
       
  2461                                                   chFrequency );
       
  2462 
       
  2463         if ( chFrequency != KErrNotFound )
       
  2464             {
       
  2465             FTRACE( FPrint( _L("CFMRadioChannelListView::ChannelInUse  inside if") ) );
       
  2466             CFMRadioPreset* preset = CFMRadioPreset::NewL();
       
  2467             CleanupStack::PushL( preset );
       
  2468             preset->SetPresetNameL( chName );
       
  2469             preset->SetPresetFrequency( chFrequency );
       
  2470             
       
  2471             RBuf url;
       
  2472             url.CleanupClosePushL();
       
  2473             url.CreateL( KFMRadioWebLinkMaxLength );
       
  2474             TInt err = iRadioEngine->PresetUrlL( index, url );
       
  2475             if ( !err )
       
  2476                 {
       
  2477                 preset->SetPresetUrlL( url );
       
  2478                 }
       
  2479             
       
  2480             iChannels.AppendL( preset );
       
  2481             CleanupStack::PopAndDestroy( &url );
       
  2482             CleanupStack::Pop( preset );
       
  2483             }
       
  2484         }
       
  2485     }
       
  2486 
       
  2487 // ---------------------------------------------------------------------------
       
  2488 // From class CEikAppUi.
       
  2489 // Handles window server messages.
       
  2490 // ---------------------------------------------------------------------------
       
  2491 //
       
  2492 MCoeMessageObserver::TMessageResponse CFMRadioAppUi::HandleMessageL( 
       
  2493         TUint32 aClientHandleOfTargetWindowGroup, TUid aMessageUid, 
       
  2494         const TDesC8& aMessageParameters )
       
  2495     {
       
  2496     FTRACE(FPrint(_L(" *** S60 FMRadio-- CFMRadioAppUi::HandleMessageL" )));
       
  2497 
       
  2498     TMessageResponse resp = CAknViewAppUi::HandleMessageL( 
       
  2499         aClientHandleOfTargetWindowGroup, aMessageUid, aMessageParameters );
       
  2500         
       
  2501     if ( resp == EMessageNotHandled && aMessageUid == TUid::Uid( KUidFMRadioApplication ) )
       
  2502         {
       
  2503         ProcessCommandTailL( aMessageParameters );
       
  2504         resp = EMessageHandled;
       
  2505         }
       
  2506 
       
  2507     return resp;
       
  2508     }
       
  2509 
       
  2510 // ---------------------------------------------------------------------------
       
  2511 // CFMRadioAppUi::ProcessCommandParametersL
       
  2512 // Processes the shell commands
       
  2513 // ---------------------------------------------------------------------------
       
  2514 //
       
  2515 TBool CFMRadioAppUi::ProcessCommandParametersL( TApaCommand aCommand, 
       
  2516                                                 TFileName& aDocumentName, 
       
  2517                                                 const TDesC8& aTail )
       
  2518     {
       
  2519     FTRACE(FPrint(_L("CFMRadioAppUi::ProcessCommandParametersL(%d, %S)" ), aCommand, &aTail ));
       
  2520     SecondaryConstructL();
       
  2521     
       
  2522     TBool ret = CAknViewAppUi::ProcessCommandParametersL( aCommand, aDocumentName, aTail );
       
  2523     ProcessCommandTailL( aTail );
       
  2524 
       
  2525     return ret;
       
  2526     }
       
  2527 
       
  2528 // ---------------------------------------------------------------------------
       
  2529 // CFMRadioAppUi::ProcessCommandParametersL
       
  2530 // Processes the command tail in any situation
       
  2531 // ---------------------------------------------------------------------------
       
  2532 //
       
  2533 void CFMRadioAppUi::ProcessCommandTailL( const TDesC8& aTail )
       
  2534     {
       
  2535     TLex8 tailLex( aTail );
       
  2536     if ( tailLex.Peek() != 0 )
       
  2537         {
       
  2538         TPtrC8 command = tailLex.NextToken();
       
  2539         if ( command == KFMRadioCommandFrequency )
       
  2540             {
       
  2541             // tune to frequency
       
  2542             TLex8 frequencyLex( tailLex.NextToken() );
       
  2543             TInt32 frequency = 0;
       
  2544             TInt min = 0;
       
  2545             TInt max = 0;
       
  2546             iRadioEngine->GetFrequencyBandRange( min, max );
       
  2547             TInt ret = frequencyLex.BoundedVal( frequency, max );
       
  2548             if ( ret == KErrNone && frequency >= min )
       
  2549                 {
       
  2550                 iRadioEngine->CancelScan();
       
  2551                 TuneL( frequency );
       
  2552                 }
       
  2553             }
       
  2554         else if ( command == KFMRadioCommandStationIndex )
       
  2555             {
       
  2556             // tune to station index
       
  2557             TLex8 indexLex( tailLex.NextToken() );
       
  2558             TInt32 index = 0;
       
  2559             TInt ret = indexLex.BoundedVal( index, iChannels.Count() - 1 );
       
  2560             if ( ret == KErrNone && index >= 0 )
       
  2561                 {
       
  2562                 iRadioEngine->CancelScan();
       
  2563                 PlayChannel( index );
       
  2564                 }
       
  2565             }
       
  2566         else if( command == KFMRadioCommandActivateView )
       
  2567             {
       
  2568             TLex8 viewIdLex( tailLex.NextToken() );
       
  2569             TInt viewId = 0;
       
  2570             TInt ret = viewIdLex.Val( viewId );
       
  2571             if ( ret == KErrNone )
       
  2572                 {
       
  2573                 TUid uid = TUid::Uid( viewId );
       
  2574                 CAknView* view = View( uid );
       
  2575                 // Currently this API supports only activating main view or channel list view
       
  2576                 if ( view && ( uid == KFMRadioMainViewId || uid == KFMRadioChannelListViewId ) )
       
  2577                     {
       
  2578                     if ( iStartUp )
       
  2579                         {
       
  2580                         SetDefaultViewL( *view );
       
  2581                         }
       
  2582                     else
       
  2583                         {
       
  2584                         TFMRadioRegionSetting region = iRadioEngine->GetRegionL();  
       
  2585                         
       
  2586                         if ( iOfflineQueryDialogActivated || 
       
  2587                              iConnectHeadsetQuery || 
       
  2588                              region == EFMRadioRegionNone )
       
  2589                             {
       
  2590                             iPendingViewId = view->Id(); 
       
  2591                             }
       
  2592                         else
       
  2593                             {
       
  2594                             iChannelListView->CancelMoveL();
       
  2595                             ActivateLocalViewL( view->Id() );
       
  2596                             }
       
  2597                         TApaTask task( iCoeEnv->WsSession() );
       
  2598                         task.SetWgId( iCoeEnv->RootWin().Identifier() );
       
  2599                         task.BringToForeground();
       
  2600                         }
       
  2601                     }
       
  2602                 }
       
  2603             }
       
  2604         else
       
  2605             {
       
  2606             }
       
  2607         }
       
  2608     }
       
  2609 
       
  2610 // ---------------------------------------------------------------------------
       
  2611 // CFMRadioAppUi::Channels
       
  2612 // Returns channels array
       
  2613 // ---------------------------------------------------------------------------
       
  2614 //
       
  2615 RPointerArray<CFMRadioPreset>& CFMRadioAppUi::Channels()
       
  2616 	{
       
  2617 	return iChannels;
       
  2618 	}
       
  2619 
       
  2620 // ---------------------------------------------------------------------------
       
  2621 // CFMRadioAppUi::HandleIADUpdateCheckL
       
  2622 // Initialize software update check using IAD api
       
  2623 // ---------------------------------------------------------------------------
       
  2624 //
       
  2625 void CFMRadioAppUi::HandleIADUpdateCheckL()
       
  2626     {
       
  2627     FTRACE( FPrint( _L("CFMRadioAppUi::HandleIADUpdateCheckL") ) );
       
  2628     if ( FeatureManager::FeatureSupported( KFeatureIdIAUpdate ) )
       
  2629         {
       
  2630         FTRACE( FPrint( _L("CFMRadioAppUi::HandleIADUpdateCheckL - KFeatureIdIAUpdate supported") ) );
       
  2631         TRAPD( err, iUpdate = CIAUpdate::NewL( *this ) )
       
  2632         if ( err && err != KErrNotSupported )
       
  2633             {
       
  2634             User::Leave( err );
       
  2635             }
       
  2636         if ( !err )
       
  2637             {
       
  2638             iParameters = CIAUpdateParameters::NewL();
       
  2639             // Use SIS package UID
       
  2640             iParameters->SetUid( TUid::Uid( KUidFMRadioApplication ) );
       
  2641             iUpdate->CheckUpdates( *iParameters );
       
  2642             }
       
  2643         }
       
  2644     }
       
  2645 
       
  2646 // ---------------------------------------------------------------------------
       
  2647 // CFMRadioAppUi::CheckUpdatesComplete
       
  2648 // from base class MIAUpdateObserver
       
  2649 // ---------------------------------------------------------------------------
       
  2650 //
       
  2651 void CFMRadioAppUi::CheckUpdatesComplete( TInt aErrorCode, TInt aAvailableUpdates )
       
  2652     {
       
  2653     FTRACE( FPrint( _L("CFMRadioAppUi::CheckUpdatesComplete(%d, %d)"), aErrorCode, aAvailableUpdates ) );
       
  2654     if ( aErrorCode == KErrNone )
       
  2655         {
       
  2656         if ( aAvailableUpdates > 0 )
       
  2657             {
       
  2658             // There were some updates available. Let's ask if the user wants to update them.
       
  2659             iUpdate->UpdateQuery();
       
  2660             }
       
  2661         else
       
  2662             {
       
  2663             // No updates available. CIAUpdate object could be deleted already now, since we are not
       
  2664             // going to call anything else from the API. This will also close down the IAUpdate server.
       
  2665             delete iUpdate;
       
  2666             iUpdate = NULL;
       
  2667             delete iParameters;
       
  2668             iParameters = NULL;
       
  2669             }
       
  2670         }
       
  2671     }
       
  2672 
       
  2673 // ---------------------------------------------------------------------------
       
  2674 // CFMRadioAppUi::UpdateComplete
       
  2675 // from base class MIAUpdateObserver
       
  2676 // ---------------------------------------------------------------------------
       
  2677 //
       
  2678 void CFMRadioAppUi::UpdateComplete( TInt FDEBUGVAR( aErrorCode ), CIAUpdateResult* aResultDetails )
       
  2679     {
       
  2680     FTRACE( FPrint( _L("CFMRadioAppUi::UpdateComplete(%d)"), aErrorCode ) );
       
  2681     // The update process that the user started from IAUpdate UI is now completed.
       
  2682     // If the client application itself was updated in the update process, this callback
       
  2683     // is never called, since the client is not running anymore.
       
  2684 
       
  2685     delete aResultDetails; // Ownership was transferred, so this must be deleted by the client
       
  2686 
       
  2687     // We do not need the client-server session anymore, let's delete the object to close the session
       
  2688     delete iUpdate;
       
  2689     iUpdate = NULL;
       
  2690     delete iParameters;
       
  2691     iParameters = NULL;	
       
  2692     }
       
  2693 
       
  2694 // ---------------------------------------------------------------------------
       
  2695 // CFMRadioAppUi::UpdateQueryComplete
       
  2696 // from base class MIAUpdateObserver
       
  2697 // ---------------------------------------------------------------------------
       
  2698 //	
       
  2699 void CFMRadioAppUi::UpdateQueryComplete( TInt aErrorCode, TBool aUpdateNow )			
       
  2700     {
       
  2701     FTRACE( FPrint( _L("CFMRadioAppUi::UpdateQueryComplete(%d, %d)"), aErrorCode, aUpdateNow ) );
       
  2702     if ( aErrorCode == KErrNone )
       
  2703         {
       
  2704         if ( aUpdateNow )
       
  2705             {
       
  2706             // User choosed to update now, so let's launch the IAUpdate UI.
       
  2707             iUpdate->ShowUpdates( *iParameters );
       
  2708             }
       
  2709         else
       
  2710             {
       
  2711             // The answer was 'Later'. CIAUpdate object could be deleted already now, since we are not
       
  2712             // going to call anything else from the API. This will also close down the IAUpdate server.
       
  2713             delete iUpdate;
       
  2714             iUpdate = NULL;
       
  2715             delete iParameters;
       
  2716             iParameters = NULL;
       
  2717             }
       
  2718         }
       
  2719     }
       
  2720 
       
  2721 // ---------------------------------------------------------------------------
       
  2722 // CFMRadioAppUi::AutoTuneInMainView
       
  2723 // Set autotune true, if scan is interrupted
       
  2724 // ---------------------------------------------------------------------------
       
  2725 //	
       
  2726 void CFMRadioAppUi::AutoTuneInMainView ( TBool /*aTune*/ )
       
  2727     {
       
  2728     FTRACE( FPrint( _L("CFMRadioAppUi::AutoTuneInMainView()")));
       
  2729     }
       
  2730 
       
  2731 // ---------------------------------------------------------------------------
       
  2732 // CFMRadioAppUi::IsStartupWizardHandled
       
  2733 // ---------------------------------------------------------------------------
       
  2734 //
       
  2735 TBool CFMRadioAppUi::IsStartupWizardHandled() const
       
  2736     {
       
  2737     return iStartupWizardHandled;
       
  2738     }
       
  2739 
       
  2740 // -----------------------------------------------------------------------------
       
  2741 // Check if Active Idle app is on foreground
       
  2742 // -----------------------------------------------------------------------------
       
  2743 //
       
  2744 TBool CFMRadioAppUi::IsIdleAppForeground()
       
  2745     {
       
  2746     FTRACE( FPrint( _L( "CFMRadioAppUi::IsIdleAppForeground" ) ) );
       
  2747     TBool isIdleActive( EFalse );
       
  2748     // Gets the window group id of the app in foreground
       
  2749     RWsSession& wsSession = iCoeEnv->Static()->WsSession();
       
  2750     TInt windowGroupId = wsSession.GetFocusWindowGroup();
       
  2751     if ( windowGroupId >= 0 )
       
  2752         {
       
  2753         TRAP_IGNORE(
       
  2754             {
       
  2755             CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(
       
  2756                 wsSession, windowGroupId );
       
  2757             
       
  2758             isIdleActive = ( wgName->AppUid() == KFMRadioUidIdleApp );
       
  2759             delete wgName;
       
  2760             } );
       
  2761         }
       
  2762     return isIdleActive;
       
  2763     }
       
  2764 
       
  2765 // -----------------------------------------------------------------------------
       
  2766 // Check if Active Idle is enabled
       
  2767 // -----------------------------------------------------------------------------
       
  2768 //
       
  2769 TBool CFMRadioAppUi::IsActiveIdleEnabled()
       
  2770     {
       
  2771     FTRACE( FPrint( _L( "CFMRadioAppUi::IsActiveIdleEnabled" ) ) );
       
  2772     TBool res( EFalse );
       
  2773 
       
  2774 #ifdef __ACTIVE_IDLE
       
  2775     if (! FeatureManager::FeatureSupported( KFeatureIdActiveIdle ) )
       
  2776         return EFalse;
       
  2777 #endif
       
  2778     if ( !iSettingsRepository )
       
  2779         {
       
  2780         TRAP_IGNORE(
       
  2781             {
       
  2782             iSettingsRepository = CRepository::NewL(
       
  2783                 KCRUidPersonalizationSettings );
       
  2784             } );
       
  2785         }
       
  2786 
       
  2787     if ( iSettingsRepository )
       
  2788         {
       
  2789         TInt value( 0 );
       
  2790         TInt err( iSettingsRepository->Get( KSettingsActiveIdleState, value ) );
       
  2791         if ( !err && value )
       
  2792             {
       
  2793             res = ETrue;
       
  2794             }
       
  2795         }
       
  2796     return res;
       
  2797     }
       
  2798 
       
  2799 // ---------------------------------------------------------
       
  2800 // CFMRadioAppUi::MatchingChannel
       
  2801 // Return the index of the first channel that matches the
       
  2802 // frequency specified.
       
  2803 // ---------------------------------------------------------
       
  2804 //
       
  2805 TInt CFMRadioAppUi::MatchingChannelL( TInt aFrequency )
       
  2806     {
       
  2807     TInt channelIndex = KErrNotFound;
       
  2808     TInt numberOfChannels = iChannels.Count();
       
  2809     
       
  2810     for ( TInt i = 0; i < numberOfChannels; i++ )
       
  2811         {
       
  2812         TInt presetFrequency = iChannels[ i ]->PresetFrequency();
       
  2813         
       
  2814         if ( aFrequency == presetFrequency )
       
  2815             {
       
  2816             channelIndex = i;
       
  2817             break;
       
  2818             }
       
  2819         }
       
  2820     FTRACE(FPrint(_L("CFMRadioAppUi::MatchingChannel i[%d] aFrequency[%d]"), channelIndex, aFrequency));
       
  2821     return channelIndex;
       
  2822     }
       
  2823 
       
  2824 // ---------------------------------------------------------
       
  2825 // CFMRadioAppUi::HandlePendingViewActivationL
       
  2826 // Activates the view that is pending
       
  2827 // ---------------------------------------------------------
       
  2828 //
       
  2829 void CFMRadioAppUi::HandlePendingViewActivationL()
       
  2830     {
       
  2831     if ( iPendingViewId != TUid::Null() )
       
  2832         {
       
  2833         ActivateLocalViewL( iPendingViewId );
       
  2834         iPendingViewId == TUid::Null();
       
  2835         }
       
  2836     }
       
  2837 
       
  2838 // ---------------------------------------------------------
       
  2839 // CFMRadioAppUi::ActiveVolumePopup
       
  2840 // ---------------------------------------------------------
       
  2841 //
       
  2842 CAknVolumePopup* CFMRadioAppUi::ActiveVolumePopup() const
       
  2843     {
       
  2844     return iActiveVolumePopupControl;
       
  2845     }
       
  2846 
       
  2847 // ---------------------------------------------------------
       
  2848 // CFMRadioAppUi::RadioState
       
  2849 // ---------------------------------------------------------
       
  2850 //
       
  2851 CFMRadioAppUi::TRadioState CFMRadioAppUi::RadioState() const
       
  2852     {
       
  2853     return iCurrentRadioState;
       
  2854     }
       
  2855 	
       
  2856 // End of File