--- a/ncdengine/engine/transport/src/catalogshttpdownload.cpp Wed Jun 23 18:20:02 2010 +0300
+++ b/ncdengine/engine/transport/src/catalogshttpdownload.cpp Tue Jul 06 14:23:31 2010 +0300
@@ -23,7 +23,10 @@
#include <DocumentHandler.h>
#include <apmstd.h> // TDataType
#include <escapeutils.h>
+#include <downloadmanager.h>
+
+#include <QtGlobal>
#include "catalogshttpdownloadmanagerimpl.h"
#include "catalogshttpobserver.h"
#include "catalogshttpconfigimpl.h"
@@ -95,7 +98,7 @@
//
CCatalogsHttpDownload* CCatalogsHttpDownload::NewLC(
CCatalogsHttpDownloadManager& aOwner,
- RHttpDownload* aDownload,
+ Download* aDownload,
const CCatalogsHttpConfig& aConfig )
{
CCatalogsHttpDownload* self = new( ELeave ) CCatalogsHttpDownload(
@@ -140,7 +143,7 @@
else
{
DLTRACE(( "Deleting download" ));
- iDownload->Delete();
+ iOwner.GetDownloadManager()->removeOne(iDownload);
if ( iState.iOperationState != ECatalogsHttpOpCompleted )
{
@@ -244,8 +247,8 @@
{
iObserver = NULL;
TInt32 state = 0;
- iDownload->GetIntAttribute( EDlAttrState, state );
-
+
+ state = (Download::State)iDownload->attribute(State).toInt();
if ( IsOneOf(
static_cast<THttpDownloadState>( state ),
EHttpDlCreated,
@@ -473,7 +476,14 @@
TInt err = KErrNone;
if ( iDownload )
{
- err = iDownload->Pause();
+ try
+ {
+ iDownload->pause();
+ }
+ catch(const std::exception& exception)
+ {
+ err = qt_symbian_exception2Error(exception);
+ }
}
DLTRACE(("Pause err: %d", err ));
@@ -680,7 +690,8 @@
// client-server communication with the Download manager server
if ( iDownload && iContentSize <= 0 )
{
- iDownload->GetIntAttribute( EDlAttrLength, iContentSize );
+
+ int downloadbytes = iDownload->attribute(DownloadedSize).toInt();
DLTRACE(("Content size from download: %i", iContentSize ));
}
return iContentSize;
@@ -706,7 +717,8 @@
TBool pausable = ETrue;
if ( iDownload )
{
- iDownload->GetBoolAttribute( EDlAttrPausable, pausable );
+
+ pausable=iDownload->attribute(Pausable).toBool();
}
return pausable;
}
@@ -839,7 +851,88 @@
return KErrNone;
}
+void CCatalogsHttpDownload::HandledownloadEventL(DownloadEvent& aEvent)
+{
+
+ switch(aEvent.type())
+ {
+
+ case DownloadEvent::Started:
+
+ break;
+
+ case DownloadEvent::Failed:
+ {
+ TInt32 errorId = -1;
+ SetTransferring( EFalse );
+ errorId = iDownload->attribute(LastError).toInt();
+ if ( ( errorId == ConnectionFailed ||
+ errorId == TransactionFailed ))
+ {
+ DLTRACE(("Try to reconnect"));
+ iReconnectWhenFail = EFalse;
+ iDownload->start();
+ break;
+ }
+ else if ( errorId == ContentExpired ||
+ errorId == PartialContentModified )
+ {
+ DLTRACE(("Content has changed, reset and restart"));
+ iReconnectWhenFail = EFalse;
+ iDownload->cancel();
+ iDownload->start();
+ break;
+ }
+
+ }
+ break;
+
+ case DownloadEvent::Cancelled:
+
+ break;
+ case DownloadEvent::ContentTypeChanged:
+
+ break;
+ case DownloadEvent::HeadersReceived:
+ {
+ // Read the response headers from platform DL manager
+ UpdateResponseHeadersL();
+ UpdateContentType();
+ }
+ break;
+
+ case DownloadEvent::NetworkLoss:
+
+ break;
+
+ case DownloadEvent::Completed:
+ {
+ // move/rename temp file as the target file
+ TRAPD( err, MoveFileL() );
+
+ // DLMAIN-546, delete DL manager's download before starting
+ // the next one so that downloads don't jam, again
+ if ( iDownload )
+ {
+ iTransferredSize = iDownload->attribute(DownloadedSize).toInt();
+
+
+ DLTRACE(("Deleting download"));
+ DeletePlatformDownload();
+ }
+ }
+ break;
+
+ case DownloadEvent::InProgress:
+
+ break;
+
+ default:
+ {
+ }
+ };
+}
// ---------------------------------------------------------------------------
// Handles events from the transaction
// ---------------------------------------------------------------------------
@@ -1025,20 +1118,20 @@
TInt32 statusCode = -1;
- iDownload->GetIntAttribute( EDlAttrStatusCode, statusCode );
- DLINFO( ("Response status: %i", statusCode ) );
+ statusCode = (Download::State)iDownload->attribute(WRT::State).toInt();
+ DLINFO( ("Response status: %i", statusCode ) );
#ifdef CATALOGS_BUILD_CONFIG_DEBUG
TInt32 errorId = 0;
+ errorId=iDownload->attribute(LastError).toInt();
- iDownload->GetIntAttribute( EDlAttrErrorId, errorId );
DLINFO( ("Error id: %i", errorId ) );
#endif
TInt32 globalErrorId = 0;
- iDownload->GetIntAttribute(
- EDlAttrGlobalErrorId, globalErrorId );
+ globalErrorId= iDownload->attribute(LastError).toInt();
+
DLINFO( ("Global error id: %i", globalErrorId ) );
@@ -1085,7 +1178,7 @@
{
DLTRACE(("Try to reconnect"));
iReconnectWhenFail = EFalse;
- iDownload->Start();
+ iDownload->start();
break;
}
@@ -1143,9 +1236,9 @@
// DLMAIN-546, delete DL manager's download before starting
// the next one so that downloads don't jam, again
if ( iDownload )
- {
- iDownload->GetIntAttribute(
- EDlAttrDownloadedSize, iTransferredSize );
+ {
+ iTransferredSize = iDownload->attribute(DownloadedSize).toInt();
+
DLTRACE(("Deleting download"));
DeletePlatformDownload();
@@ -1179,7 +1272,8 @@
DLTRACE(( "Download failed" ));
TInt32 errorId = -1;
SetTransferring( EFalse );
- iDownload->GetIntAttribute( EDlAttrErrorId, errorId );
+ errorId = iDownload->attribute(LastError).toInt();
+
DLINFO( ("Error id: %i", errorId ) );
DLINFO( ("Global error id: %i", globalErrorId ) );
@@ -1190,7 +1284,7 @@
{
DLTRACE(("Try to reconnect"));
iReconnectWhenFail = EFalse;
- iDownload->Start();
+ iDownload->start();
break;
}
else if ( errorId == EContentExpired ||
@@ -1198,8 +1292,8 @@
{
DLTRACE(("Content has changed, reset and restart"));
iReconnectWhenFail = EFalse;
- iDownload->Reset();
- iDownload->Start();
+ iDownload->cancel();
+ iDownload->start();
break;
}
@@ -1388,8 +1482,7 @@
if ( !iPaused )
{
TInt32 globalErrorId = 0;
- iDownload->GetIntAttribute(
- EDlAttrGlobalErrorId, globalErrorId );
+ globalErrorId = iDownload->attribute(LastError).toInt();
DLINFO( ("Global error id: %i", globalErrorId ) );
if ( globalErrorId == KErrCancel )
@@ -1495,7 +1588,8 @@
iReconnectCount = KReconnectAttempts;
TInt32 size = 0;
- iDownload->GetIntAttribute( EDlAttrDownloadedSize, size );
+ size = iDownload->attribute(DownloadedSize).toInt();
+
DLTRACE(("Transferred size from download: %i", size));
if ( size != iTransferredSize )
@@ -1636,7 +1730,7 @@
//
CCatalogsHttpDownload::CCatalogsHttpDownload(
CCatalogsHttpDownloadManager& aOwner,
- RHttpDownload* aDownload ) :
+ Download* aDownload ) :
iOwner( aOwner ),
iDownload( aDownload ),
iState( ECatalogsHttpOpCreated, ECatalogsHttpNone ),
@@ -1659,7 +1753,8 @@
{
// id part will be updated from disk
iId = TCatalogsTransportOperationId( iOwner.SessionId(), KErrNotFound );
-
+ iQTDownload = new CCatalogsHttpQTDownload(this,iDownload);
+
UpdateSecondaryIdL();
User::LeaveIfError( SetDeleteState( EDownloadCanBeDeleted ) );
@@ -1700,8 +1795,11 @@
{
// Download always exists when this is called so no need to check
DLTRACE(("Updating the content type"));
- iDownload->GetStringAttribute( EDlAttrContentType,
- iContentType );
+ QString contentType;
+ contentType= iDownload->attribute(WRT::ContentType).toString();
+ TBuf<KMaxContentTypeLength> ContentType(contentType.utf16());
+ iContentType.Copy(ContentType);
+
}
DLTRACEOUT(("Content-type: %S", &iContentType ));
}
@@ -1821,9 +1919,16 @@
RBuf8 buf;
CleanupClosePushL( buf );
buf.CreateL( KMaxUrlLength );
-
- User::LeaveIfError( iDownload->GetStringAttribute( EDlAttrCurrentUrl,
- buf ) );
+ QString string;
+ try
+ {
+ string = iDownload->attribute(SourceUrl).toString();
+ }
+ catch(const std::exception& exception)
+ {
+ qt_symbian_exception2LeaveL(exception);
+ }
+
// DL manager has the encoded URI
AssignDesL( iEncodedUri, buf );
@@ -1867,8 +1972,8 @@
}
else
{
- User::LeaveIfError( iDownload->SetStringAttribute(
- predefined, headers[i]->Value() ) );
+/* User::LeaveIfError( iDownload->SetStringAttribute(
+ predefined, headers[i]->Value() ) );*/
}
}
@@ -1877,8 +1982,8 @@
if ( iAddedRequestHeaders )
{
DLTRACE(( "added request headers: %S", iAddedRequestHeaders ));
- User::LeaveIfError( iDownload->SetStringAttribute(
- EDlAttrRequestHeaderAddon, *iAddedRequestHeaders ) );
+ /* User::LeaveIfError( iDownload->SetStringAttribute(
+ EDlAttrRequestHeaderAddon, *iAddedRequestHeaders ) );*/
delete iAddedRequestHeaders;
iAddedRequestHeaders = NULL;
}
@@ -2254,10 +2359,17 @@
InitializeDownloadL();
}
});
-
+
if ( err == KErrNone )
{
- err = iDownload->Start();
+ try
+ {
+ iDownload->start();
+ }
+ catch(const std::exception& exception)
+ {
+ qt_symbian_exception2LeaveL(exception);
+ }
}
return err;
}
@@ -2471,13 +2583,17 @@
TInt err = KErrNone;
if ( iDownload )
{
- err = iDownload->SetIntAttribute( EDlAttrUserData, aStatus );
+
+ iStatus = aStatus;
}
return err;
}
-
+CCatalogsHttpDownload::TDownloadDeleteState CCatalogsHttpDownload::GetStatusState()
+ {
+ return iStatus;
+ }
// ---------------------------------------------------------------------------
// Gets delete status and download id from the platform download
// ---------------------------------------------------------------------------
@@ -2491,7 +2607,8 @@
TInt err = KErrNotReady;
if ( iDownload )
{
- err = iDownload->GetIntAttribute( EDlAttrUserData, data );
+
+ err = iStatus;
DLTRACE(("Data: %d", data));
aStatus = static_cast<TDownloadDeleteState>( data );
}
@@ -2572,8 +2689,14 @@
// Check if the download has been set progressive
TBool progressive = EFalse;
- User::LeaveIfError( iDownload->GetBoolAttribute(
- EDlAttrProgressive, progressive ) );
+ try
+ {
+ progressive =iDownload->attribute(Progressive).toBool();
+ }
+ catch(const std::exception& exception)
+ {
+ qt_symbian_exception2LeaveL(exception);
+ }
// We want to have progressive downloads because then DL manager uses
@@ -2591,18 +2714,30 @@
!iFileIsSet )
{
DLTRACE(("Setting download as progressive"));
- User::LeaveIfError( iDownload->SetBoolAttribute(
- EDlAttrProgressive, ETrue ) );
- }
+ try
+ {
+ iDownload->setAttribute(Progressive,ETrue);
+ }
+ catch(const std::exception& exception)
+ {
+ qt_symbian_exception2LeaveL(exception);
+ }
+ }
// Doesn't pause the download after content type has been received
- User::LeaveIfError( iDownload->SetBoolAttribute(
- EDlAttrNoContentTypeCheck, ETrue ) );
+ try
+ {
+ iDownload->setAttribute(Progressive,ETrue);
+ }
+ catch(const std::exception& exception)
+ {
+ qt_symbian_exception2LeaveL(exception);
+ }
if ( !iFileIsSet )
{
DLTRACE(("Setting filehandle to download"));
- User::LeaveIfError( iDownload->SetFileHandleAttribute( file ) );
+ // User::LeaveIfError( iDownload->SetFileHandleAttribute( file ) );
iFileIsSet = ETrue;
}
@@ -2610,7 +2745,10 @@
}
}
-
+Download* CCatalogsHttpDownload::GetDownload()
+{
+ return iDownload;
+}
// ---------------------------------------------------------------------------
// Delete platform download and reset secondary id
// ---------------------------------------------------------------------------
@@ -2619,7 +2757,7 @@
{
if ( iDownload )
{
- iDownload->Delete();
+ iOwner.GetDownloadManager()->removeOne(iDownload);
iDownload = NULL;
iId.SetSecondaryId( KErrNotFound );
}
@@ -2633,8 +2771,7 @@
void CCatalogsHttpDownload::UpdateSecondaryIdL()
{
TInt32 secondaryId = KErrNotFound;
- User::LeaveIfError(
- iDownload->GetIntAttribute( EDlAttrId, secondaryId ) );
+ secondaryId = iDownload->id();
iId.SetSecondaryId( secondaryId );
}
@@ -2675,3 +2812,19 @@
aName.Append( aExt );
}
}
+
+CCatalogsHttpQTDownload::CCatalogsHttpQTDownload(CCatalogsHttpDownload* aHttpDownload,Download* aDownload)
+ {
+ iCatalogsHttpDownload = aHttpDownload;
+ iDownload = aDownload;
+ connect(iDownload, SIGNAL(downloadEvent(DownloadManagerEvent*)), this,SLOT(downloadEvent(DownloadEvent*)));
+ }
+
+void CCatalogsHttpQTDownload::downloadEvent(WRT::DownloadEvent* aEvent)
+ {
+ iCatalogsHttpDownload->HandledownloadEventL(*aEvent);
+ }
+void CCatalogsHttpQTDownload::downloadError(WRT::Error)
+ {
+ //iCatalogsHttpDownload->HandledownloadEventL(*aEvent);
+ }
\ No newline at end of file