browserutilities/downloadmgr/DownloadMgrUiLib/Src/UserInteractionsEventHandler.cpp
changeset 0 dd21522fd290
child 8 7c90e6132015
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 the License "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:  User Interactions event handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "UserInteractionsEventHandler.h"
       
    22 #include    "CUserInteractionsUtils.h"
       
    23 #include    "ProgressInfoCreator.h"
       
    24 #include    "CDownloadMgrUiLibRegistry.h"
       
    25 #include    "CDownloadMgrUiDownloadsList.h"
       
    26 #include    "CDownloadMgrUiUserInteractions.h"
       
    27 #include    "UiLibLogger.h"
       
    28 #include    "DMgrUiLibPanic.h"
       
    29 #include    <bldvariant.hrh>
       
    30 #include    <DownloadMgrUiLib.rsg>
       
    31 #include    <aknlists.h>
       
    32 #include    <aknPopup.h>
       
    33 #include    <StringLoader.h>
       
    34 #include    <apgcli.h>
       
    35 #include    <eikbtgpc.h>
       
    36 #include    <SysUtil.h>
       
    37 #include    <exterror.h>
       
    38 #include    <etelpckt.h>
       
    39 #include    <AknNoteDialog.h>
       
    40 #include    <UriUtils.h>
       
    41 #include    <MGXFileManagerFactory.h>
       
    42 #include    <CMGXFileManager.h>
       
    43 
       
    44 #include    <pathinfo.h>
       
    45 #include    <driveinfo.h>
       
    46 
       
    47 #include    <apmrec.h>
       
    48 #include    <apmstd.h>
       
    49 #include    <s32std.h>
       
    50 #include    <e32des8.h>
       
    51 
       
    52 #include    <AiwGenericParam.h>
       
    53 #include    <DocumentHandler.h>
       
    54 
       
    55 
       
    56 // LOCAL CONSTANTS AND MACROS
       
    57 _LIT( KListBoxSeparator, "\t" );
       
    58 _LIT( KDownloadPath,"download");
       
    59 
       
    60 
       
    61 const TInt KDownloadConfSizeLimit = 100000;
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CUserInteractionsEventHandler::CUserInteractionsEventHandler
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CUserInteractionsEventHandler::CUserInteractionsEventHandler
       
    70     ( RHttpDownload& aDownload, THttpDownloadEvent aEvent, 
       
    71       MDownloadMgrUiLibRegModel& aRegistryModel, 
       
    72       CAsyncEventHandlerArray& aOwner,
       
    73       CUserInteractionsUtils& aUiUtils )
       
    74 :   CAsyncEventHandlerBase( aDownload, aEvent, aRegistryModel, aOwner ),
       
    75     iUiUtils( aUiUtils ),
       
    76     iDownloadConfirmationShown( EFalse )
       
    77     {
       
    78     CLOG_ENTERFN("CUserInteractionsEventHandler::CUserInteractionsEventHandler");
       
    79     CLOG_WRITE_FORMAT(" %x", this);
       
    80     CLOG_LEAVEFN("CUserInteractionsEventHandler::CUserInteractionsEventHandler");
       
    81     }
       
    82 
       
    83 // Destructor
       
    84 CUserInteractionsEventHandler::~CUserInteractionsEventHandler()
       
    85     {
       
    86     CLOG_ENTERFN("CUserInteractionsEventHandler::~CUserInteractionsEventHandler");
       
    87     CLOG_WRITE_FORMAT(" %x", this);
       
    88     if ( iPopupList )
       
    89         {
       
    90         iPopupList->CancelPopup();
       
    91         iPopupList = NULL;
       
    92         }
       
    93     if ( iDeletedPtr )
       
    94         {
       
    95         *iDeletedPtr = ETrue;
       
    96         }
       
    97     if ( iDownloadConfirmationDeletedPtr )
       
    98         {
       
    99         *iDownloadConfirmationDeletedPtr = ETrue;
       
   100         }
       
   101     Cancel();
       
   102     CLOG_LEAVEFN("CUserInteractionsEventHandler::~CUserInteractionsEventHandler");
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CUserInteractionsEventHandler::DiskSpaceBelowCriticalLevelL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 #ifdef RD_MULTIPLE_DRIVE
       
   110 TBool CUserInteractionsEventHandler::DiskSpaceBelowCriticalLevelL( RHttpDownload& aDownload, TInt aSize ) const
       
   111 #else
       
   112 TBool CUserInteractionsEventHandler::DiskSpaceBelowCriticalLevelL( TInt aSize ) const
       
   113 #endif
       
   114     {
       
   115     CLOG_ENTERFN("CUserInteractionsEventHandler::DiskSpaceBelowCriticalLevelL");
       
   116 
       
   117    	TBool isSpaceBelowCL( EFalse );
       
   118 
       
   119     RFs fs;
       
   120     User::LeaveIfError( fs.Connect() );
       
   121     CleanupClosePushL( fs );
       
   122     
       
   123     TInt bytesToWrite = aSize;
       
   124     if (bytesToWrite < 0)
       
   125         bytesToWrite = 0;
       
   126 
       
   127 #ifdef RD_MULTIPLE_DRIVE
       
   128     // Destination is FFS in default
       
   129     TInt selectedDrive;
       
   130     User::LeaveIfError(
       
   131         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory,
       
   132                                     selectedDrive ) );
       
   133     TInt err( KErrNone );
       
   134 
       
   135     HBufC* fileName = HBufC::NewLC( KMaxPath );
       
   136     TPtr fileNamePtr = fileName->Des();
       
   137     User::LeaveIfError
       
   138         ( aDownload.GetStringAttribute( EDlAttrDestFilename, fileNamePtr ) );
       
   139     CLOG_WRITE_FORMAT(" EDlAttrDestFilename: %S",&fileNamePtr);
       
   140 
       
   141     // only that drive needs to be checked
       
   142     CLOG_WRITE( "cfds1" );
       
   143     if( (err = fs.CharToDrive( (*fileName)[0], selectedDrive )) != KErrNone )
       
   144         {
       
   145         CLOG_WRITE( "Bad drive letter" );
       
   146         User::Leave( err );
       
   147         }
       
   148     else if( !fs.IsValidDrive( selectedDrive ) )
       
   149         // invalid drive letter in filename
       
   150         {
       
   151         CLOG_WRITE( "Invalid drive" );
       
   152         User::Leave( KErrBadName );
       
   153         }
       
   154 
       
   155     CleanupStack::PopAndDestroy( fileName ); // fileName
       
   156     fileName = NULL;
       
   157 
       
   158     // Check if there's enough memory in the phone
       
   159 	TRAP_IGNORE( isSpaceBelowCL = SysUtil::DiskSpaceBelowCriticalLevelL(
       
   160                                             &fs,
       
   161                                             bytesToWrite,
       
   162                                             selectedDrive ) );
       
   163 
       
   164     // If there is error, then isSpaceBelowCL is untouched and 
       
   165     // contains the right value. Otherwise it also contains 
       
   166     // the right value.
       
   167     CLOG_WRITE_FORMAT(" DiskSpace: isSpaceBelowCL: %d",isSpaceBelowCL);
       
   168 
       
   169 #else
       
   170 	isSpaceBelowCL = SysUtil::DiskSpaceBelowCriticalLevelL( &fs, 
       
   171 			                                bytesToWrite,
       
   172                                             EDriveC );
       
   173     CLOG_WRITE_FORMAT(" C: isSpaceBelowCL: %d",isSpaceBelowCL);
       
   174 
       
   175     if ( isSpaceBelowCL )
       
   176         {
       
   177         // Check MMC
       
   178         TRAP_IGNORE( isSpaceBelowCL = 
       
   179                      SysUtil::MMCSpaceBelowCriticalLevelL( &fs, bytesToWrite ) );
       
   180         // If there is error, then isSpaceBelowCL is untouched and 
       
   181         // contains the right value. Otherwise it also contains 
       
   182         // the right value.
       
   183         CLOG_WRITE_FORMAT(" MMC: isSpaceBelowCL: %d",isSpaceBelowCL);
       
   184         }
       
   185 #endif
       
   186 
       
   187     CleanupStack::PopAndDestroy( &fs ); // fs
       
   188 
       
   189     CLOG_LEAVEFN("CUserInteractionsEventHandler::DiskSpaceBelowCriticalLevelL");
       
   190     return isSpaceBelowCL;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CUserInteractionsEventHandler::ShowDownloadConfirmationL
       
   195 // Confirmation is not shown, if:
       
   196 // - the downloaded size = total size
       
   197 // - or the total size is less than 100 kB
       
   198 // The confirmation query is shown, if aForce is ETrue!
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 TBool CUserInteractionsEventHandler::ShowDownloadConfirmationL
       
   202     ( RHttpDownload& aDownload, TInt aCbaResource, TBool aForce )
       
   203     {
       
   204     CLOG_ENTERFN("CUserInteractionsEventHandler::ShowDownloadConfirmationL aForce");
       
   205 
       
   206     TBool ret;
       
   207     if ( aForce )
       
   208         {
       
   209         ret = ShowDownloadConfirmationL( aDownload, aCbaResource );
       
   210         }
       
   211     else
       
   212         {
       
   213         TInt32 totalLength( KErrNotFound );
       
   214         TInt32 downloadedSize( KErrNotFound );
       
   215 
       
   216         /*
       
   217         * Get full size of media content and downloaded size
       
   218         */
       
   219 
       
   220         User::LeaveIfError( aDownload.GetIntAttribute
       
   221                           ( EDlAttrMultipleMOLength, totalLength ) );
       
   222         CLOG_WRITE_FORMAT(" EDlAttrMultipleMOLength: %d",totalLength);
       
   223         
       
   224         User::LeaveIfError( aDownload.GetIntAttribute
       
   225                           ( EDlAttrMultipleMODownloadedSize, downloadedSize ) );
       
   226         CLOG_WRITE_FORMAT(" EDlAttrMultipleMODownloadedSizes: %d",downloadedSize);
       
   227 
       
   228         HBufC8* contentType = iUiUtils.ContentTypeL( aDownload, ETrue );
       
   229         CleanupStack::PushL( contentType );
       
   230 
       
   231         // Don't show the confirmation query if the downloading 
       
   232         // already finished
       
   233         if ( downloadedSize == totalLength )
       
   234             {
       
   235             ret = ETrue;
       
   236             }
       
   237         else if ( 0 <= totalLength && totalLength < KDownloadConfSizeLimit )
       
   238             {
       
   239             ret = ETrue;
       
   240             }
       
   241         // GGUO-775RXR for widgets we don't need to have download confirmation either             
       
   242         else if ( contentType->Compare( KWidgetMimeType) == 0 ) 
       
   243             {
       
   244             ret = ETrue;                                
       
   245             }                                            
       
   246         else
       
   247             {
       
   248             ret = ShowDownloadConfirmationL( aDownload, aCbaResource );
       
   249             }
       
   250         CleanupStack::PopAndDestroy( contentType );            
       
   251         }
       
   252 
       
   253     CLOG_LEAVEFN("CUserInteractionsEventHandler::ShowDownloadConfirmationL aForce");
       
   254     return ret;
       
   255     }
       
   256 // -----------------------------------------------------------------------------
       
   257 // CUserInteractionsEventHandler::ShowDownloadConfirmationL
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 // Cod we used the following order
       
   261 // 		name/size/type/price(optional)/description(no)/vendor(no) 
       
   262 
       
   263 TBool CUserInteractionsEventHandler::ShowDownloadConfirmationL
       
   264     ( RHttpDownload& aDownload, TInt aCbaResource )
       
   265     {
       
   266     CLOG_ENTERFN("CUserInteractionsEventHandler::ShowDownloadConfirmationL");
       
   267 
       
   268     HBufC* itemText = NULL; // a buffer holding the text for each list item
       
   269 
       
   270     CEikFormattedCellListBox* listBox = new ( ELeave ) CAknDoublePopupMenuStyleListBox;
       
   271     CleanupStack::PushL( listBox );
       
   272 
       
   273     // If supported show OK & Cancel buttons, otherwise just CANCEL
       
   274     iPopupList = NULL; // reset pointer.
       
   275     CAknPopupList* popupList = CAknPopupList::NewL
       
   276             ( listBox, aCbaResource, AknPopupLayouts::EMenuDoubleWindow );
       
   277     CleanupStack::PushL( popupList );
       
   278 
       
   279     TInt flags = CEikListBox::EDisableHighlight;
       
   280     listBox->ConstructL( popupList, flags );
       
   281     listBox->CreateScrollBarFrameL( ETrue );
       
   282     listBox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   283         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   284 
       
   285     MDesCArray* itemList = listBox->Model()->ItemTextArray();
       
   286     CDesCArray* itemArray = (CDesCArray*)itemList;
       
   287     
       
   288     //-------------------------------------------
       
   289     // Header
       
   290     //
       
   291     HBufC* header = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_TITLE ); //"Download"
       
   292     popupList->SetTitleL( *header );
       
   293     CleanupStack::PopAndDestroy( header );  // header
       
   294     header = NULL;
       
   295 
       
   296     //-------------------------------------------
       
   297     // Check the available free space
       
   298     //
       
   299     TInt32 contentSize( 0 );
       
   300     TInt err = aDownload.GetIntAttribute( EDlAttrMultipleMOLength, contentSize );
       
   301     if ( err != KErrNone && err != KErrNotFound )
       
   302         {
       
   303         User::LeaveIfError( err );
       
   304         }
       
   305 
       
   306     // if size is not known it is set to -1. 0 size content size is ok here.
       
   307     TBool isContentSizeKnown = ( err == KErrNone && contentSize > -1 );
       
   308 
       
   309 #ifdef RD_MULTIPLE_DRIVE
       
   310     if ( DiskSpaceBelowCriticalLevelL( aDownload, (TInt)contentSize ) )
       
   311 #else
       
   312     if ( DiskSpaceBelowCriticalLevelL( (TInt)contentSize ) )
       
   313 #endif
       
   314         {
       
   315         // Not enough free disk space!
       
   316         HBufC* notEnoughSpace = 
       
   317             StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_NOT_ENOUGH_MEM );        
       
   318         itemArray->AppendL( *notEnoughSpace );
       
   319         CleanupStack::PopAndDestroy( notEnoughSpace );  // notEnoughSpace
       
   320         // and disable OK button
       
   321         popupList->ButtonGroupContainer()->MakeCommandVisible( EAknSoftkeyOk, EFalse );
       
   322         }
       
   323 
       
   324     //-------------------------------------------
       
   325     // Supported?  no need - this was confirmed earlier
       
   326     //
       
   327 
       
   328     //-------------------------------------------
       
   329     // Add name here 
       
   330     // name/size/type/price(optional)/description(no)/vendor(no) 
       
   331    HBufC* nameHeader = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_NAME );
       
   332    HBufC* dlName = HBufC::NewLC( KMaxPath );            
       
   333    TPtr dlNamePtr = dlName->Des();
       
   334    User::LeaveIfError( aDownload.GetStringAttribute( EDlAttrName, dlNamePtr ) );
       
   335 
       
   336    itemText = FormatListBoxItemLC( *nameHeader, *dlName );
       
   337    itemArray->AppendL( *itemText );
       
   338    CleanupStack::PopAndDestroy( 3, nameHeader ); // itemText, sizeHeader
       
   339    dlName = NULL; 
       
   340    itemText = NULL;
       
   341    nameHeader = NULL;
       
   342 
       
   343     //-------------------------------------------
       
   344     // Content Size
       
   345     //
       
   346     HBufC* sizeHeader = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_SIZE );
       
   347     if ( !isContentSizeKnown )
       
   348         {
       
   349         HBufC* unknownString = StringLoader::LoadL( R_DMUL_DOWNLOADCONF_UNKNOWN );
       
   350         iSizeInfoRes.Copy( unknownString->Left(KMaxDownloadSizeTextLength) );
       
   351         delete unknownString;
       
   352         }
       
   353     else
       
   354         {
       
   355         CProgressInfoCreator* progInfoCreator = CProgressInfoCreator::NewL();
       
   356         progInfoCreator->ProgressInfo( contentSize, iSizeInfoRes );
       
   357         delete progInfoCreator;
       
   358         progInfoCreator = NULL;
       
   359         }
       
   360 
       
   361     itemText = FormatListBoxItemLC( *sizeHeader, iSizeInfoRes );
       
   362     itemArray->AppendL( *itemText );
       
   363     CleanupStack::PopAndDestroy( 2, sizeHeader ); // itemText, sizeHeader
       
   364     itemText = NULL;
       
   365     sizeHeader = NULL;
       
   366 
       
   367     //-------------------------------------------
       
   368     // Application Name - only show if Supported
       
   369     //  
       
   370     HBufC* handlerHeader = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_OPENWITH );
       
   371 
       
   372     RApaLsSession apaLs;
       
   373     User::LeaveIfError( apaLs.Connect() );
       
   374     CleanupClosePushL( apaLs );
       
   375     TUid appUid;
       
   376     HBufC8* contentType = iUiUtils.ContentTypeL( aDownload, ETrue );
       
   377     CleanupStack::PushL( contentType );
       
   378     
       
   379     #ifdef _DEBUG
       
   380     HBufC* contType = HBufC::NewL( contentType->Length() );
       
   381     TPtr ptr = contType->Des();
       
   382     ptr.Copy( *contentType );
       
   383     CLOG_WRITE_FORMAT(" contentType: %S",&ptr);
       
   384     delete contType;
       
   385     contType = NULL;
       
   386     #endif // _DEBUG
       
   387     
       
   388     User::LeaveIfError( apaLs.AppForDataType( TDataType(*contentType), appUid ) );
       
   389     HBufC* handlerName = ConstructHandlerAppNameLC( appUid, apaLs );
       
   390 
       
   391     itemText = FormatListBoxItemLC( *handlerHeader, *handlerName );
       
   392     CleanupStack::PopAndDestroy( itemText );
       
   393     
       
   394     CleanupStack::PopAndDestroy( handlerName );
       
   395     CleanupStack::Pop( contentType ); // Still needed - push later again
       
   396     CleanupStack::PopAndDestroy( &apaLs );
       
   397     CleanupStack::PopAndDestroy( handlerHeader );
       
   398     itemText = NULL;
       
   399     handlerName = NULL;
       
   400     handlerHeader = NULL;
       
   401     CleanupStack::PushL( contentType );
       
   402     
       
   403     
       
   404     //-------------------------------------------
       
   405     // MIME Content Type
       
   406     //
       
   407     HBufC* typeHeader = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_FILETYPE );
       
   408 
       
   409     HBufC* typeString = NULL;
       
   410     if ( contentType->Length() != 0 )
       
   411         {
       
   412         // 8 bit -> 16 bit conversion
       
   413         typeString = HBufC::NewLC( contentType->Length() );
       
   414         typeString->Des().Copy( *contentType );
       
   415         }
       
   416     else
       
   417         {       
       
   418         typeString = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_UNKNOWN );
       
   419         }
       
   420 
       
   421     itemText = FormatListBoxItemLC( *typeHeader, *typeString );
       
   422     itemArray->AppendL( *itemText );
       
   423     CleanupStack::PopAndDestroy( 3, typeHeader ); // itemText, typeString , typeHeader
       
   424     CleanupStack::PopAndDestroy( contentType );
       
   425     itemText = NULL;
       
   426     typeString = NULL;
       
   427     typeHeader = NULL;
       
   428     contentType = NULL;
       
   429 
       
   430     //-------------------------------------------
       
   431     // Price: since dm has no info, we don't need this at all here 
       
   432     //
       
   433 
       
   434     //-------------------------------------------
       
   435     // Description: since dm has no info, we don't need this at all here 
       
   436     //
       
   437 
       
   438     //-------------------------------------------
       
   439     // Vendor: since dm has no info, we don't need this at all here 
       
   440     //
       
   441 
       
   442     // Show popup list - it calls CActiveScheduler::Start(), so be careful 
       
   443     // when using data members after ExecuteLD!
       
   444     iDownloadConfirmationShown = ETrue;
       
   445     iPopupList = popupList;
       
   446     TBool deleted( EFalse );
       
   447     iDownloadConfirmationDeletedPtr = &deleted;
       
   448     TInt pressedOk = popupList->ExecuteLD();
       
   449     CleanupStack::Pop( popupList );    // popupList 
       
   450     if ( !deleted )
       
   451         {
       
   452         // We can use members only in this case!
       
   453         iDownloadConfirmationShown = EFalse;
       
   454         iPopupList = NULL;
       
   455         }
       
   456 
       
   457     // cleanup
       
   458     CleanupStack::PopAndDestroy( /*listBox*/ ); // listBox
       
   459 
       
   460     CLOG_WRITE_FORMAT(" pressedOk: %d",pressedOk);
       
   461     CLOG_LEAVEFN("CUserInteractionsEventHandler::ShowDownloadConfirmationL");
       
   462     return (TBool)pressedOk;
       
   463     }
       
   464     
       
   465 // -----------------------------------------------------------------------------
       
   466 // CUserInteractionsEventHandler::ConstructHandlerAppNameLC
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 HBufC* CUserInteractionsEventHandler::ConstructHandlerAppNameLC
       
   470     ( const TUid& aAppUid, RApaLsSession& aApaLs )
       
   471     {
       
   472     CLOG_ENTERFN("CUserInteractionsEventHandler::ConstructHandlerAppNameLC");
       
   473     
       
   474     HBufC* handlerName = NULL;
       
   475     if ( aAppUid == TUid::Null() )
       
   476         {
       
   477         // No handler found
       
   478         handlerName = StringLoader::LoadLC( R_DMUL_DOWNLOADCONF_UNKNOWN );
       
   479         }
       
   480     else
       
   481         {
       
   482         TApaAppInfo appInfo;
       
   483         User::LeaveIfError( aApaLs.GetAppInfo( appInfo, aAppUid ) );
       
   484         CLOG_WRITE_FORMAT(" appInfo.iFullName: %S",&appInfo.iFullName);
       
   485         CLOG_WRITE_FORMAT(" appInfo.iCaption: %S",&appInfo.iCaption);
       
   486         CLOG_WRITE_FORMAT(" appInfo.iShortCaption: %S",&appInfo.iShortCaption);
       
   487         // In many cases there is long caption. We should use short caption only 
       
   488         // if it is empty. They say that sometimes the long caption is not empty, 
       
   489         // but it contains only a space (0x20). In this case we must use the short.
       
   490         // For safety reasons, we will check the whole long caption, if it 
       
   491         // contains only space characters.
       
   492         const TDesC& longCap = appInfo.iCaption;
       
   493         TBool longCapIsEmpty = (longCap.Length() == 0);
       
   494         if ( longCapIsEmpty == EFalse )
       
   495             {
       
   496             TInt longCapLength = longCap.Length();
       
   497             TBool containsOnlySpaces = ETrue; // We'll change it, if it's not true.
       
   498             for (TInt i = 0; i < longCapLength; ++i)
       
   499                 {
       
   500                 if ( TChar(longCap[i]).IsSpace() == EFalse )
       
   501                     {
       
   502                     containsOnlySpaces = EFalse;
       
   503                     break;
       
   504                     }
       
   505                 }
       
   506             if ( containsOnlySpaces )
       
   507                 {
       
   508                 longCapIsEmpty = ETrue;
       
   509                 }
       
   510             }
       
   511 
       
   512         if ( longCapIsEmpty )
       
   513             {
       
   514             // Using short caption
       
   515             handlerName = appInfo.iShortCaption.AllocLC();
       
   516             }
       
   517         else
       
   518             {
       
   519             // Using long caption
       
   520             handlerName = appInfo.iCaption.AllocLC();
       
   521             }
       
   522         }
       
   523         
       
   524     CLOG_LEAVEFN("CUserInteractionsEventHandler::ConstructHandlerAppNameLC");
       
   525     return handlerName;
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CUserInteractionsEventHandler::FormatListBoxItemLC
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 HBufC* CUserInteractionsEventHandler::FormatListBoxItemLC
       
   533     ( const TDesC& aFirst, const TDesC& aSecond )
       
   534     {
       
   535     HBufC* res = HBufC::NewLC( aFirst.Length() + 
       
   536                                aSecond.Length() + 
       
   537                                KListBoxSeparator().Length() );
       
   538     res->Des().Copy( aFirst );
       
   539     res->Des().Append( KListBoxSeparator );
       
   540     res->Des().Append( aSecond );
       
   541     return res;
       
   542     }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CUserInteractionsEventHandler::HandleInProgressStateL
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void CUserInteractionsEventHandler::HandleInProgressStateL( TBool& aThisDeleted )
       
   549     {
       
   550     CLOG_ENTERFN("CUserInteractionsEventHandler::HandleInProgressStateL");
       
   551 
       
   552     // GET - download is in progress - user can cancel
       
   553     if( iEvent.iProgressState == EHttpProgCodDownloadStarted && iEvent.iDownloadState == EHttpDlInprogress )
       
   554         {
       
   555         iRegistryModel.DownloadsList().CancelDisplayingDownloadsList();                                          
       
   556         }
       
   557     if ( iEvent.iProgressState == EHttpContTypeRecognitionAvail )
       
   558         {
       
   559         // Don't show confirmation query for COD downloads
       
   560         TBool isCodDownload( EFalse );
       
   561 		TBool userConfirms( EFalse );
       
   562         User::LeaveIfError( iDownload.GetBoolAttribute
       
   563                           ( EDlAttrCodDownload, isCodDownload ) );
       
   564         if ( isCodDownload )
       
   565             {
       
   566             // Do nothing.
       
   567             }
       
   568         else
       
   569             {
       
   570             // Check if multipart
       
   571             HBufC8* contentType = HBufC8::NewLC( KMaxContentTypeLength );
       
   572             TPtr8 contentTypePtr = contentType->Des();
       
   573             User::LeaveIfError
       
   574                 ( iDownload.GetStringAttribute( EDlAttrContentType, contentTypePtr ) );
       
   575             if( 0 == contentType->Compare( KMultiPartMimeType ) )
       
   576                 {
       
   577                 // Don't show confirmation query yet, but 
       
   578                 // observe EHttpProgSupportedMultiPart.
       
   579                 }
       
   580             else
       
   581                 {
       
   582                 iUiUtils.IsContentTypeSupportedL( iDownload );
       
   583                 TBool suppressDownloadConfirmation( EFalse );
       
   584                 iRegistryModel.UserInteractions().GetBoolAttributeL
       
   585                     ( CDownloadMgrUiUserInteractions::EAttrSuppressDownloadConfirmation, 
       
   586                       suppressDownloadConfirmation );
       
   587                 CLOG_WRITE_FORMAT(" suppressDownloadConfirmation: %d", 
       
   588                                     suppressDownloadConfirmation);
       
   589 
       
   590                 if ( suppressDownloadConfirmation )
       
   591                     {
       
   592                     // Nothing to do.
       
   593                     }
       
   594                 else
       
   595                     {
       
   596                     TInt32 statusCode(0);
       
   597                     User::LeaveIfError( iDownload.GetIntAttribute
       
   598                                       ( EDlAttrStatusCode, statusCode ) );
       
   599                     if ( statusCode == 206 ) // http status code
       
   600                         {
       
   601                         // Display information note (only if the DL is not visible)
       
   602                         if ( iRegistryModel.DownloadsListInstalled() )
       
   603                             {
       
   604                             if ( !iRegistryModel.DownloadsList().IsVisible() )
       
   605                                 {
       
   606                                 CUserInteractionsUtils::InfoNoteL
       
   607                                     ( R_DMUL_OK_NOTE, R_DMUL_NOTE_DOWNLOADING );
       
   608                                 }
       
   609                             }
       
   610                         }
       
   611                     else
       
   612                         {
       
   613                         userConfirms = ShowDownloadConfirmationL
       
   614                             ( iDownload, R_AVKON_SOFTKEYS_OK_CANCEL__OK, EFalse );
       
   615                                              
       
   616                         // executes a wait dialog! Check if this is deleted meanwhile
       
   617                         if ( aThisDeleted )
       
   618                             {
       
   619                             CLOG_WRITE_FORMAT(" this deleted: %x", this);
       
   620                             CLOG_LEAVEFN("CUserInteractionsEventHandler::HandleInProgressStateL");
       
   621                             return;
       
   622                             }
       
   623                             
       
   624                         if ( userConfirms )
       
   625                             {
       
   626                             TBool isLaunchType( EFalse );
       
   627                             if( iUiUtils.DrmDownloadL( iDownload ) )
       
   628                                 {
       
   629                                 // get content type of media file in drm content
       
   630                                 HBufC8* ctype = iUiUtils.ContentTypeL( iDownload, ETrue );
       
   631                                 if( KDrmInnerContentTypesToLaunch().Find( *ctype )
       
   632                                     != KErrNotFound )
       
   633                                     {
       
   634                                     isLaunchType = ETrue;
       
   635                                     }
       
   636                                 delete ctype;
       
   637                                 }
       
   638                             if( isLaunchType )
       
   639                                 {
       
   640                                 User::LeaveIfError( iDownload.SetIntAttribute(
       
   641                                     EDlAttrAction, ELaunch ) );
       
   642                                 }
       
   643                             else
       
   644                                 {
       
   645                                 //part of error PNIO-73GEM3.Sis file progress should be visible to user
       
   646                                 if( (KSisxApplication().Find( contentTypePtr)!= KErrNotFound) || 
       
   647                                     (KPipApplication().Find( contentTypePtr)!= KErrNotFound) ||
       
   648                                     (KWidgetMimeType().Find( contentTypePtr)!= KErrNotFound) ||
       
   649                                     (KSharingConfig().Find( contentTypePtr)!= KErrNotFound) )
       
   650                                     {
       
   651                                     isLaunchType = ETrue;
       
   652                                     User::LeaveIfError( iDownload.SetIntAttribute(
       
   653                                         EDlAttrAction, ELaunch ) );                                    
       
   654                                     }
       
   655                                 // Open the download list if there is no more 
       
   656                                 // download confirmation shown:
       
   657                                 if ( iRegistryModel.UserInteractions().
       
   658                                     DownloadConfirmationsShown() == 0 )
       
   659                                     {
       
   660                                     if ( iRegistryModel.DownloadsListInstalled() )
       
   661                                         {
       
   662                                         iRegistryModel.DownloadsList().
       
   663                                             DisplayDownloadsListL( iDownload );
       
   664                                         }
       
   665                                     }
       
   666                                 }
       
   667                             }
       
   668                         else
       
   669                             {
       
   670                             // The download must be removed from Downloads List
       
   671                             User::LeaveIfError( iDownload.Delete() );
       
   672                             CLOG_WRITE(" Delete OK");
       
   673                             }
       
   674                         }
       
   675                      }
       
   676                     if (userConfirms)
       
   677 					{
       
   678                    
       
   679 	#ifdef __DMGR_PD_TESTHARNESS
       
   680                         iUiUtils.TestLaunchPdAppL(iDownload);
       
   681 	#else	           
       
   682  		//#ifdef RD_BROWSER_PROGRESSIVE_DOWNLOAD	               
       
   683 
       
   684                         // check if it's PdLaunch action 
       
   685 		                TInt32 action(0);
       
   686                         User::LeaveIfError( iDownload.GetIntAttribute( EDlAttrAction, action ) );                    
       
   687                         if( (action & EPdLaunch) && 
       
   688                             iUiUtils.CanLaunchAsProgDownload( iDownload, iRegistryModel.DownloadsList(),EFalse ))
       
   689                             {
       
   690       						CLOG_WRITE( " launchPdAppL(iDownload)" );
       
   691 						    iUiUtils.LaunchPdAppL(iDownload, ETrue);
       
   692 						    }
       
   693 		//#endif	//RD_BROWSER_PROGRESSIVE_DOWNLOAD
       
   694 	#endif	//__DMGR_PD_TESTHARNESS	
       
   695 					}
       
   696                 }
       
   697             CleanupStack::PopAndDestroy( contentType ); // contentType
       
   698             }
       
   699         }
       
   700     else if ( iEvent.iProgressState == EHttpProgCodPdAvailable )
       
   701         {
       
   702         TBool isCodPdAvailable( EFalse );
       
   703         User::LeaveIfError( iDownload.GetBoolAttribute
       
   704                           ( EDlAttrCodPdAvailable, isCodPdAvailable ) );
       
   705         if ( isCodPdAvailable )
       
   706             {
       
   707 			
       
   708 			#ifdef __DMGR_PD_TESTHARNESS
       
   709 				iUiUtils.TestLaunchPdAppL(iDownload);
       
   710 			#else
       
   711 	            // check if it's PdLaunch action 
       
   712 	            TInt32 action(0);
       
   713                 User::LeaveIfError( iDownload.GetIntAttribute( EDlAttrAction, action ) );                    
       
   714 				if ( (action & EPdLaunch) && 
       
   715                     iUiUtils.CanLaunchAsProgDownload( iDownload, iRegistryModel.DownloadsList(),ETrue ))
       
   716 					{
       
   717 					iUiUtils.LaunchPdAppL(iDownload, ETrue);
       
   718 					}
       
   719 			#endif	//__DMGR_PD_TESTHARNESS
       
   720 			}
       
   721         }        
       
   722     else if ( iEvent.iProgressState == EHttpProgCodDescriptorAccepted )
       
   723         {
       
   724         // COD load accepted. Download is turned to visible, and 
       
   725         // downloads list is shown.
       
   726         User::LeaveIfError( iDownload.SetBoolAttribute
       
   727                           ( EDlAttrHidden, EFalse ) );
       
   728         CLOG_WRITE(" SetBoolAttribute EDlAttrHidden OK");
       
   729         // If this download's ServiceFlow was running, it's not more 
       
   730         // a ServiceFlow, thus the next postponed download can be 
       
   731         // scheduled.
       
   732         if ( iRegistryModel.UserInteractions().IsCodServiceFlowRunning( iDownload ) )
       
   733             {
       
   734             iRegistryModel.UserInteractions().SchedulePostponedDownloadL();
       
   735             }
       
   736         // Display downloads list
       
   737         if ( iRegistryModel.DownloadsListInstalled() )
       
   738             {
       
   739             iRegistryModel.DownloadsList().
       
   740                 DisplayDownloadsListL( iDownload );
       
   741             }
       
   742         }
       
   743     else if ( iEvent.iProgressState == EHttpProgCodLoadEnd )
       
   744         {
       
   745         // UI state must be checked before we set download to hidden!
       
   746         TBool isUiBusyNow = iRegistryModel.UserInteractions().IsUiBusy();
       
   747         // COD load has ended. Download is turned to hidden, removed from 
       
   748         // downloads list, and restarted (ServiceFlow).
       
   749         CLOG_WRITE(" SetBoolAttribute EDlAttrHidden OK");
       
   750 
       
   751         // Restart if possible - start ServiceFlow.
       
   752         // (UserInteractions must be installed...)
       
   753         if ( isUiBusyNow )
       
   754             {
       
   755             // Not possible to do it. Postpone the Service Flow and 
       
   756             // invoke when no more handler is running.
       
   757             // The download is already hidden!
       
   758             iRegistryModel.UserInteractions().PostponeCodHandlingL( iDownload );
       
   759              //Download will be handled when the UI becomes free.
       
   760             }
       
   761         else
       
   762             {
       
   763             CLOG_WRITE(" (Re)Starting...");
       
   764             User::LeaveIfError( iDownload.Start() );
       
   765             CLOG_WRITE(" (Re)Start OK");
       
   766             }
       
   767         }
       
   768     else if ( iEvent.iProgressState == EHttpProgSupportedMultiPart )
       
   769         {
       
   770         // Show download confirmation for multipart download, if appropriate.
       
   771         // Don't show confirmation query for COD downloads
       
   772         TBool isCodDownload( EFalse );
       
   773         User::LeaveIfError( iDownload.GetBoolAttribute
       
   774                           ( EDlAttrCodDownload, isCodDownload ) );
       
   775         if ( isCodDownload )
       
   776             {
       
   777             // Do nothing.
       
   778             }
       
   779         else
       
   780             {
       
   781             TBool suppressDownloadConfirmation( EFalse );
       
   782             iRegistryModel.UserInteractions().GetBoolAttributeL
       
   783                 ( CDownloadMgrUiUserInteractions::EAttrSuppressDownloadConfirmation, 
       
   784                   suppressDownloadConfirmation );
       
   785             CLOG_WRITE_FORMAT(" suppressDownloadConfirmation: %d", 
       
   786                                 suppressDownloadConfirmation);
       
   787 
       
   788             if ( suppressDownloadConfirmation )
       
   789                 {
       
   790                 // Nothing to do.
       
   791                 }
       
   792             else
       
   793                 {
       
   794                 TBool userConfirms = ShowDownloadConfirmationL
       
   795                     ( iDownload, R_AVKON_SOFTKEYS_OK_CANCEL__OK, EFalse );
       
   796                                      
       
   797                 // executes a wait dialog! Check if this is deleted meanwhile
       
   798                 if ( aThisDeleted )
       
   799                     {
       
   800                     CLOG_WRITE_FORMAT(" this deleted: %x", this);
       
   801                     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandleInProgressStateL");
       
   802                     return;
       
   803                     }
       
   804                     
       
   805                 if ( userConfirms )
       
   806                     {
       
   807                     // Open the download list if there is no more 
       
   808                     // download confirmation shown:
       
   809                     if ( iRegistryModel.UserInteractions().
       
   810                                         DownloadConfirmationsShown() == 0 )
       
   811                         {
       
   812                         if ( iRegistryModel.DownloadsListInstalled() )
       
   813                             {
       
   814                             iRegistryModel.DownloadsList().
       
   815                                 DisplayDownloadsListL( iDownload );
       
   816                             }
       
   817                         }
       
   818                     }
       
   819                 else
       
   820                     {
       
   821                     // The download must be removed from Downloads List
       
   822                     User::LeaveIfError( iDownload.Delete() );
       
   823                     CLOG_WRITE(" Delete OK");
       
   824                     }
       
   825                 }
       
   826             }
       
   827         }
       
   828 
       
   829     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandleInProgressStateL");
       
   830     }
       
   831 
       
   832     
       
   833 // -----------------------------------------------------------------------------
       
   834 // CUserInteractionsEventHandler::HandlePausedStateL
       
   835 // -----------------------------------------------------------------------------
       
   836 //
       
   837 void CUserInteractionsEventHandler::HandlePausedStateL( TBool& aThisDeleted )
       
   838     {
       
   839     CLOG_ENTERFN("CUserInteractionsEventHandler::HandlePausedStateL");
       
   840 
       
   841     // HEAD - download is paused - started if user confirms
       
   842     if ( iEvent.iProgressState == EHttpContentTypeReceived )
       
   843         {
       
   844         // Don't show confirmation query for COD downloads
       
   845         TBool isCodDownload( EFalse );
       
   846         User::LeaveIfError( iDownload.GetBoolAttribute
       
   847                           ( EDlAttrCodDownload, isCodDownload ) );
       
   848         if ( isCodDownload )
       
   849             {
       
   850             // COD downloads cannot be paused!
       
   851             }
       
   852         else
       
   853             {
       
   854             TBool suppressDownloadConfirmation( EFalse );
       
   855             iRegistryModel.UserInteractions().GetBoolAttributeL
       
   856                 ( CDownloadMgrUiUserInteractions::EAttrSuppressDownloadConfirmation, 
       
   857                   suppressDownloadConfirmation );
       
   858             CLOG_WRITE_FORMAT(" suppressDownloadConfirmation: %d", 
       
   859                                 suppressDownloadConfirmation);
       
   860 
       
   861             if ( suppressDownloadConfirmation )
       
   862                 {
       
   863                 // Nothing to do, just resume the download.
       
   864                 User::LeaveIfError( iDownload.Start() );
       
   865                 CLOG_WRITE(" Restart OK");
       
   866                 }
       
   867             else
       
   868                 {
       
   869                 aThisDeleted = EFalse;
       
   870                 TBool userConfirms = ShowDownloadConfirmationL
       
   871                                      ( iDownload, R_AVKON_SOFTKEYS_OK_CANCEL__OK, EFalse );
       
   872 
       
   873                 // executes a wait dialog! Check if this is deleted meanwhile
       
   874                 if ( aThisDeleted )
       
   875                     {
       
   876                     CLOG_WRITE_FORMAT(" this deleted: %x", this);
       
   877                     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandlePausedStateL");
       
   878                     return;
       
   879                     }
       
   880                     
       
   881                 // Open Downloads List if user confirms:
       
   882                 if ( userConfirms )
       
   883                     {
       
   884                     // Resume the download:
       
   885                     User::LeaveIfError( iDownload.Start() );
       
   886                     // and open the download list if there is no more 
       
   887                     // download confirmation shown:
       
   888                     if ( iRegistryModel.UserInteractions().
       
   889                                         DownloadConfirmationsShown() == 0 )
       
   890                         {
       
   891                         if ( iRegistryModel.DownloadsListInstalled() )
       
   892                             {
       
   893                             iRegistryModel.DownloadsList().
       
   894                                 DisplayDownloadsListL( iDownload );
       
   895                             }
       
   896                         }
       
   897                     }
       
   898                 else
       
   899                     {
       
   900                     // The download must be removed from Downloads List
       
   901                     User::LeaveIfError( iDownload.Delete() );
       
   902                     CLOG_WRITE(" Delete OK");
       
   903                     }
       
   904                 }
       
   905             }
       
   906         }
       
   907 
       
   908     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandlePausedStateL");
       
   909     }
       
   910 
       
   911 // -----------------------------------------------------------------------------
       
   912 // CUserInteractionsEventHandler::HandleCompletedStateL
       
   913 // -----------------------------------------------------------------------------
       
   914 //
       
   915 void CUserInteractionsEventHandler::HandleCompletedStateL()
       
   916     {
       
   917     CLOG_ENTERFN("CUserInteractionsEventHandler::HandleCompletedStateL");
       
   918 
       
   919     if ( iEvent.iProgressState == EHttpProgMovingContentFile )
       
   920         {
       
   921         // An asynchronous move has started. Do nothing.
       
   922         CLOG_WRITE(" Move has started");
       
   923         }
       
   924     else if ( iEvent.iProgressState == EHttpProgContentFileMoved || iEvent.iProgressState == EHttpProgContentFileMovedAndDestFNChanged )
       
   925         {
       
   926         // An asynchronous move has ended.
       
   927         
       
   928         CLOG_WRITE(" Move has ended");
       
   929         // After successful moving, display updated download list
       
   930         iRegistryModel.DownloadsList().DisplayDownloadsListL( iDownload );
       
   931         // Notify Media Gallery about new media file
       
   932         // first get path to gallery where file was moved
       
   933         HBufC* fileName = HBufC::NewLC( KMaxPath );
       
   934         TPtr fileNamePtr = fileName->Des();
       
   935         TInt attErr = iDownload.GetStringAttribute( 
       
   936             EDlAttrDestFilename, fileNamePtr );
       
   937         CLOG_WRITE_FORMAT(" EDlAttrDestFilename: %S",&fileNamePtr);
       
   938         TBool havePath = (attErr == KErrNone) && (fileNamePtr.Length() > 0);
       
   939         //
       
   940         CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL(
       
   941             CEikonEnv::Static()->FsSession() );
       
   942         if( havePath )
       
   943             {
       
   944             TRAP_IGNORE( mgFileManager->UpdateL( fileNamePtr ) );
       
   945             TRAP_IGNORE( iUiUtils.UpdateDCFRepositoryL( fileNamePtr ) );
       
   946             }
       
   947         else
       
   948             {
       
   949             TRAP_IGNORE( mgFileManager->UpdateL() );
       
   950             }
       
   951         CleanupStack::PopAndDestroy( fileName );
       
   952         delete mgFileManager;
       
   953         mgFileManager = NULL;
       
   954         
       
   955         }
       
   956     else
       
   957         {
       
   958         // Normal completed state. Handling depends on EDlAttrAction
       
   959         TInt32 action(0);
       
   960         User::LeaveIfError( iDownload.GetIntAttribute
       
   961                             ( EDlAttrAction, action ) );
       
   962         CLOG_WRITE_FORMAT(" EDlAttrAction: %d",action);
       
   963         if ( action == EDoNothing )
       
   964             {
       
   965             // Do nothing
       
   966             }
       
   967         else if ( action & EMove )
       
   968             {
       
   969             // check if COD download
       
   970             TBool isCodDownload( EFalse );
       
   971             User::LeaveIfError( iDownload.GetBoolAttribute
       
   972                               ( EDlAttrCodDownload, isCodDownload ) );
       
   973 
       
   974             // check if progressive download
       
   975             TBool isProgressive = EFalse;
       
   976             TInt err = iDownload.GetBoolAttribute
       
   977                 ( EDlAttrProgressive, isProgressive );
       
   978             CLOG_WRITE_FORMAT(" EDlAttrProgressive err: %d",err);
       
   979             // 'err' is ignored.
       
   980             CLOG_WRITE_FORMAT(" EDlAttrProgressive: %d", isProgressive);
       
   981             
       
   982             // check if move is already issued
       
   983             TBool isMoveIssued = EFalse;
       
   984             TInt32 progState(0);
       
   985             User::LeaveIfError( iDownload.GetIntAttribute
       
   986                             ( EDlAttrProgressState, progState ) );
       
   987             
       
   988             if(progState == EHttpProgMovingContentFile) isMoveIssued = ETrue;    
       
   989 
       
   990             if( isCodDownload )
       
   991                 {
       
   992                 HBufC8* contentType = HBufC8::NewLC( KMaxContentTypeLength );
       
   993                 TPtr8 contentTypePtr = contentType->Des();
       
   994                 User::LeaveIfError
       
   995                     ( iDownload.GetStringAttribute( EDlAttrContentType, contentTypePtr ) ); 
       
   996                 if( !contentType->Compare(KRoapMimeType))
       
   997                     {
       
   998                     User::LeaveIfError
       
   999                     ( iDownload.Delete());
       
  1000                     }
       
  1001                 CleanupStack::PopAndDestroy( contentType );    
       
  1002                 }
       
  1003              else if( isProgressive || isMoveIssued )
       
  1004                 {
       
  1005                 //do not move
       
  1006                 
       
  1007                 }
       
  1008              else
       
  1009                 {
       
  1010                 // Move content to the location defined by KDownloadPath
       
  1011 
       
  1012                 // first, get current EDlAttrDestFilename
       
  1013 			    HBufC* fileName = HBufC::NewLC( KMaxPath );
       
  1014 			    TPtr fileNamePtr = fileName->Des();
       
  1015 			    User::LeaveIfError
       
  1016                     ( iDownload.GetStringAttribute( EDlAttrDestFilename, fileNamePtr ) );
       
  1017 
       
  1018                 RFs& fs = CEikonEnv::Static()->FsSession();
       
  1019 
       
  1020 #ifdef RD_MULTIPLE_DRIVE
       
  1021                 TDriveUnit currentDrive(fileNamePtr);
       
  1022 
       
  1023                 // using PathInfo::RootPath to set correct destination folder
       
  1024                 // depending on memory used
       
  1025 
       
  1026                 // Getting RootPath for selected Drive
       
  1027                 TFileName rootPath;
       
  1028                 User::LeaveIfError( PathInfo::GetRootPath( rootPath, currentDrive ) );
       
  1029 
       
  1030                 // remove path from EDlAttrDestFilename
       
  1031                 if( fileNamePtr.Length() > 0 )
       
  1032                     {
       
  1033                     TInt lastSlashPos = fileNamePtr.LocateReverse( '\\' );
       
  1034                     if( lastSlashPos != KErrNotFound )
       
  1035                         {
       
  1036                         fileNamePtr.Delete( 0, lastSlashPos );
       
  1037                         }
       
  1038                     }
       
  1039             
       
  1040                 // Setting RootPath for new Destination file
       
  1041                 fileNamePtr.Insert( 0, rootPath );
       
  1042                 // Setting KDownloadPath
       
  1043                 fileNamePtr.Insert( rootPath.Length(), KDownloadPath );
       
  1044 #else
       
  1045                 
       
  1046                 TParse p;
       
  1047                 p.SetNoWild(fileNamePtr, NULL, NULL);
       
  1048                 TDriveUnit currentDrive(fileNamePtr);
       
  1049                 TFileName rootPath;
       
  1050                 User::LeaveIfError( PathInfo::GetRootPath( rootPath, currentDrive ) );
       
  1051                 
       
  1052                 TPtrC namePtr = p.NameAndExt();
       
  1053                 fileNamePtr.Format( _L("%S%S\\%S"), &rootPath,
       
  1054                                                     &KDownloadPath,
       
  1055                                                     &namePtr );
       
  1056 #endif
       
  1057                 // next, creating directory
       
  1058                 TInt error = 0;
       
  1059 
       
  1060                 // next, get the directory path from new EDlAttrDestFilename
       
  1061                 if( fileNamePtr.Length() > 0 )
       
  1062                     {
       
  1063                     TInt lastSlashPos = fileNamePtr.LocateReverse( '\\' );
       
  1064                     if( lastSlashPos != KErrNotFound )
       
  1065                         {
       
  1066                         error = fs.MkDirAll( fileNamePtr.LeftTPtr( lastSlashPos + 1 ) );
       
  1067                         if ( error != KErrNone && error != KErrAlreadyExists )
       
  1068                             // leave if makedir failed in some way
       
  1069                             // don't leave if already exists
       
  1070                             {
       
  1071                             CLOG_WRITE_FORMAT( "MkDirAll: %d", error );
       
  1072                             User::Leave( error );
       
  1073                             }
       
  1074                         }
       
  1075                     }
       
  1076 
       
  1077 
       
  1078                 // update EDlAttrDestFilename with new path
       
  1079                 User::LeaveIfError
       
  1080 		                ( iDownload.SetStringAttribute( EDlAttrDestFilename, *fileName ) );
       
  1081                 // move file
       
  1082                 User::LeaveIfError( iDownload.Move() );
       
  1083           	    CleanupStack::PopAndDestroy( fileName ); // fileName
       
  1084                 }
       
  1085             }
       
  1086         else if ( action & EPdLaunch )
       
  1087         {
       
  1088         	// do nothing since PdLaunch was already launched during the progress 
       
  1089         }
       
  1090         else
       
  1091             {
       
  1092             // Defaulting to Launch
       
  1093             iRegistryModel.UserInteractions().HandleDownloadL( iDownload );
       
  1094             }
       
  1095         }
       
  1096 
       
  1097     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandleCompletedStateL");
       
  1098 
       
  1099     }
       
  1100 
       
  1101 // -----------------------------------------------------------------------------
       
  1102 // CUserInteractionsEventHandler::HandleFailedStateL
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //
       
  1105 void CUserInteractionsEventHandler::HandleFailedStateL()
       
  1106     {
       
  1107     CLOG_ENTERFN("CUserInteractionsEventHandler::HandleFailedStateL");
       
  1108 
       
  1109     // check if it is COD download
       
  1110     TBool isCodDownload( EFalse );
       
  1111     User::LeaveIfError( iDownload.GetBoolAttribute
       
  1112                       ( EDlAttrCodDownload, isCodDownload ) );
       
  1113     CLOG_WRITE_FORMAT("EDlAttrCodDownload: %d",isCodDownload);
       
  1114     if ( isCodDownload )
       
  1115         {
       
  1116         // If the ServiceFlow of the download was running, but failed, 
       
  1117         // schedule the next download for running. 
       
  1118         // UserInteractions is assumed to be installed.
       
  1119         // Do not delete the download yet (because IsCodServiceFlowRunning needs it)!
       
  1120         if ( iRegistryModel.UserInteractions().IsCodServiceFlowRunning( iDownload ) )
       
  1121             {
       
  1122             iRegistryModel.UserInteractions().SchedulePostponedDownloadL();
       
  1123             }
       
  1124         // Nothing to do with COD - just delete it.
       
  1125         HandleUnrecoverableFailL();
       
  1126         }
       
  1127     else // NORMAL download
       
  1128         {
       
  1129         // What is the error?
       
  1130         TInt32 errorId( KErrNone ); // DMgr specific error ID
       
  1131         User::LeaveIfError( iDownload.GetIntAttribute( EDlAttrErrorId, errorId ) );
       
  1132         CLOG_WRITE_FORMAT(" Fail reason: %d", errorId);
       
  1133         //
       
  1134         if ( errorId == EHttpAuthenticationFailed )
       
  1135             {
       
  1136             if ( iUiUtils.GetAndSetHttpAuthCredentialsL( iDownload ) )
       
  1137                 {
       
  1138                 // and continue download
       
  1139                 User::LeaveIfError( iDownload.Start() );
       
  1140                 }
       
  1141             }
       
  1142         else if ( errorId == EProxyAuthenticationFailed )
       
  1143             {
       
  1144             if ( iUiUtils.GetAndSetProxyAuthCredentialsL( iDownload ) )
       
  1145                 {
       
  1146                 // and continue download
       
  1147                 User::LeaveIfError( iDownload.Start() );
       
  1148                 }
       
  1149             }
       
  1150         else if ( errorId == EHttpRestartFailed )
       
  1151             {
       
  1152             // Do not handle it.
       
  1153             }
       
  1154         else
       
  1155             {
       
  1156             TBool errorHandled( EFalse );
       
  1157             
       
  1158             if ( !errorHandled )
       
  1159                 {
       
  1160                 iUiUtils.ShowErrorNoteL( iDownload, errorId );
       
  1161                 // This component is responsible for deleting 
       
  1162                 // not recoverable downloads
       
  1163                 if ( iUiUtils.IsRecoverableFailL( iDownload, errorId ) )
       
  1164                     {
       
  1165                     // Do nothing.
       
  1166                     }
       
  1167                 else
       
  1168                     {
       
  1169                     // Delete the download
       
  1170                     HandleUnrecoverableFailL();
       
  1171                     }
       
  1172                 }
       
  1173             }
       
  1174         }
       
  1175 
       
  1176     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandleFailedStateL");
       
  1177     }
       
  1178 
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // CUserInteractionsEventHandler::HandleUnrecoverableFailL
       
  1181 // -----------------------------------------------------------------------------
       
  1182 //
       
  1183 void CUserInteractionsEventHandler::HandleUnrecoverableFailL()
       
  1184     {
       
  1185     CLOG_ENTERFN("CUserInteractionsEventHandler::HandleUnrecoverableFailL");
       
  1186 
       
  1187     HBufC* dlName = HBufC::NewLC( KMaxPath );
       
  1188     TPtr dlNamePtr = dlName->Des();
       
  1189     User::LeaveIfError( iDownload.GetStringAttribute( EDlAttrName, dlNamePtr ) );
       
  1190     CLOG_WRITE_FORMAT(" EDlAttrName: %S",&dlNamePtr);
       
  1191 
       
  1192     // If download name is empty, use the file name got from URI
       
  1193     if ( dlName->Length() == 0 )
       
  1194         {
       
  1195         HBufC* url = HBufC::NewLC( KMaxUrlLength );
       
  1196         TPtr urlPtr = url->Des();
       
  1197         TInt err = iDownload.GetStringAttribute( EDlAttrCurrentUrl, urlPtr );
       
  1198         CLOG_WRITE_FORMAT(" EDlAttrCurrentUrl err: %d",err);
       
  1199         if ( err != KErrNone && err != KErrNotFound )
       
  1200             {
       
  1201             User::LeaveIfError( err );
       
  1202             }
       
  1203         CLOG_WRITE_FORMAT(" EDlAttrCurrentUrl: %S",url);
       
  1204         if ( url->Length() > 0 )
       
  1205             {
       
  1206             // Extract file name, if possible
       
  1207             CUri8* converted = UriUtils::CreateUriL( *url );
       
  1208             CleanupStack::PushL( converted );
       
  1209             HBufC* extracted = converted->Uri().GetFileNameL( EUriFileNameTail );
       
  1210             CleanupStack::PushL( extracted );
       
  1211             // Use this for download name
       
  1212             // (Left() is used to avoid overflow.)
       
  1213             dlNamePtr.Copy( extracted->Left( dlNamePtr.MaxLength() ) );
       
  1214             CleanupStack::PopAndDestroy( extracted );
       
  1215             CleanupStack::PopAndDestroy( converted );
       
  1216             }
       
  1217         CleanupStack::PopAndDestroy( url );
       
  1218         }
       
  1219 
       
  1220     // iDownload can now been deleted        
       
  1221     User::LeaveIfError( iDownload.Delete() );
       
  1222     CLOG_WRITE(" Delete OK");
       
  1223 
       
  1224     HBufC* infoPrompt = StringLoader::LoadLC( R_DMUL_ERROR_CANCELLED, *dlName );
       
  1225     CLOG_WRITE(" StringLoader OK");
       
  1226     
       
  1227     CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog();
       
  1228     dlg->PrepareLC( R_DMUL_DOWNLOAD_OK_INFO );
       
  1229     dlg->SetTextL( *infoPrompt );
       
  1230     dlg->RunLD();
       
  1231     CLOG_WRITE(" RunLD OK");
       
  1232 
       
  1233     CleanupStack::PopAndDestroy( infoPrompt );
       
  1234     CleanupStack::PopAndDestroy( dlName );
       
  1235 
       
  1236     CLOG_LEAVEFN("CUserInteractionsEventHandler::HandleUnrecoverableFailL");
       
  1237     }
       
  1238 
       
  1239 // -----------------------------------------------------------------------------
       
  1240 // CUserInteractionsEventHandler::DoCancel
       
  1241 // -----------------------------------------------------------------------------
       
  1242 //
       
  1243 void CUserInteractionsEventHandler::DoCancel()
       
  1244     {
       
  1245     }
       
  1246 
       
  1247 // -----------------------------------------------------------------------------
       
  1248 // CUserInteractionsEventHandler::RunL
       
  1249 // -----------------------------------------------------------------------------
       
  1250 //
       
  1251 void CUserInteractionsEventHandler::RunL()
       
  1252     {
       
  1253     CLOG_ENTERFN("CUserInteractionsEventHandler::RunL");
       
  1254     CLOG_WRITE_FORMAT(" %x", this);
       
  1255     CLOG_WRITE_EVENT("UsrIntEve",&iDownload,iEvent);
       
  1256 
       
  1257     // This RunL may show wait dialogs. Use an indicator for if this is deleted
       
  1258     TBool deleted( EFalse );
       
  1259     iDeletedPtr = &deleted;
       
  1260 
       
  1261     // Incase of completed and moved downloads, subsession will be closed and whole download info will be cached client side. 
       
  1262     // No need to check for subsession close    
       
  1263     if(!(iEvent.iDownloadState == EHttpDlMultipleMOCompleted && (iEvent.iProgressState == EHttpProgContentFileMoved || iEvent.iProgressState == EHttpProgContentFileMovedAndDestFNChanged )))
       
  1264         {
       
  1265         // Due to the postponed event handling, it may happen that somebody already 
       
  1266         // closed the download meanwhile. Check if it is still alive:
       
  1267         if ( iDownload.SubSessionHandle() == 0 )
       
  1268             {
       
  1269             // No, it's already closed!! Do nothing.
       
  1270             // Necessary task done in RunL. This object is no more necessary.
       
  1271             CLOG_WRITE(" Zero handle!");
       
  1272             delete this;
       
  1273             CLOG_LEAVEFN("CUserInteractionsEventHandler::RunL");
       
  1274             return;
       
  1275             }
       
  1276         }
       
  1277     
       
  1278     switch ( iEvent.iDownloadState )
       
  1279         {
       
  1280         //---------------------------------------------
       
  1281         case EHttpDlCreated:
       
  1282         //---------------------------------------------
       
  1283             {
       
  1284             break;
       
  1285             }
       
  1286         //---------------------------------------------
       
  1287         case EHttpDlInprogress:
       
  1288         //---------------------------------------------
       
  1289             {
       
  1290             HandleInProgressStateL( deleted );
       
  1291             break;
       
  1292             }
       
  1293         //---------------------------------------------
       
  1294         case EHttpDlPaused:
       
  1295         //---------------------------------------------
       
  1296             {
       
  1297             HandlePausedStateL( deleted );
       
  1298             break;
       
  1299             }
       
  1300         //---------------------------------------------
       
  1301         case EHttpDlMultipleMOCompleted:
       
  1302         //---------------------------------------------
       
  1303             {
       
  1304             HandleCompletedStateL();
       
  1305             break;
       
  1306             }
       
  1307         //---------------------------------------------
       
  1308         case EHttpDlMultipleMOFailed:
       
  1309         //---------------------------------------------
       
  1310             {
       
  1311             HandleFailedStateL();
       
  1312             break;
       
  1313             }
       
  1314         //---------------------------------------------
       
  1315         case EHttpDlMoved:
       
  1316         //---------------------------------------------
       
  1317             {
       
  1318             // Do nothing. Downloads List handles it.
       
  1319             break;
       
  1320             }
       
  1321         //---------------------------------------------
       
  1322         case EHttpDlMediaRemoved:
       
  1323         //---------------------------------------------
       
  1324             {
       
  1325             iUiUtils.ShowMediaRemovedNoteL();
       
  1326             break;
       
  1327             }
       
  1328         //---------------------------------------------
       
  1329         default:
       
  1330         //---------------------------------------------
       
  1331             {
       
  1332             break;
       
  1333             }
       
  1334         }
       
  1335 
       
  1336     CLOG_WRITE_FORMAT(" deleted: %d",deleted);
       
  1337     if ( !deleted )
       
  1338         {
       
  1339         // Necessary task done in RunL. This object is no more necessary.
       
  1340         delete this;
       
  1341         }
       
  1342     
       
  1343     CLOG_LEAVEFN("CUserInteractionsEventHandler::RunL");
       
  1344     }
       
  1345 
       
  1346 // -----------------------------------------------------------------------------
       
  1347 // CUserInteractionsEventHandler::RunError
       
  1348 // -----------------------------------------------------------------------------
       
  1349 //
       
  1350 TInt CUserInteractionsEventHandler::RunError( TInt aError )
       
  1351     {
       
  1352     if ( aError )
       
  1353         {
       
  1354         TRAP_IGNORE( iUiUtils.ShowErrorNoteL( aError ) );
       
  1355         }
       
  1356     return KErrNone;
       
  1357     }
       
  1358 
       
  1359 // End of file.