mmsharing/mmshindicator/src/musindicatorapi.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  MusIndicatorApi provides means to show notes and indicate
       
    15 *                availability of videosharing to user.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include "musindicatorapi.h"
       
    22 #include "musresourcefinderutil.h"
       
    23 #include "muslogger.h"
       
    24 #include "musindicatordsa.h"
       
    25 #include "mussettings.h"
       
    26 #include "mussettingskeys.h"
       
    27 #include "mussoundplayer.h"
       
    28 #include "musresourceutil.h"
       
    29 #include <musindicator.rsg>
       
    30 #include <AknGlobalConfirmationQuery.h>
       
    31 #include <AknGlobalMsgQuery.h>
       
    32 #include <coreapplicationuisdomainpskeys.h>
       
    33 
       
    34 
       
    35 const TInt KMusLiveSharingQueryTimeout = 5000000;
       
    36 
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 using namespace MusSettingsKeys;
       
    41 
       
    42 
       
    43 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewL( MMusIndicatorObserver& aObserver )
       
    44     {
       
    45     CMusIndicatorApi* self = CMusIndicatorApi::NewLC( aObserver );
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 
       
    51 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewLC( MMusIndicatorObserver& aObserver )
       
    52     {
       
    53     CMusIndicatorApi* self = new (ELeave) CMusIndicatorApi( &aObserver );
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     return self;
       
    57     }
       
    58 
       
    59 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewL()
       
    60     {
       
    61     CMusIndicatorApi* self = new (ELeave) CMusIndicatorApi( NULL );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 CMusIndicatorApi::~CMusIndicatorApi()
       
    70     {
       
    71     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::~CMusIndicatorApi" );
       
    72     
       
    73     Cancel();
       
    74     delete iQuery;
       
    75     delete iIndicatorWindow;
       
    76     delete iSoundPlayer;
       
    77     delete iLiveSharingQueryTimeout;
       
    78     if ( !IsSubscriber() )
       
    79         {
       
    80         Indicator( EFalse );
       
    81         }
       
    82     
       
    83     iProperty.Close();
       
    84 
       
    85     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::~CMusIndicatorApi" );
       
    86     }
       
    87 
       
    88 
       
    89 TBool CMusIndicatorApi::IsSubscriber() const
       
    90     {
       
    91     return !iObserver;
       
    92     }
       
    93 
       
    94 
       
    95     
       
    96 // ---------------------------------------------------------------------------
       
    97 // Provides a confirmation query to user and returns true if user selected
       
    98 // "yes".
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C TBool CMusIndicatorApi::ConfirmationQueryL( TVsPopupQuery aQuery )
       
   102     {
       
   103     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::ConfirmationQueryL" );
       
   104     
       
   105     CAknGlobalConfirmationQuery* dlg = CAknGlobalConfirmationQuery::NewLC();
       
   106     TRequestStatus status( KRequestPending );
       
   107     HBufC* prompt = NoteTextLC( aQuery );
       
   108     dlg->ShowConfirmationQueryL( status, *prompt, R_AVKON_SOFTKEYS_YES_NO );
       
   109     User::WaitForRequest( status );
       
   110     CleanupStack::PopAndDestroy( prompt );
       
   111     CleanupStack::PopAndDestroy( dlg );
       
   112     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::ConfirmationQueryL" );
       
   113     return status == EAknSoftkeyYes;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Indicates VS availability to user.
       
   118 // In operator specific variant this can include a popup-note, DSA note and
       
   119 // an audio tone played with CMdaAudioPlayerUtility.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C void CMusIndicatorApi::IndicateAvailabilityL()
       
   123     {
       
   124     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::IndicateAvailabilityL" )
       
   125     __ASSERT_ALWAYS( !IsSubscriber(), User::Leave( KErrArgument ) );
       
   126     
       
   127     Indicator( ETrue );
       
   128 
       
   129     if( MultimediaSharingSettings::PopupNotificationSettingL() ==
       
   130         EPopupNotificationOn )
       
   131         {
       
   132         // Show dialog
       
   133         MUS_LOG( "mus: [MUSIND]  CMusIndicatorApi::IndicateAvailabilityL - Show popup" )
       
   134         ShowLiveSharingQueryL( EFalse );
       
   135         }
       
   136 
       
   137     if( MultimediaSharingSettings::AuditoryNotificationSettingL() ==
       
   138         EAuditoryNotificationOn )
       
   139         {
       
   140         MUS_LOG( "mus: [MUSIND]  CMusIndicatorApi::IndicateAvailabilityL - Play tone" )
       
   141         PlayToneL();
       
   142         }
       
   143 
       
   144     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::IndicateAvailabilityL" )
       
   145     }
       
   146 
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // From CActive.
       
   150 // Handles completion of an outstanding asynchronous request.
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CMusIndicatorApi::RunL()
       
   154     {
       
   155     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::RunL" )
       
   156     
       
   157     if ( !IsSubscriber() )
       
   158         {
       
   159         MUS_LOG( "mus: [MUSIND ] : publisher" )
       
   160         StartLiveSharingL();
       
   161         }
       
   162     else
       
   163         {
       
   164         MUS_LOG( "mus: [MUSIND ] : subscriber" )
       
   165         ToggleIndicatorL();
       
   166         }
       
   167 
       
   168     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::RunL" )
       
   169     }
       
   170 
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CMusIndicatorApi::StartLiveSharingL()
       
   177     {
       
   178     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::StartLiveSharingL" )
       
   179     delete iQuery;
       
   180     iQuery = NULL;
       
   181    
       
   182     if( iLiveSharingQueryTimeout )
       
   183         {
       
   184         iLiveSharingQueryTimeout->Cancel();
       
   185         }  
       
   186     delete iLiveSharingQueryTimeout;
       
   187     iLiveSharingQueryTimeout = NULL;
       
   188 
       
   189     if( iStatus.Int() != KErrNotFound ) // eq. Cancel -button
       
   190         {
       
   191         if ( iObserver )
       
   192             {
       
   193             iObserver->StartLiveSharingL();
       
   194             }
       
   195         }
       
   196 
       
   197     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::StartLiveSharingL" )
       
   198     }
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // 
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CMusIndicatorApi::ToggleIndicatorL()
       
   206     {
       
   207     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::ToggleIndicatorL" )
       
   208     TInt val;
       
   209     
       
   210 
       
   211     
       
   212     User::LeaveIfError( RProperty::Get( KPSUidCoreApplicationUIs,
       
   213                                         KCoreAppUIsVideoSharingIndicator,
       
   214                                         val ) );
       
   215     iProperty.Subscribe( iStatus );
       
   216     SetActive();
       
   217     
       
   218     TBool on = ( val == ECoreAppUIsVideoSharingIndicatorOn );
       
   219     
       
   220     if ( on && !iIndicatorWindow 
       
   221          && MultimediaSharingSettings::OperatorVariantSettingL() ==
       
   222          EOperatorSpecific )
       
   223         {
       
   224         iIndicatorWindow = CMusIndicatorDsa::NewL();
       
   225         }
       
   226     else if ( !on )
       
   227         {
       
   228         delete iIndicatorWindow;
       
   229         iIndicatorWindow = NULL;
       
   230         }
       
   231     else
       
   232         {
       
   233         //NOP
       
   234         }
       
   235     
       
   236     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::ToggleIndicatorL" )
       
   237     }
       
   238 
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // From CActive.
       
   242 // Cancels an outstanding asynchronous request.
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 void CMusIndicatorApi::DoCancel()
       
   246     {
       
   247     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::DoCancel" )
       
   248 
       
   249     if( iLiveSharingQueryTimeout )
       
   250         {
       
   251         iLiveSharingQueryTimeout->Cancel();
       
   252         }
       
   253     delete iLiveSharingQueryTimeout;
       
   254     iLiveSharingQueryTimeout = NULL;
       
   255         
       
   256     if ( iQuery )
       
   257         {
       
   258         iQuery->CancelMsgQuery();
       
   259         }
       
   260     delete iQuery;
       
   261     iQuery = NULL;
       
   262     
       
   263     if ( IsSubscriber() )
       
   264         {
       
   265         iProperty.Cancel();
       
   266         }
       
   267     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::DoCancel" )
       
   268     }
       
   269 
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // From CActive.
       
   273 // Handles a leave occurring in the request completion event handler RunL.
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 #ifdef _DEBUG
       
   277 TInt CMusIndicatorApi::RunError( TInt aError )
       
   278 #else
       
   279 TInt CMusIndicatorApi::RunError( TInt )
       
   280 #endif
       
   281     {
       
   282     MUS_LOG1( "mus: [MUSIND]  -> CMusIndicatorApi::RunError(%d)", aError )
       
   283 
       
   284     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::RunError(%d)" )
       
   285     return KErrNone;
       
   286     }
       
   287 
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // From MMusSoundPlayerObserver.
       
   291 // Indicates completion of sound playback.
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 #ifdef _DEBUG
       
   295 void CMusIndicatorApi::PlaySoundComplete( TInt aError )
       
   296 #else
       
   297 void CMusIndicatorApi::PlaySoundComplete( TInt /* aError */ )
       
   298 #endif
       
   299     {
       
   300     MUS_LOG1( "mus: [MUSIND ] -> MusIndicatorApi::PlaySoundComplete(%d)", aError )
       
   301     delete iSoundPlayer;
       
   302     iSoundPlayer = NULL;
       
   303     MUS_LOG( "mus: [MUSIND ] <- MusIndicatorApi::PlaySoundComplete" )
       
   304     }
       
   305 
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 CMusIndicatorApi::CMusIndicatorApi( MMusIndicatorObserver* aObserver )
       
   312     : CActive( EPriorityStandard ),
       
   313     iObserver( aObserver )
       
   314     {
       
   315     }
       
   316 
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // 
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CMusIndicatorApi::ConstructL()
       
   323     {
       
   324     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::ConstructL" )
       
   325     
       
   326     if ( IsSubscriber() )
       
   327         {
       
   328         MUS_LOG( "mus: [MUSIND ] :  subscriber (called by aiwprovider)" )
       
   329 
       
   330         User::LeaveIfError( iProperty.Attach( KPSUidCoreApplicationUIs,
       
   331                                               KCoreAppUIsVideoSharingIndicator ) );
       
   332         CActiveScheduler::Add( this );
       
   333         iProperty.Subscribe( iStatus );
       
   334         SetActive();
       
   335         }
       
   336     else
       
   337         {
       
   338         MUS_LOG( "mus: [MUSIND ] : publisher (called by manager)" )
       
   339         CActiveScheduler::Add( this );
       
   340         }
       
   341     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::ConstructL" )
       
   342     }
       
   343 
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // Indicating availability of VS.
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void CMusIndicatorApi::Indicator( TBool aShown )
       
   350 	{
       
   351     MUS_LOG1( "mus: [MUSIND ]  <-  MusIndicatorApi::Indicator( %d)" , aShown )
       
   352     
       
   353 	RProperty property;
       
   354     TInt error( KErrNone );
       
   355 
       
   356     error = property.Attach( KPSUidCoreApplicationUIs, KCoreAppUIsVideoSharingIndicator );
       
   357     if ( error == KErrNone )
       
   358         {
       
   359         if ( aShown )
       
   360             {
       
   361             MUS_LOG( "mus: [MUSIND ] : indicator ON" )
       
   362             
       
   363             property.Set( ECoreAppUIsVideoSharingIndicatorOn );
       
   364             }
       
   365         else
       
   366             {
       
   367             MUS_LOG( "mus: [MUSIND ] : indicator OFF" )
       
   368             property.Set( ECoreAppUIsVideoSharingIndicatorOff );
       
   369             }
       
   370         }
       
   371     property.Close();
       
   372     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::Indicator" )
       
   373     
       
   374 	}
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // Plays tone indicating availability of VS.
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 void CMusIndicatorApi::PlayToneL()
       
   381     {    
       
   382     MUS_LOG( "mus: [MUSIND ] -> MusIndicatorApi::PlayToneL" )
       
   383     delete iSoundPlayer;
       
   384     iSoundPlayer = NULL;
       
   385     iSoundPlayer = CMusSoundPlayer::NewL( *this );
       
   386     MUS_LOG( "mus: [MUSIND ]    MusIndicatorApi::PlayToneL - Play sound" )
       
   387     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound );
       
   388     MUS_LOG( "mus: [MUSIND ] <- MusIndicatorApi::PlayToneL" )
       
   389     }
       
   390 
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // Returns text associated with specified dialog.
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 HBufC* CMusIndicatorApi::NoteTextLC( TVsPopupQuery aQuery )
       
   397     {
       
   398     MUS_LOG1( "mus: [MUSIND]  -> MusIndicatorApi::NoteTextLC( %d )", aQuery )
       
   399 
       
   400     HBufC* dlgPrompt( NULL );
       
   401 
       
   402     switch ( aQuery )
       
   403         {
       
   404         case EVsRoamingActivationQuery:
       
   405             {
       
   406             dlgPrompt = MusResourceUtil::ReadResourceString16LC(
       
   407                 R_MUSINDICATOR_MANUAL_ACTIVATION_TXT,
       
   408                 KMusIndicatorResource );
       
   409             break;
       
   410             }
       
   411 
       
   412         default:
       
   413             {
       
   414             MUS_LOG( "mus: [MUSIND]   MusIndicatorApi::NoteTextLC, UNKNOWN" )
       
   415             User::Leave( KErrNotFound );
       
   416             }
       
   417         }
       
   418     // now pop and destroy the resource reader
       
   419 
       
   420     MUS_LOG( "mus: [MUSIND]  <- MusIndicatorApi::NoteTextLC" )
       
   421 
       
   422     return dlgPrompt;
       
   423     }
       
   424 
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // Reads resource string
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 void CMusIndicatorApi::ShowLiveSharingQueryL( TBool aPlayTone )
       
   431     {
       
   432     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::ShowLiveSharingQuery" )
       
   433     Cancel();
       
   434 
       
   435     delete iQuery;
       
   436     iQuery = NULL;
       
   437 
       
   438     HBufC* dlgPrompt = MusResourceUtil::ReadResourceString16LC(
       
   439                                             R_MUSINDICATOR_NOTE_CAPABILITY_TXT,
       
   440                                             KMusIndicatorResource );
       
   441 
       
   442     HBufC* dlgHeader = MusResourceUtil::ReadResourceString16LC(
       
   443                                             R_MUSINDICATOR_NOTE_VSREADY_TXT,
       
   444                                             KMusIndicatorResource );
       
   445 
       
   446     iQuery = CAknGlobalMsgQuery::NewL();
       
   447     TRAPD( error,
       
   448         iQuery->ShowMsgQueryL(
       
   449             iStatus,
       
   450             *dlgPrompt,
       
   451             R_AVKON_SOFTKEYS_OK_CANCEL,
       
   452             *dlgHeader,
       
   453             KNullDesC,
       
   454             0,  // default image id
       
   455             -1, // default image mask id
       
   456             ( aPlayTone ?
       
   457                 CAknQueryDialog::EConfirmationTone :
       
   458                 CAknQueryDialog::ENoTone ) ) );
       
   459 
       
   460     CleanupStack::PopAndDestroy( dlgHeader );
       
   461     CleanupStack::PopAndDestroy( dlgPrompt );
       
   462 
       
   463     if ( !error )
       
   464         {
       
   465         SetActive();
       
   466         
       
   467         delete iLiveSharingQueryTimeout;
       
   468         iLiveSharingQueryTimeout = NULL;
       
   469         iLiveSharingQueryTimeout = 
       
   470                         CPeriodic::NewL( CActive::EPriorityStandard );
       
   471         
       
   472         iLiveSharingQueryTimeout->Start( 
       
   473                             KMusLiveSharingQueryTimeout,
       
   474                             KMusLiveSharingQueryTimeout,
       
   475                             TCallBack( LiveSharingQueryTimeout, this ) );
       
   476         
       
   477         }
       
   478     else
       
   479         {
       
   480         delete iQuery;
       
   481         iQuery = NULL;
       
   482         }
       
   483 
       
   484     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::ShowLiveSharingQuery" )
       
   485     }
       
   486 
       
   487 
       
   488 
       
   489 TInt CMusIndicatorApi::LiveSharingQueryTimeout( TAny* aThis )
       
   490     {
       
   491     static_cast< CMusIndicatorApi* >( aThis )->Cancel();    
       
   492     return KErrNone;
       
   493     }
       
   494 
       
   495