ncdengine/engine/transport/src/catalogshttpdownload.cpp
changeset 53 ae54820ef82c
parent 25 98b66e4fb0be
child 50 c6e8afe0ba85
equal deleted inserted replaced
52:92f864ef0288 53:ae54820ef82c
    21 #include <bautils.h>
    21 #include <bautils.h>
    22 #include <e32err.h>
    22 #include <e32err.h>
    23 #include <DocumentHandler.h>
    23 #include <DocumentHandler.h>
    24 #include <apmstd.h> // TDataType
    24 #include <apmstd.h> // TDataType
    25 #include <escapeutils.h>
    25 #include <escapeutils.h>
    26 
    26 #include <downloadmanager.h>
       
    27 
       
    28 
       
    29 #include <QtGlobal>
    27 #include "catalogshttpdownloadmanagerimpl.h"
    30 #include "catalogshttpdownloadmanagerimpl.h"
    28 #include "catalogshttpobserver.h"
    31 #include "catalogshttpobserver.h"
    29 #include "catalogshttpconfigimpl.h"
    32 #include "catalogshttpconfigimpl.h"
    30 #include "catalogskeyvaluepair.h"
    33 #include "catalogskeyvaluepair.h"
    31 #include "catalogshttpheadersimpl.h"
    34 #include "catalogshttpheadersimpl.h"
    93 // Creator
    96 // Creator
    94 // ---------------------------------------------------------------------------
    97 // ---------------------------------------------------------------------------
    95 //	
    98 //	
    96 CCatalogsHttpDownload* CCatalogsHttpDownload::NewLC( 
    99 CCatalogsHttpDownload* CCatalogsHttpDownload::NewLC( 
    97     CCatalogsHttpDownloadManager& aOwner, 
   100     CCatalogsHttpDownloadManager& aOwner, 
    98     RHttpDownload* aDownload,
   101     Download* aDownload,
    99     const CCatalogsHttpConfig& aConfig )
   102     const CCatalogsHttpConfig& aConfig )
   100     {
   103     {
   101     CCatalogsHttpDownload* self = new( ELeave ) CCatalogsHttpDownload( 
   104     CCatalogsHttpDownload* self = new( ELeave ) CCatalogsHttpDownload( 
   102         aOwner,
   105         aOwner,
   103         aDownload );
   106         aDownload );
   138             SetDeleteState( EDownloadPaused );
   141             SetDeleteState( EDownloadPaused );
   139             }
   142             }
   140         else 
   143         else 
   141             {
   144             {
   142             DLTRACE(( "Deleting download" ));
   145             DLTRACE(( "Deleting download" ));
   143             iDownload->Delete();                        
   146              iOwner.GetDownloadManager()->removeOne(iDownload);                      
   144             
   147             
   145             if ( iState.iOperationState != ECatalogsHttpOpCompleted ) 
   148             if ( iState.iOperationState != ECatalogsHttpOpCompleted ) 
   146                 {
   149                 {
   147                 // Ensure that temp files are really deleted
   150                 // Ensure that temp files are really deleted
   148                 DeleteFiles();
   151                 DeleteFiles();
   242     iCancelled = ETrue;
   245     iCancelled = ETrue;
   243     if ( iDownload )
   246     if ( iDownload )
   244         {
   247         {
   245         iObserver = NULL;
   248         iObserver = NULL;
   246         TInt32 state = 0;
   249         TInt32 state = 0;
   247         iDownload->GetIntAttribute( EDlAttrState, state );
   250 
   248         
   251          state = (Download::State)iDownload->attribute(State).toInt();
   249         if ( IsOneOf( 
   252         if ( IsOneOf( 
   250                 static_cast<THttpDownloadState>( state ), 
   253                 static_cast<THttpDownloadState>( state ), 
   251                 EHttpDlCreated,
   254                 EHttpDlCreated,
   252                 EHttpDlPaused,
   255                 EHttpDlPaused,
   253                 EHttpDlCompleted,
   256                 EHttpDlCompleted,
   471         // just restarted when it's resumed
   474         // just restarted when it's resumed
   472         DLTRACE(("Thread semaphore count: %d", RThread().RequestCount() ));
   475         DLTRACE(("Thread semaphore count: %d", RThread().RequestCount() ));
   473         TInt err = KErrNone;
   476         TInt err = KErrNone;
   474         if ( iDownload ) 
   477         if ( iDownload ) 
   475             {
   478             {
   476             err = iDownload->Pause();
   479 					    try
       
   480 							{
       
   481 							iDownload->pause();
       
   482 							}
       
   483 			        catch(const std::exception& exception)
       
   484 			        	{
       
   485 							 err = qt_symbian_exception2Error(exception);
       
   486 			        	}
   477             }
   487             }
   478         
   488         
   479         DLTRACE(("Pause err: %d", err ));
   489         DLTRACE(("Pause err: %d", err ));
   480         if ( err == KErrNone ) 
   490         if ( err == KErrNone ) 
   481             {
   491             {
   678     DLTRACEIN((""));
   688     DLTRACEIN((""));
   679     // We get the content size only once in order to minimize 
   689     // We get the content size only once in order to minimize 
   680     // client-server communication with the Download manager server
   690     // client-server communication with the Download manager server
   681     if ( iDownload && iContentSize <= 0 ) 
   691     if ( iDownload && iContentSize <= 0 ) 
   682         {                
   692         {                
   683         iDownload->GetIntAttribute( EDlAttrLength, iContentSize );    
   693     
       
   694         int  downloadbytes   =  iDownload->attribute(DownloadedSize).toInt();
   684         DLTRACE(("Content size from download: %i", iContentSize ));
   695         DLTRACE(("Content size from download: %i", iContentSize ));
   685         }
   696         }
   686     return iContentSize;
   697     return iContentSize;
   687     }
   698     }
   688 
   699 
   704 TBool CCatalogsHttpDownload::IsPausable() const
   715 TBool CCatalogsHttpDownload::IsPausable() const
   705     {    
   716     {    
   706     TBool pausable = ETrue;
   717     TBool pausable = ETrue;
   707     if ( iDownload ) 
   718     if ( iDownload ) 
   708         {        
   719         {        
   709         iDownload->GetBoolAttribute( EDlAttrPausable, pausable );
   720 
       
   721         pausable=iDownload->attribute(Pausable).toBool();
   710         }
   722         }
   711     return pausable;
   723     return pausable;
   712     }
   724     }
   713 
   725 
   714 
   726 
   837         return iOwner.OperationPriorityChanged( this );
   849         return iOwner.OperationPriorityChanged( this );
   838         }
   850         }
   839     return KErrNone;
   851     return KErrNone;
   840     }
   852     }
   841 
   853 
   842 
   854 void CCatalogsHttpDownload::HandledownloadEventL(DownloadEvent& aEvent)
       
   855 {
       
   856 	
       
   857 	switch(aEvent.type())
       
   858 	{
       
   859 		
       
   860 		case DownloadEvent::Started:
       
   861 		
       
   862 			break;
       
   863 		
       
   864 		case DownloadEvent::Failed:
       
   865 			{
       
   866 		      TInt32 errorId = -1;
       
   867             SetTransferring( EFalse );
       
   868             errorId = iDownload->attribute(LastError).toInt();
       
   869             if ( ( errorId == ConnectionFailed || 
       
   870                    errorId == TransactionFailed )) 
       
   871                 {
       
   872                 DLTRACE(("Try to reconnect"));
       
   873                 iReconnectWhenFail = EFalse;
       
   874                 iDownload->start();
       
   875                 break;
       
   876                 }
       
   877             else if ( errorId == ContentExpired ||
       
   878                       errorId == PartialContentModified )
       
   879                 {
       
   880                 DLTRACE(("Content has changed, reset and restart"));
       
   881                 iReconnectWhenFail = EFalse;
       
   882                 iDownload->cancel();
       
   883                 iDownload->start();
       
   884                 break;
       
   885                 }
       
   886  
       
   887 			}
       
   888 			break;
       
   889 		
       
   890 		case DownloadEvent::Cancelled:
       
   891 		
       
   892 			break;
       
   893 		case DownloadEvent::ContentTypeChanged:
       
   894 			
       
   895 			break;
       
   896 		case DownloadEvent::HeadersReceived:
       
   897 			{
       
   898 					// Read the response headers from platform DL manager
       
   899 			UpdateResponseHeadersL();		
       
   900 			UpdateContentType();
       
   901 		  }
       
   902 			break;
       
   903 		
       
   904 		case DownloadEvent::NetworkLoss:
       
   905 			
       
   906 		  break;
       
   907 		  
       
   908 		case DownloadEvent::Completed:
       
   909 			  {            
       
   910             // move/rename temp file as the target file
       
   911             TRAPD( err, MoveFileL() );
       
   912             
       
   913             // DLMAIN-546, delete DL manager's download before starting
       
   914             // the next one so that downloads don't jam, again
       
   915             if ( iDownload ) 
       
   916                 {   
       
   917                 	iTransferredSize = iDownload->attribute(DownloadedSize).toInt();             
       
   918          
       
   919                     
       
   920                 DLTRACE(("Deleting download"));                
       
   921                 DeletePlatformDownload();                
       
   922                 }
       
   923 
       
   924 	     }
       
   925 			break;
       
   926 			
       
   927 		case DownloadEvent::InProgress:
       
   928 		
       
   929 		  break;
       
   930 		  
       
   931 	  default:
       
   932             {
       
   933             }		  
       
   934 	};
       
   935 }
   843 // ---------------------------------------------------------------------------
   936 // ---------------------------------------------------------------------------
   844 // Handles events from the transaction
   937 // Handles events from the transaction
   845 // ---------------------------------------------------------------------------
   938 // ---------------------------------------------------------------------------
   846 //	
   939 //	
   847 void CCatalogsHttpDownload::HandleHttpEventL( 
   940 void CCatalogsHttpDownload::HandleHttpEventL( 
  1023         return;
  1116         return;
  1024         }
  1117         }
  1025     
  1118     
  1026 	TInt32 statusCode = -1;
  1119 	TInt32 statusCode = -1;
  1027 	
  1120 	
  1028 	iDownload->GetIntAttribute( EDlAttrStatusCode, statusCode );
  1121 	 statusCode  = (Download::State)iDownload->attribute(WRT::State).toInt(); 
  1029 	DLINFO( ("Response status: %i", statusCode ) );
  1122 	 DLINFO( ("Response status: %i", statusCode ) );
  1030 
  1123 
  1031 #ifdef CATALOGS_BUILD_CONFIG_DEBUG    
  1124 #ifdef CATALOGS_BUILD_CONFIG_DEBUG    
  1032     TInt32 errorId = 0;
  1125     TInt32 errorId = 0;
  1033 
  1126 		errorId=iDownload->attribute(LastError).toInt();
  1034 	iDownload->GetIntAttribute( EDlAttrErrorId, errorId );
  1127 
  1035 	DLINFO( ("Error id: %i", errorId ) );
  1128 	DLINFO( ("Error id: %i", errorId ) );
  1036 	    
  1129 	    
  1037 #endif
  1130 #endif
  1038 
  1131 
  1039     TInt32 globalErrorId = 0;    
  1132     TInt32 globalErrorId = 0;    
  1040 	iDownload->GetIntAttribute( 
  1133    globalErrorId= iDownload->attribute(LastError).toInt();
  1041 	    EDlAttrGlobalErrorId, globalErrorId );
  1134 
  1042 	DLINFO( ("Global error id: %i", globalErrorId ) );
  1135 	DLINFO( ("Global error id: %i", globalErrorId ) );
  1043 	
  1136 	
  1044 
  1137 
  1045     // was >=, DL manager should give us proper errors but it doesn't always
  1138     // was >=, DL manager should give us proper errors but it doesn't always
  1046     if ( ( statusCode == KHttpErrorStatus ||
  1139     if ( ( statusCode == KHttpErrorStatus ||
  1083             if ( iReconnectWhenFail && 
  1176             if ( iReconnectWhenFail && 
  1084                  iState.iProgressState == ECatalogsHttpDisconnected ) 
  1177                  iState.iProgressState == ECatalogsHttpDisconnected ) 
  1085                 {
  1178                 {
  1086                 DLTRACE(("Try to reconnect"));
  1179                 DLTRACE(("Try to reconnect"));
  1087                 iReconnectWhenFail = EFalse;
  1180                 iReconnectWhenFail = EFalse;
  1088                 iDownload->Start();                
  1181                 iDownload->start();                
  1089                 break;
  1182                 break;
  1090                 }
  1183                 }
  1091             
  1184             
  1092             if ( iState.iOperationState != ECatalogsHttpOpQueued ) 
  1185             if ( iState.iOperationState != ECatalogsHttpOpQueued ) 
  1093                 {                
  1186                 {                
  1141             TRAPD( err, MoveFileL() );
  1234             TRAPD( err, MoveFileL() );
  1142             
  1235             
  1143             // DLMAIN-546, delete DL manager's download before starting
  1236             // DLMAIN-546, delete DL manager's download before starting
  1144             // the next one so that downloads don't jam, again
  1237             // the next one so that downloads don't jam, again
  1145             if ( iDownload ) 
  1238             if ( iDownload ) 
  1146                 {                
  1239                 {   
  1147                 iDownload->GetIntAttribute( 
  1240                 	iTransferredSize = iDownload->attribute(DownloadedSize).toInt();             
  1148                     EDlAttrDownloadedSize, iTransferredSize );   
  1241          
  1149                     
  1242                     
  1150                 DLTRACE(("Deleting download"));                
  1243                 DLTRACE(("Deleting download"));                
  1151                 DeletePlatformDownload();                
  1244                 DeletePlatformDownload();                
  1152                 }
  1245                 }
  1153             
  1246             
  1177         case EHttpDlFailed:
  1270         case EHttpDlFailed:
  1178             {
  1271             {
  1179             DLTRACE(( "Download failed" ));
  1272             DLTRACE(( "Download failed" ));
  1180             TInt32 errorId = -1;
  1273             TInt32 errorId = -1;
  1181             SetTransferring( EFalse );
  1274             SetTransferring( EFalse );
  1182         	iDownload->GetIntAttribute( EDlAttrErrorId, errorId );
  1275             errorId = iDownload->attribute(LastError).toInt();
       
  1276         
  1183         	DLINFO( ("Error id: %i", errorId ) );
  1277         	DLINFO( ("Error id: %i", errorId ) );
  1184 
  1278 
  1185         	DLINFO( ("Global error id: %i", globalErrorId ) );
  1279         	DLINFO( ("Global error id: %i", globalErrorId ) );
  1186 
  1280 
  1187             if ( iReconnectWhenFail && 
  1281             if ( iReconnectWhenFail && 
  1188                  ( errorId == EConnectionFailed || 
  1282                  ( errorId == EConnectionFailed || 
  1189                    errorId == ETransactionFailed )) 
  1283                    errorId == ETransactionFailed )) 
  1190                 {
  1284                 {
  1191                 DLTRACE(("Try to reconnect"));
  1285                 DLTRACE(("Try to reconnect"));
  1192                 iReconnectWhenFail = EFalse;
  1286                 iReconnectWhenFail = EFalse;
  1193                 iDownload->Start();
  1287                 iDownload->start();
  1194                 break;
  1288                 break;
  1195                 }
  1289                 }
  1196             else if ( errorId == EContentExpired ||
  1290             else if ( errorId == EContentExpired ||
  1197                       errorId == EPartialContentModified )
  1291                       errorId == EPartialContentModified )
  1198                 {
  1292                 {
  1199                 DLTRACE(("Content has changed, reset and restart"));
  1293                 DLTRACE(("Content has changed, reset and restart"));
  1200                 iReconnectWhenFail = EFalse;
  1294                 iReconnectWhenFail = EFalse;
  1201                 iDownload->Reset();
  1295                 iDownload->cancel();
  1202                 iDownload->Start();
  1296                 iDownload->start();
  1203                 break;
  1297                 break;
  1204                 }
  1298                 }
  1205             
  1299             
  1206             ReleasePtr( iConnection );    
  1300             ReleasePtr( iConnection );    
  1207             iState.iOperationState = ECatalogsHttpOpFailed;
  1301             iState.iOperationState = ECatalogsHttpOpFailed;
  1386 		    SetTransferring( EFalse );
  1480 		    SetTransferring( EFalse );
  1387 		    // Don't restart paused downloads or notify about disconnection
  1481 		    // Don't restart paused downloads or notify about disconnection
  1388 		    if ( !iPaused ) 
  1482 		    if ( !iPaused ) 
  1389 		        {		  
  1483 		        {		  
  1390                 TInt32 globalErrorId = 0;
  1484                 TInt32 globalErrorId = 0;
  1391             	iDownload->GetIntAttribute( 
  1485             	    globalErrorId = iDownload->attribute(LastError).toInt();
  1392             	    EDlAttrGlobalErrorId, globalErrorId );
       
  1393             	DLINFO( ("Global error id: %i", globalErrorId ) );
  1486             	DLINFO( ("Global error id: %i", globalErrorId ) );
  1394 
  1487 
  1395                 if ( globalErrorId == KErrCancel ) 
  1488                 if ( globalErrorId == KErrCancel ) 
  1396                     {
  1489                     {
  1397                     DLTRACE(("Cancelled"));
  1490                     DLTRACE(("Cancelled"));
  1493 
  1586 
  1494 		    // Reset reconnect count
  1587 		    // Reset reconnect count
  1495 		    iReconnectCount = KReconnectAttempts;
  1588 		    iReconnectCount = KReconnectAttempts;
  1496 
  1589 
  1497 		    TInt32 size = 0;
  1590 		    TInt32 size = 0;
  1498 	        iDownload->GetIntAttribute( EDlAttrDownloadedSize, size );   
  1591 		     size = iDownload->attribute(DownloadedSize).toInt();
       
  1592 
  1499 	        DLTRACE(("Transferred size from download: %i", size));
  1593 	        DLTRACE(("Transferred size from download: %i", size));
  1500 
  1594 
  1501 	        if ( size != iTransferredSize ) 
  1595 	        if ( size != iTransferredSize ) 
  1502 	            {
  1596 	            {
  1503 	            DLTRACE(("Updating transferred size"));
  1597 	            DLTRACE(("Updating transferred size"));
  1634 // Constructor
  1728 // Constructor
  1635 // ---------------------------------------------------------------------------
  1729 // ---------------------------------------------------------------------------
  1636 //	
  1730 //	
  1637 CCatalogsHttpDownload::CCatalogsHttpDownload( 
  1731 CCatalogsHttpDownload::CCatalogsHttpDownload( 
  1638     CCatalogsHttpDownloadManager& aOwner, 
  1732     CCatalogsHttpDownloadManager& aOwner, 
  1639     RHttpDownload* aDownload ) :
  1733     Download* aDownload ) :
  1640     iOwner( aOwner ), 
  1734     iOwner( aOwner ), 
  1641     iDownload( aDownload ), 
  1735     iDownload( aDownload ), 
  1642     iState( ECatalogsHttpOpCreated, ECatalogsHttpNone ),
  1736     iState( ECatalogsHttpOpCreated, ECatalogsHttpNone ),
  1643     iRefCount( 1 ), 
  1737     iRefCount( 1 ), 
  1644     iNormalDelete( EFalse ),
  1738     iNormalDelete( EFalse ),
  1657     // Get the id for the download and update iUri
  1751     // Get the id for the download and update iUri
  1658     if ( iDownload ) 
  1752     if ( iDownload ) 
  1659         {        
  1753         {        
  1660         // id part will be updated from disk
  1754         // id part will be updated from disk
  1661         iId = TCatalogsTransportOperationId( iOwner.SessionId(), KErrNotFound );
  1755         iId = TCatalogsTransportOperationId( iOwner.SessionId(), KErrNotFound );
  1662 
  1756 				iQTDownload = new CCatalogsHttpQTDownload(this,iDownload);
       
  1757 				 
  1663         UpdateSecondaryIdL();
  1758         UpdateSecondaryIdL();
  1664         
  1759         
  1665         User::LeaveIfError( SetDeleteState( EDownloadCanBeDeleted ) );
  1760         User::LeaveIfError( SetDeleteState( EDownloadCanBeDeleted ) );
  1666         // Update iUri to match the current URI
  1761         // Update iUri to match the current URI
  1667         UpdateUriL();
  1762         UpdateUriL();
  1698     DLTRACEIN(( "" ));
  1793     DLTRACEIN(( "" ));
  1699     if ( !iContentType.Length() ) 
  1794     if ( !iContentType.Length() ) 
  1700         {
  1795         {
  1701         // Download always exists when this is called so no need to check
  1796         // Download always exists when this is called so no need to check
  1702         DLTRACE(("Updating the content type"));
  1797         DLTRACE(("Updating the content type"));
  1703         iDownload->GetStringAttribute( EDlAttrContentType,
  1798         QString contentType;
  1704             iContentType );
  1799         contentType= iDownload->attribute(WRT::ContentType).toString();
       
  1800         	TBuf<KMaxContentTypeLength>  ContentType(contentType.utf16());
       
  1801         	iContentType.Copy(ContentType);
       
  1802    
  1705         }
  1803         }
  1706     DLTRACEOUT(("Content-type: %S", &iContentType ));
  1804     DLTRACEOUT(("Content-type: %S", &iContentType ));
  1707     }
  1805     }
  1708 
  1806 
  1709 
  1807 
  1819     DLTRACEIN( ("") );
  1917     DLTRACEIN( ("") );
  1820     // Get the current url of the download
  1918     // Get the current url of the download
  1821     RBuf8 buf;
  1919     RBuf8 buf;
  1822     CleanupClosePushL( buf );
  1920     CleanupClosePushL( buf );
  1823     buf.CreateL( KMaxUrlLength );
  1921     buf.CreateL( KMaxUrlLength );
  1824     
  1922     QString string;
  1825     User::LeaveIfError( iDownload->GetStringAttribute( EDlAttrCurrentUrl,
  1923 	try
  1826         buf ) );
  1924 	{
       
  1925     string = iDownload->attribute(SourceUrl).toString();
       
  1926 	}
       
  1927     catch(const std::exception& exception)
       
  1928     	{
       
  1929 			 qt_symbian_exception2LeaveL(exception);
       
  1930     	}
       
  1931 
  1827     
  1932     
  1828     // DL manager has the encoded URI
  1933     // DL manager has the encoded URI
  1829     AssignDesL( iEncodedUri, buf );
  1934     AssignDesL( iEncodedUri, buf );
  1830     CleanupStack::PopAndDestroy( &buf );
  1935     CleanupStack::PopAndDestroy( &buf );
  1831     
  1936     
  1865             {
  1970             {
  1866             AddRequestHeaderL( iAddedRequestHeaders, *headers[i] );
  1971             AddRequestHeaderL( iAddedRequestHeaders, *headers[i] );
  1867             }
  1972             }
  1868         else 
  1973         else 
  1869             {
  1974             {
  1870             User::LeaveIfError( iDownload->SetStringAttribute(
  1975 /*            User::LeaveIfError( iDownload->SetStringAttribute(
  1871                 predefined, headers[i]->Value() ) );
  1976                 predefined, headers[i]->Value() ) );*/
  1872             }
  1977             }
  1873         }
  1978         }
  1874 
  1979 
  1875     // Add the headers that don't have a predefined enumeration in
  1980     // Add the headers that don't have a predefined enumeration in
  1876     // the platform DL manager 
  1981     // the platform DL manager 
  1877     if ( iAddedRequestHeaders ) 
  1982     if ( iAddedRequestHeaders ) 
  1878         {
  1983         {
  1879         DLTRACE(( "added request headers: %S", iAddedRequestHeaders ));
  1984         DLTRACE(( "added request headers: %S", iAddedRequestHeaders ));
  1880         User::LeaveIfError( iDownload->SetStringAttribute(
  1985      /*   User::LeaveIfError( iDownload->SetStringAttribute(
  1881             EDlAttrRequestHeaderAddon, *iAddedRequestHeaders ) );
  1986             EDlAttrRequestHeaderAddon, *iAddedRequestHeaders ) );*/
  1882         delete iAddedRequestHeaders;
  1987         delete iAddedRequestHeaders;
  1883         iAddedRequestHeaders = NULL;
  1988         iAddedRequestHeaders = NULL;
  1884         }    
  1989         }    
  1885     DLTRACEOUT((""));
  1990     DLTRACEOUT((""));
  1886     }
  1991     }
  2252             {
  2357             {
  2253             DLTRACE(("Updating dl config"));
  2358             DLTRACE(("Updating dl config"));
  2254             InitializeDownloadL();
  2359             InitializeDownloadL();
  2255             }
  2360             }
  2256         });
  2361         });
  2257     
  2362    
  2258     if ( err == KErrNone ) 
  2363     if ( err == KErrNone ) 
  2259         {
  2364         {
  2260         err = iDownload->Start();
  2365 						 try
       
  2366 							{
       
  2367 							iDownload->start();
       
  2368 							}
       
  2369 			        catch(const std::exception& exception)
       
  2370 			        	{
       
  2371 							 qt_symbian_exception2LeaveL(exception);
       
  2372 			        	}
  2261         }
  2373         }
  2262     return err;
  2374     return err;
  2263     }
  2375     }
  2264 
  2376 
  2265 
  2377 
  2469     DLTRACEIN(( "aStatus: %x, id: %x", aStatus, OperationId().Id() ));
  2581     DLTRACEIN(( "aStatus: %x, id: %x", aStatus, OperationId().Id() ));
  2470     
  2582     
  2471     TInt err = KErrNone;
  2583     TInt err = KErrNone;
  2472     if ( iDownload ) 
  2584     if ( iDownload ) 
  2473         {    
  2585         {    
  2474         err = iDownload->SetIntAttribute( EDlAttrUserData, aStatus );
  2586 
       
  2587         iStatus = aStatus;
  2475         }
  2588         }
  2476     
  2589     
  2477     return err;
  2590     return err;
  2478     }
  2591     }
  2479 
  2592 
  2480 
  2593 CCatalogsHttpDownload::TDownloadDeleteState CCatalogsHttpDownload::GetStatusState()
       
  2594 	{
       
  2595 		return iStatus;
       
  2596 	}
  2481 // ---------------------------------------------------------------------------
  2597 // ---------------------------------------------------------------------------
  2482 // Gets delete status and download id from the platform download
  2598 // Gets delete status and download id from the platform download
  2483 // ---------------------------------------------------------------------------
  2599 // ---------------------------------------------------------------------------
  2484 //  
  2600 //  
  2485 TInt CCatalogsHttpDownload::GetDeleteState( 
  2601 TInt CCatalogsHttpDownload::GetDeleteState( 
  2489     TInt32 data = 0;
  2605     TInt32 data = 0;
  2490 
  2606 
  2491     TInt err = KErrNotReady;
  2607     TInt err = KErrNotReady;
  2492     if ( iDownload ) 
  2608     if ( iDownload ) 
  2493         {
  2609         {
  2494         err = iDownload->GetIntAttribute( EDlAttrUserData, data );
  2610 
       
  2611         err = iStatus;
  2495         DLTRACE(("Data: %d", data));
  2612         DLTRACE(("Data: %d", data));
  2496         aStatus = static_cast<TDownloadDeleteState>( data );
  2613         aStatus = static_cast<TDownloadDeleteState>( data );
  2497         }
  2614         }
  2498     DLTRACEOUT(("status: %x", aStatus ));
  2615     DLTRACEOUT(("status: %x", aStatus ));
  2499     return err;
  2616     return err;
  2570             UpdateRequestHeadersL();                    
  2687             UpdateRequestHeadersL();                    
  2571             }
  2688             }
  2572                 
  2689                 
  2573         // Check if the download has been set progressive
  2690         // Check if the download has been set progressive
  2574         TBool progressive = EFalse;
  2691         TBool progressive = EFalse;
  2575         User::LeaveIfError( iDownload->GetBoolAttribute( 
  2692 		try
  2576             EDlAttrProgressive, progressive ) );
  2693 		{
       
  2694 		         progressive =iDownload->attribute(Progressive).toBool(); 
       
  2695 		}
       
  2696         catch(const std::exception& exception)
       
  2697         	{
       
  2698 				 qt_symbian_exception2LeaveL(exception);
       
  2699         	}  
  2577 
  2700 
  2578         
  2701         
  2579         // We want to have progressive downloads because then DL manager uses
  2702         // We want to have progressive downloads because then DL manager uses
  2580         // a smaller download buffer which makes progress events much more
  2703         // a smaller download buffer which makes progress events much more
  2581         // frequent. However, something goes wrong if the progressive flag is
  2704         // frequent. However, something goes wrong if the progressive flag is
  2589              // set the flag if it has already been set because it 
  2712              // set the flag if it has already been set because it 
  2590              // messes the download
  2713              // messes the download
  2591              !iFileIsSet ) 
  2714              !iFileIsSet ) 
  2592             {
  2715             {
  2593             DLTRACE(("Setting download as progressive"));
  2716             DLTRACE(("Setting download as progressive"));
  2594             User::LeaveIfError( iDownload->SetBoolAttribute( 
  2717 						try
  2595                 EDlAttrProgressive, ETrue ) );
  2718 						{
  2596             }
  2719 						   iDownload->setAttribute(Progressive,ETrue);
       
  2720 						}
       
  2721 						catch(const std::exception& exception)
       
  2722 						{
       
  2723 							qt_symbian_exception2LeaveL(exception);
       
  2724 						}  
       
  2725 						}
  2597         
  2726         
  2598         // Doesn't pause the download after content type has been received
  2727         // Doesn't pause the download after content type has been received
  2599         User::LeaveIfError( iDownload->SetBoolAttribute( 
  2728 					try
  2600             EDlAttrNoContentTypeCheck, ETrue ) );
  2729 					{
       
  2730 						iDownload->setAttribute(Progressive,ETrue);
       
  2731 					}
       
  2732 					catch(const std::exception& exception)
       
  2733 					{
       
  2734 						qt_symbian_exception2LeaveL(exception);
       
  2735 					}  
  2601 
  2736 
  2602         if ( !iFileIsSet )
  2737         if ( !iFileIsSet )
  2603             {
  2738             {
  2604             DLTRACE(("Setting filehandle to download"));
  2739             DLTRACE(("Setting filehandle to download"));
  2605             User::LeaveIfError( iDownload->SetFileHandleAttribute( file ) );
  2740            // User::LeaveIfError( iDownload->SetFileHandleAttribute( file ) );
  2606             iFileIsSet = ETrue;                        
  2741             iFileIsSet = ETrue;                        
  2607             }
  2742             }
  2608 
  2743 
  2609         CleanupStack::PopAndDestroy( &file );        
  2744         CleanupStack::PopAndDestroy( &file );        
  2610         }        
  2745         }        
  2611     }
  2746     }
  2612 
  2747 
  2613 
  2748 Download* CCatalogsHttpDownload::GetDownload()
       
  2749 {
       
  2750 	return iDownload;
       
  2751 }
  2614 // ---------------------------------------------------------------------------
  2752 // ---------------------------------------------------------------------------
  2615 // Delete platform download and reset secondary id
  2753 // Delete platform download and reset secondary id
  2616 // ---------------------------------------------------------------------------
  2754 // ---------------------------------------------------------------------------
  2617 //  
  2755 //  
  2618 void CCatalogsHttpDownload::DeletePlatformDownload()
  2756 void CCatalogsHttpDownload::DeletePlatformDownload()
  2619     {
  2757     {
  2620     if ( iDownload )
  2758     if ( iDownload )
  2621         {
  2759         {
  2622         iDownload->Delete();
  2760         iOwner.GetDownloadManager()->removeOne(iDownload);
  2623         iDownload = NULL;
  2761         iDownload = NULL;
  2624         iId.SetSecondaryId( KErrNotFound );
  2762         iId.SetSecondaryId( KErrNotFound );
  2625         }
  2763         }
  2626     }
  2764     }
  2627 
  2765 
  2631 // ---------------------------------------------------------------------------
  2769 // ---------------------------------------------------------------------------
  2632 //  
  2770 //  
  2633 void CCatalogsHttpDownload::UpdateSecondaryIdL()
  2771 void CCatalogsHttpDownload::UpdateSecondaryIdL()
  2634     {
  2772     {
  2635     TInt32 secondaryId = KErrNotFound;
  2773     TInt32 secondaryId = KErrNotFound;
  2636     User::LeaveIfError( 
  2774     secondaryId = iDownload->id();
  2637         iDownload->GetIntAttribute( EDlAttrId, secondaryId ) );
       
  2638     iId.SetSecondaryId( secondaryId );    
  2775     iId.SetSecondaryId( secondaryId );    
  2639     }
  2776     }
  2640 
  2777 
  2641 
  2778 
  2642 // ---------------------------------------------------------------------------
  2779 // ---------------------------------------------------------------------------
  2673        {
  2810        {
  2674        aName.Delete( dotPos, aName.Length()- dotPos );
  2811        aName.Delete( dotPos, aName.Length()- dotPos );
  2675        aName.Append( aExt );
  2812        aName.Append( aExt );
  2676        }
  2813        }
  2677     }
  2814     }
       
  2815     
       
  2816 CCatalogsHttpQTDownload::CCatalogsHttpQTDownload(CCatalogsHttpDownload* aHttpDownload,Download* aDownload)
       
  2817 	{
       
  2818 		iCatalogsHttpDownload = aHttpDownload;
       
  2819 		iDownload = aDownload;
       
  2820 		connect(iDownload, SIGNAL(downloadEvent(DownloadManagerEvent*)), this,SLOT(downloadEvent(DownloadEvent*)));
       
  2821 	}
       
  2822 	
       
  2823 void CCatalogsHttpQTDownload::downloadEvent(WRT::DownloadEvent* aEvent)
       
  2824 	{
       
  2825 		iCatalogsHttpDownload->HandledownloadEventL(*aEvent);
       
  2826 	}
       
  2827 void CCatalogsHttpQTDownload::downloadError(WRT::Error)
       
  2828 	{
       
  2829 		//iCatalogsHttpDownload->HandledownloadEventL(*aEvent);
       
  2830 	}