fmradio/fmradiomcpplugin/src/fmradiomcpplugin.cpp
branchRCL_3
changeset 12 9f3ff466f56b
parent 9 0004e923f486
equal deleted inserted replaced
11:97dcae98e602 12:9f3ff466f56b
    22 #include <data_caging_paths_strings.hrh>
    22 #include <data_caging_paths_strings.hrh>
    23 #include <e32cmn.h>
    23 #include <e32cmn.h>
    24 #include <ecom/implementationproxy.h>
    24 #include <ecom/implementationproxy.h>
    25 #include <liwvariant.h>
    25 #include <liwvariant.h>
    26 #include <StringLoader.h>
    26 #include <StringLoader.h>
    27 #include <aknsconstants.hrh>
    27 #include <AknsConstants.h>
    28 #include <AknsItemID.h>
    28 #include <AknsItemID.h>
    29 #include <fmradiomcpplugin.rsg>
    29 #include <fmradiomcpplugin.rsg>
    30 #include <fmradio.mbg>
    30 #include <fmradio.mbg>
    31 
    31 
    32 #include "fmradioactionhandler.h"
    32 #include "fmradioactionhandler.h"
    36 #include "fmradioactiveidleenginenotifyhandler.h"
    36 #include "fmradioactiveidleenginenotifyhandler.h"
    37 #include "fmradiodefines.h"
    37 #include "fmradiodefines.h"
    38 #include "debug.h"
    38 #include "debug.h"
    39 #include "fmradiomcpplugin.h"
    39 #include "fmradiomcpplugin.h"
    40 #include "fmradiomcpplugin.hrh"
    40 #include "fmradiomcpplugin.hrh"
    41 #include "AknsConstants.h"
       
    42 
    41 
    43 _LIT( KFMRadioMifFileName, "fmradio.mif" );
    42 _LIT( KFMRadioMifFileName, "fmradio.mif" );
    44 _LIT( KFMRadioMifDir, "\\resource\\apps\\" );
    43 _LIT( KFMRadioMifDir, "\\resource\\apps\\" );
    45 
    44 
    46 _LIT( KFMRadioMCPPluginResourceFileName, "fmradiomcpplugin.rsc" );
    45 _LIT( KFMRadioMCPPluginResourceFileName, "fmradiomcpplugin.rsc" );
    74         {
    73         {
    75         CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
    74         CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
    76         }
    75         }
    77 
    76 
    78     delete iEngine;
    77     delete iEngine;
    79     iNowPlayingText.Close();
       
    80     iLastPlayedText.Close();
       
    81     iAntennaNotConnectedText.Close();
    78     iAntennaNotConnectedText.Close();
    82     iTuningText.Close();
    79     iTuningText.Close();
    83     iSavedStationFormat.Close();
    80     iSavedStationFormat.Close();
    84     iSavedStationFormatNoName.Close();
    81     iSavedStationFormatNoName.Close();
    85     iFrequencyFormat.Close();
    82     iFrequencyFormat.Close();
    86     iSavedStationFormatMenu.Close();
       
    87     iSavedStationFormatNoNameMenu.Close();
       
    88     iFrequencyFormatMenu.Close();
       
    89     
    83     
    90     iMifFileName.Close();
    84     iMifFileName.Close();
    91     }
    85     }
    92 
    86 
    93 CFMRadioMCPPlugin::CFMRadioMCPPlugin( MMCPPluginObserver* aObserver )
    87 CFMRadioMCPPlugin::CFMRadioMCPPlugin( MMCPPluginObserver* aObserver )
   100     FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::ConstructL" )));
    94     FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::ConstructL" )));
   101     InitializeResourceLoadingL();
    95     InitializeResourceLoadingL();
   102     
    96     
   103     CCoeEnv* coeEnv = CCoeEnv::Static();
    97     CCoeEnv* coeEnv = CCoeEnv::Static();
   104 
    98 
   105     iNowPlayingText.Assign( StringLoader::LoadL( R_QTN_FMRADIO_SUITE_NOW_PLAYING, coeEnv ) );
       
   106     iLastPlayedText.Assign( StringLoader::LoadL( R_QTN_FMRADIO_SUITE_LAST_PLAYED, coeEnv ) );
       
   107     
       
   108     iAntennaNotConnectedText.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_CON_HEADSET, coeEnv ) );
    99     iAntennaNotConnectedText.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_CON_HEADSET, coeEnv ) );
   109     iTuningText.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_TUNING, coeEnv ) );
   100     iTuningText.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_TUNING, coeEnv ) );
   110     iSavedStationFormat.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_STATION_SAVED, coeEnv ) );
   101     iSavedStationFormat.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_STATION_SAVED, coeEnv ) );
   111     iSavedStationFormatNoName.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_STATION_SAVED_FREQ, coeEnv ) );
   102     iSavedStationFormatNoName.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_STATION_SAVED_FREQ, coeEnv ) );
   112     iFrequencyFormat.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_NOTSAVED_FREQUENCY, coeEnv ) );
   103     iFrequencyFormat.Assign( StringLoader::LoadL( R_QTN_FMRADIO_WIDGET_NOTSAVED_FREQUENCY, coeEnv ) );
   113     
       
   114     iSavedStationFormatMenu.Assign( StringLoader::LoadL( R_QTN_FMRADIO_SUITE_PLAYING_SAVED_WITH_NAME, coeEnv ) );
       
   115     iSavedStationFormatNoNameMenu.Assign( StringLoader::LoadL( R_QTN_FMRADIO_SUITE_PLAYING_SAVED_WITHOUT_NAME, coeEnv ) );
       
   116     iFrequencyFormatMenu.Assign( StringLoader::LoadL( R_QTN_FMRADIO_SUITE_PLAYING_NOT_SAVED, coeEnv ) );
       
   117     
   104     
   118     // Release the resource file, because we don't want to keep file handle open.
   105     // Release the resource file, because we don't want to keep file handle open.
   119     // That would prevent updating the binary with SIS. 
   106     // That would prevent updating the binary with SIS. 
   120     if ( iResourceOffset > 0 )
   107     if ( iResourceOffset > 0 )
   121         {
   108         {
   217     FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::ActivateL()" )));
   204     FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::ActivateL()" )));
   218     iActive = ETrue;
   205     iActive = ETrue;
   219     iObserver->BecameActiveL( this );
   206     iObserver->BecameActiveL( this );
   220     
   207     
   221     iObserver->PublishTextL( this, EMusicWidgetDefaultText, KNullDesC );
   208     iObserver->PublishTextL( this, EMusicWidgetDefaultText, KNullDesC );
   222 
   209     
   223     iObserver->PublishImageL( this, EMusicMenuMusicInfoImage1,
       
   224                     KAknsIIDQgnIndiRadioDefault, 
       
   225                     iMifFileName, 
       
   226                     EMbmFmradioQgn_indi_radio_default, 
       
   227                     EMbmFmradioQgn_indi_radio_default_mask);
       
   228 
       
   229     iObserver->PublishImageL( this, EMusicWidgetImage1,
   210     iObserver->PublishImageL( this, EMusicWidgetImage1,
   230                     KAknsIIDNone,
   211                     KAknsIIDQgnIndiRadioDefault,
   231                     iMifFileName,
   212                     iMifFileName,
   232                     EMbmFmradioQgn_menu_radio,
   213                     EMbmFmradioQgn_indi_radio_default,
   233                     EMbmFmradioQgn_menu_radio_mask );
   214                     EMbmFmradioQgn_indi_radio_default_mask );
   234 
   215 
   235     InstallFMRadioCommandActionL( KFMRadioCommandValueStartNowPlaying, EMusicWidgetTrigger1 );
   216     InstallFMRadioCommandActionL( KFMRadioCommandValueStartNowPlaying, EMusicWidgetTrigger1 );
   236     InstallFMRadioCommandActionL( KFMRadioCommandValueStartNowPlaying, EMusicMenuMusicInfoTrigger );
       
   237     HandleChannelChangeL( iEngine->Channel() );
   217     HandleChannelChangeL( iEngine->Channel() );
   238     }
   218     }
   239 
   219 
   240 // ---------------------------------------------------------------------------
   220 // ---------------------------------------------------------------------------
   241 // CFMRadioMCPPlugin::UpdatePublishedToolBarL
   221 // CFMRadioMCPPlugin::UpdatePublishedToolBarL
   481                     }
   461                     }
   482                 
   462                 
   483                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Widget saved station: \"%S\""), &name ));
   463                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Widget saved station: \"%S\""), &name ));
   484                 iObserver->PublishTextL( this, EMusicWidgetText1, name );
   464                 iObserver->PublishTextL( this, EMusicWidgetText1, name );
   485                 CleanupStack::PopAndDestroy(); // name
   465                 CleanupStack::PopAndDestroy(); // name
   486 
       
   487                 // For Music Suite
       
   488                 // Preserve space for the channel name, format string and maximum index number
       
   489                 name.CreateL( iEngine->ChannelName().Length() + 
       
   490                               iSavedStationFormatMenu.Length() + 
       
   491                               KDefaultRealWidth + 
       
   492                               rightToLeftCharWidth );
       
   493                 name.CleanupClosePushL();
       
   494                 StringLoader::Format( name, iSavedStationFormatMenu, KErrNotFound, iEngine->Channel() + 1 );
       
   495                 
       
   496                 tempName = name.AllocL();
       
   497                 StringLoader::Format( name, *tempName, KErrNotFound, iEngine->ChannelName() );
       
   498                 delete tempName;
       
   499                 tempName = NULL;
       
   500                 
       
   501                 if ( rightToLeftCharWidth )
       
   502                     {
       
   503                     //E.g. 1. Name -> Name .1
       
   504                     name.Insert( 0, KRightToLeftMark );
       
   505                     }
       
   506                 
       
   507                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Suite saved station: \"%S\""), &name ));
       
   508                 iObserver->PublishTextL( this, EMusicMenuMusicInfoLine2, name );
       
   509                 CleanupStack::PopAndDestroy(); // name
       
   510                 }
   466                 }
   511             else
   467             else
   512                 {
   468                 {
   513                 // Station saved, but name for it is not available
   469                 // Station saved, but name for it is not available
   514                 HBufC* frequencyString = FrequencyStringLC( iEngine->Frequency() );
   470                 HBufC* frequencyString = FrequencyStringLC( iEngine->Frequency() );
   534                     formattedFrequency.Insert( 0, KRightToLeftMark );
   490                     formattedFrequency.Insert( 0, KRightToLeftMark );
   535                     }
   491                     }
   536 
   492 
   537                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Widget saved station with frequency: \"%S\""), &formattedFrequency ));
   493                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Widget saved station with frequency: \"%S\""), &formattedFrequency ));
   538                 iObserver->PublishTextL( this, EMusicWidgetText1, formattedFrequency );
   494                 iObserver->PublishTextL( this, EMusicWidgetText1, formattedFrequency );
   539                 CleanupStack::PopAndDestroy(); // formattedFrequency
   495                 CleanupStack::PopAndDestroy( 2 ); // formattedFrequency, frequencyString
   540                 
       
   541                 // For Music Suite
       
   542                 formattedFrequency.CreateL( iSavedStationFormatNoNameMenu.Length() + 
       
   543                                             frequencyString->Length() + 
       
   544                                             KDefaultRealWidth + 
       
   545                                             rightToLeftCharWidth );
       
   546                 formattedFrequency.CleanupClosePushL();
       
   547                 StringLoader::Format( formattedFrequency, iSavedStationFormatNoNameMenu, KErrNotFound, iEngine->Channel() + 1 );
       
   548                 
       
   549                 tempFrequency = formattedFrequency.AllocL();
       
   550                 StringLoader::Format( formattedFrequency, *tempFrequency, KErrNotFound, *frequencyString );
       
   551                 delete tempFrequency;
       
   552                 tempFrequency = NULL;
       
   553                 
       
   554                 AknTextUtils::LanguageSpecificNumberConversion( formattedFrequency );
       
   555                 if ( rightToLeftCharWidth )
       
   556                     {
       
   557                     //E.g. 1. Name -> Name .1
       
   558                     formattedFrequency.Insert( 0, KRightToLeftMark );
       
   559                     }
       
   560 
       
   561                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Suite saved station with frequency: \"%S\""), &formattedFrequency ));
       
   562                 iObserver->PublishTextL( this, EMusicMenuMusicInfoLine2, formattedFrequency );
       
   563                 CleanupStack::PopAndDestroy( 2, frequencyString ); // formattedFrequency, frequencyString
       
   564                 }
   496                 }
   565             }
   497             }
   566         else if ( iEngine->RDSProgramService().Length() > 0 )
   498         else if ( iEngine->RDSProgramService().Length() > 0 )
   567             {
   499             {
   568             FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing HS PS name: \"%S\""), &iEngine->RDSProgramService() ));
   500             FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing HS PS name: \"%S\""), &iEngine->RDSProgramService() ));
   569             iObserver->PublishTextL( this, EMusicWidgetText1, iEngine->RDSProgramService() );
   501             iObserver->PublishTextL( this, EMusicWidgetText1, iEngine->RDSProgramService() );
   570             iObserver->PublishTextL( this, EMusicMenuMusicInfoLine2, iEngine->RDSProgramService() );
       
   571             }
   502             }
   572         else
   503         else
   573             {
   504             {
   574             TInt currentFrequency = iEngine->Frequency();
   505             TInt currentFrequency = iEngine->Frequency();
   575             // publish only valid frequency
   506             // publish only valid frequency
   593                     formattedFrequency.Insert( 0, KRightToLeftMark );
   524                     formattedFrequency.Insert( 0, KRightToLeftMark );
   594                     }
   525                     }
   595                 
   526                 
   596                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Widget frequency: \"%S\""), &formattedFrequency ));
   527                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Widget frequency: \"%S\""), &formattedFrequency ));
   597                 iObserver->PublishTextL( this, EMusicWidgetText1, formattedFrequency );
   528                 iObserver->PublishTextL( this, EMusicWidgetText1, formattedFrequency );
   598                 CleanupStack::PopAndDestroy(); // formattedFrequency
   529                 CleanupStack::PopAndDestroy( 2 ); // formattedFrequency,frequencyString
   599                 
       
   600                 // For Music Suite
       
   601                 // Preserve space for the format string and maximum index number
       
   602                 formattedFrequency.CreateL( iFrequencyFormatMenu.Length() + 
       
   603                                             frequencyString->Length() + 
       
   604                                             rightToLeftCharWidth );
       
   605                 formattedFrequency.CleanupClosePushL();
       
   606                 StringLoader::Format( formattedFrequency, iFrequencyFormatMenu, KErrNotFound, *frequencyString );
       
   607                 AknTextUtils::LanguageSpecificNumberConversion( formattedFrequency );
       
   608                
       
   609                 if ( rightToLeftCharWidth )
       
   610                     {
       
   611                     //E.g. 1. Name -> Name .1
       
   612                     formattedFrequency.Insert( 0, KRightToLeftMark );
       
   613                     }
       
   614                 
       
   615                 FTRACE(FPrint(_L(" *** S60 FMRadio -- CFMRadioMCPPlugin::UpdateMusicWidgetTextL - Publishing Music Suite frequency: \"%S\""), &formattedFrequency ));
       
   616                 iObserver->PublishTextL( this, EMusicMenuMusicInfoLine2, formattedFrequency );
       
   617                 CleanupStack::PopAndDestroy( 2, frequencyString ); // formattedFrequency, frequencyString
       
   618                 }
   530                 }
   619             else
   531             else
   620                 {
   532                 {
   621                 // Publish empty text instead of 0.00 MHz
   533                 // Publish empty text instead of 0.00 MHz
   622                 iObserver->PublishTextL( this, EMusicWidgetText1, KNullDesC );
   534                 iObserver->PublishTextL( this, EMusicWidgetText1, KNullDesC );
   623                 iObserver->PublishTextL( this, EMusicMenuMusicInfoLine2, KNullDesC );
       
   624                 }
   535                 }
   625             }
       
   626         if( iEngine->PowerState() == EFMRadioPSRadioPowerOn && !aForceApplicationClosing )
       
   627             {
       
   628             iObserver->PublishTextL( this, EMusicMenuMusicInfoLine1, iNowPlayingText );
       
   629             }
       
   630         else
       
   631             {
       
   632             iObserver->PublishTextL( this, EMusicMenuMusicInfoLine1, iLastPlayedText );
       
   633             }
   536             }
   634         }
   537         }
   635     }
   538     }
   636 
   539 
   637 // ---------------------------------------------------------------------------
   540 // ---------------------------------------------------------------------------