mmsharing/mmshui/src/musuireceivecontroller.cpp
branchRCL_3
changeset 33 bc78a40cd63c
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Application's UI class.
       
    15 *  Version     : %version:  be1sipx1#75.1.17 % << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include "musuireceivecontroller.h"
       
    22 #include "musuieventobserver.h"
       
    23 #include "musuisharingobserver.h"
       
    24 #include "musuireceiveobserver.h"
       
    25 #include "musuicallbackservice.h"
       
    26 #include "musuiactivetimer.h"
       
    27 #include "musuidialogutil.h"
       
    28 #include "musuicontactutil.h"
       
    29 #include "mussettings.h"
       
    30 #include "mussettingskeys.h"
       
    31 #include "musuiresourcehandler.h"
       
    32 #include "musengreceivesession.h"
       
    33 #include "musenguriparser.h"
       
    34 #include "mussessionproperties.h"
       
    35 #include "muslogger.h" // debug logging
       
    36 #include "musuiappui.h"
       
    37 #include "musuireceiveview.h"
       
    38 #include "musuipropertywatch.h"
       
    39 #include "mussesseioninformationapi.h"
       
    40 #include "musui.hrh"
       
    41 #include <musui.rsg>
       
    42 
       
    43 #include <avkon.hrh>
       
    44 #include <aknappui.h>           
       
    45 #include <StringLoader.h>
       
    46 
       
    47 using namespace MusSettingsKeys;
       
    48 using namespace NMusSessionApi;
       
    49 
       
    50 const TInt KMusMinDigitCountInValidTelNumber = 7;
       
    51 
       
    52 /*
       
    53  * Private number.
       
    54 */
       
    55 _LIT( KPrivateNumber, "" );
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CMusUiReceiveController* CMusUiReceiveController::NewL(
       
    62                         MMusUiEventObserver& aEventObserver,
       
    63                         MMusUiSharingObserver& aSharingObserver,
       
    64                         MMusUiReceiveObserver& aReceiveObserver,
       
    65                         const TRect& aRect )
       
    66     {
       
    67     CMusUiReceiveController* self = new( ELeave ) CMusUiReceiveController( 
       
    68                                                         aEventObserver,
       
    69                                                         aSharingObserver, 
       
    70                                                         aReceiveObserver );
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL( aRect );
       
    73     CleanupStack::Pop( self );
       
    74     return self;
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CMusUiReceiveController::~CMusUiReceiveController()
       
    83     {
       
    84     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::~CMusUiReceiveController" );
       
    85     delete iSession;
       
    86     delete iOriginator;
       
    87     delete iTimer;
       
    88     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::~CMusUiReceiveController" );
       
    89     }
       
    90 
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CMusUiReceiveController::CMusUiReceiveController(
       
    97                                 MMusUiEventObserver& aEventObserver,
       
    98                                 MMusUiSharingObserver& aSharingObserver,
       
    99                                 MMusUiReceiveObserver& aReceiveObserver )
       
   100     : CMusUiEventController( aEventObserver, aSharingObserver ), 
       
   101       iReceiveObserver( aReceiveObserver )
       
   102     {
       
   103 
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CMusUiReceiveController::ConstructL( const TRect& aRect )
       
   112     {
       
   113     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::ConstructL" );
       
   114 
       
   115     // construct event listener
       
   116     CMusUiEventController::ConstructL();
       
   117 
       
   118     // construct an engine session
       
   119     iSession = CMusEngReceiveSession::NewL( aRect, *this, *this );
       
   120     iSession->SetAudioRoutingObserver( this );
       
   121     iSession->SetVolumeChangeObserver( this );
       
   122         
       
   123     iTimer = CMusUiActiveTimer::NewL( this );
       
   124     iTimer->After( KMusReceiveTimeout );
       
   125 
       
   126     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::ConstructL" );
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CMusUiReceiveController::ChangeFullScreenModeL()
       
   134     {
       
   135     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::ChangeFullScreenModeL" );
       
   136 
       
   137     iFullScreenSelected = !iFullScreenSelected;
       
   138     
       
   139     if ( !MUS_NO_TOOLBAR )
       
   140         {
       
   141         iSharingObserver.HighlightSelectedToolbarItem( EMusuiCmdToolbarFullScreen );
       
   142         }
       
   143         
       
   144     iReceiveObserver.SetFullScreenL( iFullScreenSelected );
       
   145 
       
   146     if ( ( iEventObserver.AppOrientation()!= CAknAppUiBase::EAppUiOrientationLandscape ) 
       
   147             && iFullScreenSelected )
       
   148         {
       
   149         if( !iEventObserver.OrientationCanBeChanged() ) 
       
   150             {
       
   151             MUS_LOG( "mus: [MUSUI ]    !OrientationCanBeChanged()" );
       
   152             iSession->SetOrientationL( CMusEngMceSession::ELandscape );
       
   153             }
       
   154         }
       
   155     else if ( ( iSession->OrientationL() != iOriginalMceOrientation ) 
       
   156                             && !iFullScreenSelected )
       
   157         {
       
   158         if( !iEventObserver.OrientationCanBeChanged() ) 
       
   159             {
       
   160             MUS_LOG( "mus: [MUSUI ]    !OrientationCanBeChanged()" );
       
   161             iSession->SetOrientationL( iOriginalMceOrientation );
       
   162             }
       
   163         }    
       
   164 
       
   165     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::ChangeFullScreenModeL" );
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CMusUiReceiveController::OfferToolbarEventL( TInt aCommand )
       
   173     {
       
   174     MUS_LOG1( "mus: [MUSUI ]  -> CMusUiReceiveController::OfferToolbarEventL [%d]",
       
   175                             aCommand );
       
   176     
       
   177     switch ( aCommand )
       
   178         {
       
   179         case EMusuiCmdToolbarFullScreen:
       
   180             {
       
   181             ChangeFullScreenModeL();
       
   182             break;
       
   183             }
       
   184         default:    // Not receive specific, let the base class handle
       
   185             {
       
   186             CMusUiEventController::OfferToolbarEventL( aCommand );
       
   187             break;
       
   188             }
       
   189             
       
   190         }
       
   191     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::OfferToolbarEventL" );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CMusUiReceiveController::HandleCommandL( TInt aCommand )
       
   199     {
       
   200     MUS_LOG1( "mus: [MUSUI ] ->  CMusUiReceiveController::HandleCommandL: %d",
       
   201                             aCommand );
       
   202 
       
   203     switch ( aCommand )
       
   204         {
       
   205         // Menu commands from view's HandleCommandL:
       
   206         case EMusuiCmdViewAudioNormal:
       
   207             {
       
   208             MUS_LOG( "mus: [MUSUI ]     CMusUiReceiveController::ConstructL:\
       
   209                                     EMusuiCmdViewAudioNormal" );
       
   210             if ( iSession->ContainsAudioL() )
       
   211                 {
       
   212                 iSession->UnmuteL();
       
   213                 }
       
   214             break;
       
   215             }
       
   216         case EMusuiCmdViewAudioMute:
       
   217             {
       
   218             MUS_LOG( "mus: [MUSUI ]     CMusUiReceiveController::ConstructL:\
       
   219                                     EMusuiCmdViewAudioMute" );
       
   220             if ( iSession->ContainsAudioL() )
       
   221                 {
       
   222                 iSession->MuteL();
       
   223                 }
       
   224             break;
       
   225             }
       
   226         case EMusuiCmdToolbarFullScreen:
       
   227             {
       
   228             OfferToolbarEventL( EMusuiCmdToolbarFullScreen );
       
   229             break;
       
   230             }            
       
   231         case EMusuiCmdViewFullScreen:
       
   232             {
       
   233             ChangeFullScreenModeL();
       
   234             break;
       
   235             }
       
   236         default:
       
   237             {
       
   238             // Try more general handling
       
   239             CMusUiEventController::HandleCommandL( aCommand );
       
   240             break;
       
   241             }
       
   242         }
       
   243     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::HandleCommandL" );
       
   244     }
       
   245     
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void CMusUiReceiveController::HandleIncomingSessionL( 
       
   252                                             const TDesC& aOriginator,
       
   253                                             const TDesC& aOriginatorIdentity )
       
   254     {
       
   255     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::HandleIncomingSessionL" )
       
   256     
       
   257     delete iOriginator;
       
   258     iOriginator = NULL;
       
   259     TInt privacyStatus(0);
       
   260     
       
   261     
       
   262     MUS_LOG( "mus: [MUSUI ]  Check private number" )
       
   263     TRAPD( errorPrivacyStatus, privacyStatus = 
       
   264             CMusUiPropertyWatch::ReadIntPropertyL( NMusSessionApi::KPrivacyStatus ) );        
       
   265     if ( errorPrivacyStatus != KErrNone )
       
   266         {
       
   267        	MUS_LOG1( "mus: [MUSUI ]     ReadIntPropertyL leave code: %d", errorPrivacyStatus )
       
   268         HandleError( errorPrivacyStatus );
       
   269         }
       
   270         
       
   271     if ( privacyStatus == 1 && !iOperatorSpecificFunctionality )
       
   272       {
       
   273        MUS_LOG( "mus: [MUSUI ]  Call is from private number" )
       
   274        iOriginator = KPrivateNumber().AllocL();
       
   275       }
       
   276     else if( iOperatorSpecificFunctionality )
       
   277         {
       
   278         iOriginator = aOriginatorIdentity.AllocL();	
       
   279         }
       
   280     else
       
   281       {
       
   282       iOriginator = aOriginator.AllocL();
       
   283       }
       
   284          
       
   285     // Cancel the 10 seconds timer:
       
   286     iTimer->Cancel();
       
   287     
       
   288     // Display the query dialog:
       
   289     
       
   290     if ( privacyStatus == 1 && !iOperatorSpecificFunctionality )
       
   291         {
       
   292         iReceiveObserver.ShowInvitationQueryL( *iOriginator );
       
   293         }  
       
   294     else if ( iOperatorSpecificFunctionality && aOriginatorIdentity.Length() != 0 )
       
   295         {
       
   296         // We compare last seven digits, since that is the minimum amount
       
   297         // that can make up a valid telephone number.
       
   298         MUS_LOG_TDESC( "mus: [MUSUI ]       Right7 of MusTelNumberValue(): ",
       
   299                        MusTelNumberValue().Right( KMusMinDigitCountInValidTelNumber ) )
       
   300         MUS_LOG_TDESC( "mus: [MUSUI ]       Right7 of aOriginatorIdentity: ",
       
   301                        aOriginatorIdentity.Right( KMusMinDigitCountInValidTelNumber ) )
       
   302         MUS_LOG_TDESC( "mus: [MUSUI ]       MusContactName: ", MusContactName() )                            
       
   303             
       
   304         if  ( !( MusTelNumberValue().Length() >= 
       
   305               						KMusMinDigitCountInValidTelNumber && 
       
   306               aOriginatorIdentity.Length() >= 
       
   307               						KMusMinDigitCountInValidTelNumber &&
       
   308               MusTelNumberValue().Right( KMusMinDigitCountInValidTelNumber ) ==
       
   309               aOriginatorIdentity.Right( KMusMinDigitCountInValidTelNumber ) &&
       
   310               MusContactName().Length() > 0 ) )
       
   311             {
       
   312             // In some very rare scenario a valid session may come from MSISDN
       
   313         	// that is not the same as the one received from manager. To avoid
       
   314         	// showing of wrong MSISDN, we replace phone number with one 
       
   315         	// received from P-Asserted-Identity header. Since in this scenario 
       
   316         	// we cannot be sure about contact name either, we replace it with 
       
   317         	// phone number. Replacing of contact name must happen also when we 
       
   318         	// have no name for contact.
       
   319         	delete iTelNumber;
       
   320         	iTelNumber = NULL;
       
   321         	iTelNumber = aOriginatorIdentity.AllocL();
       
   322         	
       
   323         	delete iContactName;
       
   324         	iContactName = NULL;
       
   325         	iContactName = aOriginatorIdentity.AllocL();
       
   326             }
       
   327             
       
   328         iReceiveObserver.ShowInvitationQueryL( MusContactName() );
       
   329         
       
   330         }
       
   331     else
       
   332         {
       
   333        	if( MusUiContactUtil::CheckPbContactForVSAddressesL(
       
   334        	            *( iEventObserver.EikonEnv() ), *iOriginator, iContactId ) )
       
   335         	{
       
   336         	if ( MusContactName().Length() < 1 )
       
   337         	    { // originator is defined in Contacts but the name is empty
       
   338         	    iReceiveObserver.ShowInvitationQueryL( *iOriginator );
       
   339         	    }
       
   340         	else
       
   341         	    {
       
   342         	    iReceiveObserver.ShowInvitationQueryL( MusContactName() );
       
   343         	    }
       
   344        		}
       
   345        	else
       
   346        	    {
       
   347         	iReceiveObserver.ShowInvitationQueryL( *iOriginator );
       
   348         	}        
       
   349         }
       
   350    
       
   351     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::HandleIncomingSessionL" )
       
   352     }
       
   353     
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 TBool CMusUiReceiveController::ClipMutedL()
       
   360     {
       
   361     return iSession->IsMutedL();
       
   362     }
       
   363     
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 TBool CMusUiReceiveController::ClipContainsAudioL()
       
   370     {
       
   371     if ( !ConnectionInitialized() )
       
   372         {
       
   373         return EFalse; // We cannot be sure yet
       
   374         }
       
   375         
       
   376     return iSession->ContainsAudioL();
       
   377     }
       
   378 
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 // -----------------------------------------------------------------------------
       
   383 // 
       
   384 CMusEngMceSession* CMusUiReceiveController::EngineSession()
       
   385     {
       
   386     return iSession; // CMusEngReceiveSession is CMusEngMceSession
       
   387     }
       
   388     
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // Virtual function from CMusUiEventController
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CMusUiReceiveController::HandleAsyncEventL( TMusUiAsyncEvent aEventId )
       
   395     {
       
   396     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::HandleAsyncEventL" );
       
   397     switch ( aEventId )
       
   398         {
       
   399         case EMusUiAsyncInviteAccepted:
       
   400             {
       
   401             ShowWaitDialogL();
       
   402             break;
       
   403             }
       
   404         default:
       
   405             {
       
   406             // Not receive specific, let the base class handle
       
   407             CMusUiEventController::HandleAsyncEventL( aEventId );
       
   408             }
       
   409         }
       
   410     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::HandleAsyncEventL" );
       
   411     }
       
   412 
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // Virtual function from CMusUiEventController
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 const TDesC& CMusUiReceiveController::TypedAddress() const
       
   419     {
       
   420     return *iOriginator;
       
   421     }
       
   422     
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // Virtual function from CMusUiEventController
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 void CMusUiReceiveController::DeleteEngineSession()
       
   429     {
       
   430     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::DeleteEngineSession" );
       
   431     if ( iSession && iSession->IsAudioRoutingLoudSpeaker() )
       
   432 	    {
       
   433 	    iShowDialog = ETrue; 
       
   434 	    }
       
   435     delete iSession;
       
   436     iSession = NULL;
       
   437     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::DeleteEngineSession" );
       
   438     }
       
   439     
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 TBool CMusUiReceiveController::FullScreenSelected()
       
   446     {
       
   447     return iFullScreenSelected;
       
   448     }
       
   449 
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // From MMusEngReceiveSessionObserver
       
   453 // -----------------------------------------------------------------------------
       
   454 //
       
   455 void CMusUiReceiveController::IncomingSessionPreNotification()
       
   456     {
       
   457     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::IncomingSessionPreNotification" );
       
   458     iTimer->Cancel();
       
   459     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::IncomingSessionPreNotification" );
       
   460     }
       
   461 
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // From MMusEngReceiveSessionObserver
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CMusUiReceiveController::IncomingSession( const TDesC& aOriginator, 
       
   468                                                const TDesC& aOriginatorIdentity )
       
   469     {
       
   470     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::IncomingSession" );
       
   471     TRAPD( err, HandleIncomingSessionL( aOriginator, aOriginatorIdentity ) );
       
   472     if ( err != KErrNone )
       
   473         {
       
   474         iEventObserver.HandleError( err );
       
   475         }
       
   476     else
       
   477         {
       
   478         SetConnectionInitialized( ETrue );
       
   479         }
       
   480     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::IncomingSession" );
       
   481     }
       
   482 
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 // From MMusEngReceiveSessionObserver
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 void CMusUiReceiveController::StreamBuffering()
       
   489     {
       
   490     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::StreamBuffering" );
       
   491     if ( iStreamPaused )
       
   492         {
       
   493         MUS_LOG( "mus: [MUSUI ]  Stream was paused, not show buffering state" );
       
   494         }
       
   495     else
       
   496         {
       
   497         TRAPD( err, iEventObserver.ShowNaviPaneIconL( EMusUiNaviIconWaitAnim ) );
       
   498         if ( err != KErrNone )
       
   499             {
       
   500             iEventObserver.HandleError( err );
       
   501             }        
       
   502         }
       
   503 
       
   504     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::StreamBuffering" );
       
   505     }
       
   506 
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // From MMusEngSessionObserver
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 void CMusUiReceiveController::SessionEstablished()
       
   513     {
       
   514     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::SessionEstablished" );
       
   515     
       
   516     // Common handling first
       
   517     CMusUiEventController::SessionEstablished();
       
   518 
       
   519     TRAPD( error, SessionEstablishedL() )
       
   520 
       
   521     if ( error != KErrNone )
       
   522         {
       
   523         iEventObserver.HandleError( error );
       
   524         }
       
   525 
       
   526     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::SessionEstablished" );
       
   527     }
       
   528 
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // From MMusEngSessionObserver
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void CMusUiReceiveController::SessionTerminated()
       
   535     {
       
   536     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::SessionTerminated" );
       
   537     if ( !ConnectionEstablished() )
       
   538         {
       
   539         iReceiveObserver.DismissInvitationQuery( ETrue );
       
   540         TRAP_IGNORE( MusUiDialogUtil::ShowInformationDialogL(
       
   541                         R_MUS_LIVE_SHARING_VIEW_NOTE_INVITATION_CANCELLED ) )
       
   542         iEventObserver.HandleExit();
       
   543         }
       
   544     else
       
   545         {
       
   546         TRAP_IGNORE( iSharingObserver.DismissWaitDialogL() );
       
   547         
       
   548         TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   549             
       
   550         }
       
   551     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::SessionTerminated" );
       
   552     }
       
   553 
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // From MMusEngSessionObserver
       
   557 // -----------------------------------------------------------------------------
       
   558 //
       
   559 void CMusUiReceiveController::SessionConnectionLost()
       
   560     {
       
   561     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::SessionConnectionLost" );
       
   562     TRAPD( err,
       
   563            iSharingObserver.DismissWaitDialogL();
       
   564            MusUiDialogUtil::ShowGlobalErrorDialogL( 
       
   565                                 R_MUS_LIVE_SHARING_VIEW_NOTE_CONNECTION_LOST ) );
       
   566     if ( err != KErrNone )
       
   567         {
       
   568         iEventObserver.HandleError( err );
       
   569         }
       
   570     
       
   571     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );   
       
   572 
       
   573     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::SessionConnectionLost" );
       
   574     }
       
   575 
       
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // From MMusEngSessionObserver
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 void CMusUiReceiveController::SessionFailed()
       
   582     {
       
   583     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::SessionFailed" );
       
   584     TRAPD( error, iSharingObserver.DismissWaitDialogL() );
       
   585     if ( error != KErrNone )
       
   586         {
       
   587         iEventObserver.HandleError( error );
       
   588         }
       
   589     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::SessionFailed" );
       
   590     }
       
   591 
       
   592 
       
   593 // -----------------------------------------------------------------------------
       
   594 // From MMusEngSessionObserver
       
   595 // -----------------------------------------------------------------------------
       
   596 //
       
   597 void CMusUiReceiveController::StreamIdle()
       
   598     {
       
   599     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::StreamIdle" );
       
   600     iStreamPaused = ETrue;
       
   601     TRAPD( err, iEventObserver.ShowNaviPaneIconL( EMusUiNaviIconPause ) );
       
   602     if ( iFullScreenSelected )
       
   603     	{
       
   604         TRAP_IGNORE( ChangeFullScreenModeL() );
       
   605     	}
       
   606     if ( err != KErrNone )
       
   607         {
       
   608         iEventObserver.HandleError( err );
       
   609         }
       
   610     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::StreamIdle" );
       
   611     }
       
   612 
       
   613 
       
   614 // -----------------------------------------------------------------------------
       
   615 // From MMusEngSessionObserver
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 void CMusUiReceiveController::StreamStreaming()
       
   619     {
       
   620     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::StreamStreaming" );
       
   621     
       
   622     if ( ConnectionEstablished() )
       
   623         {
       
   624         TRAP_IGNORE( iSharingObserver.DismissWaitDialogL() )
       
   625         TRAPD( err, iEventObserver.ShowNaviPaneIconL( EMusUiNaviIconPlay ) )
       
   626         
       
   627         if ( err != KErrNone )
       
   628             {
       
   629             iEventObserver.HandleError( err );
       
   630             }
       
   631         iStreamPaused = EFalse;    
       
   632         }
       
   633    
       
   634     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::StreamStreaming" );
       
   635     }
       
   636 
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // From MMusEngSessionObserver
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void CMusUiReceiveController::SessionTimeChanged(
       
   643                         const TTimeIntervalSeconds& aSeconds )
       
   644     {
       
   645     if ( aSeconds.Int() > -1 )
       
   646         {
       
   647         iSharingObserver.UpdateSessionTime( SessionTimeFormatted( aSeconds ) );
       
   648         }
       
   649     }
       
   650 
       
   651 
       
   652 // -----------------------------------------------------------------------------
       
   653 // From MMusEngSessionObserver
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 void CMusUiReceiveController::InactivityTimeout()
       
   657     {
       
   658     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::InactivityTimeout" );
       
   659     TRAP_IGNORE( iSharingObserver.DismissWaitDialogL();
       
   660                  MusUiDialogUtil::ShowGlobalErrorDialogL( 
       
   661                             R_MUS_LIVE_SHARING_VIEW_NOTE_SERVICE_N_A ) );
       
   662     
       
   663     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   664         
       
   665     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::InactivityTimeout" );
       
   666     }
       
   667 
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // From MMusUiInvitationQueryObserver: Invitation accepted by the user
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CMusUiReceiveController::InvitationAcceptedL()
       
   674     {
       
   675     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::InvitationAcceptedL" );
       
   676     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   677     
       
   678     // Enable loud speaker already before answering but disable it immediately
       
   679     // if accepting fails for some reason
       
   680     if ( iSession->AudioRoutingCanBeChanged() && !iSession->IsAudioRoutingHeadset() )
       
   681         {
       
   682         iSession->EnableLoudspeakerL( ELoudspeakerEnabled, ETrue );
       
   683         }
       
   684             
       
   685     TRAPD( err, iSession->AcceptInvitationL( ETrue ) );
       
   686     if ( err )
       
   687         {
       
   688         if ( iSession->AudioRoutingCanBeChanged() )
       
   689             {
       
   690             iSession->EnableLoudspeakerL( ELoudspeakerDisabled, ETrue );
       
   691             }
       
   692         User::Leave( err );
       
   693         }
       
   694           
       
   695     iCallbackService->AsyncEventL( EMusUiAsyncInviteAccepted );
       
   696     
       
   697         
       
   698     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::InvitationAcceptedL" );
       
   699     }
       
   700 
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // From MMusUiInvitationQueryObserver: Invitation rejected by the user
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 void CMusUiReceiveController::InvitationRejectedL()
       
   707     {
       
   708     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::InvitationRejectedL" );
       
   709     __ASSERT_ALWAYS( iSession, User::Leave( KErrNotReady ) );
       
   710     iSession->AcceptInvitationL( EFalse );
       
   711     HandleExitL();
       
   712     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::InvitationRejectedL" );
       
   713     }
       
   714 
       
   715 
       
   716 // -----------------------------------------------------------------------------
       
   717 // From MMusUiActiveTimerObserver
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 void CMusUiReceiveController::TimerComplete( CMusUiActiveTimer* /*aTimer*/ )
       
   721     {
       
   722     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::TimerComplete" );
       
   723     iEventObserver.HandleExit();
       
   724     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::TimerComplete" );
       
   725     }
       
   726 
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 // -----------------------------------------------------------------------------
       
   731 //
       
   732 void CMusUiReceiveController::ExitProcedureL( TBool aUserAcceptance )
       
   733     {
       
   734     
       
   735     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::ExitProcedureL" );
       
   736     
       
   737     switch ( iShutdownState )
       
   738         {
       
   739         case EMusUiShutdownVideoSaved:
       
   740             {
       
   741             MUS_LOG( "mus: [MUSUI ]     ExitProcedureL: EMusuiShutdownVideoSaved" );
       
   742             
       
   743             // Check if our address is valid sip or tel uri. If not, there is no
       
   744             // reason to query user about permission to save it to contacts.
       
   745             
       
   746             TInt error = KErrNotFound;
       
   747             if ( iOriginator )
       
   748                 {
       
   749                 TMusEngUriParser parser( *iOriginator );
       
   750                 TRAP( error, parser.ParseUriL() )                
       
   751                 }
       
   752 
       
   753             // Save Address to Contacts query if contact found and
       
   754             // there is no address in contacts 
       
   755             // and if is the standard variant.
       
   756             if ( !iOperatorSpecificFunctionality && iContactId > 0 && 
       
   757                  !MusUiContactUtil::ShareViewFieldExistsL( 
       
   758                             *( iEventObserver.EikonEnv() ), iContactId ) &&
       
   759                  error == KErrNone )
       
   760                 {
       
   761                 iShutdownState = EMusUiShutdownContactSavingQueried;
       
   762                 iEventObserver.SetToolbarVisibility( EFalse );
       
   763                 SaveContactQueryL();
       
   764                 }
       
   765             else
       
   766                 {
       
   767                 // Nothing receive specific, let the base class handle
       
   768                 CMusUiEventController::ExitProcedureL( aUserAcceptance );
       
   769                 }
       
   770             break;
       
   771             }
       
   772 
       
   773         default:
       
   774             {
       
   775             // Nothing receive specific, let the base class handle
       
   776             CMusUiEventController::ExitProcedureL( aUserAcceptance );
       
   777             break;
       
   778             }
       
   779         }
       
   780     
       
   781     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::ExitProcedureL" );
       
   782     }
       
   783     
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 //
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 void CMusUiReceiveController::ShowWaitDialogL()
       
   790     {
       
   791     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::ShowWaitDialogL" );
       
   792     
       
   793     delete iDialogPrompt;
       
   794     iDialogPrompt = NULL;
       
   795         
       
   796     iDialogPrompt = StringLoader::LoadL( 
       
   797                             R_MUS_RECEIVE_VIEW_WAITING_FOR_STREAM,
       
   798                             ( MusContactName().Length() > 0 ) ?
       
   799                                                     MusContactName() :
       
   800                                                     *iOriginator );
       
   801     
       
   802     if ( !iSharingObserver.ShowWaitDialogL( 
       
   803                             *iDialogPrompt, 
       
   804                             KMusInviteExpireTimeout,
       
   805                             R_MUS_LIVE_SHARING_VIEW_NOTE_TIMEOUT_EXPIRED ) )
       
   806         {
       
   807         HandleExitL();
       
   808         }
       
   809         
       
   810     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::ShowWaitDialogL" );
       
   811     }
       
   812 
       
   813 
       
   814 // -----------------------------------------------------------------------------
       
   815 // From MMusEngSessionObserver
       
   816 // -----------------------------------------------------------------------------
       
   817 //
       
   818 void CMusUiReceiveController::SessionEstablishedL()
       
   819     {
       
   820     MUS_LOG( "mus: [MUSUI ]  -> CMusUiReceiveController::SessionEstablishedL" );
       
   821 
       
   822     iConnectionEstablished = ETrue;
       
   823     iSharingObserver.DismissWaitDialogL();
       
   824 
       
   825     if ( iCallbackService->CurrentEvent() == EMusUiAsyncInviteAccepted )
       
   826         {
       
   827         iCallbackService->Cancel();
       
   828         }
       
   829     
       
   830     // Orientation for video player
       
   831     iResourceHandler->RequestVideoPlayerL( ETrue );
       
   832 
       
   833     iOriginalMceOrientation = iSession->OrientationL();
       
   834 
       
   835     // set the mce orientation if different than videoplayer orientation
       
   836     CAknAppUiBase::TAppUiOrientation currentOrientation = 
       
   837         STATIC_CAST(CMusUiReceiveView&,iReceiveObserver).MusAppUi()->Orientation();
       
   838 
       
   839     if( (iOriginalMceOrientation == CMusEngMceSession::EPortrait && 
       
   840         currentOrientation== CAknAppUiBase::EAppUiOrientationPortrait ) ||
       
   841         (iOriginalMceOrientation == CMusEngMceSession::ELandscape && 
       
   842         currentOrientation== CAknAppUiBase::EAppUiOrientationLandscape ))
       
   843         {
       
   844         MUS_LOG( "mus: [MUSUI ]  -> MCE & Videoplayer orientation is same" );
       
   845         // Both MCE and Videoplayer has same orientation.
       
   846         }
       
   847     else
       
   848         {        
       
   849         if(currentOrientation == CAknAppUiBase::EAppUiOrientationPortrait)
       
   850             {
       
   851             MUS_LOG( "mus: [MUSUI ]  -> Setting MCE Orientation to Portrait" );
       
   852             iSession->SetOrientationL(CMusEngMceSession::EPortrait);    
       
   853             }
       
   854         else if(currentOrientation == CAknAppUiBase::EAppUiOrientationLandscape)
       
   855             {
       
   856             MUS_LOG( "mus: [MUSUI ]  -> Setting MCE Orientation to Landscape" );
       
   857             iSession->SetOrientationL(CMusEngMceSession::ELandscape); 
       
   858             }        
       
   859         else
       
   860             {
       
   861             MUS_LOG( "mus: [MUSUI ]  -> Undefined Orientation. " );
       
   862             }
       
   863         }       
       
   864 
       
   865     if ( iForeground )
       
   866         {
       
   867         EnableDisplayL( ETrue );
       
   868         iEventObserver.SetToolbarVisibility( ETrue );
       
   869         }
       
   870         
       
   871     MUS_LOG( "mus: [MUSUI ]  <- CMusUiReceiveController::SessionEstablishedL" );
       
   872     }
       
   873 
       
   874 
       
   875 // End of file
       
   876