browserutilities/downloadmgr/DownloadMgrUiLib/Src/CDownloadMgrUiUserInteractions.cpp
changeset 0 dd21522fd290
child 10 a359256acfc6
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:  Supports user interaction dialogs for downloads
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CDownloadMgrUiUserInteractions.h"
       
    22 #include    "CUserInteractionsUtils.h"
       
    23 #include    "CDownloadMgrUiDownloadsList.h"
       
    24 #include    "CDownloadMgrUiLibRegistry.h"
       
    25 #include    "UserInteractionsEventHandler.h"
       
    26 #include    "AsyncEventHandlerArray.h"
       
    27 #include    "UiLibLogger.h"
       
    28 #include    "DMgrUiLibPanic.h"
       
    29 #include    "MDownloadHandlerObserver.h"
       
    30 #include    <e32std.h>
       
    31 #include    <e32def.h>
       
    32 #include    <StringLoader.h>
       
    33 #include    <DownloadMgrUiLib.rsg>
       
    34 #include    <AknQueryDialog.h>
       
    35 #include    <avkon.rsg>
       
    36 #include    <eikon.hrh>
       
    37 #include    <eikappui.h>
       
    38 #include    <apparc.h>
       
    39 #include    <AknServerApp.h>
       
    40 #include    <DRMCommon.h>
       
    41 
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 const TInt KPostponedDownloadsGranularity = 1;
       
    44 
       
    45 /**
       
    46 * Extension class.
       
    47 */
       
    48 NONSHARABLE_CLASS( CUserInteractionsExtension ) : public CBase,
       
    49                                                   public MDownloadHandlerObserver
       
    50     {
       
    51     public:  // Constructors and destructor
       
    52         
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         */
       
    56         static CUserInteractionsExtension* NewL
       
    57              ( CDownloadMgrUiUserInteractions& aUserInteractions );
       
    58         
       
    59         /**
       
    60         * Destructor.
       
    61         */
       
    62         virtual ~CUserInteractionsExtension();
       
    63 
       
    64     public: // New functions
       
    65 
       
    66         /**
       
    67         * Postpone handling the given COD download. The download is placed to a 
       
    68         * LIFO queue. Call SchedulePostponedDownloadL() to invoke the handling 
       
    69         * of a download in the list.
       
    70         * @param aDownload The download to be postponed.
       
    71         */
       
    72         void PostponeCodHandlingL( RHttpDownload& aDownload );
       
    73 
       
    74         /**
       
    75         * Check if the given download is postponed.
       
    76         * @param aDownload The download in question.
       
    77         * @return true/false.
       
    78         */
       
    79         TBool IsPostponed( RHttpDownload& aDownload ) const;
       
    80 
       
    81         /**
       
    82         * Schedule a postponed download for running.
       
    83         */
       
    84         void SchedulePostponedDownloadL();
       
    85 
       
    86     protected: // Constructors
       
    87 
       
    88         /**
       
    89         * C++ default constructor.
       
    90         */
       
    91         CUserInteractionsExtension( CDownloadMgrUiUserInteractions& aUserInteractions );
       
    92 
       
    93         /**
       
    94         * By default Symbian 2nd phase constructor is private.
       
    95         */
       
    96         void ConstructL();
       
    97 
       
    98     protected: // From MDownloadHandlerObserver
       
    99 
       
   100         void NotifyHandlerExit( RHttpDownload* aDownload, TInt aReason );
       
   101 
       
   102     public: // Data
       
   103 
       
   104         CDownloadMgrUiUserInteractions& iUserInteractions;
       
   105         TBuf<KMaxPath> iFileName; ///< Buffer for file name.
       
   106         // Attributes
       
   107         TBool iIsCompletedStateHandled; ///< Event handling preferencies
       
   108         TBool iSuppressDownloadConfirmation;
       
   109         CArrayPtrFlat< RHttpDownload >* iPostponedCodDownloads; ///< Owned.
       
   110     };
       
   111 
       
   112 
       
   113 // ============================ MEMBER FUNCTIONS ===============================
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CUserInteractionsExtension::CUserInteractionsExtension
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 CUserInteractionsExtension::CUserInteractionsExtension
       
   120     ( CDownloadMgrUiUserInteractions& aUserInteractions )
       
   121 :   iUserInteractions( aUserInteractions ), 
       
   122     iFileName( KNullDesC ), 
       
   123     iIsCompletedStateHandled( ETrue )
       
   124     {
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CUserInteractionsExtension::ConstructL
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CUserInteractionsExtension::ConstructL()
       
   132     {
       
   133     CLOG_ENTERFN("CUserInteractionsExtension::ConstructL");
       
   134     CLOG_LEAVEFN("CUserInteractionsExtension::ConstructL");
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CUserInteractionsExtension::NewL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 CUserInteractionsExtension* CUserInteractionsExtension::NewL
       
   142     ( CDownloadMgrUiUserInteractions& aUserInteractions )
       
   143     {
       
   144     CUserInteractionsExtension* self = 
       
   145         new (ELeave) CUserInteractionsExtension( aUserInteractions );
       
   146     CleanupStack::PushL( self );
       
   147     self->ConstructL();
       
   148     CleanupStack::Pop();
       
   149     return self;
       
   150     }
       
   151 
       
   152 // Destructor
       
   153 CUserInteractionsExtension::~CUserInteractionsExtension()
       
   154     {
       
   155     CLOG_ENTERFN("CUserInteractionsExtension::~CUserInteractionsExtension");
       
   156     delete iPostponedCodDownloads;
       
   157     CLOG_WRITE(" iPostponedCodDownloads OK");
       
   158     CLOG_LEAVEFN("CUserInteractionsExtension::~CUserInteractionsExtension");
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CUserInteractionsExtension::PostponeCodHandlingL
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CUserInteractionsExtension::PostponeCodHandlingL( RHttpDownload& aDownload )
       
   166     {
       
   167     CLOG_ENTERFN("CUserInteractionsExtension::PostponeCodHandlingL");
       
   168 
       
   169     if ( !iPostponedCodDownloads )
       
   170         {
       
   171         iPostponedCodDownloads = new (ELeave) CArrayPtrFlat< RHttpDownload >
       
   172                                             ( KPostponedDownloadsGranularity );
       
   173         CLOG_WRITE(" new OK");
       
   174         }
       
   175     // Insert download at the end of the array
       
   176     iPostponedCodDownloads->AppendL( &aDownload );
       
   177 
       
   178     CLOG_LEAVEFN("CUserInteractionsExtension::PostponeCodHandlingL");
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CUserInteractionsExtension::IsPostponed
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 TBool CUserInteractionsExtension::IsPostponed( RHttpDownload& aDownload ) const
       
   186     {
       
   187     CLOG_ENTERFN("CUserInteractionsExtension::IsPostponed");
       
   188     
       
   189     TInt index( KErrNotFound );
       
   190     TKeyArrayFix cmpKey( 0, ECmpTUint32 );
       
   191     TInt err = KErrNotFound;
       
   192     if ( iPostponedCodDownloads )
       
   193         {
       
   194         err = iPostponedCodDownloads->Find( &aDownload, cmpKey, index );
       
   195         CLOG_WRITE_FORMAT(" err: %d", err);
       
   196         CLOG_WRITE_FORMAT(" index: %d", index);
       
   197         }
       
   198         
       
   199     CLOG_LEAVEFN("CUserInteractionsExtension::IsPostponed");
       
   200     return !err;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CUserInteractionsExtension::SchedulePostponedDownloadL
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CUserInteractionsExtension::SchedulePostponedDownloadL()
       
   208     {
       
   209     CLOG_ENTERFN("CUserInteractionsExtension::SchedulePostponedDownloadL");
       
   210     
       
   211     // Start next download handling
       
   212     if ( iPostponedCodDownloads )
       
   213         {
       
   214         TInt postponedCodDlCount = iPostponedCodDownloads->Count();
       
   215         CLOG_WRITE_FORMAT(" postponedCodDlCount: %d", postponedCodDlCount);
       
   216         if ( postponedCodDlCount )
       
   217             {
       
   218             // Restart the first COD download in the list
       
   219             RHttpDownload* codDl = (RHttpDownload*) iPostponedCodDownloads->At(0);
       
   220             TInt errorRet = codDl->Start();
       
   221             CLOG_WRITE_FORMAT(" errorRet: %d", errorRet);
       
   222             User::LeaveIfError( errorRet );
       
   223             // Remove the download from the lifo list, but do not delete it!
       
   224             iPostponedCodDownloads->Delete(0);
       
   225             }
       
   226         }
       
   227         
       
   228     CLOG_LEAVEFN("CUserInteractionsExtension::SchedulePostponedDownloadL");
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CUserInteractionsExtension::NotifyHandlerExit
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CUserInteractionsExtension::NotifyHandlerExit( RHttpDownload* aDownload, 
       
   236                                                      TInt aReason )
       
   237     {
       
   238     CLOG_ENTERFN("CUserInteractionsExtension::NotifyHandlerExit");
       
   239     CLOG_WRITE_FORMAT(" aReason: %d", aReason);
       
   240 
       
   241     // Delete the download if the handler terminated without error
       
   242     if ( aReason == KErrNone || aReason == EEikCmdExit || aReason == EAknCmdExit )
       
   243         {
       
   244         if ( aDownload )
       
   245             {
       
   246             /* return value is ignored */aDownload->Delete();
       
   247             CLOG_WRITE(" Delete OK");
       
   248             }
       
   249         }
       
   250 
       
   251     // Propagate the event to the registered observer, too
       
   252     if ( iUserInteractions.iServerAppExitObserver != 0 )
       
   253         {
       
   254         CLOG_WRITE(" Propagating event...");
       
   255         iUserInteractions.iServerAppExitObserver->HandleServerAppExit( aReason );
       
   256         }
       
   257 
       
   258     CLOG_LEAVEFN("CUserInteractionsExtension::NotifyHandlerExit");
       
   259     }
       
   260 
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CDownloadMgrUiUserInteractions::CDownloadMgrUiUserInteractions
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 CDownloadMgrUiUserInteractions::CDownloadMgrUiUserInteractions
       
   267     ( CDownloadMgrUiLibRegistry& aRegistryModel )
       
   268 :   CDownloadMgrUiBase( aRegistryModel ),
       
   269     iDlgActive ( EFalse )
       
   270     {
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CDownloadMgrUiUserInteractions::ConstructL
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void CDownloadMgrUiUserInteractions::ConstructL()
       
   278     {
       
   279     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::ConstructL");
       
   280 
       
   281     BaseConstructL();
       
   282     CLOG_WRITE(" BaseConstructL");
       
   283     iExtension = CUserInteractionsExtension::NewL( *this );
       
   284     CLOG_WRITE(" iExtension");
       
   285     iUiUtils = CUserInteractionsUtils::NewL( *this, iRegistryModel );
       
   286     CLOG_WRITE(" iUiUtils");
       
   287     iEventHandlerArray = new(ELeave)CAsyncEventHandlerArray();
       
   288     CLOG_WRITE(" iEventHandlerArray");
       
   289     // Cancel the Soft Notifications belonging to this client
       
   290     iUiUtils->CancelSoftNotifStndL
       
   291         ( TVwsViewId(iRegistryModel.ClientAppUid(),TUid::Null()), 
       
   292           TUid::Null(), KNullDesC8 );
       
   293     iUiUtils->CancelSoftNotifEmbL
       
   294         ( TVwsViewId(iRegistryModel.ClientAppUid(),TUid::Null()), 
       
   295           TUid::Null(), KNullDesC8 );
       
   296 
       
   297     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::ConstructL");
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CDownloadMgrUiUserInteractions::NewL
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 CDownloadMgrUiUserInteractions* CDownloadMgrUiUserInteractions::NewL
       
   305     ( CDownloadMgrUiLibRegistry& aRegistryModel )
       
   306     {
       
   307     CDownloadMgrUiUserInteractions* self = 
       
   308         new ( ELeave ) CDownloadMgrUiUserInteractions( aRegistryModel );
       
   309     CleanupStack::PushL( self );
       
   310     self->ConstructL();
       
   311     CleanupStack::Pop();
       
   312     return self;
       
   313     }
       
   314 
       
   315 // Destructor
       
   316 CDownloadMgrUiUserInteractions::~CDownloadMgrUiUserInteractions()
       
   317     {
       
   318     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::~CDownloadMgrUiUserInteractions");
       
   319 
       
   320     delete iEventHandlerArray;
       
   321     iEventHandlerArray = 0;
       
   322     CLOG_WRITE(" iEventHandlerArray");
       
   323     delete iUiUtils;
       
   324     iUiUtils = 0;
       
   325     CLOG_WRITE(" iUiUtils");
       
   326     // iExtension should be the last deleted.
       
   327     delete iExtension;
       
   328     iExtension = 0;
       
   329     CLOG_WRITE(" iExtension");
       
   330 
       
   331     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::~CDownloadMgrUiUserInteractions");
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CDownloadMgrUiUserInteractions::OkToExitL
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 EXPORT_C 
       
   339 TBool CDownloadMgrUiUserInteractions::OkToExitL()
       
   340     {
       
   341     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::OkToExitL");
       
   342 
       
   343     TBool okToExit = EFalse;
       
   344     TInt downloadCnt = iRegistryModel.DownloadCount();
       
   345     CLOG_WRITE_FORMAT(" downloadCnt: %d", downloadCnt);
       
   346     // do nothing if this is 0
       
   347     if ( downloadCnt == 0 )
       
   348         {
       
   349         okToExit = ETrue;
       
   350         CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::OkToExitL");
       
   351         return okToExit;
       
   352         }
       
   353 
       
   354     // will delete client's completed, not hidden downloads
       
   355     THttpDownloadState state;
       
   356     THttpProgressState progState;
       
   357     TBool isHiddenDel = EFalse;
       
   358     TBool isCodDownload( EFalse );
       
   359     TBool isProg (EFalse);
       
   360     // check if progressive download, if yes, will NOT delete from the list, otherwise will
       
   361     const CDownloadArray& downloadsDel = iRegistryModel.DownloadMgr().CurrentDownloads();
       
   362     for ( TInt i = downloadCnt - 1; i >= 0; --i )
       
   363         {
       
   364         RHttpDownload* dl = downloadsDel.At(i); // current download
       
   365         dl->GetIntAttribute(EDlAttrState, (TInt32&)state);
       
   366         
       
   367          //Changes for the bug JERI-7P8CF2
       
   368          //Changes made in the server side to fix the video center receiving unexpected events
       
   369          //Reassigning these events back to the changes done in server side
       
   370          if( state  == EHttpDlCompleted )
       
   371 		     {
       
   372              state  = EHttpDlMultipleMOCompleted;
       
   373 		     }
       
   374          else if(state  == EHttpDlFailed )
       
   375 		     {
       
   376 		      state  = EHttpDlMultipleMOFailed;
       
   377 		     }
       
   378         
       
   379         if ( state == EHttpDlMultipleMOCompleted )
       
   380             {
       
   381             dl->GetBoolAttribute( EDlAttrHidden, isHiddenDel ); // return value ignored
       
   382             dl->GetIntAttribute( EDlAttrProgressState, (TInt32&)progState );
       
   383             dl->GetBoolAttribute( EDlAttrProgressive, isProg ); 
       
   384             if ( (!isHiddenDel && ( progState == EHttpProgContentFileMoved || progState == EHttpProgContentFileMovedAndDestFNChanged )&& !isProg) )
       
   385                 {
       
   386                 User::LeaveIfError( dl->Delete() );
       
   387                 }
       
   388             }
       
   389         }
       
   390        
       
   391     downloadCnt = iRegistryModel.DownloadCount();
       
   392 
       
   393     // Client is intrested in only those downloads for that the 
       
   394     // media has not been removed or pausable (non-pausable downloads 
       
   395     // will be deleted).
       
   396     TInt32 noMediaDownloads(0);
       
   397     iRegistryModel.DownloadMgr().GetIntAttribute( EDlMgrNoMediaDls, noMediaDownloads );
       
   398     CLOG_WRITE_FORMAT(" noMediaDownloads: %d", noMediaDownloads);
       
   399     // Return value is ignored.
       
   400     // If it returns an error, then 'noMediaDownloads' is considered 0.
       
   401 
       
   402     // Count hidden downloads, too.
       
   403     TInt32 hiddenDownloads = 0;
       
   404     TBool isHidden;
       
   405     const CDownloadArray& downloads = iRegistryModel.DownloadMgr().CurrentDownloads();
       
   406     for ( TInt i = 0; i < downloadCnt; ++i )
       
   407         {
       
   408         RHttpDownload* dl = downloads.At(i); // current download
       
   409         dl->GetBoolAttribute( EDlAttrHidden, isHidden ); // return value ignored
       
   410         if ( isHidden )
       
   411             {
       
   412             ++hiddenDownloads;
       
   413             }
       
   414         }
       
   415        
       
   416     CLOG_WRITE_FORMAT(" hiddenDownloads: %d", hiddenDownloads);
       
   417 
       
   418     // Check if there is progressively played download
       
   419     TInt32 progressivelyPlayed = 0;
       
   420     for ( TInt i = downloadCnt - 1; i >=0; --i )
       
   421 	{
       
   422         RHttpDownload* dl = downloads.At(i); //current download
       
   423         dl->GetBoolAttribute( EDlAttrProgressive, isProg );
       
   424         if (isProg && state==EHttpDlMultipleMOCompleted) 
       
   425 		{
       
   426                 progressivelyPlayed++;
       
   427                 break;
       
   428 		}
       
   429 	}
       
   430       
       
   431     TBool isPausable; 
       
   432     for ( TInt i = 0; i < downloadCnt; ++i )
       
   433         {
       
   434             RHttpDownload* dl = downloads.At(i);
       
   435             dl->GetBoolAttribute( EDlAttrPausable, isPausable );
       
   436             if(!isPausable)
       
   437             {
       
   438                    break;
       
   439             }
       
   440         }
       
   441     downloadCnt = downloadCnt - noMediaDownloads - hiddenDownloads - progressivelyPlayed;
       
   442     CLOG_WRITE_FORMAT(" downloads result: %d", downloadCnt);
       
   443     if ( downloadCnt < 1 ||  isPausable)
       
   444         {
       
   445         okToExit = ETrue;
       
   446         }
       
   447     else
       
   448         {
       
   449         HBufC* prompt = StringLoader::LoadLC( downloadCnt==1 ? 
       
   450                         R_DMUL_EXIT_CONF_SING : R_DMUL_EXIT_CONF_PLUR );
       
   451         CAknQueryDialog* conf = CAknQueryDialog::NewL();
       
   452         conf->PrepareLC( R_DMUL_EXIT_CONF );
       
   453         conf->SetPromptL( *prompt );
       
   454         TInt resp = conf->RunLD();
       
   455         CleanupStack::PopAndDestroy( prompt ); // prompt
       
   456         
       
   457         downloadCnt = iRegistryModel.DownloadCount();
       
   458 
       
   459         TBool isProgressive (EFalse);
       
   460         if ( resp == EAknSoftkeyYes || resp == EAknSoftkeyOk )
       
   461 		    {
       
   462             for ( TInt i = downloadCnt - 1; i >=0; --i )
       
   463 		        {
       
   464 	            RHttpDownload* dl = downloads.At(i); //current download
       
   465                 dl->GetBoolAttribute( EDlAttrProgressive, isProgressive );
       
   466                 dl->GetBoolAttribute( EDlAttrPausable , isPausable );
       
   467                 if (!( isProgressive || isPausable ) ) // delete only no-PDL downloads and Non pausable Downloads
       
   468     			    {
       
   469                     // Delete not attached downloads.
       
   470     	            dl->Delete(); // Return value ignored.
       
   471 			        }
       
   472 		        }
       
   473             okToExit = ETrue;
       
   474     		}
       
   475         else
       
   476             {
       
   477             if ( iRegistryModel.DownloadsListInstalled() )
       
   478                 {
       
   479                 // Make visible
       
   480                 iRegistryModel.DownloadsList().DisplayDownloadsListL();
       
   481                 }
       
   482             }
       
   483         }
       
   484 
       
   485     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::OkToExitL");
       
   486     return okToExit;
       
   487     }
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // CDownloadMgrUiUserInteractions::PrepareToExit
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 EXPORT_C 
       
   494 TInt CDownloadMgrUiUserInteractions::PrepareToExit( CEikAppUi& aAppUi, 
       
   495                                                     TClientAppExitType aExitType, 
       
   496                                                     TVwsViewId aViewId, 
       
   497                                                     TUid aCustomMessageId, 
       
   498                                                     const TDesC8& aViewActivationMsg )
       
   499     {
       
   500     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::PrepareToExit");
       
   501 
       
   502     // send a message to all running PD applications and tell that browser is exiting
       
   503     TRAP_IGNORE( iUiUtils->SendMsgTerminateToPdAppsL());
       
   504 
       
   505     TRAPD( err, PrepareToExitL( &aAppUi, aExitType, aViewId, aCustomMessageId, 
       
   506                                 aViewActivationMsg ) );
       
   507 	CLOG_WRITE_FORMAT(" err: %d",err);
       
   508 
       
   509     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::PrepareToExit");
       
   510     return err;
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CDownloadMgrUiUserInteractions::PrepareToExit
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 EXPORT_C 
       
   518 TInt CDownloadMgrUiUserInteractions::PrepareToExit( TUint32 aAppUid,
       
   519                                                     TUint32 aViewId, 
       
   520                                                     TUint32 aCustomMessageId )
       
   521     {
       
   522     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::PrepareToExit 2");
       
   523 
       
   524     // send a message to all running PD applications and tell that browser is exiting
       
   525     TRAP_IGNORE( iUiUtils->SendMsgTerminateToPdAppsL());
       
   526 
       
   527     // Convert parameters to the necessary form
       
   528     TVwsViewId viewId( TUid::Uid(aAppUid), TUid::Uid(aViewId) );
       
   529     TUid customMessageId( TUid::Uid(aCustomMessageId) );
       
   530     
       
   531     TRAPD( err, PrepareToExitL( 0, ETerminatedBySystem, viewId, customMessageId, 
       
   532                                 KNullDesC8 ) );
       
   533 	CLOG_WRITE_FORMAT(" err: %d",err);
       
   534 
       
   535     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::PrepareToExit 2");
       
   536     return err;
       
   537     }
       
   538 
       
   539 // -----------------------------------------------------------------------------
       
   540 // CDownloadMgrUiUserInteractions::HandleDownloadL
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 EXPORT_C 
       
   544 void CDownloadMgrUiUserInteractions::HandleDownloadL( RHttpDownload& aDownload )
       
   545     {
       
   546     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::HandleDownloadL");
       
   547     CLOG_WRITE_FORMAT("aDownload: 0x%x",&aDownload);
       
   548 
       
   549     // Handle only completed downloads.
       
   550     // check if it is COD download. They do not require any handling - just delete them.
       
   551     if ( CodDownloadL( aDownload ) )
       
   552         {
       
   553         // Nothing to do with COD - just delete it.
       
   554         User::LeaveIfError( aDownload.Delete() );
       
   555         CLOG_WRITE(" Delete OK");
       
   556         }
       
   557     else
       
   558         {
       
   559         // Handling depends on EDlAttrAction
       
   560         TInt32 action(0);
       
   561         User::LeaveIfError( aDownload.GetIntAttribute
       
   562                             ( EDlAttrAction, action ) );
       
   563         CLOG_WRITE_FORMAT(" EDlAttrAction: %d",action);
       
   564 
       
   565         if ( action == EDoNothing )
       
   566             {
       
   567             // Do nothing
       
   568             }
       
   569         else if ( action & EMove )
       
   570             {
       
   571             // Move content to the location pointed by EDlAttrDestFilename.
       
   572             User::LeaveIfError( aDownload.Move() );
       
   573             }
       
   574         else if ( action & EPdLaunch )
       
   575             {
       
   576         	// again do nothing since it's already launched during the process 
       
   577             }
       
   578         else
       
   579             {
       
   580             // Defaulting to Launch
       
   581             HBufC8* ctype = iUiUtils->ContentTypeL( aDownload, ETrue );
       
   582             CleanupStack::PushL( ctype );
       
   583             TBool isLaunchType( KSisxApplication().Find( *ctype ) != KErrNotFound || KWidgetMimeType().Find (*ctype) != KErrNotFound );
       
   584             if(!isLaunchType)
       
   585                 {
       
   586                 isLaunchType = KPipApplication().Find( *ctype ) != KErrNotFound ;
       
   587                 }
       
   588             if(!isLaunchType)
       
   589                 {
       
   590                 isLaunchType = KSharingConfig().Find( *ctype ) != KErrNotFound ;
       
   591                 }                
       
   592             if( isLaunchType )
       
   593                 {
       
   594                 // launch content
       
   595                 iUiUtils->HandleContentL( aDownload, *iExtension );
       
   596                 }
       
   597             else if ( iUiUtils->DrmDownloadL( aDownload ) )
       
   598                 {
       
   599 
       
   600                 if( iUiUtils->IsCorruptedDcfL( aDownload ) )
       
   601                     {
       
   602                     aDownload.Delete();
       
   603                     // Show 'File corrupted' info note.
       
   604                     iUiUtils->InfoNoteL( R_DMUL_OK_NOTE, R_DMUL_ERROR_CORRUPTED );
       
   605                     }
       
   606                 else
       
   607                     {
       
   608                     TBool isBadMimeInDcf = iUiUtils->IsBadMimeInDcfL( aDownload );
       
   609                     TBool isSupported = EFalse;
       
   610                     if ( isBadMimeInDcf )
       
   611                         {
       
   612                         isSupported = EFalse;
       
   613                         }
       
   614                     else
       
   615                         {
       
   616                         isSupported = iUiUtils->IsContentTypeSupportedL( aDownload );
       
   617                         }
       
   618                     TBool previewRights;
       
   619                     if ( iUiUtils->DrmRightsOnThePhoneL( aDownload, previewRights ) )
       
   620                         {
       
   621                         // get content type of media file in drm content
       
   622                         isLaunchType = KDrmInnerContentTypesToLaunch().Find( *ctype ) != KErrNotFound;
       
   623                         if( isLaunchType )
       
   624                             {
       
   625                             // launch content
       
   626                             iUiUtils->HandleContentL( aDownload, *iExtension );
       
   627                             }
       
   628                         else if ( previewRights )
       
   629                             {
       
   630                             // Normal behaviour
       
   631                             HandleNormalDownloadL( aDownload );
       
   632                             }
       
   633                         else
       
   634                             {
       
   635                             HandleCompletionWithQueryL( aDownload, IsUiBusy(), isSupported, ETrue, ETrue );
       
   636                             }
       
   637                         }
       
   638                     else
       
   639                         {
       
   640                         // No rights on the phone
       
   641                         HandleCompletionWithQueryL( aDownload, IsUiBusy(), isSupported, ETrue, EFalse );
       
   642                         }
       
   643                     }
       
   644                 }
       
   645             else // Normal download
       
   646                 {
       
   647                 HandleNormalDownloadL( aDownload );
       
   648                 }
       
   649              CleanupStack::PopAndDestroy( ctype );    
       
   650             }
       
   651         }
       
   652 
       
   653     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::HandleDownloadL");
       
   654     }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 // CDownloadMgrUiUserInteractions::GetIntAttributeL
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 EXPORT_C 
       
   661 void CDownloadMgrUiUserInteractions::GetIntAttributeL( const TUint /*aAttribute*/, TInt32& /*aValue*/ )
       
   662     {
       
   663     User::Leave( KErrNotSupported );
       
   664     }
       
   665     
       
   666 // -----------------------------------------------------------------------------
       
   667 // CDownloadMgrUiUserInteractions::GetBoolAttributeL
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 EXPORT_C 
       
   671 void CDownloadMgrUiUserInteractions::GetBoolAttributeL( const TUint aAttribute, TBool& aValue )
       
   672     {
       
   673     if ( aAttribute == EAttrSuppressDownloadConfirmation )
       
   674         {
       
   675         aValue = iExtension->iSuppressDownloadConfirmation;
       
   676         }
       
   677     else
       
   678         {
       
   679         User::Leave( KErrNotSupported );
       
   680         }
       
   681     }
       
   682     
       
   683 // -----------------------------------------------------------------------------
       
   684 // CDownloadMgrUiUserInteractions::GetStringAttributeL
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 EXPORT_C 
       
   688 void CDownloadMgrUiUserInteractions::GetStringAttributeL( const TUint /*aAttribute*/, TDes16& /*aValue*/  )
       
   689     {
       
   690     User::Leave( KErrNotSupported );
       
   691     }
       
   692     
       
   693 // -----------------------------------------------------------------------------
       
   694 // CDownloadMgrUiUserInteractions::GetStringAttributeL
       
   695 // -----------------------------------------------------------------------------
       
   696 //
       
   697 EXPORT_C 
       
   698 void CDownloadMgrUiUserInteractions::GetStringAttributeL( const TUint /*aAttribute*/, TDes8& /*aValue*/  )
       
   699     {
       
   700     User::Leave( KErrNotSupported );
       
   701     }
       
   702     
       
   703 // -----------------------------------------------------------------------------
       
   704 // CDownloadMgrUiUserInteractions::SetIntAttributeL
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 EXPORT_C 
       
   708 void CDownloadMgrUiUserInteractions::SetIntAttributeL( const TUint /*aAttribute*/, TInt32 /*aValue*/ )
       
   709     {
       
   710     User::Leave( KErrNotSupported );
       
   711     }
       
   712     
       
   713 // -----------------------------------------------------------------------------
       
   714 // CDownloadMgrUiUserInteractions::SetBoolAttributeL
       
   715 // -----------------------------------------------------------------------------
       
   716 //
       
   717 EXPORT_C 
       
   718 void CDownloadMgrUiUserInteractions::SetBoolAttributeL( const TUint aAttribute, TBool aValue )
       
   719     {
       
   720     if ( aAttribute == EAttrSuppressDownloadConfirmation )
       
   721         {
       
   722         iExtension->iSuppressDownloadConfirmation = aValue;
       
   723         }
       
   724     else
       
   725         {
       
   726         User::Leave( KErrNotSupported );
       
   727         }
       
   728     }
       
   729     
       
   730 // -----------------------------------------------------------------------------
       
   731 // CDownloadMgrUiUserInteractions::SetStringAttributeL
       
   732 // -----------------------------------------------------------------------------
       
   733 //
       
   734 EXPORT_C 
       
   735 void CDownloadMgrUiUserInteractions::SetStringAttributeL( const TUint /*aAttribute*/, const TDesC16& /*aValue*/ )
       
   736     {
       
   737     User::Leave( KErrNotSupported );
       
   738     }
       
   739     
       
   740 // -----------------------------------------------------------------------------
       
   741 // CDownloadMgrUiUserInteractions::SetStringAttributeL
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 EXPORT_C 
       
   745 void CDownloadMgrUiUserInteractions::SetStringAttributeL( const TUint /*aAttribute*/, const TDesC8& /*aValue*/ )
       
   746     {
       
   747     User::Leave( KErrNotSupported );
       
   748     }
       
   749     
       
   750 // -----------------------------------------------------------------------------
       
   751 // CDownloadMgrUiUserInteractions::HandleCompletionWithQueryL
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 void CDownloadMgrUiUserInteractions::HandleCompletionWithQueryL
       
   755     ( RHttpDownload& aDownload,
       
   756       TBool aIsUiBusy,
       
   757       TBool aIsSupported,
       
   758       TBool aIsDrm,
       
   759       TBool aDrmRightsOnPhone )
       
   760     {
       
   761     if( !iDlgActive )
       
   762         {
       
   763         iDlgActive = ETrue;
       
   764         TRAPD( err, DoHandleCompletionWithQueryL( aDownload, aIsUiBusy,
       
   765             aIsSupported, aIsDrm, aDrmRightsOnPhone ));
       
   766         iDlgActive = EFalse;
       
   767         User::LeaveIfError( err );
       
   768         }
       
   769     }
       
   770   
       
   771 // -----------------------------------------------------------------------------
       
   772 // CDownloadMgrUiUserInteractions::DoHandleCompletionWithQueryL
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 void CDownloadMgrUiUserInteractions::DoHandleCompletionWithQueryL
       
   776     ( RHttpDownload& aDownload, TBool CLOG_ONLY( aIsUiBusy ), 
       
   777                                                       TBool aIsSupported, 
       
   778                                                       TBool aIsDrm, 
       
   779                                                       TBool aDrmRightsOnPhone )
       
   780     {
       
   781     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::HandleCompletionWithQueryL");
       
   782     CLOG_WRITE_FORMAT(" aIsUiBusy: %d",aIsUiBusy);
       
   783     CLOG_WRITE_FORMAT(" aIsSupported: %d",aIsSupported);
       
   784     CLOG_WRITE_FORMAT(" aIsDrm: %d",aIsDrm);
       
   785     CLOG_WRITE_FORMAT(" aDrmRightsOnPhone: %d",aDrmRightsOnPhone);
       
   786 
       
   787     // File name :
       
   788     User::LeaveIfError( aDownload.GetStringAttribute
       
   789                       ( EDlAttrName, iExtension->iFileName ) );
       
   790 
       
   791     HBufC* queryText = StringLoader::LoadLC
       
   792                        ( R_DMUL_COMPLETED_CONF, iExtension->iFileName );
       
   793 
       
   794     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   795     // Set up the initial dialog. Some parameters are changed then.
       
   796     dlg->PrepareLC( R_DMUL_COMPL_DOWNLOAD_CONF );
       
   797     CLOG_WRITE(" PrepareLC OK");
       
   798     dlg->SetPromptL( *queryText );
       
   799     
       
   800     // Set up softkeys:
       
   801     TInt cbaResourceId(0);
       
   802     TInt okSkMeans(0);
       
   803     if ( aIsDrm && aIsSupported )
       
   804         {
       
   805         if ( !aDrmRightsOnPhone )
       
   806             {
       
   807             // aIsUiBusy must be EFalse!
       
   808             cbaResourceId = R_DMUL_SOFTKEYS_COMPL_DRM_SAVE;
       
   809             okSkMeans = EAknSoftkeySave;
       
   810             }
       
   811         else
       
   812             {
       
   813             cbaResourceId = R_DMUL_SOFTKEYS_COMPL_DRM;
       
   814             okSkMeans = EAknSoftkeyShow;
       
   815             }
       
   816         }
       
   817     else
       
   818         {
       
   819         // aIsUiBusy must be EFalse!
       
   820         if ( aIsSupported )
       
   821             {
       
   822             cbaResourceId = R_DMUL_SOFTKEYS_COMPL_DL;
       
   823             okSkMeans = EAknSoftkeyShow;
       
   824             }
       
   825         else
       
   826             {
       
   827             cbaResourceId = R_DMUL_SOFTKEYS_UNSUPP_COMPL_DL;
       
   828             okSkMeans = EAknSoftkeySave;
       
   829             }
       
   830         }
       
   831     dlg->ButtonGroupContainer().SetCommandSetL( cbaResourceId );
       
   832 
       
   833     // Execute it.
       
   834     TInt skId = dlg->RunLD();
       
   835     CLOG_WRITE_FORMAT(" RunLD %d",skId);
       
   836     dlg = NULL;
       
   837 
       
   838     CleanupStack::PopAndDestroy( /*queryText*/ ); // queryText
       
   839 
       
   840     // Translate OK key to the proper meaning
       
   841     if ( skId == EAknSoftkeyOk )
       
   842         {
       
   843         skId = okSkMeans;
       
   844         }
       
   845         
       
   846     if ( skId == EAknSoftkeyShow )
       
   847         {
       
   848         // First clode the downloads list.
       
   849         if ( iRegistryModel.DownloadsListInstalled() )
       
   850             {
       
   851             iRegistryModel.DownloadsList().CancelDisplayingDownloadsList();
       
   852             }
       
   853         iUiUtils->HandleContentL( aDownload, *iExtension );
       
   854         // After the termination of the handler, download is removed 
       
   855         // from the list of downloads in NotifyHandlerExit().
       
   856         }
       
   857     else if ( skId == EAknSoftkeySave )
       
   858         {
       
   859         iUiUtils->SaveContentL( aDownload );
       
   860         // The save (moving) procedure is asynchronous!
       
   861         // When ends, HandleDMgrEventL() is called.
       
   862         }
       
   863     else
       
   864         {
       
   865         // Do nothing.
       
   866         }
       
   867 
       
   868     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::HandleCompletionWithQueryL");
       
   869     }
       
   870 
       
   871 // -----------------------------------------------------------------------------
       
   872 // CDownloadMgrUiUserInteractions::PrepareToExitL
       
   873 // Behaviour depends on:
       
   874 // - EDlMgrExitAction is EExitDelete or not
       
   875 // - some download is non-pausable - these will always be deleted by DM engine
       
   876 // - hidden downloads
       
   877 // - no media downloads are taken into account!
       
   878 // -----------------------------------------------------------------------------
       
   879 //
       
   880 void CDownloadMgrUiUserInteractions::PrepareToExitL( CEikAppUi* /*aAppUi*/, 
       
   881                                                      TClientAppExitType aExitType, 
       
   882                                                      TVwsViewId aViewId, 
       
   883                                                      TUid aCustomMessageId, 
       
   884                                                      const TDesC8& aViewActivationMsg )
       
   885     {
       
   886     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::PrepareToExitL");
       
   887 
       
   888     __ASSERT_ALWAYS( aExitType==ETerminatedBySystem, Panic( EUiLibPanCalledWhenUserExit ) );
       
   889 
       
   890     TInt32 exitAction( EExitNothing );
       
   891     User::LeaveIfError( iRegistryModel.DownloadMgr().
       
   892                         GetIntAttribute( EDlMgrExitAction, exitAction ) );
       
   893     CLOG_WRITE_FORMAT(" exitAction: %d",exitAction);
       
   894     
       
   895     if ( exitAction == EExitDelete )
       
   896         {
       
   897         // No need to initialize soft notifications - downloads will be deleted
       
   898         CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::PrepareToExitL");
       
   899         return;
       
   900         }
       
   901         
       
   902     // count non-pausable and hidden downloads
       
   903     TInt downloadCnt = iRegistryModel.DownloadCount();
       
   904     TInt ignoredDownloads = 0;
       
   905     TBool isPausable(0);
       
   906     TBool isHidden(0);
       
   907     TBool isNoMedia(0);
       
   908     TInt err(0);
       
   909     THttpDownloadState state;
       
   910     const CDownloadArray& downloads = iRegistryModel.DownloadMgr().CurrentDownloads();
       
   911     for( TInt i = 0; i < downloadCnt; ++i )
       
   912         {
       
   913         RHttpDownload* dl = downloads.At(i); // current download
       
   914         err = dl->GetBoolAttribute( EDlAttrPausable, isPausable );
       
   915         if ( !err )
       
   916             {
       
   917             err = dl->GetBoolAttribute( EDlAttrHidden, isHidden );
       
   918             }
       
   919         if( !err )
       
   920             {
       
   921             err = dl->GetIntAttribute(EDlAttrState, (TInt32&)state);
       
   922             //Changes for the bug JERI-7P8CF2
       
   923             //Changes made in the server side to fix  the video center receiving unexpected events
       
   924             //Reassigning these events back to the changes done in server side
       
   925             if(!err && state  == EHttpDlCompleted )
       
   926 		       {
       
   927                 state  = EHttpDlMultipleMOCompleted;
       
   928 		       }
       
   929             else if(!err && state  == EHttpDlFailed )
       
   930 		       {
       
   931 		       state  = EHttpDlMultipleMOFailed;
       
   932 		       }
       
   933           
       
   934             }
       
   935         if ( !err )
       
   936         	{
       
   937         	err = dl->GetBoolAttribute( EDlAttrNoMedia, isNoMedia );
       
   938         	}
       
   939         CLOG_WRITE_FORMAT(" err: %d",err);
       
   940         if ( !err && ( !isPausable || isHidden ||isNoMedia || state == EHttpDlMultipleMOCompleted  ) )
       
   941             {
       
   942             ++ignoredDownloads;
       
   943             }
       
   944         }
       
   945     CLOG_WRITE_FORMAT(" downloadCnt: %d",downloadCnt);
       
   946     CLOG_WRITE_FORMAT(" ignoredDownloads: %d",ignoredDownloads);
       
   947         
       
   948     // the new downloadCnt holds only those downloads, that count from the 
       
   949     // point of soft notifications
       
   950     downloadCnt = downloadCnt - ignoredDownloads;
       
   951     
       
   952     // Is the App server app?
       
   953     TBool startedAsServerApp = ((CEikonEnv&)iCoeEnv).StartedAsServerApp();
       
   954     CLOG_WRITE_FORMAT(" startedAsServerApp: %d",startedAsServerApp);
       
   955     if ( startedAsServerApp )
       
   956         {
       
   957         if ( downloadCnt > 0 )
       
   958             {
       
   959             // Display GSN-Emb.
       
   960             iUiUtils->InitializeSoftNotifEmbL
       
   961                 ( aViewId, aCustomMessageId, aViewActivationMsg );
       
   962 
       
   963             // And check if there is a running stand-alone instance from the 
       
   964             // same application. If there is no such, then initialize GSN-Stnd.
       
   965             if ( IsStandAloneAppRunning() )
       
   966                 {
       
   967                 // The stand-alone app will show GSN, if necessary when terminated.
       
   968                 }
       
   969             else
       
   970                 {
       
   971                 // It has to initialize GSN-Stnd
       
   972                 iUiUtils->InitializeSoftNotifStndL
       
   973                     ( aViewId, aCustomMessageId, aViewActivationMsg );
       
   974                 }
       
   975             }
       
   976         else
       
   977             {
       
   978             // No downloads left in - don't show GSN.
       
   979             }
       
   980         }
       
   981     else                                        // Stand-alone
       
   982         {
       
   983         if ( downloadCnt > 0 )
       
   984             {
       
   985             // Display GSN-Stnd.
       
   986             iUiUtils->InitializeSoftNotifStndL
       
   987                 ( aViewId, aCustomMessageId, aViewActivationMsg );
       
   988             }
       
   989         else
       
   990             {
       
   991             // No downloads left in - don't show GSN.
       
   992             }
       
   993         }
       
   994 
       
   995     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::PrepareToExitL");
       
   996     }
       
   997     
       
   998 // -----------------------------------------------------------------------------
       
   999 // CDownloadMgrUiUserInteractions::IsStandAloneAppRunning
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 TBool CDownloadMgrUiUserInteractions::IsStandAloneAppRunning()
       
  1003     {
       
  1004     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::IsStandAloneAppRunning");
       
  1005 
       
  1006     TBool ret(0);
       
  1007     if ( !((CEikonEnv&)iCoeEnv).StartedAsServerApp() )
       
  1008         {
       
  1009         // This is the stand-alone app.
       
  1010         ret = ETrue;
       
  1011         }
       
  1012     else
       
  1013         {
       
  1014         TApaTaskList apaTaskList( iCoeEnv.WsSession() );
       
  1015         TUid appUid = iRegistryModel.ClientAppUid();
       
  1016         TApaTask apaTask = apaTaskList.FindApp( appUid );
       
  1017         ret = apaTask.Exists();
       
  1018         }
       
  1019 
       
  1020     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::IsStandAloneAppRunning");
       
  1021     return ret;
       
  1022     }
       
  1023 
       
  1024 // -----------------------------------------------------------------------------
       
  1025 // CDownloadMgrUiUserInteractions::DeleteEventHandlerShowingDlConfirmation
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 void CDownloadMgrUiUserInteractions::DeleteEventHandlerShowingDlConfirmation
       
  1029                                    ( RHttpDownload& aDownload )
       
  1030     {
       
  1031     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::DeleteEventHandlerShowingDlConfirmation");
       
  1032 
       
  1033     // Find the event handler of this download
       
  1034     TInt handlerCount = iEventHandlerArray->Count();
       
  1035     for( TInt i = 0; i < handlerCount; ++i )
       
  1036         {
       
  1037         CUserInteractionsEventHandler* handlerI = 
       
  1038             (CUserInteractionsEventHandler*)iEventHandlerArray->At(i);
       
  1039         if ( &(handlerI->Download()) == &aDownload )
       
  1040             {
       
  1041             // found one.
       
  1042             if ( handlerI->DownloadConfirmationShown() )
       
  1043                 {
       
  1044                 delete handlerI;
       
  1045                 iEventHandlerArray->Remove( handlerI );
       
  1046                 --i;
       
  1047                 --handlerCount;
       
  1048                 }
       
  1049             }
       
  1050         }
       
  1051 
       
  1052     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::DeleteEventHandlerShowingDlConfirmation");
       
  1053     }
       
  1054 
       
  1055 // -----------------------------------------------------------------------------
       
  1056 // CDownloadMgrUiUserInteractions::DeleteEventHandlers
       
  1057 // -----------------------------------------------------------------------------
       
  1058 //
       
  1059 void CDownloadMgrUiUserInteractions::DeleteEventHandlers( RHttpDownload& aDownload )
       
  1060     {
       
  1061     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::DeleteEventHandlers");
       
  1062 
       
  1063     // Find the event handler of this download
       
  1064     TInt handlerCount = iEventHandlerArray->Count();
       
  1065     for( TInt i = 0; i < handlerCount; ++i )
       
  1066         {
       
  1067         CUserInteractionsEventHandler* handlerI = 
       
  1068             (CUserInteractionsEventHandler*)iEventHandlerArray->At(i);
       
  1069         if ( &(handlerI->Download()) == &aDownload )
       
  1070             {
       
  1071             // found one.
       
  1072             delete handlerI;
       
  1073             iEventHandlerArray->Remove( handlerI );
       
  1074             --i;
       
  1075             --handlerCount;
       
  1076             }
       
  1077         }
       
  1078 
       
  1079     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::DeleteEventHandlers");
       
  1080     }
       
  1081 
       
  1082 // -----------------------------------------------------------------------------
       
  1083 // CDownloadMgrUiUserInteractions::DownloadConfirmationsShown
       
  1084 // -----------------------------------------------------------------------------
       
  1085 //
       
  1086 TInt CDownloadMgrUiUserInteractions::DownloadConfirmationsShown() const
       
  1087     {
       
  1088     TInt count( 0 );
       
  1089     TInt totalCount = iEventHandlerArray->Count();
       
  1090     CUserInteractionsEventHandler* eventHandler = NULL;
       
  1091     for ( TInt i = 0; i < totalCount; ++i )
       
  1092         {
       
  1093         eventHandler = (CUserInteractionsEventHandler*)(*iEventHandlerArray)[i];
       
  1094         if ( eventHandler->DownloadConfirmationShown() )
       
  1095             {
       
  1096             count++;
       
  1097             }
       
  1098         }
       
  1099     return count;
       
  1100     }
       
  1101 
       
  1102 // -----------------------------------------------------------------------------
       
  1103 // CDownloadMgrUiUserInteractions::IsUiBusy
       
  1104 // UI is busy, if:
       
  1105 // - DocHandler exists in CUserInteractionsUtils.
       
  1106 // - CodHandler ServiceFlow is running.
       
  1107 // -----------------------------------------------------------------------------
       
  1108 //
       
  1109 TBool CDownloadMgrUiUserInteractions::IsUiBusy() const
       
  1110     {
       
  1111     TBool isUiBusy( ETrue ); // True by default.
       
  1112     if ( iUiUtils->IsUiBusy() )
       
  1113         {
       
  1114         isUiBusy = ETrue;
       
  1115         }
       
  1116     else if ( IsCodServiceFlowRunning() )
       
  1117         {
       
  1118         isUiBusy = ETrue;
       
  1119         }
       
  1120     else
       
  1121         {
       
  1122         isUiBusy = EFalse;
       
  1123         }
       
  1124     return isUiBusy;
       
  1125     }
       
  1126 
       
  1127 // -----------------------------------------------------------------------------
       
  1128 // CDownloadMgrUiUserInteractions::PostponeCodHandlingL
       
  1129 // -----------------------------------------------------------------------------
       
  1130 //
       
  1131 void CDownloadMgrUiUserInteractions::PostponeCodHandlingL( RHttpDownload& aDownload )
       
  1132     {
       
  1133     iExtension->PostponeCodHandlingL( aDownload );
       
  1134     }
       
  1135 
       
  1136 // -----------------------------------------------------------------------------
       
  1137 // CDownloadMgrUiUserInteractions::IsPostponed
       
  1138 // -----------------------------------------------------------------------------
       
  1139 //
       
  1140 TBool CDownloadMgrUiUserInteractions::IsPostponed( RHttpDownload& aDownload ) const
       
  1141     {
       
  1142     return iExtension->IsPostponed( aDownload );
       
  1143     }
       
  1144 
       
  1145 // -----------------------------------------------------------------------------
       
  1146 // CDownloadMgrUiUserInteractions::SchedulePostponedDownloadL
       
  1147 // -----------------------------------------------------------------------------
       
  1148 //
       
  1149 void CDownloadMgrUiUserInteractions::SchedulePostponedDownloadL()
       
  1150     {
       
  1151     iExtension->SchedulePostponedDownloadL();
       
  1152     }
       
  1153 
       
  1154 // -----------------------------------------------------------------------------
       
  1155 // CDownloadMgrUiUserInteractions::IsCodServiceFlowRunning
       
  1156 // -----------------------------------------------------------------------------
       
  1157 //
       
  1158 TBool CDownloadMgrUiUserInteractions::IsCodServiceFlowRunning() const
       
  1159     {
       
  1160     TBool isCodServiceFlowRunning( ETrue ); // true by default
       
  1161     TRAP_IGNORE( isCodServiceFlowRunning = IsCodServiceFlowRunningL() );
       
  1162     return isCodServiceFlowRunning;
       
  1163     }
       
  1164 
       
  1165 // -----------------------------------------------------------------------------
       
  1166 // CDownloadMgrUiUserInteractions::IsCodServiceFlowRunning
       
  1167 // -----------------------------------------------------------------------------
       
  1168 //
       
  1169 TBool CDownloadMgrUiUserInteractions::IsCodServiceFlowRunning
       
  1170                                     ( RHttpDownload& aDownload ) const
       
  1171     {
       
  1172     TBool isCodServiceFlowRunning( ETrue ); // true by default
       
  1173     TRAP_IGNORE( isCodServiceFlowRunning = IsCodServiceFlowRunningL( aDownload ) );
       
  1174     return isCodServiceFlowRunning;
       
  1175     }
       
  1176 
       
  1177 // -----------------------------------------------------------------------------
       
  1178 // CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL
       
  1179 // -----------------------------------------------------------------------------
       
  1180 //
       
  1181 TBool CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL() const
       
  1182     {
       
  1183     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL");
       
  1184     
       
  1185     TBool isCodServiceFlowRunning( EFalse ); // false by default!
       
  1186     // Walk through the list of downloads.
       
  1187     RHttpDownloadMgr& dMgr = iRegistryModel.DownloadMgr();
       
  1188     TInt downloads = dMgr.CurrentDownloads().Count();
       
  1189     for ( TInt i = 0; i < downloads; ++i )
       
  1190         {
       
  1191         RHttpDownload* download = 
       
  1192             (RHttpDownload*)(dMgr.CurrentDownloads().At(i));
       
  1193         CLOG_WRITE_FORMAT(" download: %x",download);
       
  1194         
       
  1195         if ( IsCodServiceFlowRunningL( *download ) )
       
  1196             {
       
  1197             CLOG_WRITE(" Found!");
       
  1198             isCodServiceFlowRunning = ETrue;
       
  1199             break;
       
  1200             }
       
  1201         }
       
  1202 
       
  1203     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL");
       
  1204     return isCodServiceFlowRunning;
       
  1205     }
       
  1206 
       
  1207 // -----------------------------------------------------------------------------
       
  1208 // CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL
       
  1209 // CodHandler ServiceFlow is running, if a COD download is hidden, but it is 
       
  1210 // not in the so called postponed downloads list.
       
  1211 // -----------------------------------------------------------------------------
       
  1212 //
       
  1213 TBool CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL
       
  1214                                     ( RHttpDownload& aDownload ) const
       
  1215     {
       
  1216     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL DL");
       
  1217     
       
  1218     TBool isCodServiceFlowRunning( EFalse ); // false by default!
       
  1219     // COD download?
       
  1220     TBool isCodDownload( EFalse );
       
  1221     User::LeaveIfError( aDownload.GetBoolAttribute
       
  1222                       ( EDlAttrCodDownload, isCodDownload ) );
       
  1223     CLOG_WRITE_FORMAT(" isCodDownload: %d",isCodDownload);
       
  1224     if ( isCodDownload )
       
  1225         {
       
  1226         // check if hidden?
       
  1227         TBool isHidden( EFalse );
       
  1228         User::LeaveIfError( aDownload.GetBoolAttribute
       
  1229                           ( EDlAttrHidden, isHidden ) );
       
  1230         CLOG_WRITE_FORMAT(" isHidden: %d",isHidden);
       
  1231         if ( isHidden )
       
  1232             {
       
  1233             // if it is not in postponed downloads list...
       
  1234             if ( !IsPostponed( aDownload ) )
       
  1235                 {
       
  1236                 isCodServiceFlowRunning = ETrue;
       
  1237                 }
       
  1238             }
       
  1239         }
       
  1240 
       
  1241     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::IsCodServiceFlowRunningL DL");
       
  1242     return isCodServiceFlowRunning;
       
  1243     }
       
  1244 
       
  1245 // -----------------------------------------------------------------------------
       
  1246 // CDownloadMgrUiUserInteractions::HandleNormalDownloadL
       
  1247 // -----------------------------------------------------------------------------
       
  1248 //
       
  1249 void CDownloadMgrUiUserInteractions::HandleNormalDownloadL( RHttpDownload& aDownload )
       
  1250     {
       
  1251     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::HandleNormalDownloadL");
       
  1252 
       
  1253     if ( IsUiBusy() )
       
  1254         {
       
  1255         // It's handling a downloaded content. Do not open a new.
       
  1256         CLOG_WRITE(" IsUiBusy() true");
       
  1257         }
       
  1258     else
       
  1259         {
       
  1260         iRegistryModel.DownloadsList().DisplayDownloadsListL(aDownload);
       
  1261         } 
       
  1262     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::HandleNormalDownloadL");
       
  1263     }
       
  1264 
       
  1265 // -----------------------------------------------------------------------------
       
  1266 // CDownloadMgrUiUserInteractions::CodDownloadL
       
  1267 // -----------------------------------------------------------------------------
       
  1268 //
       
  1269 TBool CDownloadMgrUiUserInteractions::CodDownloadL( RHttpDownload& aDownload ) const
       
  1270     {
       
  1271     CLOG_ENTERFN("CDownloadMgrUiUserInteractions::CodDownloadL");
       
  1272 
       
  1273     TBool isCodDownload( EFalse );
       
  1274     User::LeaveIfError( aDownload.GetBoolAttribute
       
  1275                         ( EDlAttrCodDownload, isCodDownload ) );
       
  1276                         
       
  1277     CLOG_WRITE_FORMAT(" ret: %d",isCodDownload);
       
  1278     CLOG_LEAVEFN("CDownloadMgrUiUserInteractions::CodDownloadL");
       
  1279     return isCodDownload;
       
  1280     }
       
  1281 
       
  1282 // -----------------------------------------------------------------------------
       
  1283 // CDownloadMgrUiUserInteractions::HandleDMgrEventL
       
  1284 // -----------------------------------------------------------------------------
       
  1285 //
       
  1286 void CDownloadMgrUiUserInteractions::HandleDMgrEventL
       
  1287     ( RHttpDownload& aDownload, THttpDownloadEvent aEvent )
       
  1288     {
       
  1289     CLOG_WRITE_EVENT("UsrInt",&aDownload,aEvent);
       
  1290 
       
  1291     if ( aEvent.iDownloadState == EHttpDlMediaInserted ||  
       
  1292          aEvent.iDownloadState == EHttpDlPausable || 
       
  1293          aEvent.iDownloadState == EHttpDlNonPausable )
       
  1294         {
       
  1295         // This event is not handled by User Interactions Event Handler
       
  1296         }
       
  1297     else if ( aEvent.iDownloadState == EHttpDlDeleted || 
       
  1298               aEvent.iDownloadState == EHttpDlDeleting )
       
  1299         {
       
  1300         DeleteEventHandlers( aDownload );
       
  1301         iUiUtils->DownloadHasBeenDeleted( &aDownload );
       
  1302         }
       
  1303     else if ( aEvent.iDownloadState == EHttpDlAlreadyRunning )
       
  1304         {
       
  1305         // Display information note
       
  1306         CUserInteractionsUtils::InfoNoteL( R_DMUL_OK_NOTE, R_DMUL_NOTE_DOWNLOADING );
       
  1307         }
       
  1308     else if ( aEvent.iDownloadState == EHttpDlInprogress )
       
  1309         {
       
  1310         if ( aEvent.iProgressState == EHttpProgResponseHeaderReceived || 
       
  1311              aEvent.iProgressState == EHttpContTypeRecognitionAvail || 
       
  1312              aEvent.iProgressState == EHttpProgSupportedMultiPart || 
       
  1313              aEvent.iProgressState == EHttpProgDlNameChanged )             
       
  1314             {
       
  1315             // Create the asynchronous event handler that will handle the event.
       
  1316             CUserInteractionsEventHandler* asyncHandler = 
       
  1317                 new (ELeave) CUserInteractionsEventHandler
       
  1318                 ( aDownload, aEvent, iRegistryModel, *iEventHandlerArray, *iUiUtils );
       
  1319             CleanupStack::PushL( asyncHandler );
       
  1320             // iEventHandlerArray will own it
       
  1321             iEventHandlerArray->AppendL( asyncHandler );
       
  1322             CleanupStack::Pop( asyncHandler ); // asyncHandler - ownership transferred
       
  1323             }
       
  1324         // If COD is downloaded, close download confirmation query for this download:
       
  1325         // COD shows accept/reject query too.
       
  1326         else if ( aEvent.iProgressState == EHttpProgCodDescriptorDownloaded )
       
  1327             {
       
  1328             // delete event handlers showing download confirmation.
       
  1329             DeleteEventHandlerShowingDlConfirmation( aDownload );
       
  1330             }
       
  1331         else if ( aEvent.iProgressState == EHttpProgCodDescriptorAccepted || 
       
  1332                   aEvent.iProgressState == EHttpProgCodLoadEnd            ||
       
  1333 			      aEvent.iProgressState == EHttpProgCodPdAvailable ) 
       
  1334             {
       
  1335             // Open downloads list.
       
  1336             // Create the asynchronous event handler that will handle the event, because 
       
  1337             // it will run a 'wait' dialog.
       
  1338             CUserInteractionsEventHandler* asyncHandler = 
       
  1339                 new (ELeave) CUserInteractionsEventHandler
       
  1340                 ( aDownload, aEvent, iRegistryModel, *iEventHandlerArray, *iUiUtils );
       
  1341             CleanupStack::PushL( asyncHandler );
       
  1342             // iEventHandlerArray will own it
       
  1343             iEventHandlerArray->AppendL( asyncHandler );
       
  1344             CleanupStack::Pop( asyncHandler ); // asyncHandler - ownership transferred
       
  1345             }
       
  1346         }
       
  1347     else if ( aEvent.iDownloadState == EHttpDlPaused )
       
  1348         {
       
  1349         if ( aEvent.iProgressState == EHttpContentTypeReceived )
       
  1350             {
       
  1351             // Create the asynchronous event handler that will handle the event.
       
  1352             CUserInteractionsEventHandler* asyncHandler = 
       
  1353                 new (ELeave) CUserInteractionsEventHandler
       
  1354                 ( aDownload, aEvent, iRegistryModel, *iEventHandlerArray, *iUiUtils );
       
  1355             CleanupStack::PushL( asyncHandler );
       
  1356             // iEventHandlerArray will own it
       
  1357             iEventHandlerArray->AppendL( asyncHandler );
       
  1358             CleanupStack::Pop( asyncHandler ); // asyncHandler - ownership transferred
       
  1359             }
       
  1360         }
       
  1361     else
       
  1362         {
       
  1363         // In case of completed or failed download, delete event handlers 
       
  1364         // that are showing download confirmation.
       
  1365         if ( aEvent.iDownloadState == EHttpDlMultipleMOCompleted || 
       
  1366              aEvent.iDownloadState == EHttpDlMultipleMOFailed )
       
  1367             {
       
  1368             DeleteEventHandlerShowingDlConfirmation( aDownload );
       
  1369             }
       
  1370             
       
  1371         // Create the asynchronous event handler that will handle the event.
       
  1372         CUserInteractionsEventHandler* asyncHandler = 
       
  1373             new (ELeave) CUserInteractionsEventHandler
       
  1374             ( aDownload, aEvent, iRegistryModel, *iEventHandlerArray, *iUiUtils );
       
  1375         CleanupStack::PushL( asyncHandler );
       
  1376         // iEventHandlerArray will own it
       
  1377         iEventHandlerArray->AppendL( asyncHandler );
       
  1378         CleanupStack::Pop( asyncHandler ); // asyncHandler - ownership transferred
       
  1379         }
       
  1380     }
       
  1381 
       
  1382 /* End of file. */
       
  1383