mmsharing/mmshui/src/musuisendcontroller.cpp
branchRCL_3
changeset 33 bc78a40cd63c
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "musuisendcontroller.h"
       
    21 #include "musuieventobserver.h"
       
    22 #include "musuisharingobserver.h"
       
    23 #include "musuisendobserver.h"
       
    24 #include "musuidialogutil.h"
       
    25 #include "musuicallbackservice.h"
       
    26 #include "musuifileutil.h"
       
    27 #include "mussettings.h"
       
    28 #include "musuipropertywatch.h"
       
    29 #include "mussessionproperties.h"
       
    30 #include "mussettingskeys.h"
       
    31 #include "musuiresourcehandler.h"
       
    32 #include "muslogger.h" // debug logging
       
    33 
       
    34 #include "musengmceoutsession.h"
       
    35 #include "musenguriparser.h"
       
    36 #include <musui.rsg>
       
    37 
       
    38 #include <StringLoader.h>
       
    39 #include <pathinfo.h>
       
    40 #include <CDirectoryLocalizer.h>
       
    41 
       
    42 
       
    43 using namespace NMusSessionApi;
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CMusUiSendController::~CMusUiSendController()
       
    50     {
       
    51     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::~CMusUiSendController" );
       
    52     
       
    53     delete iAddress;
       
    54     delete iRemoteSipAddress;
       
    55     delete iRemoteSipAddressProposal;
       
    56     TRAP_IGNORE( DeleteFileL() );  
       
    57     delete iVideoFileName;
       
    58     delete iLocalizer;
       
    59     
       
    60     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::~CMusUiSendController" );
       
    61     }
       
    62     
       
    63     
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CMusEngMceSession* CMusUiSendController::EngineSession()
       
    69     {
       
    70     return EngineOutSession(); // Engine out session is CMusEngMceSession
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CMusUiSendController::DeleteEngineSession()
       
    79     {
       
    80     // Cancel invite
       
    81     if ( EngineOutSession() && !ConnectionEstablished() )
       
    82         {
       
    83         MUS_LOG( "mus: [MUSUI ]     CMusUiSendController::DeleteEngineSession:\
       
    84                             Canceling inviting..." );
       
    85         TRAP_IGNORE( EngineOutSession()->CancelInviteL() );
       
    86         }
       
    87     }     
       
    88         
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CMusUiSendController::HandlePropertyError( const TInt aReason )
       
    95     {
       
    96     MUS_LOG1( "mus: [MUSUI ]     -> CMusUiEventController::HandleError [%d]",
       
    97                             aReason );
       
    98     TRAP_IGNORE( DeleteVideoL() );
       
    99     
       
   100     CMusUiEventController::HandlePropertyError( aReason ); // For the base class
       
   101     
       
   102     MUS_LOG( "mus: [MUSUI ]  <- CMusUiEventController::HandleError" );
       
   103     }
       
   104     
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CMusUiSendController::HandleAsyncEventL( TMusUiAsyncEvent aEventId )
       
   111     {
       
   112     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::HandleAsyncEventL" );
       
   113     switch ( aEventId )
       
   114         {
       
   115         case EMusUiAsyncInviteCancel:
       
   116             {
       
   117             MUS_LOG( "mus: [MUSUI ]     CMusUiSendController::\
       
   118                      HandleAsyncEventL: EMusUiAsyncInviteCancel" );
       
   119             HandleExitL();
       
   120             break;
       
   121             }
       
   122         case EMusUiAsyncManualAddressEntry:
       
   123             {
       
   124             iResourceHandler->RequestKeypadL( ETrue ); // Exits on fail                    
       
   125             iSendObserver.ManualAddressEntryL( *iRemoteSipAddressProposal );
       
   126             break;
       
   127             }
       
   128         case EMusUiAsyncStartInvitation:
       
   129             {
       
   130             MUS_LOG( "mus: [MUSUI ]     CMusUiSendController::\
       
   131                      HandleAsyncEventL: EMusUiAsyncStartInvitation" );
       
   132             InviteL();	            
       
   133             break;
       
   134             }
       
   135         default:
       
   136             {
       
   137             // Not send specific, let the base class handle
       
   138             CMusUiEventController::HandleAsyncEventL( aEventId );
       
   139             }
       
   140         }
       
   141     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::HandleAsyncEventL" );
       
   142     
       
   143     }
       
   144 
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 const TDesC& CMusUiSendController::TypedAddress() const
       
   151     {
       
   152     return *iAddress;
       
   153     }
       
   154     
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 TBool CMusUiSendController::ManualAddressTyped() const
       
   161     {
       
   162     return iManualAddressTyped;
       
   163     }
       
   164 
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CMusUiSendController::StartInvitationL()
       
   171     {
       
   172     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::StartInvitationL" );
       
   173     
       
   174     iCallbackService->AsyncEventL( EMusUiAsyncStartInvitation );
       
   175         
       
   176     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::StartInvitationL" );
       
   177     }
       
   178     
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CMusUiSendController::InviteL()
       
   185     {
       
   186     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::InviteL" );
       
   187     
       
   188     if ( !iSipRegistrationPending )
       
   189         {
       
   190         TRAPD( error, 
       
   191                iRemoteSipAddress = CMusUiPropertyWatch::ReadDescPropertyL(
       
   192                                                     KRemoteSipAddress ) );
       
   193         if ( error != KErrNone )
       
   194             {
       
   195             iRemoteSipAddress = KNullDesC().AllocL();
       
   196             }
       
   197 
       
   198         TRAP( error, iRemoteSipAddressProposal =
       
   199                                 CMusUiPropertyWatch::ReadDescPropertyL(
       
   200                                                     KRemoteSipAddressProposal ) );
       
   201         if ( error != KErrNone )
       
   202             {
       
   203             iRemoteSipAddressProposal = KNullDesC().AllocL();
       
   204             }
       
   205         
       
   206         if ( iRemoteSipAddress->Length() > 0 )
       
   207             {
       
   208             if ( iRemoteSipAddress->Find( KMusCommaSymbol ) == KErrNotFound )
       
   209                 {
       
   210                 InviteL( *iRemoteSipAddress );
       
   211                 }
       
   212             else
       
   213                 {
       
   214                 // Split the addresses using KMusCommaSymbol as a separator
       
   215                 CDesCArray* addressArray =
       
   216                             new ( ELeave ) CDesCArrayFlat(
       
   217                                                     KMusSipAddressesMaxAmount );
       
   218                 SplitL( *iRemoteSipAddress, KMusCommaSymbol, addressArray );
       
   219                 // Show List Query Dialog
       
   220                 TBuf<KMusSipAddressMaxLength> selectedAddress;
       
   221                 if ( MusUiDialogUtil::SelectAddressDialogL( addressArray, 
       
   222                                                             selectedAddress ) )
       
   223                     {
       
   224                     // Invite with the chosen address                    
       
   225                     InviteL( selectedAddress );
       
   226                     }
       
   227                 else
       
   228                     {
       
   229                     HandleExitL();
       
   230                     }
       
   231                 }
       
   232             }
       
   233         else
       
   234             {
       
   235             iResourceHandler->RequestKeypadL( ETrue ); // Exits on failure
       
   236             iManualAddressTyped = ETrue;
       
   237             iSendObserver.ManualAddressEntryL( *iRemoteSipAddressProposal );
       
   238             }
       
   239         }
       
   240     else
       
   241         {
       
   242         // Show waiting dialog
       
   243         delete iDialogPrompt;
       
   244         iDialogPrompt = NULL;
       
   245         iDialogPrompt = StringLoader::LoadL(
       
   246                                 R_MUS_REGISTRATION_PENDING_WAIT_NOTE_TXT );
       
   247                        
       
   248         if ( !iSharingObserver.ShowWaitDialogL( 
       
   249                                     *iDialogPrompt, 
       
   250                                     KMusInviteExpireTimeout, //Reuse 1 min timer
       
   251                                     R_MUS_LIVE_SHARING_VIEW_NOTE_NO_REG ) )
       
   252             {
       
   253             iEventObserver.HandleExit();
       
   254             }
       
   255             
       
   256         }
       
   257         
       
   258     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::InviteL" );
       
   259     }    
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CMusUiSendController::CancelInvitationL()
       
   267     {
       
   268     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::CancelInvitationL" );
       
   269     
       
   270     if ( EngineOutSession() && !ConnectionEstablished() )
       
   271         {
       
   272         TRAP_IGNORE( EngineOutSession()->CancelInviteL() );
       
   273         }
       
   274         
       
   275     HandleExitL();
       
   276     
       
   277     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::CancelInvitationL" );
       
   278     }
       
   279     
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void CMusUiSendController::HandleForegroundEventL( TBool aForeground )
       
   286     {
       
   287     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::HandleForegroundEventL" );
       
   288     
       
   289     CMusUiEventController::HandleForegroundEventL( aForeground );
       
   290     
       
   291     if ( ConnectionEstablished() &&  !ExitOccured() )
       
   292         {
       
   293         if ( aForeground )
       
   294             { 
       
   295             if ( iContinuePlayingWhenForeground )
       
   296                 {
       
   297                 MUS_LOG( "mus: [MUSUI ]     Resume playing" );
       
   298                 PlayL();
       
   299                 }
       
   300             }
       
   301         else
       
   302             {
       
   303             MUS_LOG( "mus: [MUSUI ]     Pause playing" );
       
   304             if ( EngineOutSession() )
       
   305                 {
       
   306                 iContinuePlayingWhenForeground = IsPlayingL(); 
       
   307                 }
       
   308             PauseL();
       
   309             }
       
   310         }
       
   311     
       
   312     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::HandleForegroundEventL" );
       
   313     }
       
   314 
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CMusUiSendController::PlayL()
       
   321     {
       
   322     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::PlayL" );
       
   323     if ( EngineOutSession() )
       
   324         {
       
   325         EngineOutSession()->PlayL();
       
   326         }
       
   327     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::PlayL" );
       
   328     }
       
   329 
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CMusUiSendController::PauseL()
       
   336     {
       
   337     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::PauseL" );
       
   338     if ( EngineOutSession() )
       
   339         {
       
   340         EngineOutSession()->PauseL();
       
   341         }
       
   342     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::PauseL" );
       
   343     }
       
   344 
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 TBool CMusUiSendController::IsPlayingL()
       
   351     {
       
   352     TBool isPlaying( EFalse );
       
   353     
       
   354     if ( EngineOutSession() )
       
   355         {
       
   356         isPlaying = EngineOutSession()->IsPlayingL();
       
   357         }
       
   358     
       
   359     return isPlaying;
       
   360     }
       
   361 
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 void CMusUiSendController::SessionEstablished()
       
   368     {
       
   369     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionEstablished" );
       
   370     
       
   371     // Common handling first
       
   372     CMusUiEventController::SessionEstablished();
       
   373     
       
   374     iConnectionEstablished = ETrue;
       
   375     DismissWaitDialog();
       
   376     
       
   377     if ( iForeground )
       
   378         {
       
   379         MUS_LOG( "mus: [MUSUI ]     Enable display and start playing" );
       
   380         TRAP_IGNORE( PlayL(); 
       
   381                      EnableDisplayL( ETrue ); )
       
   382                      
       
   383         iEventObserver.SetToolbarVisibility( ETrue );
       
   384         
       
   385         }
       
   386     else
       
   387         {
       
   388         MUS_LOG( "mus: [MUSUI ]     In background, don't start playing yet" );
       
   389         iContinuePlayingWhenForeground = ETrue;
       
   390         }
       
   391         
       
   392     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionEstablished" );
       
   393     }
       
   394 
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CMusUiSendController::SessionRejected()
       
   401     {
       
   402     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionRejected" );
       
   403     DismissWaitDialog();
       
   404     TRAP_IGNORE (
       
   405             MusUiDialogUtil::ShowInformationDialogL( 
       
   406                         R_MUS_LIVE_SHARING_VIEW_NOTE_CONNECTION_REJECTED ) );
       
   407     
       
   408     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   409        
       
   410     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionRejected" );
       
   411     }
       
   412 
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CMusUiSendController::SessionBadRequest()
       
   419     {
       
   420     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionBadRequest" );
       
   421     
       
   422     DismissWaitDialog();
       
   423     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   424     
       
   425     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionBadRequest" );
       
   426     }
       
   427 
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 void CMusUiSendController::SessionUnauthorized()
       
   434     {
       
   435     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionUnauthorized" );
       
   436     
       
   437     DismissWaitDialog();
       
   438     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   439     
       
   440     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionUnauthorized" );
       
   441     }
       
   442 
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 void CMusUiSendController::SessionPaymentRequired()
       
   449     {
       
   450     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionPaymentRequired" );
       
   451     
       
   452     DismissWaitDialog();
       
   453     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   454     
       
   455     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionPaymentRequired" );
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CMusUiSendController::SessionRecipientNotFound()
       
   463     {
       
   464     MUS_LOG1( "mus: [MUSUI ]     -> CMusUiSendController::SessionRecipientNotFound [%d]",
       
   465                             iTriedInvitations );
       
   466     DismissWaitDialog();
       
   467     if ( ExitOccured() )
       
   468         {
       
   469         return;
       
   470         }
       
   471     if ( ++iTriedInvitations > 1 )
       
   472         {
       
   473         TRAP_IGNORE( MusUiDialogUtil::ShowInformationDialogL(
       
   474                                 R_MUS_LIVE_SHARING_VIEW_NOTE_WRONG_ADDRESS ) );
       
   475         
       
   476         TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncInviteCancel ) );
       
   477            
       
   478         }
       
   479     else
       
   480         {
       
   481         TRAP_IGNORE( MusUiDialogUtil::ShowInformationDialogL(
       
   482                                 R_MUS_LIVE_SHARING_VIEW_NOTE_WRONG_ADDRESS ) );
       
   483         iManualAddressTyped = ETrue;
       
   484         
       
   485         TRAP_IGNORE(
       
   486             iCallbackService->AsyncEventL( EMusUiAsyncManualAddressEntry ) );
       
   487             
       
   488         }
       
   489     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionRecipientNotFound" );
       
   490     }
       
   491 
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CMusUiSendController::SessionProxyAuthenticationRequired()
       
   498     {
       
   499     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionProxyAuthenticationRequired" );
       
   500     
       
   501     DismissWaitDialog();
       
   502     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   503     
       
   504     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionProxyAuthenticationRequired" );
       
   505     }
       
   506 
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 void CMusUiSendController::SessionRequestTimeOut()
       
   513     {
       
   514     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionRequestTimeOut" );
       
   515     DismissWaitDialog();    
       
   516     TRAP_IGNORE( MusUiDialogUtil::ShowInformationDialogL( 
       
   517                             R_MUS_LIVE_SHARING_VIEW_NOTE_NO_RESPONSE ) );
       
   518     
       
   519     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   520         
       
   521     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionRequestTimeOut" );
       
   522     }
       
   523 
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 void CMusUiSendController::SessionUnsupportedMediaType()
       
   530     {
       
   531     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionUnsupportedMediaType" );
       
   532     DismissWaitDialog();
       
   533     if ( !ExitOccured() )
       
   534         {
       
   535         TRAP_IGNORE( MusUiDialogUtil::ShowGlobalErrorDialogL( 
       
   536                                     R_MUS_LIVE_SHARING_VIEW_NOTE_APP_N_A ) );
       
   537         }
       
   538     
       
   539     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   540     
       
   541     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionUnsupportedMediaType" );
       
   542     }
       
   543 
       
   544 
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 void CMusUiSendController::SessionBusyHere()
       
   550     {
       
   551     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionBusyHere" );
       
   552     DismissWaitDialog();
       
   553     TRAP_IGNORE( 
       
   554             MusUiDialogUtil::ShowInformationDialogL( 
       
   555                                R_MUS_LIVE_SHARING_VIEW_NOTE_RECIPIENT_N_A ) );
       
   556     
       
   557     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   558         
       
   559     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionBusyHere" );
       
   560     }
       
   561 
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 //
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CMusUiSendController::SessionRequestCancelled()
       
   568     {
       
   569     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionRequestCancelled" );
       
   570     DismissWaitDialog();
       
   571     TRAP_IGNORE( 
       
   572           MusUiDialogUtil::ShowInformationDialogL( 
       
   573                         R_MUS_LIVE_SHARING_VIEW_NOTE_INVITATION_CANCELLED ) );
       
   574     
       
   575     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   576         
       
   577     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionRequestCancelled" );
       
   578     }
       
   579 
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 //
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 void CMusUiSendController::SessionTemporarilyNotAvailable()
       
   586     {
       
   587     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SessionRequestCancelled" );
       
   588     DismissWaitDialog();
       
   589     if ( !ExitOccured() )
       
   590         {
       
   591         TRAP_IGNORE( MusUiDialogUtil::ShowGlobalErrorDialogL( 
       
   592                             R_MUS_LIVE_SHARING_VIEW_NOTE_SERVICE_N_A ) );
       
   593         }
       
   594     
       
   595     TRAP_IGNORE( iCallbackService->AsyncEventL( EMusUiAsyncHandleExit ) );
       
   596     
       
   597     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::SessionRequestCancelled" );
       
   598     }
       
   599 
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 void CMusUiSendController::ConstructL()
       
   606     {
       
   607     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::ConstructL" );
       
   608     
       
   609     CMusUiEventController::ConstructL(); // Base class construction
       
   610     iLocalizer = CDirectoryLocalizer::NewL();
       
   611      
       
   612     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::ConstructL" );   
       
   613     }
       
   614     
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 // -----------------------------------------------------------------------------
       
   619 //
       
   620 CMusUiSendController::CMusUiSendController(
       
   621                                     MMusUiEventObserver& aEventObserver,
       
   622                                     MMusUiSharingObserver& aSharingObserver, 
       
   623 	                                MMusUiSendObserver& aSendObserver )
       
   624 	: CMusUiEventController( aEventObserver, aSharingObserver ),
       
   625 	  iSendObserver( aSendObserver ),
       
   626 	  iTriedInvitations( 0 ),
       
   627 	  iContinuePlayingWhenForeground( ETrue ),
       
   628 	  iWaitDialogCallback( *this )
       
   629     {
       
   630     
       
   631     }
       
   632 
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 void CMusUiSendController::ExitProcedureL( TBool aUserAcceptance )
       
   639     {
       
   640     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::ExitProcedureL" );
       
   641     
       
   642     DismissWaitDialog();
       
   643     
       
   644     switch ( iShutdownState )
       
   645         {
       
   646         case EMusUiShutdownStarted:
       
   647             {
       
   648             MUS_LOG( "mus: [MUSUI ]     ExitProcedureL: EMusuiShutdownStarted" );
       
   649         
       
   650             if ( iVideoToBeSaved && 
       
   651                  iVideoFileName &&
       
   652                  MusUiFileUtil::FileExists( *iVideoFileName ) )
       
   653                 {
       
   654                 iShutdownState = EMusUiShutdownVideoSaved;
       
   655                 ShowVideoSavedDialogL();
       
   656                 ExitProcedureL( ETrue ); // Accept saving
       
   657                 }
       
   658             else
       
   659                 {
       
   660                 CMusUiEventController::ExitProcedureL( aUserAcceptance );
       
   661                 }
       
   662             break;
       
   663             }
       
   664             
       
   665         case EMusUiShutdownVideoSaved:
       
   666             {
       
   667             MUS_LOG( "mus: [MUSUI ]     ExitProcedureL: EMusuiShutdownVideoSaved" );
       
   668             
       
   669             // Check if our address is valid sip or tel uri. If not, there is no
       
   670             // point to query user about permission to save it to contacts.
       
   671             
       
   672             TInt error = KErrNotFound;
       
   673             if ( iAddress )
       
   674                 {
       
   675                 TMusEngUriParser parser( *iAddress );
       
   676                 TRAP( error, parser.ParseUriL() )                
       
   677                 }
       
   678    
       
   679             // Save Address to Contacts query if manually entered
       
   680             // and if is the standard variant.
       
   681             // NOTE: KErrNotSupported means there is more than one contact id.
       
   682             if ( !iOperatorSpecificFunctionality && ManualAddressTyped() && 
       
   683                  iContactId != KErrNotSupported &&
       
   684                  error == KErrNone )
       
   685                 {
       
   686                 iShutdownState = EMusUiShutdownContactSavingQueried;
       
   687                 SaveContactQueryL();
       
   688                 }
       
   689             else
       
   690                 {
       
   691                 // Nothing send specific, let the base class handle
       
   692                 CMusUiEventController::ExitProcedureL( aUserAcceptance );
       
   693                 }
       
   694             break;
       
   695             }
       
   696 
       
   697         default:
       
   698             {
       
   699             // Nothing send specific, let the base class handle
       
   700             CMusUiEventController::ExitProcedureL( aUserAcceptance );
       
   701             break;
       
   702             }
       
   703         }
       
   704     
       
   705     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::ExitProcedureL" );
       
   706     }
       
   707     
       
   708     
       
   709 // -----------------------------------------------------------------------------
       
   710 // Handles status changes specific to sending sharing types.
       
   711 // Calls base class version for status changes that are not sending specific. 
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 void CMusUiSendController::HandleChangedStatusL(
       
   715                         TMusAvailabilityStatus aStatus )
       
   716     {
       
   717     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::HandleChangedStatusL" )
       
   718     switch( aStatus )
       
   719         {
       
   720         case ESipRegistrationPending:
       
   721             {
       
   722             MUS_LOG( "mus: [MUSUI ]     ESipRegistrationPending" );
       
   723             iSipRegistrationPending = ETrue;
       
   724             break;
       
   725             }
       
   726         case ESipOptionsNotSent:    // FALLTHROUGH
       
   727         case ESipOptionsSent:       // FALLTHROUGH
       
   728         	{
       
   729         	break;	
       
   730         	}
       
   731         case EManualActivation:     // FALLTHROUGH
       
   732         case EMultimediaSharingAvailable:
       
   733             {
       
   734             MUS_LOG( "mus: [MUSUI ]     EManualActivation or EMultimediaSharingAvailable" )
       
   735       
       
   736             if( iSipRegistrationPending )
       
   737                 {
       
   738                 iSipRegistrationPending = EFalse;
       
   739                 // Set callback service, Call StartInvitationL when wait dialog dismissed
       
   740                 TRAPD( err, iSharingObserver.SetWaitDialogCallbackL( 
       
   741                             &iWaitDialogCallback ) );
       
   742                 // Dismiss pending wait note
       
   743                 iSharingObserver.DismissWaitDialogL();
       
   744                 if ( err == KErrNotReady )
       
   745                     {
       
   746                     StartInvitationL(); 
       
   747                     }
       
   748                 }
       
   749             break;
       
   750             }
       
   751 
       
   752         default:
       
   753             {
       
   754             // Not sending specific, let the base class handle
       
   755             CMusUiEventController::HandleChangedStatusL( aStatus );
       
   756             break;
       
   757             }
       
   758         }
       
   759     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::HandleChangedStatusL" )
       
   760     }
       
   761     
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 const TDesC& CMusUiSendController::VideoFileNameL()
       
   768     {
       
   769     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::VideoFileNameL" );
       
   770     
       
   771     TParse parse;
       
   772     TPtrC rootPath;
       
   773     
       
   774     SetVideoPathValueL();//sets video rootpath according to setting value.
       
   775    
       
   776     if ( parse.Set( iVideoFilePath,NULL,NULL) != KErrBadName )
       
   777         {
       
   778          
       
   779          if(parse.Drive().Compare( PathInfo::MemoryCardRootPath()))
       
   780             {
       
   781             TRAPD(error,MusUiFileUtil::VideoFilePathExistsL(iVideoFilePath));
       
   782             
       
   783             switch(error)
       
   784                 {
       
   785                 case KErrNotReady:
       
   786                 case KErrCorrupt:
       
   787                 case KErrLocked:
       
   788                     {
       
   789                     MusUiDialogUtil::ShowGlobalInformationDialogL(
       
   790                                            R_MUS_VIEW_NOTE_MEMORYCARD_PROBLEM);
       
   791                     
       
   792                     MUS_LOG( "mus: [MUSUI ]  -> Changing to Phone Memory " );
       
   793     		        rootPath.Set(PathInfo::PhoneMemoryRootPath());
       
   794     		        TParsePtrC pathPtr(rootPath);
       
   795     	            iVideoFilePath  = rootPath;
       
   796     	            iVideoFilePath  += PathInfo::VideosPath();
       
   797     	            // Make sure the new path exists
       
   798     	            TRAP_IGNORE( MusUiFileUtil::VideoFilePathExistsL(iVideoFilePath) )
       
   799                     break;
       
   800                     }
       
   801                 case KErrAlreadyExists:
       
   802                 case KErrNone:
       
   803                     {
       
   804                     MUS_LOG( "mus: [MUSUI ]  -> Using MMC " );
       
   805                     rootPath.Set(PathInfo::MemoryCardRootPath());
       
   806                     break;
       
   807                     }
       
   808                 default:
       
   809                     {
       
   810                     delete iVideoFileName;
       
   811                     iVideoFileNamePlain = KNullDesC;
       
   812         	    	iVideoFileName = iVideoFileNamePlain.AllocL(); 
       
   813                     HandleError( error);
       
   814                     break;
       
   815                     }
       
   816                 }
       
   817             }
       
   818         else//Phone memory is being used.
       
   819             {
       
   820             TRAPD(error,MusUiFileUtil::VideoFilePathExistsL(iVideoFilePath));
       
   821                
       
   822             switch(error)
       
   823                 {
       
   824                 case KErrAlreadyExists:
       
   825                 case KErrNone:
       
   826                     {
       
   827                     MUS_LOG( "mus: [MUSUI ] -> Using Phone memory" );
       
   828                     rootPath.Set(PathInfo::PhoneMemoryRootPath());
       
   829                     break;
       
   830                     }
       
   831                 default:
       
   832                     {
       
   833                     delete iVideoFileName;
       
   834                     iVideoFileNamePlain = KNullDesC;
       
   835         	    	iVideoFileName = iVideoFileNamePlain.AllocL(); 
       
   836                     HandleError( error);
       
   837                     break;
       
   838                     }
       
   839                 }
       
   840              }
       
   841         
       
   842         }
       
   843         else
       
   844             {
       
   845             delete iVideoFileName;
       
   846             iVideoFileNamePlain = KNullDesC;
       
   847 	    	iVideoFileName = iVideoFileNamePlain.AllocL(); 
       
   848             HandleError(KErrBadName);
       
   849             }
       
   850         
       
   851     TParsePtrC pathPtr(rootPath);
       
   852 	iVideoFilePath  += pathPtr.NameAndExt();
       
   853 	MusUiFileUtil::CreateVideoFileNameL(iVideoFilePath,
       
   854 	                                    iVideoFileNamePlain);
       
   855 
       
   856     delete iVideoFileName;
       
   857     TFileName videoFileName;
       
   858     videoFileName += iVideoFilePath;
       
   859     videoFileName += iVideoFileNamePlain;
       
   860     videoFileName += KMusVideoFileNameExtension;
       
   861     iVideoFileName = videoFileName.AllocL();
       
   862    
       
   863     MUS_LOG_TDESC( "mus: [MUSUI ]    <- CMusUiSendController::VideoFileNameL:",
       
   864                             iVideoFileName->Des() );
       
   865     return *iVideoFileName;
       
   866     }
       
   867 
       
   868 
       
   869 // -----------------------------------------------------------------------------
       
   870 //
       
   871 // -----------------------------------------------------------------------------
       
   872 //
       
   873 void CMusUiSendController::ShowInvitingWaitDialogL()
       
   874     {
       
   875     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::ShowWaitDialogL" );
       
   876     delete iDialogPrompt;
       
   877     iDialogPrompt = NULL;
       
   878     iDialogPrompt = StringLoader::LoadL(
       
   879                             R_MUS_LIVE_SHARING_VIEW_INVITING_WAIT_NOTE_TXT,
       
   880                             MusContactName().Length() > 0 ?
       
   881                             MusContactName() : iOperatorSpecificFunctionality ?
       
   882                             MusTelNumberValue() : *iAddress );
       
   883                    
       
   884     if ( !iSharingObserver.ShowWaitDialogL( 
       
   885                                 *iDialogPrompt, 
       
   886                                 KMusInviteExpireTimeout,
       
   887                                 R_MUS_LIVE_SHARING_VIEW_NOTE_NO_RESPONSE ) )
       
   888         {
       
   889         CancelInvitationL();
       
   890         }
       
   891             
       
   892     
       
   893     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::ShowWaitDialogL" );
       
   894     }
       
   895         
       
   896     
       
   897 // -----------------------------------------------------------------------------
       
   898 //
       
   899 // -----------------------------------------------------------------------------
       
   900 //
       
   901 void CMusUiSendController::DismissWaitDialog()
       
   902     {
       
   903     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::DismissWaitDialog" );
       
   904     TRAPD( err, iSharingObserver.DismissWaitDialogL(); );
       
   905     if ( err != KErrNone )
       
   906         {
       
   907         HandleError( err );
       
   908         }
       
   909     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::DismissWaitDialog" );
       
   910     }
       
   911     
       
   912     
       
   913 // -----------------------------------------------------------------------------
       
   914 //
       
   915 // -----------------------------------------------------------------------------
       
   916 //
       
   917 void CMusUiSendController::SplitL( const TDesC& aDes,
       
   918                                    const TDesC& aChar,
       
   919                                    CDesCArray* aArray )
       
   920     {
       
   921     TInt charPos( 0 );
       
   922     TPtrC ptr( aDes );
       
   923     TBool found = EFalse;
       
   924     while( ( charPos = ptr.Find( aChar ) ) > 0 )
       
   925         {
       
   926         found = ETrue;
       
   927         TPtrC str = ptr.Left( charPos );
       
   928         aArray->AppendL( str );
       
   929         ptr.Set( ptr.Right( ptr.Length() - str.Length() - 1 ) );
       
   930         }
       
   931     if ( found && ptr.Length() > 0 )
       
   932         {
       
   933         aArray->AppendL( ptr );
       
   934         }
       
   935     }
       
   936 
       
   937 
       
   938 // -----------------------------------------------------------------------------
       
   939 //
       
   940 // -----------------------------------------------------------------------------
       
   941 //
       
   942 void CMusUiSendController::SetVideoPathValueL()
       
   943     {
       
   944     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::SetVideoPathValueL" );
       
   945     TInt drive = MultimediaSharingSettings::VideoLocationSettingL();                
       
   946 
       
   947     TFileName rootPath;
       
   948     User::LeaveIfError( PathInfo::GetRootPath( rootPath, drive ) );
       
   949 
       
   950 	TParsePtrC pathPtr(rootPath);
       
   951 	iVideoFilePath  = rootPath;
       
   952 	iVideoFilePath  += PathInfo::VideosPath();
       
   953     MUS_LOG_TDESC( "mus: [MUSUI ]  <- CMusUiSendController::SetVideoPathValueL: ",
       
   954                    iVideoFilePath ); 
       
   955     iLocalizer->SetFullPath( iVideoFilePath );
       
   956     if ( iLocalizer->IsLocalized() )
       
   957         {
       
   958         iLocalizedVideoFilePath =iLocalizer->LocalizedName();
       
   959         }
       
   960     }
       
   961 
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 //
       
   965 // -----------------------------------------------------------------------------
       
   966 //
       
   967 void CMusUiSendController::ShowVideoSavedDialogL()
       
   968     {
       
   969     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::ShowVideoSavedDialogL" );
       
   970     //MUS_LOG_TDESC( "mus: [MUSUI ]      ", iVideoFileNamePlain );
       
   971     //MUS_LOG_TDESC( "mus: [MUSUI ]      ", iVideoFilePath );
       
   972     
       
   973     delete iDialogPrompt;
       
   974     iDialogPrompt = NULL;
       
   975     
       
   976     TBuf<KMusFileNameMaxLength> buf;
       
   977     TFileName videoFileName;
       
   978     videoFileName += iVideoFileNamePlain;
       
   979     videoFileName += KMusVideoFileNameExtension;
       
   980     buf = videoFileName;
       
   981     
       
   982     CDesCArrayFlat* savingTextsArray = 
       
   983             new ( ELeave ) CDesCArrayFlat( KMusStringSubstArrayGranularity );
       
   984     CleanupStack::PushL( savingTextsArray );
       
   985     //"File %0U saved to folder %1U"
       
   986     //%0U = iVideoFileName
       
   987     //%1U = iVideoFilePath
       
   988     savingTextsArray->InsertL( 0, videoFileName );
       
   989 
       
   990     if ( MultimediaSharingSettings::OperatorVariantSettingL() ==
       
   991     	 MusSettingsKeys::EOperatorSpecific ) // For AT&T products
       
   992         {
       
   993     	HBufC* folder = StringLoader::LoadLC( R_MUS_VIDEO_SAVE_FOLDER_NAME );
       
   994     	savingTextsArray->InsertL( 1, *folder );
       
   995 		CleanupStack::PopAndDestroy( folder );
       
   996         }
       
   997     else // Standard products
       
   998         {
       
   999 	    if ( iLocalizer->IsLocalized() )
       
  1000 	        {
       
  1001 	        savingTextsArray->InsertL( 1, iLocalizedVideoFilePath );
       
  1002 	        }
       
  1003 	    else
       
  1004 	        {
       
  1005 	        savingTextsArray->InsertL( 1, iVideoFilePath );
       
  1006 	        }
       
  1007 	    }
       
  1008 
       
  1009     MUS_LOG_TDESC( "mus: [MUSUI ]      filename:", savingTextsArray->MdcaPoint( 0 ) );
       
  1010     MUS_LOG_TDESC( "mus: [MUSUI ]      path:", savingTextsArray->MdcaPoint( 1 ) );
       
  1011 
       
  1012     iDialogPrompt = StringLoader::LoadL( R_MUS_VIEW_NOTE_VIDEO_SAVED,
       
  1013                                          *savingTextsArray );        
       
  1014     CleanupStack::Pop( savingTextsArray );
       
  1015                                          
       
  1016     MUS_LOG_TDESC( "mus: [MUSUI ]      ", iDialogPrompt->Des() );
       
  1017 
       
  1018     MusUiDialogUtil::ShowGlobalInformationDialogL( *iDialogPrompt );
       
  1019     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::ShowVideoSavedDialogL" );
       
  1020     }
       
  1021 
       
  1022 
       
  1023 // -----------------------------------------------------------------------------
       
  1024 //
       
  1025 // -----------------------------------------------------------------------------
       
  1026 //
       
  1027 void CMusUiSendController::DeleteVideoL()
       
  1028     {
       
  1029     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::DeleteVideoL" );
       
  1030     if ( iVideoFileName )
       
  1031         {
       
  1032         MusUiFileUtil::DeleteFileL( *iVideoFileName );
       
  1033         }
       
  1034     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::DeleteVideoL" );
       
  1035     }   
       
  1036 
       
  1037 
       
  1038 // -----------------------------------------------------------------------------
       
  1039 //
       
  1040 // -----------------------------------------------------------------------------
       
  1041 //
       
  1042 void CMusUiSendController::DeleteFileL()
       
  1043     {
       
  1044     MUS_LOG( "mus: [MUSUI ]  -> CMusUiSendController::DeleteFileL" );
       
  1045     if ( iVideoFileName && 
       
  1046     		MusUiFileUtil::FileExists( *iVideoFileName ) && !iVideoToBeSaved ) 
       
  1047 		{
       
  1048         DeleteVideoL();
       
  1049 		}
       
  1050     MUS_LOG( "mus: [MUSUI ]  <- CMusUiSendController::DeleteFileL" );
       
  1051     }   
       
  1052 
       
  1053 
       
  1054 
       
  1055 // -----------------------------------------------------------------------------
       
  1056 //
       
  1057 // -----------------------------------------------------------------------------
       
  1058 //
       
  1059 CMusUiSendController::
       
  1060 TWaitDialogCallback::TWaitDialogCallback( CMusUiSendController& aController )
       
  1061     : iController( aController )
       
  1062     {       
       
  1063     }
       
  1064     
       
  1065     
       
  1066 // -----------------------------------------------------------------------------
       
  1067 //
       
  1068 // -----------------------------------------------------------------------------
       
  1069 //
       
  1070 void CMusUiSendController::
       
  1071 TWaitDialogCallback::DialogDismissedL( TInt /*aButtonId*/ )
       
  1072     {
       
  1073     iController.StartInvitationL();
       
  1074     }
       
  1075     
       
  1076 // End of file
       
  1077