mmsharing/mmshindicator/src/musindicatorapi.cpp
branchRCL_3
changeset 22 73a1feb507fb
parent 18 407431f36921
child 23 bc78a40cd63c
equal deleted inserted replaced
21:33a5d2bbf6fc 22:73a1feb507fb
    19 
    19 
    20 
    20 
    21 #include "musindicatorapi.h"
    21 #include "musindicatorapi.h"
    22 #include "musresourcefinderutil.h"
    22 #include "musresourcefinderutil.h"
    23 #include "muslogger.h"
    23 #include "muslogger.h"
       
    24 #include "musindicatordsa.h"
    24 #include "mussettings.h"
    25 #include "mussettings.h"
    25 #include "mussettingskeys.h"
    26 #include "mussettingskeys.h"
    26 #include "mussoundplayer.h"
    27 #include "mussoundplayer.h"
    27 #include "musresourceutil.h"
    28 #include "musresourceutil.h"
    28 #include <musindicator.rsg>
    29 #include <musindicator.rsg>
       
    30 #include <AknGlobalConfirmationQuery.h>
       
    31 #include <AknGlobalMsgQuery.h>
    29 #include <coreapplicationuisdomainpskeys.h>
    32 #include <coreapplicationuisdomainpskeys.h>
    30 
    33 
    31 
    34 
       
    35 const TInt KMusLiveSharingQueryTimeout = 5000000;
       
    36 
       
    37 
    32 // ======== MEMBER FUNCTIONS ========
    38 // ======== MEMBER FUNCTIONS ========
    33 
    39 
    34 // -----------------------------------------------------------------------------
    40 using namespace MusSettingsKeys;
    35 //
    41 
    36 // -----------------------------------------------------------------------------
    42 
    37 //
       
    38 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewL( MMusIndicatorObserver& aObserver )
    43 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewL( MMusIndicatorObserver& aObserver )
    39     {
    44     {
    40     CMusIndicatorApi* self = CMusIndicatorApi::NewLC( aObserver );
    45     CMusIndicatorApi* self = CMusIndicatorApi::NewLC( aObserver );
    41     CleanupStack::Pop( self );
    46     CleanupStack::Pop( self );
    42     return self;
    47     return self;
    43     }
    48     }
    44 
    49 
    45 
    50 
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewLC( MMusIndicatorObserver& aObserver )
    51 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewLC( MMusIndicatorObserver& aObserver )
    51     {
    52     {
    52     CMusIndicatorApi* self = new (ELeave) CMusIndicatorApi( &aObserver );
    53     CMusIndicatorApi* self = new (ELeave) CMusIndicatorApi( &aObserver );
    53     CleanupStack::PushL( self );
    54     CleanupStack::PushL( self );
    54     self->ConstructL();
    55     self->ConstructL();
    55     return self;
    56     return self;
    56     }
    57     }
    57 
    58 
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewL()
    59 EXPORT_C CMusIndicatorApi* CMusIndicatorApi::NewL()
    64     {
    60     {
    65     CMusIndicatorApi* self = new (ELeave) CMusIndicatorApi( NULL );
    61     CMusIndicatorApi* self = new (ELeave) CMusIndicatorApi( NULL );
    66     CleanupStack::PushL( self );
    62     CleanupStack::PushL( self );
    67     self->ConstructL();
    63     self->ConstructL();
    68     CleanupStack::Pop( self );
    64     CleanupStack::Pop( self );
    69     return self;
    65     return self;
    70     }
    66     }
    71 
    67 
    72 
    68 
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CMusIndicatorApi::~CMusIndicatorApi()
    69 CMusIndicatorApi::~CMusIndicatorApi()
    78     {
    70     {
    79     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::~CMusIndicatorApi" );
    71     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::~CMusIndicatorApi" );
    80     
    72     
    81     Cancel();
    73     Cancel();
       
    74     delete iQuery;
       
    75     delete iIndicatorWindow;
    82     delete iSoundPlayer;
    76     delete iSoundPlayer;
    83 
    77     delete iLiveSharingQueryTimeout;
    84     Indicator( EFalse );
    78     if ( !IsSubscriber() )
    85 
    79         {
       
    80         Indicator( EFalse );
       
    81         }
    86     
    82     
    87     iProperty.Close();
    83     iProperty.Close();
    88 
    84 
    89     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::~CMusIndicatorApi" );
    85     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::~CMusIndicatorApi" );
    90     }
    86     }
    91 
    87 
    92 
    88 
    93 // -----------------------------------------------------------------------------
    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 // ---------------------------------------------------------------------------
    94 // Indicates VS availability to user.
   117 // Indicates VS availability to user.
    95 // In operator specific variant this can include DSA note and an audio tone
   118 // In operator specific variant this can include a popup-note, DSA note and
    96 // played with CMdaAudioPlayerUtility.
   119 // an audio tone played with CMdaAudioPlayerUtility.
    97 // -----------------------------------------------------------------------------
   120 // ---------------------------------------------------------------------------
    98 //
   121 //
    99 EXPORT_C void CMusIndicatorApi::IndicateAvailabilityL()
   122 EXPORT_C void CMusIndicatorApi::IndicateAvailabilityL()
   100     {
   123     {
   101     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::IndicateAvailabilityL" )
   124     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::IndicateAvailabilityL" )
       
   125     __ASSERT_ALWAYS( !IsSubscriber(), User::Leave( KErrArgument ) );
       
   126     
   102     Indicator( ETrue );
   127     Indicator( ETrue );
   103 
   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 
   104     if( MultimediaSharingSettings::AuditoryNotificationSettingL() ==
   137     if( MultimediaSharingSettings::AuditoryNotificationSettingL() ==
   105         MusSettingsKeys::EAuditoryNotificationOn )
   138         EAuditoryNotificationOn )
   106         {
   139         {
   107         MUS_LOG( "mus: [MUSIND]     Play tone" )
   140         MUS_LOG( "mus: [MUSIND]  CMusIndicatorApi::IndicateAvailabilityL - Play tone" )
   108         PlayToneL();
   141         PlayToneL();
   109         }
   142         }
   110 
   143 
   111     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::IndicateAvailabilityL" )
   144     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::IndicateAvailabilityL" )
   112     }
   145     }
   113 
   146 
   114 
   147 
   115 // -----------------------------------------------------------------------------
   148 // ---------------------------------------------------------------------------
   116 // From CActive.
   149 // From CActive.
   117 // Handles completion of an outstanding asynchronous request.
   150 // Handles completion of an outstanding asynchronous request.
   118 // -----------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   119 //
   152 //
   120 void CMusIndicatorApi::RunL()
   153 void CMusIndicatorApi::RunL()
   121     {
   154     {
   122     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::RunL" )
   155     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::RunL" )
   123     
   156     
   124 
   157     if ( !IsSubscriber() )
   125     MUS_LOG( "mus: [MUSIND ] : publisher" )
   158         {
   126     StartLiveSharingL();
   159         MUS_LOG( "mus: [MUSIND ] : publisher" )
   127 
   160         StartLiveSharingL();
       
   161         }
       
   162     else
       
   163         {
       
   164         MUS_LOG( "mus: [MUSIND ] : subscriber" )
       
   165         ToggleIndicatorL();
       
   166         }
   128 
   167 
   129     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::RunL" )
   168     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::RunL" )
   130     }
   169     }
   131 
   170 
   132 
   171 
   133 // -----------------------------------------------------------------------------
   172 // ---------------------------------------------------------------------------
   134 //
   173 //
   135 // -----------------------------------------------------------------------------
   174 // ---------------------------------------------------------------------------
   136 //
   175 //
   137 void CMusIndicatorApi::StartLiveSharingL()
   176 void CMusIndicatorApi::StartLiveSharingL()
   138     {
   177     {
   139     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::StartLiveSharingL" )
   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;
   140 
   188 
   141     if( iStatus.Int() != KErrNotFound ) // eq. Cancel -button
   189     if( iStatus.Int() != KErrNotFound ) // eq. Cancel -button
   142         {
   190         {
   143         if ( iObserver )
   191         if ( iObserver )
   144             {
   192             {
   148 
   196 
   149     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::StartLiveSharingL" )
   197     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::StartLiveSharingL" )
   150     }
   198     }
   151 
   199 
   152 
   200 
   153 // -----------------------------------------------------------------------------
   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 // ---------------------------------------------------------------------------
   154 // From CActive.
   241 // From CActive.
   155 // Cancels an outstanding asynchronous request.
   242 // Cancels an outstanding asynchronous request.
   156 // -----------------------------------------------------------------------------
   243 // ---------------------------------------------------------------------------
   157 //
   244 //
   158 void CMusIndicatorApi::DoCancel()
   245 void CMusIndicatorApi::DoCancel()
   159     {
   246     {
   160     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::DoCancel" )
   247     MUS_LOG( "mus: [MUSIND]  <- CMusIndicatorApi::DoCancel" )
   161     
   248 
   162 
   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         }
   163     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::DoCancel" )
   267     MUS_LOG( "mus: [MUSIND]  -> CMusIndicatorApi::DoCancel" )
   164     }
   268     }
   165 
   269 
   166 
   270 
   167 // -----------------------------------------------------------------------------
   271 // ---------------------------------------------------------------------------
   168 // From CActive.
   272 // From CActive.
   169 // Handles a leave occurring in the request completion event handler RunL.
   273 // Handles a leave occurring in the request completion event handler RunL.
   170 // -----------------------------------------------------------------------------
   274 // ---------------------------------------------------------------------------
   171 //
   275 //
   172 #ifdef _DEBUG
   276 #ifdef _DEBUG
   173 TInt CMusIndicatorApi::RunError( TInt aError )
   277 TInt CMusIndicatorApi::RunError( TInt aError )
   174 #else
   278 #else
   175 TInt CMusIndicatorApi::RunError( TInt )
   279 TInt CMusIndicatorApi::RunError( TInt )
   217 //
   321 //
   218 void CMusIndicatorApi::ConstructL()
   322 void CMusIndicatorApi::ConstructL()
   219     {
   323     {
   220     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::ConstructL" )
   324     MUS_LOG( "mus: [MUSIND ]  ->  MusIndicatorApi::ConstructL" )
   221     
   325     
   222     
   326     if ( IsSubscriber() )
   223     MUS_LOG( "mus: [MUSIND ] : publisher (called by manager)" )
   327         {
   224     CActiveScheduler::Add( this );
   328         MUS_LOG( "mus: [MUSIND ] :  subscriber (called by aiwprovider)" )
   225 
   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         }
   226     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::ConstructL" )
   341     MUS_LOG( "mus: [MUSIND ]  <-  MusIndicatorApi::ConstructL" )
   227     }
   342     }
   228 
   343 
   229 
   344 
   230 // -----------------------------------------------------------------------------
   345 // -----------------------------------------------------------------------------
   272     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound );
   387     iSoundPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound );
   273     MUS_LOG( "mus: [MUSIND ] <- MusIndicatorApi::PlayToneL" )
   388     MUS_LOG( "mus: [MUSIND ] <- MusIndicatorApi::PlayToneL" )
   274     }
   389     }
   275 
   390 
   276 
   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