2006-11-05 19:52:46 +01:00
|
|
|
#include "sugar-download-manager.h"
|
2006-10-26 22:21:26 +02:00
|
|
|
|
|
|
|
#include "SugarDownload.h"
|
|
|
|
|
|
|
|
GSugarDownload::GSugarDownload()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSugarDownload::~GSugarDownload()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS3 (GSugarDownload,
|
|
|
|
nsIWebProgressListener,
|
|
|
|
nsIWebProgressListener2,
|
|
|
|
nsITransfer)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::Init (nsIURI *aSource,
|
|
|
|
nsIURI *aTarget,
|
|
|
|
const nsAString &aDisplayName,
|
|
|
|
nsIMIMEInfo *aMIMEInfo,
|
|
|
|
PRTime aStartTime,
|
|
|
|
nsILocalFile *aTempFile,
|
|
|
|
nsICancelable *aCancelable)
|
|
|
|
{
|
|
|
|
mSource = aSource;
|
2006-10-27 15:39:29 +02:00
|
|
|
aTarget->GetPath(mTargetFileName);
|
2006-10-26 22:21:26 +02:00
|
|
|
mMIMEInfo = aMIMEInfo;
|
|
|
|
mTempFile = aTempFile;
|
2006-10-27 15:39:29 +02:00
|
|
|
|
2006-10-26 22:21:26 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
|
|
|
PRUint32 aStateFlags, nsresult aStatus)
|
2006-11-01 19:43:59 +01:00
|
|
|
{
|
2006-11-05 19:52:46 +01:00
|
|
|
SugarDownloadManager *download_manager = sugar_get_download_manager();
|
2006-11-01 19:43:59 +01:00
|
|
|
|
|
|
|
if (((aStateFlags & STATE_IS_REQUEST) &&
|
2006-10-26 22:21:26 +02:00
|
|
|
(aStateFlags & STATE_IS_NETWORK) &&
|
2006-11-01 19:43:59 +01:00
|
|
|
(aStateFlags & STATE_START)) ||
|
|
|
|
aStateFlags == STATE_START) {
|
|
|
|
|
|
|
|
nsCString url;
|
|
|
|
nsCString mimeType;
|
2006-10-26 22:21:26 +02:00
|
|
|
|
|
|
|
mMIMEInfo->GetMIMEType(mimeType);
|
|
|
|
mSource->GetSpec(url);
|
2006-10-27 15:39:29 +02:00
|
|
|
|
2006-11-05 19:52:46 +01:00
|
|
|
sugar_download_manager_download_started(download_manager,
|
2006-11-01 19:43:59 +01:00
|
|
|
url.get(),
|
|
|
|
mimeType.get(),
|
|
|
|
mTargetFileName.get());
|
|
|
|
|
|
|
|
} else if (((aStateFlags & STATE_IS_REQUEST) &&
|
|
|
|
(aStateFlags & STATE_IS_NETWORK) &&
|
|
|
|
(aStateFlags & STATE_STOP)) ||
|
|
|
|
aStateFlags == STATE_STOP) {
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED (aStatus)) {
|
2006-11-05 19:52:46 +01:00
|
|
|
sugar_download_manager_download_completed(download_manager,
|
2006-11-01 19:43:59 +01:00
|
|
|
mTargetFileName.get());
|
|
|
|
} else {
|
2006-11-05 19:52:46 +01:00
|
|
|
sugar_download_manager_download_cancelled(download_manager,
|
2006-11-01 19:43:59 +01:00
|
|
|
mTargetFileName.get());
|
|
|
|
}
|
2006-10-26 22:21:26 +02:00
|
|
|
}
|
2006-11-01 19:43:59 +01:00
|
|
|
|
2006-10-26 22:21:26 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::OnProgressChange (nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 aCurSelfProgress,
|
|
|
|
PRInt32 aMaxSelfProgress,
|
|
|
|
PRInt32 aCurTotalProgress,
|
|
|
|
PRInt32 aMaxTotalProgress)
|
|
|
|
{
|
|
|
|
return OnProgressChange64 (aWebProgress, aRequest,
|
|
|
|
aCurSelfProgress, aMaxSelfProgress,
|
|
|
|
aCurTotalProgress, aMaxTotalProgress);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::OnProgressChange64 (nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt64 aCurSelfProgress,
|
|
|
|
PRInt64 aMaxSelfProgress,
|
|
|
|
PRInt64 aCurTotalProgress,
|
|
|
|
PRInt64 aMaxTotalProgress)
|
2006-11-01 19:43:59 +01:00
|
|
|
{
|
2006-11-05 19:52:46 +01:00
|
|
|
SugarDownloadManager *download_manager = sugar_get_download_manager();
|
2006-11-01 19:43:59 +01:00
|
|
|
PRInt32 percentComplete =
|
|
|
|
(PRInt32)(((float)aCurSelfProgress / (float)aMaxSelfProgress) * 100.0);
|
|
|
|
|
2006-11-05 19:52:46 +01:00
|
|
|
sugar_download_manager_update_progress(download_manager,
|
2006-11-01 19:43:59 +01:00
|
|
|
mTargetFileName.get(),
|
|
|
|
percentComplete);
|
|
|
|
|
2006-10-26 22:21:26 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::OnLocationChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::OnStatusChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
|
|
|
nsresult aStatus, const PRUnichar *aMessage)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GSugarDownload::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|