fmradio/fmradio/src/fmradioscanlocalstationsview.cpp
branchRCL_3
changeset 20 93c594350b9a
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of the class CFMRadioScanLocalStationsView
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AknWaitDialog.h> 
       
    21 #include <featmgr.h>
       
    22 #include <aknViewAppUi.h>
       
    23 #include <aknnotedialog.h>
       
    24 #include <akntitle.h>
       
    25 #include <aknnotewrappers.h> // for basic note
       
    26 #include <aknbutton.h>
       
    27 #include <avkon.hrh>
       
    28 #include <avkon.rsg>
       
    29 #include <StringLoader.h>
       
    30 #include <eikmenup.h>
       
    31 #include <eikbtgpc.h>
       
    32 #include <fmradio.rsg>
       
    33 #include <fmradio.mbg>
       
    34 #include <fmradiouids.h>
       
    35 #include <data_caging_path_literals.hrh>
       
    36 #include <akntoolbar.h>
       
    37 
       
    38 #include "fmradiobacksteppingservicewrapper.h"
       
    39 #include "fmradioengine.h"
       
    40 #include "fmradiordsreceiverbase.h"
       
    41 #include "fmradio.hrh"
       
    42 #include "fmradioscanlocalstationsview.h"
       
    43 #include "fmradiopreset.h"
       
    44 #include "fmradioscanlocalstationscontainer.h"
       
    45 #include "debug.h"
       
    46 #include "fmradioappui.h"
       
    47 
       
    48 
       
    49 const TInt KMSKControlID(3);
       
    50 
       
    51 // ================= MEMBER FUNCTIONS =======================
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CFMRadioScanLocalStationsView::NewL
       
    55 // Two-phase constructor of CFMRadioScanLocalStationsView
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CFMRadioScanLocalStationsView* CFMRadioScanLocalStationsView::NewL( CRadioEngine& aRadioEngine,
       
    59 		MChannelListHandler& aObserver )
       
    60     {
       
    61     CFMRadioScanLocalStationsView* self = new (ELeave) CFMRadioScanLocalStationsView( aRadioEngine, 
       
    62     		aObserver );
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop( self );
       
    66     return self; 
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CFMRadioScanLocalStationsView::CFMRadioScanLocalStationsView
       
    71 // Parameter constructor ( default constructor )
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CFMRadioScanLocalStationsView::CFMRadioScanLocalStationsView( CRadioEngine& aRadioEngine,
       
    75     MChannelListHandler& aObserver ):
       
    76     iNowPlayingIndex( KErrNotFound ),
       
    77     iScanAndSaveActivated( EFalse ),
       
    78     iScanCancelled( EFalse ),
       
    79     iRadioEngine( aRadioEngine ),
       
    80     iTuneRequested( EFalse ),
       
    81     iObserver( aObserver ),
       
    82     iCancelType( EFMRadioCancelScanDefault )
       
    83     {
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CFMRadioScanLocalStationsView::ConstructL
       
    88 // EPOC two-phased constructor
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CFMRadioScanLocalStationsView::ConstructL()
       
    92     {
       
    93     BaseConstructL( R_FMRADIO_SEARCH_STATIONS_VIEW );
       
    94     PrepareToolbar();
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CFMRadioScanLocalStationsView::~CFMRadioScanLocalStationsView
       
    99 // Class destructor
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CFMRadioScanLocalStationsView::~CFMRadioScanLocalStationsView()
       
   103     {
       
   104     if ( iContainer )
       
   105         {
       
   106         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   107         delete iContainer;
       
   108     	iContainer = NULL;
       
   109         }
       
   110     
       
   111     if ( iScanningNote )
       
   112     	{
       
   113     	TRAP_IGNORE( iScanningNote->ProcessFinishedL() );
       
   114     	iScanningNote = NULL;
       
   115     	}
       
   116     iScannedChannels.ResetAndDestroy();
       
   117     iScannedChannels.Close();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CFMRadioScanLocalStationsView::Id
       
   122 // Return the unique identifier corresponding to this view
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 TUid CFMRadioScanLocalStationsView::Id() const
       
   126     {
       
   127     return KFMRadioScanLocalStationsViewId;
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CFMRadioScanLocalStationsView::DoActivateL
       
   132 // Activate the channel list view
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CFMRadioScanLocalStationsView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   136 												 TUid /*aCustomMessageId*/,
       
   137 												 const TDesC8& /*aCustomMessage*/ )
       
   138     {
       
   139     FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::DoActivateL  Start") ) );
       
   140     Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_EMPTY ); 
       
   141     Cba()->DrawDeferred(); // Redraw softkeys
       
   142     
       
   143 
       
   144     HBufC* title = StringLoader::LoadLC( R_FMRADIO_SEARCH_STATIONS_VIEW_TITLE, iCoeEnv );
       
   145     static_cast<CAknTitlePane*>( StatusPane()->ControlL( 
       
   146         TUid::Uid( EEikStatusPaneUidTitle ) ) )->SetTextL( *title );
       
   147     CleanupStack::PopAndDestroy( title );
       
   148 
       
   149     if ( !iContainer )
       
   150         {
       
   151         FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::DoActivateL  inside second, not iContainer if") ) );
       
   152         iContainer = CFMRadioScanLocalStationsContainer::NewL( ClientRect(), iRadioEngine );
       
   153         iContainer->SetMopParent( this );
       
   154         iContainer->SetObserver( this );
       
   155         AppUi()->AddToStackL( *this, iContainer );
       
   156         }
       
   157     AppUi()->HandleCommandL( EFMRadioCmdScanLocalStationsViewActive );
       
   158 
       
   159     ResetListAndStartScanL();
       
   160     iRadioEngine.RdsReceiver().AddObserver( this );
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CFMRadioScanLocalStationsView::HandleCommandL
       
   165 // Interprets view's menu,softkey and other commands and acts
       
   166 // accordingly by calling the appropriate command handler
       
   167 // function for further action.
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CFMRadioScanLocalStationsView::HandleCommandL( TInt aCommand )
       
   171     {
       
   172     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( AppUi() );
       
   173     switch ( aCommand )
       
   174         {
       
   175         case EAknSoftkeyBack: // go back to the main view
       
   176             {
       
   177             appUi->ActivateLocalViewL( KFMRadioChannelListViewId );
       
   178             break;
       
   179             }
       
   180         case EEikBidCancel:
       
   181             {
       
   182             if ( iFaded )
       
   183                 {
       
   184                 appUi->HandleCommandL( aCommand );
       
   185                 }
       
   186             else
       
   187                 {
       
   188                 appUi->ActivateLocalViewL( KFMRadioChannelListViewId );
       
   189                 }
       
   190             break;
       
   191             }
       
   192         case EFMRadioCmdSaveChannel:
       
   193             {
       
   194             HandleOneChannelSaveL();
       
   195             break;      	        
       
   196         	}        	
       
   197         case EFMRadioCmdSaveAllChannels:
       
   198             SaveAllChannelsL();
       
   199             break;
       
   200         case EFMRadioCmdScanLocalStationsScan: // start station scanning
       
   201             {
       
   202             Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_EMPTY ); 
       
   203             Cba()->DrawDeferred(); // Redraw softkeys
       
   204             //reset all counters, make station list empty
       
   205             ResetListAndStartScanL();
       
   206         	break;
       
   207         	}
       
   208         	
       
   209         case EFMRadioCmdListenCh:
       
   210         	{
       
   211         	PlayCurrentlySelectedChannelL();
       
   212         	SetContextMenu( R_FMRADIO_SCAN_STATIONS_CTX_MENUBAR_SAVE );
       
   213         	break;
       
   214         	}
       
   215         default: // Send all other commands to AppUi
       
   216             appUi->HandleCommandL( aCommand );
       
   217             break;
       
   218         }
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CFMRadioScanLocalStationsView::SetLastListenedChannel
       
   223 // Keep track of the last selected channel
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CFMRadioScanLocalStationsView::SetLastListenedChannel( TInt aIndex )
       
   227     {
       
   228     iChIndex = aIndex;
       
   229     if ( iContainer )
       
   230         {
       
   231         iContainer->UpdateLastListenedChannel( aIndex ); // Update index
       
   232         }
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CFMRadioScanLocalStationsView::SetNowPlayingChannelL
       
   237 // Keep track of the current selected channel
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CFMRadioScanLocalStationsView::SetNowPlayingChannelL( TInt aChannelIndex )
       
   241     {
       
   242     TInt oldIndex = iNowPlayingIndex;
       
   243     iNowPlayingIndex = aChannelIndex;
       
   244     
       
   245     if ( iContainer && ( aChannelIndex != oldIndex ) )
       
   246         {
       
   247         if ( ChannelInUse( oldIndex ) &&
       
   248                 !iScannedChannels[ oldIndex ]->PresetNameValid() )
       
   249             {
       
   250             // Remove dynamic ps name
       
   251             iContainer->UpdateChannelListContentL( oldIndex,
       
   252                     KNullDesC,
       
   253                     iScannedChannels[ oldIndex ]->PresetFrequency(),
       
   254                     EFalse,
       
   255                     EFalse );
       
   256             }
       
   257         iContainer->UpdateNowPlayingIconL( iNowPlayingIndex, oldIndex );
       
   258         }
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CFMRadioScanLocalStationsView::CurrentlyPlayingChannel
       
   263 // Returns the index of the playing channel item from the channel list.
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 TInt CFMRadioScanLocalStationsView::CurrentlyPlayingChannel()
       
   267 	{
       
   268 	return iNowPlayingIndex;
       
   269 	}
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // CFMRadioScanLocalStationsView::ChannelInPlay
       
   273 // Return true/false to indicate whether the channel specified
       
   274 // is in play
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 TBool CFMRadioScanLocalStationsView::ChannelInPlay( TInt aChannelIndex ) const
       
   278     {
       
   279     if( aChannelIndex == iNowPlayingIndex )
       
   280     	{
       
   281     	return ETrue;
       
   282     	}
       
   283     else 
       
   284     	{
       
   285     	return EFalse;
       
   286     	}
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CFMRadioScanLocalStationsView::ChannelInUse
       
   291 // Return true/false to indicate whether the channel specified
       
   292 // is in use
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 TBool CFMRadioScanLocalStationsView::ChannelInUse( const TInt aChannelIndex ) const
       
   296     {
       
   297     TBool ret = EFalse;
       
   298     FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::ChannelInUse  Start") ) );
       
   299 
       
   300     if ( aChannelIndex >= KMinNumberOfChannelListItems &&
       
   301             aChannelIndex < iScannedChannels.Count() )
       
   302         {
       
   303         ret = ETrue;
       
   304         }
       
   305     return ret;
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // CFMRadioScanLocalStationsView::FadeAndShowExit
       
   310 // Fade the view and all controls associated with it. Change
       
   311 // the soft keys so that "Exit" is displayed
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 void CFMRadioScanLocalStationsView::FadeAndShowExit( TBool aFaded )
       
   315     {
       
   316     TInt err = KErrNone;
       
   317     iFaded = aFaded;
       
   318     SetToolbarDimmedState( aFaded ); 
       
   319     if ( iContainer )
       
   320         {
       
   321         if ( aFaded ) // Fade
       
   322             {
       
   323             // In case options menu is open when headset is disconnected
       
   324             StopDisplayingMenuBar();
       
   325             iContainer->SetFaded( aFaded );
       
   326             TRAP( err,Cba()->SetCommandSetL( R_FMRADIO_SOFTKEYS_EXIT ) );
       
   327             }
       
   328         else
       
   329             {
       
   330             iContainer->SetFaded( aFaded );
       
   331             TRAP( err,Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK ) );
       
   332             // Update index to be sure it is up-to-date (in case if list was scrolled in idle state)
       
   333             iContainer->UpdateLastListenedChannel( iChIndex );
       
   334             
       
   335             if( iScannedChannels.Count() > 0 )
       
   336                 {
       
   337                 TRAP_IGNORE( SetMiddleSoftKeyIconL(); )
       
   338                 
       
   339                 if ( ( CurrentlyPlayingChannel() == CurrentlySelectedChannel() ) )
       
   340                     {
       
   341                     SetContextMenu( R_FMRADIO_SCAN_STATIONS_CTX_MENUBAR_SAVE );
       
   342                     }
       
   343                 else
       
   344                     {
       
   345                     SetContextMenu( R_FMRADIO_SCAN_STATIONS_CTX_MENUBAR );
       
   346                     }
       
   347                 }
       
   348             }
       
   349         Cba()->DrawDeferred();
       
   350         }
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // CFMRadioScanLocalStationsView::UpdateDisplayForFocusGained
       
   355 // Update the view after a focus gained event.
       
   356 // 1. Fade/Unfade view
       
   357 // 2. Update MSK label
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 void CFMRadioScanLocalStationsView::UpdateDisplayForFocusGained()
       
   361     {
       
   362     FadeAndShowExit( iFaded );
       
   363     }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // CFMRadioScanLocalStationsView::UpdateChannelListContentL
       
   367 // Make a request to the channel container to update the
       
   368 // content of the channel at aIndex with the values specified
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 void CFMRadioScanLocalStationsView::UpdateChannelListContentL( TInt aIndex,
       
   372 															   TInt aChannelFrequency )
       
   373     {
       
   374     TBool nowPlaying = EFalse;	
       
   375     if( ChannelInPlay( aIndex ) )
       
   376 	    {
       
   377 	    nowPlaying = ETrue;	
       
   378 	    }
       
   379 	else 
       
   380 		{
       
   381 		 nowPlaying = EFalse;	
       
   382 		}
       
   383     if ( iContainer )
       
   384         {
       
   385         iContainer->UpdateChannelListContentL( aIndex, KNullDesC, aChannelFrequency, nowPlaying );
       
   386         }
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CFMRadioScanLocalStationsView::CurrentlySelectedChannel
       
   391 // Returns the index of the selected channel item from the
       
   392 // channel list. If the container is active get the info from
       
   393 // it, because it may have more up-to-date info.
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 TInt CFMRadioScanLocalStationsView::CurrentlySelectedChannel()
       
   397     {
       
   398     if ( iContainer )
       
   399         {
       
   400         iChIndex = iContainer->CurrentlySelectedChannel();
       
   401         }
       
   402     return iChIndex;
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CFMRadioScanLocalStationsView::NextChannel
       
   407 // Retrieve the index of the next channel that has been set.
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 TInt CFMRadioScanLocalStationsView::NextChannel()
       
   411     {
       
   412     if ( iContainer )
       
   413         {
       
   414         iChIndex = iContainer->CurrentlySelectedChannel();
       
   415         }
       
   416     else
       
   417         {
       
   418         iChIndex = iRadioEngine.GetPresetIndex();
       
   419         }
       
   420 
       
   421     TInt nextChannel = iChIndex;
       
   422     for ( TInt i = iChIndex + 1; i < KMaxNumberOfChannelListItems; i++ )
       
   423         {
       
   424         if ( ChannelInUse( i ) )
       
   425             {
       
   426             nextChannel = i;
       
   427             break;
       
   428             }
       
   429         }
       
   430     if ( nextChannel == iChIndex )
       
   431         {
       
   432         for ( TInt i = 0; i < iChIndex; i++ )
       
   433             {
       
   434             if ( ChannelInUse( i ) )
       
   435                 {
       
   436                 nextChannel = i;
       
   437                 break;
       
   438                 }
       
   439             }
       
   440         }
       
   441     return nextChannel;
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // CFMRadioScanLocalStationsView::PreviousChannel
       
   446 // Retrieve the index of the previous channel that has been set.
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 TInt CFMRadioScanLocalStationsView::PreviousChannel()
       
   450     {
       
   451     if ( iContainer )
       
   452         {
       
   453         iChIndex = iContainer->CurrentlySelectedChannel();
       
   454         }
       
   455     else
       
   456         {
       
   457         iChIndex = iRadioEngine.GetPresetIndex();
       
   458         }
       
   459 
       
   460     TInt previousChannel = iChIndex;
       
   461     
       
   462     for ( TInt i = iChIndex - 1; i >= 0; i-- )
       
   463         {
       
   464         if ( ChannelInUse( i ) )
       
   465             {
       
   466             previousChannel = i;
       
   467             break;
       
   468             }
       
   469         }
       
   470     if ( previousChannel == iChIndex )
       
   471         {
       
   472         for ( TInt i = KMaxNumberOfChannelListItems - 1; i > iChIndex; i-- )
       
   473             {
       
   474             if ( ChannelInUse( i ) )
       
   475                 {
       
   476                 previousChannel = i;
       
   477                 break;
       
   478                 }
       
   479             }
       
   480         }
       
   481     return previousChannel;
       
   482     }
       
   483 
       
   484 // ---------------------------------------------------------------------------
       
   485 // CFMRadioScanLocalStationsView::HandleControlEventL
       
   486 // Handles control event observing. In this case the interest
       
   487 // is only on the channel selection from the channel list.
       
   488 // Other events are not reported by the container,
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CFMRadioScanLocalStationsView::HandleControlEventL( CCoeControl* aControl,
       
   492                                                          TCoeEvent aEventType )
       
   493     {
       
   494     if ( aControl == iContainer )
       
   495         {
       
   496         if ( aEventType == MCoeControlObserver::EEventRequestFocus )
       
   497             {
       
   498             // Don't display MSK when display is faded.
       
   499             if ( !iFaded && !AknLayoutUtils::PenEnabled() )
       
   500                 {
       
   501                 // event sent if up or down arrow keys are pressed
       
   502            	    if ( ( CurrentlyPlayingChannel() == CurrentlySelectedChannel() ) )
       
   503                     {
       
   504                     SetContextMenu( R_FMRADIO_SCAN_STATIONS_CTX_MENUBAR_SAVE );
       
   505                     }
       
   506                 else
       
   507                     {
       
   508                 	SetContextMenu( R_FMRADIO_SCAN_STATIONS_CTX_MENUBAR );
       
   509                     }
       
   510                 }
       
   511             else if ( ChannelInUse( CurrentlySelectedChannel() ) )
       
   512                 {
       
   513                 PlayCurrentlySelectedChannelL();
       
   514                 }
       
   515             }
       
   516         else if ( aEventType == MCoeControlObserver::EEventStateChanged
       
   517                 && ChannelInUse( CurrentlySelectedChannel() ) )
       
   518             {
       
   519             PlayCurrentlySelectedChannelL();
       
   520             }
       
   521         }
       
   522     }
       
   523 
       
   524 // ---------------------------------------------------------------------------
       
   525 // CFMRadioScanLocalStationsView::DoDeactivate
       
   526 // Deactivate the channel list view
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CFMRadioScanLocalStationsView::DoDeactivate()
       
   530     {
       
   531     FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::DoDeactivate") ) );
       
   532     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( AppUi() );
       
   533     
       
   534     if ( iToolbar )
       
   535         {
       
   536         // hide toolbar so it is not visible when activating view again
       
   537         iToolbar->SetToolbarVisibility( EFalse );
       
   538         }
       
   539 
       
   540     if ( appUi->RadioEngine() )
       
   541     	{
       
   542         iRadioEngine.RdsReceiver().RemoveObserver( this );
       
   543     	}
       
   544     if ( iContainer )
       
   545         {
       
   546         appUi->RemoveFromViewStack( *this, iContainer );
       
   547         }
       
   548 
       
   549     iScanAndSaveActivated = EFalse;
       
   550     
       
   551     // If exiting, iRadioEngine is no longer valid object
       
   552     if( appUi->RadioEngine() )
       
   553         {
       
   554         appUi->RadioEngine()->CancelScanLocalStationsScan();
       
   555         // Stop seek doesn't get called automatically as this is not active view anymore
       
   556         TRAP_IGNORE( StopSeekL() )
       
   557         }
       
   558     
       
   559     delete iContainer;
       
   560     iContainer = NULL;
       
   561 	// release allocated memory for scanned stations
       
   562     iScannedChannels.ResetAndDestroy();
       
   563     }
       
   564 
       
   565 // ---------------------------------------------------------------------------
       
   566 // CFMRadioScanLocalStationsView::DynInitMenuPaneL
       
   567 // Sets the state of menu items dynamically according to the
       
   568 // state of application data.
       
   569 // ---------------------------------------------------------------------------
       
   570 //
       
   571 void CFMRadioScanLocalStationsView::DynInitMenuPaneL( TInt aResourceId,
       
   572                                                       CEikMenuPane* aMenuPane )
       
   573     {
       
   574     if ( aResourceId == R_FMRADIO_SEARCH_STATIONS_OPTIONS_MENU ) // Main menu
       
   575         {
       
   576         if ( iRadioEngine.IsAudioRoutingPossible() )
       
   577             {
       
   578             if ( iRadioEngine.GetAudioOutput() == CRadioEngine::EFMRadioOutputIHF )
       
   579                 {
       
   580                 // Delete existing menu option and add a new one
       
   581                 aMenuPane->DeleteMenuItem( EFMRadioCmdActivateIhf );
       
   582                 if ( iRadioEngine.IsHeadsetConnected() )
       
   583                     {
       
   584                     aMenuPane->SetItemTextL( EFMRadioCmdDeactivateIhf, R_QTN_FMRADIO_OPTIONS_DEACTIVATE );
       
   585                     }
       
   586                 }
       
   587             else
       
   588                 {
       
   589                 // Delete existing menu option and add a new one
       
   590                 aMenuPane->DeleteMenuItem( EFMRadioCmdDeactivateIhf );
       
   591                 aMenuPane->SetItemTextL( EFMRadioCmdActivateIhf, R_QTN_FMRADIO_OPTIONS_ACTIVATE );
       
   592                 }
       
   593             }
       
   594         else
       
   595             {
       
   596             aMenuPane->SetItemDimmed( EFMRadioCmdDeactivateIhf, ETrue );
       
   597             aMenuPane->SetItemDimmed( EFMRadioCmdActivateIhf, ETrue );
       
   598             }
       
   599         
       
   600         TInt scannedChannelCount = iScannedChannels.Count();
       
   601         
       
   602         if ( scannedChannelCount < 2 )
       
   603             {
       
   604             aMenuPane->DeleteMenuItem( EFMRadioCmdSaveAllChannels );
       
   605             }
       
   606 
       
   607         if ( scannedChannelCount < 1)
       
   608             {
       
   609             aMenuPane->SetItemDimmed( EFMRadioCmdSaveChannel, ETrue );
       
   610             }
       
   611         
       
   612         // if help is not enabled, disable help option
       
   613         if ( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   614             {
       
   615             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   616             }
       
   617         }
       
   618     }
       
   619 
       
   620 // ---------------------------------------------------------------------------
       
   621 // CFMRadioScanLocalStationsView::LayoutChangedL
       
   622 // ---------------------------------------------------------------------------
       
   623 //
       
   624 void CFMRadioScanLocalStationsView::LayoutChangedL( TInt aType )
       
   625     {
       
   626     if( iContainer )
       
   627         {
       
   628         iContainer->SetRect( ClientRect() );
       
   629         iContainer->HandleResourceChange( aType );
       
   630         }
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------------------------------------------
       
   634 // CFMRadioScanLocalStationsView::SetMiddleSoftKeyLabelL
       
   635 // Sets middle softkey label.
       
   636 // ---------------------------------------------------------------------------------------------
       
   637 //
       
   638 void CFMRadioScanLocalStationsView::SetMiddleSoftKeyLabelL( const TInt aResourceId,
       
   639                                                       const TInt aCommandId )
       
   640     {
       
   641     if ( !AknLayoutUtils::PenEnabled() )
       
   642         {
       
   643         CEikButtonGroupContainer* cbaGroup = Cba();
       
   644         if ( cbaGroup )
       
   645             {
       
   646             cbaGroup->RemoveCommandFromStack( KMSKControlID, iCurrentMSKCommandId );
       
   647             HBufC* middleSKText = StringLoader::LoadLC( aResourceId, iCoeEnv );
       
   648             TPtr mskPtr = middleSKText->Des();
       
   649             cbaGroup->AddCommandToStackL(
       
   650                 KMSKControlID,
       
   651                 aCommandId,
       
   652                 mskPtr );
       
   653             CleanupStack::PopAndDestroy( middleSKText );
       
   654             iCurrentMSKCommandId = aCommandId;
       
   655             }
       
   656         }
       
   657     }
       
   658 
       
   659 // ---------------------------------------------------------------------------------------------
       
   660 // CFMRadioScanLocalStationsView::SetMiddleSoftKeyIconL
       
   661 // Sets middle softkey icon.
       
   662 // ---------------------------------------------------------------------------------------------
       
   663 //
       
   664 void CFMRadioScanLocalStationsView::SetMiddleSoftKeyIconL()
       
   665     {
       
   666     if ( !AknLayoutUtils::PenEnabled() )
       
   667         {
       
   668         CEikButtonGroupContainer* cbaGroup = Cba();
       
   669         CFbsBitmap* bitmap = NULL;
       
   670         CFbsBitmap* mask = NULL;
       
   671         if ( cbaGroup )
       
   672             {
       
   673             TFileName mbmFileName;
       
   674             TFindFile finder( iCoeEnv->FsSession() );
       
   675             TInt err = finder.FindByDir( KFMRadioBmpFile, KDC_APP_BITMAP_DIR );
       
   676             if ( err == KErrNone )
       
   677                 {
       
   678                 mbmFileName.Copy( finder.File() );
       
   679                 }
       
   680 
       
   681             AknsUtils::CreateColorIconL(
       
   682                 AknsUtils::SkinInstance(),
       
   683                 KAknsIIDQgnPropMskMenu,
       
   684                 KAknsIIDQsnComponentColors,
       
   685                 EAknsCIQsnComponentColorsCG13,
       
   686                 bitmap,
       
   687                 mask,
       
   688                 mbmFileName,
       
   689                 EMbmFmradioQgn_prop_msk_menu,
       
   690                 EMbmFmradioQgn_prop_msk_menu_mask,
       
   691                 KRgbBlack );
       
   692 
       
   693             CleanupStack::PushL( bitmap );
       
   694             CleanupStack::PushL( mask );
       
   695 
       
   696             cbaGroup->RemoveCommandFromStack( KMSKControlID, iCurrentMSKCommandId );
       
   697             cbaGroup->AddCommandToStackL(
       
   698                 KMSKControlID,
       
   699                 EAknSoftkeyContextOptions,
       
   700                 *bitmap,
       
   701                 *mask );
       
   702 
       
   703             iCurrentMSKCommandId = EAknSoftkeyContextOptions;
       
   704 
       
   705             CleanupStack::PopAndDestroy( 2, bitmap );
       
   706             }
       
   707         }
       
   708     }
       
   709 
       
   710 // -----------------------------------------------------------------------------------------------
       
   711 // CFMRadioScanLocalStationsView::SaveAllChannelsL
       
   712 // Saves all the scanned channels into Radio Engine's presets.
       
   713 // -----------------------------------------------------------------------------------------------
       
   714 //
       
   715 void CFMRadioScanLocalStationsView::SaveAllChannelsL()
       
   716     {
       
   717     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
   718     
       
   719     if ( appUi->NumberOfChannelsStored() > 0 )
       
   720         {
       
   721         //We have some tuned channels,
       
   722         //so we have to check does the user want to
       
   723         //add new channes or replace the old ones.
       
   724         TInt numberOfEmptySlots = KMaxNumberOfChannelListItems - appUi->NumberOfChannelsStored();
       
   725         if( numberOfEmptySlots >= iScannedChannels.Count() )
       
   726             {
       
   727             //more vacant than new channels
       
   728             //we can add or replace
       
   729             TInt index(0);
       
   730             CAknListQueryDialog* query = new (ELeave) CAknListQueryDialog( &index );
       
   731             query->PrepareLC( R_FMRADIO_LISTQUERY_SAVE_ALL_REPLACE_APPEND );
       
   732             if( query->RunLD() )
       
   733                 {
       
   734                 const TInt KIndexOfSaveAllReplaceExistingCmd = 0;
       
   735                 const TInt KIndexOfSaveAllAppendCmd = 1;
       
   736                 if( index == KIndexOfSaveAllReplaceExistingCmd )
       
   737                     {
       
   738                     SaveFoundChannelsToPresetsL( EReplace );
       
   739                     }
       
   740                 else if( index == KIndexOfSaveAllAppendCmd )
       
   741                     {
       
   742                     SaveFoundChannelsToPresetsL( EAppend );
       
   743                     }
       
   744                 }
       
   745             else
       
   746                 {
       
   747                 ShowToolbar( ETrue );
       
   748                 }
       
   749             }
       
   750         else
       
   751             {
       
   752             //no room for all the channels
       
   753             if( numberOfEmptySlots == 0 )
       
   754                 {
       
   755                 CAknQueryDialog* query = CAknQueryDialog::NewL();
       
   756                 if ( query->ExecuteLD( R_FMRADIO_REPLACE_EXISTING_CHANNELS_QUERY ) )
       
   757                     {
       
   758                     SaveFoundChannelsToPresetsL( EReplace );
       
   759                     }
       
   760                 else
       
   761                     {
       
   762                     ShowToolbar( ETrue );
       
   763                     }
       
   764                 }
       
   765             else
       
   766                 {
       
   767                 TInt index(0);
       
   768                 CAknListQueryDialog* query = new (ELeave) CAknListQueryDialog( &index );
       
   769                 query->PrepareLC( R_FMRADIO_LISTQUERY_SAVE_ALL_REPLACE_APPEND_LIST_ALMOST_FULL );
       
   770                 if( query->RunLD() )
       
   771                     {
       
   772                     const TInt KIndexOfSaveAllAppendCmd = 0;
       
   773                     const TInt KIndexOfSaveAllReplaceExistingCmd = 1;
       
   774                     if( index == KIndexOfSaveAllReplaceExistingCmd )
       
   775                         {
       
   776                         SaveFoundChannelsToPresetsL( EReplace );
       
   777                         }
       
   778                     else if( index == KIndexOfSaveAllAppendCmd )
       
   779                         {
       
   780                         SaveFoundChannelsToPresetsL( EAppend );
       
   781                         }
       
   782                     }
       
   783                 else
       
   784                     {
       
   785                     ShowToolbar( ETrue );
       
   786                     }   
       
   787                 }
       
   788             }
       
   789         }
       
   790     else
       
   791         {
       
   792         //No previous channels
       
   793         SaveFoundChannelsToPresetsL( EReplace );
       
   794         }
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------------------------
       
   798 // CFMRadioScanLocalStationsView::ShowConfirmationQueryL
       
   799 // Get confirmation from user.
       
   800 // -----------------------------------------------------------------------------------------------
       
   801 //
       
   802 TInt CFMRadioScanLocalStationsView::ShowConfirmationQueryL(TInt aResText, TInt aResQuery) 
       
   803 	{
       
   804 	TInt accepted = EFalse;
       
   805     HBufC* prompt = StringLoader::LoadLC( aResText, iEikonEnv );
       
   806     CAknQueryDialog* queryDlg = CAknQueryDialog::NewL();
       
   807     accepted = queryDlg->ExecuteLD( aResQuery, *prompt );
       
   808     CleanupStack::PopAndDestroy( prompt );
       
   809     return accepted;
       
   810     }
       
   811 
       
   812 // -----------------------------------------------------------------------------------------------
       
   813 // CFMRadioScanLocalStationsView::StopSeekL
       
   814 // Invoked by AppUi when a seek is completed or aborted.
       
   815 // -----------------------------------------------------------------------------------------------
       
   816 //
       
   817 void CFMRadioScanLocalStationsView::StopSeekL()
       
   818     {
       
   819     FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::StopSeekL") ) );
       
   820 
       
   821     if ( iTuneRequested )
       
   822         {
       
   823         iTuneRequested = EFalse;
       
   824 
       
   825         // if tune request comes from scan all (= ResetListAndStartScanL )
       
   826         // then start the whole scan
       
   827         if ( iScanAndSaveActivated )
       
   828             {
       
   829             AppUi()->HandleCommandL( EFMRadioCmdScanLocalStationsScan );
       
   830             }
       
   831         else
       
   832             {
       
   833             iRadioEngine.SetMuteOn( EFalse );
       
   834             }
       
   835         }
       
   836     else if ( iScanAndSaveActivated )
       
   837         {
       
   838         // No channels found or user has canceled search before any channels are found
       
   839         if ( iRadioEngine.GetTunedFrequency() == iLowerFrequencyBound &&
       
   840                 iScannedChannels.Count() == 0 )
       
   841             {
       
   842             CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
   843 
       
   844             if ( appUi->IsStartupWizardRunning() )
       
   845                 {                
       
   846                 //no stations are found in Wizard
       
   847                 if (iCancelType == EFMRadioCancelScanDefault)
       
   848                     {
       
   849                     HBufC* string = NULL; 
       
   850                     string = StringLoader::LoadLC( R_QTN_FMRADIO_NO_STATIONS_FOUND, iEikonEnv );
       
   851                     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue ); // waiting
       
   852                     note->ExecuteLD( *string );
       
   853                     CleanupStack::PopAndDestroy( string );
       
   854                     }
       
   855 
       
   856                 iScanAndSaveActivated = EFalse;
       
   857 
       
   858                 RemoveScanningInProgressNoteL();
       
   859                 RestoreRadio();
       
   860                 appUi->AutoTuneInMainView(ETrue);
       
   861                 
       
   862                 ActivateMainViewL();
       
   863                 }
       
   864             else
       
   865                 {
       
   866                 if( iContainer )
       
   867                     {
       
   868                     HBufC* listEmptyText = NULL; 
       
   869                     listEmptyText = StringLoader::LoadLC( R_QTN_FMRADIO_LIST_NO_STATIONS_FOUND, iEikonEnv );
       
   870                     iContainer->SetStationListEmptyTextL( *listEmptyText );
       
   871                     CleanupStack::PopAndDestroy( listEmptyText );
       
   872                     
       
   873                     iContainer->ResetChannelListL();
       
   874                     }
       
   875 
       
   876                 iScanAndSaveActivated = EFalse;
       
   877                 Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK ); 
       
   878                 Cba()->DrawDeferred(); // Redraw softkeys
       
   879                 RemoveScanningInProgressNoteL();
       
   880 
       
   881                 UpdateToolbar();
       
   882                 ShowToolbar( ETrue );
       
   883                 RestoreRadio();
       
   884                 }
       
   885             }
       
   886         else
       
   887             {
       
   888             AddTunedFrequencyToListL();
       
   889             }
       
   890         }
       
   891     else
       
   892         {
       
   893         RemoveScanningInProgressNoteL();
       
   894         TBool restoreFrequency = EFalse;
       
   895         TInt tunedFrequency = iRadioEngine.GetTunedFrequency();
       
   896         
       
   897         if ( tunedFrequency == iLowerFrequencyBound &&
       
   898                 iScannedChannels.Count() == 0 )
       
   899             {
       
   900             restoreFrequency = ETrue;
       
   901             }
       
   902         UpdateToolbar();
       
   903         RestoreRadio( restoreFrequency );
       
   904         
       
   905         // update now playing index if the tuning is triggered from accessory 
       
   906         TInt frequencyIndex = FrequencyIndex( tunedFrequency );
       
   907         
       
   908         if ( frequencyIndex != KErrNotFound )
       
   909             {
       
   910             SetNowPlayingChannelL( frequencyIndex );
       
   911             SetLastListenedChannel( frequencyIndex );
       
   912             }
       
   913         else // frequency is not in the list, remove now playing channel status
       
   914             {
       
   915             SetNowPlayingChannelL( KErrNotFound );
       
   916             }
       
   917         }
       
   918     }
       
   919 
       
   920 // -----------------------------------------------------------------------------------------------
       
   921 // CFMRadioScanLocalStationsView::RestoreRadio
       
   922 // Restores the radio after scanning
       
   923 // -----------------------------------------------------------------------------------------------
       
   924 //
       
   925 void CFMRadioScanLocalStationsView::RestoreRadio( TBool aTuneInitialFrequency )
       
   926     {
       
   927     FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::RestoreRadio") ) );
       
   928     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
   929     // if iInitialTunedFrequency is 0, radio has already been restored
       
   930     if ( iInitialTunedFrequency )
       
   931         {
       
   932         if ( aTuneInitialFrequency )
       
   933             {
       
   934             iTuneRequested = ETrue;
       
   935             iRadioEngine.Tune( iInitialTunedFrequency );
       
   936             }
       
   937         iInitialTunedFrequency = 0;
       
   938         }
       
   939     appUi->SetStartupWizardRunning( EFalse );
       
   940     }
       
   941 
       
   942 // -----------------------------------------------------------------------------------------------
       
   943 // CFMRadioScanLocalStationsView::AddTunedFrequencyToListL
       
   944 // Updates found channels to the list.
       
   945 // -----------------------------------------------------------------------------------------------
       
   946 //
       
   947 void CFMRadioScanLocalStationsView::AddTunedFrequencyToListL()
       
   948     {
       
   949     FTRACE( FPrint( _L("CFMRadioScanLocalStationsView::AddTunedFrequencyToListL") ) );
       
   950     TInt tunedFrequency = iRadioEngine.GetTunedFrequency();
       
   951     
       
   952     if ( KErrNotFound == FrequencyIndex( tunedFrequency ) )
       
   953         {
       
   954         // the frequency is new and may be added
       
   955         CFMRadioPreset* channel = CFMRadioPreset::NewL();
       
   956         CleanupStack::PushL( channel );
       
   957         channel->SetPresetFrequency( tunedFrequency );
       
   958         // Make the name invalid by default so that possibly dynamic PS name won't get saved
       
   959         channel->SetPresetNameValid( EFalse );
       
   960         
       
   961         TInt freqIndex = SortedFrequencyListIndex( tunedFrequency );
       
   962         
       
   963         if ( freqIndex < ( iScannedChannels.Count() - 1 ) )
       
   964             {
       
   965             iScannedChannels.InsertL( channel, freqIndex );
       
   966             }
       
   967         else
       
   968             {
       
   969             iScannedChannels.AppendL( channel );
       
   970             }
       
   971         CleanupStack::Pop( channel );
       
   972         
       
   973         // update a radiostation slot in the list
       
   974         // check if there is place
       
   975         if ( iContainer )
       
   976             {
       
   977             iContainer->InsertScannedChannelToListL( freqIndex, tunedFrequency );
       
   978             iContainer->DrawDeferred();
       
   979             }
       
   980         // scan for another frequency
       
   981         AppUi()->HandleCommandL( EFMRadioCmdScanLocalStationsScan );
       
   982         }
       
   983     else
       
   984         {
       
   985         //stop scanning
       
   986         iScanAndSaveActivated = EFalse;
       
   987         Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK ); 
       
   988         Cba()->DrawDeferred(); // Redraw softkeys
       
   989 
       
   990         RemoveScanningInProgressNoteL();
       
   991         SetMiddleSoftKeyIconL();
       
   992         SetContextMenu( R_FMRADIO_SCAN_STATIONS_CTX_MENUBAR_SAVE );
       
   993 
       
   994         if ( iContainer )
       
   995             {
       
   996             iContainer->UpdateLastListenedChannel( 0 ); // select the first channel
       
   997             PlayCurrentlySelectedChannelL();
       
   998             iContainer->DrawDeferred();
       
   999             }
       
  1000         
       
  1001         CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
  1002 
       
  1003         if ( appUi->IsStartupWizardRunning() )
       
  1004             {
       
  1005             appUi->SetStartupWizardRunning( EFalse );
       
  1006 
       
  1007             if ( iScanCancelled )
       
  1008                 {
       
  1009                 iScanCancelled = EFalse;
       
  1010                 ActivateMainViewL();
       
  1011                 }
       
  1012             else
       
  1013                 {
       
  1014                 SaveAllChannelsL();
       
  1015                 }
       
  1016             }
       
  1017         else
       
  1018             {
       
  1019             UpdateToolbar();
       
  1020             ShowToolbar( ETrue );
       
  1021             }
       
  1022         }
       
  1023     }
       
  1024 
       
  1025 // -----------------------------------------------------------------------------------------------
       
  1026 // CFMRadioScanLocalStationsView::ResetCountersL
       
  1027 // Called when a new scan is activated.
       
  1028 // -----------------------------------------------------------------------------------------------
       
  1029 //
       
  1030 void CFMRadioScanLocalStationsView::ResetListAndStartScanL()
       
  1031     {
       
  1032     User::LeaveIfNull( iContainer );
       
  1033     iNowPlayingIndex = KErrNotFound;
       
  1034     ShowToolbar( EFalse );
       
  1035     iContainer->SetStationListEmptyTextL( KNullDesC );
       
  1036     iScanAndSaveActivated = ETrue;	
       
  1037     DisplayScanningInProgressNoteL();
       
  1038 
       
  1039     iInitialTunedFrequency = 0;
       
  1040     iScanCancelled = EFalse;
       
  1041     iCancelType = EFMRadioCancelScanDefault;
       
  1042     iScannedChannels.ResetAndDestroy();
       
  1043     iContainer->InitializeChannelListL();
       
  1044     
       
  1045     //mute radio
       
  1046     if ( !iRadioEngine.IsMuteOn() )
       
  1047         {
       
  1048         iRadioEngine.SetMuteOn( ETrue );
       
  1049         }
       
  1050 
       
  1051     //update upper and lower frequency bands
       
  1052     iRadioEngine.GetFrequencyBandRange( iLowerFrequencyBound, iUpperFrequencyBound );
       
  1053 
       
  1054     iInitialTunedFrequency = iRadioEngine.GetTunedFrequency();
       
  1055 
       
  1056     if ( iRadioEngine.GetTunedFrequency() != iLowerFrequencyBound )
       
  1057         {
       
  1058         iTuneRequested = ETrue;
       
  1059         iRadioEngine.Tune( iLowerFrequencyBound );
       
  1060         }
       
  1061     else
       
  1062         {
       
  1063         AppUi()->HandleCommandL( EFMRadioCmdScanLocalStationsScan );
       
  1064         }
       
  1065     }
       
  1066 
       
  1067 // ---------------------------------------------------------
       
  1068 // CFMRadioScanLocalStationsContainer::DisplayScanningInProgressNoteL
       
  1069 // Display a wait note while the channel fill is occuring.
       
  1070 // ---------------------------------------------------------
       
  1071 //
       
  1072 void CFMRadioScanLocalStationsView::DisplayScanningInProgressNoteL()
       
  1073     {
       
  1074     iScanningNote = new ( ELeave ) CAknWaitDialog( reinterpret_cast<CEikDialog**>( &iScanningNote ) );
       
  1075     iScanningNote->SetCallback( this );
       
  1076     
       
  1077     CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
  1078     
       
  1079     if ( appUi->IsStartupWizardRunning() )
       
  1080         {
       
  1081         iScanningNote->PrepareLC( R_FMRADIO_SEARCH_STATIONS_WAIT_CANCEL_NOTE );
       
  1082         }
       
  1083     else
       
  1084         {
       
  1085         iScanningNote->PrepareLC( R_FMRADIO_SEARCH_STATIONS_WAIT_NOTE );
       
  1086         }
       
  1087     
       
  1088     iScanningNote->RunLD();
       
  1089     }	
       
  1090 
       
  1091 // ---------------------------------------------------------
       
  1092 // CFMRadioScanLocalStationsContainer::RemoveScanningInProgressNoteL
       
  1093 // Remove and destroy the scanning fill note.
       
  1094 // ---------------------------------------------------------
       
  1095 //
       
  1096 void CFMRadioScanLocalStationsView::RemoveScanningInProgressNoteL()
       
  1097     {
       
  1098     FTRACE(FPrint(_L("CFMRadioScanLocalStationsView::RemoveScanningInProgressNoteL")));
       
  1099     if ( iScanningNote )
       
  1100         {
       
  1101         iScanningNote->ProcessFinishedL(); // Inform seek note to stop and hide it        
       
  1102         iScanningNote = NULL;
       
  1103         }
       
  1104     }
       
  1105 
       
  1106 // ---------------------------------------------------------
       
  1107 // CFMRadioScanLocalStationsContainer::DialogDismissedL
       
  1108 // Called when user cancels waiting note or process finishes
       
  1109 // ---------------------------------------------------------
       
  1110 //	
       
  1111 void CFMRadioScanLocalStationsView::DialogDismissedL( TInt  aButtonId ) 	
       
  1112 	{
       
  1113 	FTRACE(FPrint(_L("CFMRadioScanLocalStationsView::DialogDismissedL")));	
       
  1114 	iScanningNote = NULL;
       
  1115 	if ( aButtonId == EAknSoftkeyCancel )
       
  1116    		{
       
  1117       	// cancel any process in here    	
       
  1118    		/*Dialog get this button ID when dismissed, if headset is pulled off
       
  1119    		we don't want to change the cancel type*/
       
  1120    		if( iCancelType != EFMRadioCancelScanByHeadsetDisconnect)
       
  1121    			{
       
  1122    	   		SetScanCanceled(EFMRadioCancelScanBySoftkey);
       
  1123    			}
       
  1124    		iRadioEngine.CancelScanLocalStationsScan(); 
       
  1125   		}
       
  1126 	}
       
  1127 
       
  1128 void CFMRadioScanLocalStationsView::SetScanCanceled( TFMRadioCancelScanType aType )
       
  1129 	{
       
  1130 	CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
  1131 	
       
  1132 	if ( appUi->IsStartupWizardRunning() )
       
  1133 	    {
       
  1134 	    FTRACE(FPrint(_L("CFMRadioScanLocalStationsView::SetScanCanceled")));	
       
  1135 	    iScanCancelled = ETrue;
       
  1136 	    iCancelType = aType;
       
  1137 	    }
       
  1138 	else
       
  1139 		{
       
  1140 		iScanCancelled = EFalse;
       
  1141 		iCancelType = EFMRadioCancelScanDefault;
       
  1142 		}
       
  1143 	}
       
  1144 
       
  1145 TFMRadioCancelScanType CFMRadioScanLocalStationsView::CancelType()
       
  1146 	{
       
  1147 	return iCancelType;
       
  1148 	}
       
  1149 
       
  1150 // ---------------------------------------------------------
       
  1151 // CFMRadioScanLocalStationsContainer::SaveFoundChannelsToPresets
       
  1152 // Save scanned channels to presets 
       
  1153 // ---------------------------------------------------------
       
  1154 //	
       
  1155 void CFMRadioScanLocalStationsView::SaveFoundChannelsToPresetsL( TSavingMode aSavingMode )
       
  1156 	{
       
  1157 	FTRACE(FPrint(_L("CFMRadioScanLocalStationsView::SaveFoundChannelsToPresetsL Mode %d"), aSavingMode ) );
       
  1158 	CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
  1159 	
       
  1160 	//store as much as the list is keeping
       
  1161 	TInt limit;	
       
  1162 	TInt chCount = iScannedChannels.Count();
       
  1163 	
       
  1164 	if ( chCount >= KMaxNumberOfChannelListItems )
       
  1165 		{
       
  1166 		limit = KMaxNumberOfChannelListItems;
       
  1167 		}
       
  1168 	else
       
  1169 		{
       
  1170 		limit = chCount;
       
  1171 		}
       
  1172 	
       
  1173 	TInt savedChannelCount = 0;	
       
  1174 	
       
  1175     if ( aSavingMode == EAppend ) 
       
  1176         {
       
  1177         /** Append found channels to preset list */		
       
  1178         for ( TInt freqIx = 0; KMaxNumberOfChannelListItems > iObserver.Channels().Count() && 
       
  1179             chCount > freqIx; freqIx++ )
       
  1180             {
       
  1181             const TDesC& name = iScannedChannels[ freqIx ]->PresetNameValid() ? 
       
  1182                     iScannedChannels[ freqIx ]->PresetName() : KNullDesC;
       
  1183 
       
  1184 		    iObserver.AddChannelToListL( name,
       
  1185                                          iScannedChannels[ freqIx ]->PresetFrequency() );
       
  1186 						
       
  1187 			savedChannelCount++;
       
  1188 
       
  1189 			}
       
  1190 		
       
  1191 		iObserver.UpdateChannelsL( EStoreAllToRepository, 0, 0 );
       
  1192 
       
  1193 		}
       
  1194 	else // Replace
       
  1195 		{
       
  1196 		iObserver.UpdateChannelsL( ERemoveAllFromRepository, 0, 0  );
       
  1197 		
       
  1198 		for ( TInt index = 0; index < limit; index++ )
       
  1199 			{
       
  1200             const TDesC& name = iScannedChannels[ index ]->PresetNameValid() ? 
       
  1201                     iScannedChannels[ index ]->PresetName() : KNullDesC;
       
  1202 			iObserver.AddChannelToListL( name,
       
  1203                                          iScannedChannels[ index ]->PresetFrequency() );
       
  1204 			savedChannelCount++;
       
  1205 			}
       
  1206 		iObserver.UpdateChannelsL( EStoreAllToRepository, 0, 0 );
       
  1207 		}
       
  1208 	
       
  1209     // display note about how many many channels were saved to the preset list
       
  1210     HBufC* string = NULL;                    
       
  1211     string = StringLoader::LoadLC( R_QTN_FMRADIO_STATIONS_SAVED, savedChannelCount, iEikonEnv );        
       
  1212     CAknConfirmationNote* note = new ( ELeave ) CAknConfirmationNote( ETrue ); // waiting
       
  1213     note->ExecuteLD( *string );
       
  1214     CleanupStack::PopAndDestroy( string );
       
  1215     
       
  1216     ActivateMainViewL();
       
  1217     }
       
  1218 
       
  1219 // ---------------------------------------------------------
       
  1220 // CFMRadioScanLocalStationsView::PlayCurrentlySelectedChannel
       
  1221 // Play currently selected channel from scan local stations list
       
  1222 // ---------------------------------------------------------
       
  1223 //
       
  1224 void CFMRadioScanLocalStationsView::PlayCurrentlySelectedChannelL()
       
  1225     {
       
  1226     FTRACE(FPrint(_L("CFMRadioScanLocalStationsView::PlayCurrentlySelectedChannelL")));
       
  1227     
       
  1228     TInt selectedChannel = CurrentlySelectedChannel();    
       
  1229     if ( ChannelInUse( selectedChannel ) )
       
  1230         {
       
  1231         TInt selectedFrequency = iScannedChannels[ selectedChannel ]->PresetFrequency();
       
  1232         
       
  1233         if ( iRadioEngine.GetTunedFrequency() != selectedFrequency )
       
  1234             {
       
  1235             CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
  1236             iTuneRequested = ETrue;
       
  1237             SetNowPlayingChannelL( selectedChannel );
       
  1238             SetLastListenedChannel( selectedChannel );
       
  1239             appUi->TuneL( selectedFrequency );
       
  1240             }
       
  1241         else
       
  1242             {
       
  1243             SetNowPlayingChannelL( selectedChannel );
       
  1244             SetLastListenedChannel( selectedChannel );
       
  1245             iRadioEngine.SetMuteOn( EFalse );
       
  1246             }
       
  1247         }
       
  1248     }
       
  1249 
       
  1250 // ---------------------------------------------------------
       
  1251 // CFMRadioScanLocalStationsView::ShowToolbar
       
  1252 // Sets toolbar visibility.
       
  1253 // ---------------------------------------------------------
       
  1254 //
       
  1255 void CFMRadioScanLocalStationsView::ShowToolbar( TBool aVisible )
       
  1256 	{
       
  1257 	if ( iToolbar && AknLayoutUtils::PenEnabled() )
       
  1258 		{						
       
  1259 		iToolbar->SetToolbarVisibility( aVisible );
       
  1260 		iToolbar->UpdateBackground();
       
  1261 		iToolbar->DrawDeferred();			
       
  1262 		// just to make sure container has the right rect when toolbar is displayed
       
  1263 		if ( aVisible && iContainer )
       
  1264 			{
       
  1265 			iContainer->SetRect( ClientRect() );	
       
  1266 			}		
       
  1267 		}
       
  1268 	}
       
  1269 		
       
  1270 // ---------------------------------------------------------------------------
       
  1271 // CFMRadioScanLocalStationsView::RdsDataProgrammeService
       
  1272 // ---------------------------------------------------------------------------
       
  1273 //
       
  1274 void CFMRadioScanLocalStationsView::RdsDataProgrammeService( const TDesC& aProgramService )
       
  1275     {
       
  1276     FTRACE(FPrint(_L("CFMRadioScanLocalStationsView::RdsDataProgrammeService")));
       
  1277     if ( iContainer && !iTuneRequested && aProgramService.Length() > 0 )
       
  1278         {
       
  1279         TInt tunedChannel = CurrentlyPlayingChannel();
       
  1280         
       
  1281         TRAP_IGNORE
       
  1282             (
       
  1283             if ( ChannelInUse( tunedChannel ) )
       
  1284                 {
       
  1285                 iContainer->UpdateChannelListContentL( tunedChannel,
       
  1286                         aProgramService,
       
  1287                         iScannedChannels[ tunedChannel ]->PresetFrequency(),
       
  1288                         ETrue,
       
  1289                         ETrue );
       
  1290 
       
  1291                 // update PS name also to the list containing the scanned preset values
       
  1292                 iScannedChannels[ tunedChannel ]->SetPresetNameL( aProgramService );
       
  1293                 iContainer->DrawDeferred();
       
  1294                 }
       
  1295             )
       
  1296         }
       
  1297     }
       
  1298 
       
  1299 // ---------------------------------------------------------------------------
       
  1300 // CFMRadioScanLocalStationsView::RdsDataPsNameIsStatic
       
  1301 // ---------------------------------------------------------------------------
       
  1302 //
       
  1303 void CFMRadioScanLocalStationsView::RdsDataPsNameIsStatic( TBool aStatic )
       
  1304     {
       
  1305     TInt tunedChannel = CurrentlyPlayingChannel();
       
  1306     if( ChannelInUse( tunedChannel ) )
       
  1307         {
       
  1308         iScannedChannels[ tunedChannel ]->SetPresetNameValid( aStatic );
       
  1309         }
       
  1310     }
       
  1311 
       
  1312 // ---------------------------------------------------------
       
  1313 // CFMRadioScanLocalStationsView::RdsDataRadioText
       
  1314 // ---------------------------------------------------------
       
  1315 //
       
  1316 void CFMRadioScanLocalStationsView::RdsDataRadioText( const TDesC&/* aRadioText */)
       
  1317     {
       
  1318     }
       
  1319 
       
  1320 // ---------------------------------------------------------------------------
       
  1321 // CFMRadioScanLocalStationsView::RdsAfSearchBegin
       
  1322 // ---------------------------------------------------------------------------
       
  1323 //
       
  1324 void CFMRadioScanLocalStationsView::RdsAfSearchBegin()
       
  1325     {
       
  1326     }
       
  1327 
       
  1328 // ---------------------------------------------------------------------------
       
  1329 // CFMRadioScanLocalStationsView::RdsAfSearchEnd
       
  1330 // ---------------------------------------------------------------------------
       
  1331 //
       
  1332 void CFMRadioScanLocalStationsView::RdsAfSearchEnd( TUint32 /*aFrequency*/, TInt /*aError*/ )
       
  1333     {
       
  1334     }
       
  1335 
       
  1336 // ---------------------------------------------------------------------------
       
  1337 // CFMRadioScanLocalStationsView::RdsAfSearchStateChange
       
  1338 // ---------------------------------------------------------------------------
       
  1339 //
       
  1340 void CFMRadioScanLocalStationsView::RdsAfSearchStateChange( TBool /*aEnabled*/ )
       
  1341     { 
       
  1342     }
       
  1343 
       
  1344 // ---------------------------------------------------------------------------
       
  1345 // CFMRadioScanLocalStationsView::RdsAvailable
       
  1346 // ---------------------------------------------------------------------------
       
  1347 //
       
  1348 void CFMRadioScanLocalStationsView::RdsAvailable( TBool /*aAvailable*/ )
       
  1349     {
       
  1350     }
       
  1351 
       
  1352 // --------------------------------------------------------------------------------
       
  1353 // CFMRadioScanLocalStationsView::PrepareToolbar
       
  1354 // Prepare toolbar for displaying basic radio command buttons
       
  1355 // --------------------------------------------------------------------------------
       
  1356 //
       
  1357 void CFMRadioScanLocalStationsView::PrepareToolbar()
       
  1358 	{
       
  1359     if ( AknLayoutUtils::PenEnabled() )
       
  1360         {
       
  1361         iToolbar = Toolbar();   	
       
  1362         iToolbar->SetToolbarVisibility( EFalse );
       
  1363         // Set observer
       
  1364         iToolbar->SetToolbarObserver( this );
       
  1365         }
       
  1366     }
       
  1367 	
       
  1368 // --------------------------------------------------------------------------------
       
  1369 // CFMRadioScanLocalStationsView::OfferToolbarEventL
       
  1370 // Handle commands from toolbar.
       
  1371 // --------------------------------------------------------------------------------
       
  1372 //
       
  1373 void CFMRadioScanLocalStationsView::OfferToolbarEventL( TInt aCommandId )
       
  1374     {
       
  1375     switch ( aCommandId )
       
  1376         {
       
  1377         case EFMRadioToolbarButtonCmdSaveAll:
       
  1378             {
       
  1379             HandleCommandL( EFMRadioCmdSaveAllChannels );
       
  1380             break;
       
  1381             }
       
  1382         case EFMRadioToolbarButtonCmdScan:
       
  1383             {
       
  1384             HandleCommandL( EFMRadioCmdScanLocalStationsScan );
       
  1385             break;
       
  1386             }
       
  1387         case EFMRadioToolbarButtonCmdToggleIhf:
       
  1388             {
       
  1389             if ( iRadioEngine.GetAudioOutput() == CRadioEngine::EFMRadioOutputHeadset )
       
  1390                 {
       
  1391                 AppUi()->HandleCommandL( EFMRadioCmdActivateIhf );
       
  1392                 }
       
  1393             else
       
  1394                 {
       
  1395                 AppUi()->HandleCommandL( EFMRadioCmdDeactivateIhf );
       
  1396                 }
       
  1397             break;
       
  1398             }
       
  1399         default:
       
  1400             {
       
  1401             break;
       
  1402             }
       
  1403         }
       
  1404     }
       
  1405 
       
  1406 // --------------------------------------------------------------------------------
       
  1407 // CFMRadioScanLocalStationsView::SetToolbarDimmedState
       
  1408 // set toolbar buttons dimmed state
       
  1409 // --------------------------------------------------------------------------------
       
  1410 //
       
  1411 void CFMRadioScanLocalStationsView::SetToolbarDimmedState( const TBool aState )
       
  1412 	{
       
  1413     if ( iToolbar && AknLayoutUtils::PenEnabled() )	
       
  1414         {
       
  1415         iToolbar->SetDimmed( aState );
       
  1416         if ( !aState )
       
  1417             {
       
  1418             UpdateToolbar();
       
  1419             }
       
  1420         iToolbar->DrawDeferred();
       
  1421         }
       
  1422     }
       
  1423 
       
  1424 // --------------------------------------------------------------------------------
       
  1425 // CFMRadioScanLocalStationsView::UpdateToolbar
       
  1426 // Set save buttons dimming state
       
  1427 // --------------------------------------------------------------------------------
       
  1428 //
       
  1429 void CFMRadioScanLocalStationsView::UpdateToolbar()
       
  1430     {
       
  1431     if ( iContainer && iToolbar && AknLayoutUtils::PenEnabled() )
       
  1432         {
       
  1433         if ( iRadioEngine.IsAudioRoutingPossible() )
       
  1434             {
       
  1435                 if ( iRadioEngine.IsHeadsetConnected() )
       
  1436                     {
       
  1437                     CAknButton* centerButton = NULL;    
       
  1438                     centerButton = static_cast<CAknButton*>( iToolbar->ControlOrNull( EFMRadioToolbarButtonCmdToggleIhf ) );    
       
  1439 
       
  1440                     iToolbar->SetItemDimmed( EFMRadioToolbarButtonCmdToggleIhf, EFalse, ETrue );
       
  1441                     
       
  1442                     if ( iRadioEngine.GetAudioOutput() == CRadioEngine::EFMRadioOutputIHF )
       
  1443                         {
       
  1444                         if ( centerButton )
       
  1445                             {
       
  1446                             centerButton->SetCurrentState( 1, ETrue );
       
  1447                             }
       
  1448                         }
       
  1449                     else
       
  1450                         {
       
  1451                         if ( centerButton )
       
  1452                             {
       
  1453                             centerButton->SetCurrentState( 0, ETrue );
       
  1454                             }
       
  1455                         }
       
  1456                     }
       
  1457                 else
       
  1458                     {
       
  1459                     iToolbar->SetItemDimmed( EFMRadioToolbarButtonCmdToggleIhf, ETrue, ETrue );
       
  1460                     }
       
  1461                 }
       
  1462             else
       
  1463                 {
       
  1464                 iToolbar->SetItemDimmed( EFMRadioToolbarButtonCmdToggleIhf, ETrue, ETrue );
       
  1465                 }
       
  1466 
       
  1467         TInt chCount = iScannedChannels.Count();
       
  1468         if ( chCount == 0 )
       
  1469             { //dim save buttons
       
  1470             iToolbar->SetItemDimmed( EFMRadioToolbarButtonCmdSaveAll, ETrue, ETrue );
       
  1471             }
       
  1472         else if ( chCount == 1 )
       
  1473             { //dim 'save all' button.
       
  1474             iToolbar->SetItemDimmed( EFMRadioToolbarButtonCmdSaveAll, ETrue, ETrue );
       
  1475             }
       
  1476             else
       
  1477             { //undim both
       
  1478             iToolbar->SetItemDimmed( EFMRadioToolbarButtonCmdSaveAll, EFalse, ETrue );
       
  1479             }
       
  1480         }
       
  1481     }
       
  1482 
       
  1483 // --------------------------------------------------------------------------------
       
  1484 // CFMRadioScanLocalStationsView::IsFrequencyScanned
       
  1485 // check if the frequency is already found
       
  1486 // --------------------------------------------------------------------------------
       
  1487 //
       
  1488 TInt CFMRadioScanLocalStationsView::FrequencyIndex( TInt aFrequency )
       
  1489     {
       
  1490     TInt frequencyIndex = KErrNotFound;
       
  1491     TInt chCount = iScannedChannels.Count();
       
  1492     
       
  1493     for ( TInt i = 0; i < chCount; i++ )
       
  1494         {
       
  1495         if ( aFrequency == iScannedChannels[ i ]->PresetFrequency() )
       
  1496             {
       
  1497             frequencyIndex = i;
       
  1498             break;
       
  1499             }
       
  1500         }
       
  1501     return frequencyIndex;
       
  1502     }
       
  1503 
       
  1504 // --------------------------------------------------------------------------------
       
  1505 // CFMRadioScanLocalStationsView::HandleOneChannelSaveL
       
  1506 // Handle single channel save
       
  1507 // --------------------------------------------------------------------------------
       
  1508 //
       
  1509 void CFMRadioScanLocalStationsView::HandleOneChannelSaveL()
       
  1510     {    
       
  1511     TInt currentPresetCount = iObserver.Channels().Count();
       
  1512     TInt chIndex = iContainer->CurrentlySelectedChannel();
       
  1513     TBool continueWithSave = ETrue;
       
  1514     
       
  1515     if ( !ChannelInUse( chIndex ) )
       
  1516         {
       
  1517         User::Leave( KErrNotFound );
       
  1518         }
       
  1519     // check if the channel list is full and show replace query if necessary
       
  1520     if ( currentPresetCount == KMaxNumberOfChannelListItems )
       
  1521         {
       
  1522         CAknQueryDialog* query = CAknQueryDialog::NewL();
       
  1523         if ( query->ExecuteLD( R_FMRADIO_REPLACE_EXISTING_CHANNELS_QUERY ) )
       
  1524             {
       
  1525             iObserver.UpdateChannelsL( ERemoveAllFromRepository, 0, 0  );
       
  1526             }
       
  1527         else
       
  1528             {
       
  1529             continueWithSave = EFalse;
       
  1530             }
       
  1531         }
       
  1532     if ( continueWithSave )
       
  1533         {
       
  1534         const TDesC& name = iScannedChannels[ chIndex ]->PresetNameValid() ? 
       
  1535                 iScannedChannels[ chIndex ]->PresetName() : KNullDesC;
       
  1536         TInt presetFrequency = iScannedChannels[ chIndex ]->PresetFrequency();
       
  1537         iObserver.AddChannelToListL( name, 
       
  1538                                      presetFrequency );
       
  1539         iObserver.UpdateChannelsL( EStoreAllToRepository, 0, 0 );
       
  1540 
       
  1541         TBool updateNowPlayingIcon = EFalse;
       
  1542         TInt tunedIndex = CurrentlyPlayingChannel();
       
  1543         // update now playing icon and list index
       
  1544         if ( chIndex == tunedIndex )
       
  1545             {
       
  1546             // channel is going be deleted so now playing index is not in the list
       
  1547             iNowPlayingIndex = KErrNotFound;
       
  1548             }
       
  1549         else if ( chIndex < tunedIndex )
       
  1550             {
       
  1551             iNowPlayingIndex = tunedIndex - 1;
       
  1552             iContainer->HideNowPlayingIconL( tunedIndex, ETrue );
       
  1553             updateNowPlayingIcon = ETrue;
       
  1554             }
       
  1555          else
       
  1556             {
       
  1557             // NOP
       
  1558             }
       
  1559         
       
  1560         // remove also from the UI list
       
  1561         iContainer->RemoveChannelListContentL( chIndex );
       
  1562         
       
  1563         if ( updateNowPlayingIcon )
       
  1564             {
       
  1565             iContainer->UpdateNowPlayingIconL( tunedIndex - 1 );
       
  1566             }
       
  1567         // received PS name is shown                                
       
  1568         if ( name.Length() > 0 )
       
  1569             {
       
  1570             HBufC* nameSavedString = StringLoader::LoadLC( R_QTN_FMRADIO_SAVING_DONE_ONE, name, iEikonEnv );
       
  1571             CAknConfirmationNote* saveInfoNote = new ( ELeave ) CAknConfirmationNote( ETrue ); // waiting
       
  1572             saveInfoNote->ExecuteLD( *nameSavedString );
       
  1573             CleanupStack::PopAndDestroy( nameSavedString );  
       
  1574             }
       
  1575         else // show frequency
       
  1576             {
       
  1577             TReal frequency = static_cast<TReal>( presetFrequency / static_cast<TReal>( KHzConversionFactor ) );
       
  1578             TRealFormat format( KFrequencyMaxLength, iRadioEngine.DecimalCount() );
       
  1579             TBuf<KFrequencyMaxLength> frequencyString;
       
  1580             frequencyString.Num( frequency, format );
       
  1581             AknTextUtils::LanguageSpecificNumberConversion( frequencyString );
       
  1582 
       
  1583             HBufC* freqSavedString = StringLoader::LoadLC( R_QTN_FMRADIO_SAVING_DONE_ONE_NO_NAME, frequencyString, iEikonEnv );
       
  1584             CAknConfirmationNote* saveInfoNote = new ( ELeave ) CAknConfirmationNote( ETrue ); // waiting
       
  1585             saveInfoNote->ExecuteLD( *freqSavedString );
       
  1586             CleanupStack::PopAndDestroy( freqSavedString );
       
  1587             }
       
  1588         // channel info is removed after save
       
  1589         delete iScannedChannels[ chIndex ];
       
  1590         iScannedChannels.Remove( chIndex );
       
  1591         iScannedChannels.Compress();
       
  1592         }
       
  1593     UpdateToolbar();
       
  1594     }
       
  1595 
       
  1596 // --------------------------------------------------------------------------------
       
  1597 // CFMRadioScanLocalStationsView::ActivateMainViewL
       
  1598 // Activates main view
       
  1599 // --------------------------------------------------------------------------------
       
  1600 //
       
  1601 void CFMRadioScanLocalStationsView::ActivateMainViewL()
       
  1602     {
       
  1603     CAknViewAppUi* appUi = AppUi();
       
  1604     
       
  1605     if ( !appUi->IsForeground() )
       
  1606         {
       
  1607         // don't bring radio automatically to the foreground
       
  1608         // if the view is about to change
       
  1609         // and we are still in the background
       
  1610         appUi->SetCustomControl( 1 );
       
  1611         appUi->ActivateLocalViewL( KFMRadioMainViewId );
       
  1612         appUi->SetCustomControl( 0 );
       
  1613         }
       
  1614     else
       
  1615         {
       
  1616         appUi->ActivateLocalViewL( KFMRadioMainViewId );
       
  1617         }
       
  1618     }
       
  1619 
       
  1620 // --------------------------------------------------------------------------------
       
  1621 // CFMRadioScanLocalStationsView::SetContextMenu
       
  1622 // --------------------------------------------------------------------------------
       
  1623 //
       
  1624 void CFMRadioScanLocalStationsView::SetContextMenu( TInt aMenuTitleResourceId )
       
  1625     {
       
  1626     if ( !AknLayoutUtils::PenEnabled() )
       
  1627         {
       
  1628         CEikMenuBar* menubar = MenuBar();
       
  1629         if ( menubar )
       
  1630             {
       
  1631             menubar->SetContextMenuTitleResourceId( aMenuTitleResourceId );
       
  1632             menubar->SetMenuType( CEikMenuBar::EMenuContext );
       
  1633             }
       
  1634         }
       
  1635     }
       
  1636 
       
  1637 // --------------------------------------------------------------------------------
       
  1638 // CFMRadioScanLocalStationsView::HandleScanListRemConEventL
       
  1639 // --------------------------------------------------------------------------------
       
  1640 //
       
  1641 void CFMRadioScanLocalStationsView::HandleScanListRemConEventL( TAccessoryEvent aEvent )
       
  1642     {
       
  1643     TInt scannedChannelCount = iScannedChannels.Count();
       
  1644 
       
  1645     if ( scannedChannelCount >= 1 )
       
  1646         {
       
  1647         TInt selectedChannelIndex = CurrentlySelectedChannel();
       
  1648         TInt nextChannellIndex = 0;
       
  1649         
       
  1650         if ( aEvent == EForward )
       
  1651             {
       
  1652             nextChannellIndex = selectedChannelIndex + 1;
       
  1653             
       
  1654             if ( nextChannellIndex >= scannedChannelCount )
       
  1655                 {
       
  1656                 // go around the the list to the first channnel
       
  1657                 nextChannellIndex = 0;
       
  1658                 }
       
  1659             }
       
  1660         else if ( aEvent == ERewind )
       
  1661             {
       
  1662             nextChannellIndex = selectedChannelIndex - 1;
       
  1663         
       
  1664             if ( nextChannellIndex < KMinNumberOfChannelListItems )
       
  1665                 {
       
  1666                 // jump to the last item
       
  1667                 nextChannellIndex = scannedChannelCount - 1;
       
  1668                 }
       
  1669             }
       
  1670         // check that index is really a valid one
       
  1671         if ( ChannelInUse( nextChannellIndex ) )
       
  1672             {
       
  1673             TInt nextChannelFrequency = iScannedChannels[ nextChannellIndex ]->PresetFrequency();
       
  1674             // tune if necessary
       
  1675             if ( iRadioEngine.GetTunedFrequency() != nextChannelFrequency )
       
  1676                 {
       
  1677                 CFMRadioAppUi* appUi = static_cast<CFMRadioAppUi*>( iCoeEnv->AppUi() );
       
  1678                 appUi->TuneL( nextChannelFrequency );
       
  1679                 }
       
  1680             }
       
  1681         }
       
  1682     }
       
  1683 
       
  1684 // --------------------------------------------------------------------------------
       
  1685 // CFMRadioScanLocalStationsView::SortedFrequencyListIndex
       
  1686 // --------------------------------------------------------------------------------
       
  1687 //
       
  1688 TInt CFMRadioScanLocalStationsView::SortedFrequencyListIndex( TInt aFrequency )
       
  1689     {
       
  1690     TInt channelCount = iScannedChannels.Count();
       
  1691     TInt sortedIndex = 0;
       
  1692     
       
  1693     for ( TInt i = 0; i < channelCount; i++ )
       
  1694         {
       
  1695         TInt presetFreq = iScannedChannels[i]->PresetFrequency();
       
  1696         
       
  1697         if ( aFrequency > presetFreq )
       
  1698             {
       
  1699             sortedIndex = i + 1;
       
  1700             }
       
  1701         else if ( aFrequency < presetFreq )
       
  1702             {
       
  1703             sortedIndex = i;
       
  1704             break;
       
  1705             }        
       
  1706         }
       
  1707     return sortedIndex;
       
  1708     }
       
  1709 
       
  1710 // End of File