--- a/browsercore/appfw/Api/Managers/downloadcontroller.cpp Fri May 14 15:40:36 2010 +0300
+++ b/browsercore/appfw/Api/Managers/downloadcontroller.cpp Tue Jun 29 00:46:29 2010 -0400
@@ -1,24 +1,30 @@
/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
*
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program. If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
*
-* Description:
+* Description:
*
*/
-
#include "downloadcontroller.h"
#include "downloadcontroller_p.h"
+#include "downloadproxy_p.h"
+
+#include <QFileInfo>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QNetworkRequest>
@@ -80,7 +86,7 @@
case QNetworkReply::ProtocolFailure:
return "QNetworkReply::ProtocolFailure";
default:
- return 0;
+ return "???";
}
}
@@ -126,293 +132,6 @@
}
}
-static const char * downloadPriorityToString(DownloadPriority priority)
-{
- switch (priority) {
- case High:
- return "High";
- case Low:
- return "Low";
- default:
- return 0;
- }
-}
-
-static const char * downloadScopeToString(DownloadScope scope)
-{
- switch (scope) {
- case Normal:
- return "Normal";
- case Background:
- return "Background";
- default:
- return 0;
- }
-}
-
-static const char * downloadStateToString(DownloadState state)
-{
- switch (state) {
- case DlNone:
- return "DlNone";
- case DlCreated:
- return "DlCreated";
- case DlStarted:
- return "DlStarted";
- case DlInprogress:
- return "DlInprogress";
- case DlPaused:
- return "DlPaused";
- case DlCompleted:
- return "DlCompleted";
- case DlFailed:
- return "DlFailed";
- case DlCancelled:
- return "DlCancelled";
- case DlDescriptorUpdated:
- return "DlDescriptorUpdated";
- default:
- return 0;
- }
-}
-
-static const char * downloadTypeToString(DownloadType type)
-{
- switch (type) {
- case Parallel:
- return "Parallel";
- case Sequential:
- return "Sequential";
- default:
- return 0;
- }
-}
-
-static void debugDownloadStr(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- QString value = download->getAttribute(attribute).toString();
- if (value.length() == 0) {
- return;
- }
-
- qDebug() << "DL" << download->id() << name << value;
-}
-
-static void debugDownloadInt(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- int value = download->getAttribute(attribute).toInt();
- if (value == 0) {
- return;
- }
-
- qDebug() << "DL" << download->id() << name << value;
-}
-
-static void debugDownloadUInt(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- uint value = download->getAttribute(attribute).toUInt();
- if (value == 0) {
- return;
- }
-
- qDebug() << "DL" << download->id() << name << value;
-}
-
-static void debugDownloadError(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- int num = download->getAttribute(attribute).toInt();
-
- const char * str = downloadErrorToString(static_cast<QNetworkReply::NetworkError>(num));
- if (str == 0) {
- str = "???";
- }
-
- qDebug() << "DL" << download->id() << name << num << str;
-}
-
-static void debugDownloadPriority(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- int num = download->getAttribute(attribute).toInt();
-
- const char * str = downloadPriorityToString(static_cast<DownloadPriority>(num));
- if (str == 0) {
- str = "???";
- }
-
- qDebug() << "DL" << download->id() << name << num << str;
-}
-
-static void debugDownloadScope(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- int num = download->getAttribute(attribute).toInt();
-
- const char * str = downloadScopeToString(static_cast<DownloadScope>(num));
- if (str == 0) {
- str = "???";
- }
-
- qDebug() << "DL" << download->id() << name << num << str;
-}
-
-static void debugDownloadState(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- int num = download->getAttribute(attribute).toInt();
-
- const char * str = downloadStateToString(static_cast<DownloadState>(num));
- if (str == 0) {
- str = "???";
- }
-
- qDebug() << "DL" << download->id() << name << num << str;
-}
-
-static void debugDownloadType(
- Download * download,
- DownloadAttribute attribute,
- const char * name)
-{
- int num = download->getAttribute(attribute).toInt();
-
- const char * str = downloadTypeToString(static_cast<DownloadType>(num));
- if (str == 0) {
- str = "???";
- }
-
- qDebug() << "DL" << download->id() << name << num << str;
-}
-
-void DownloadController::debugDownload(Download * download)
-{
- debugDownloadState(download,
- DlDownloadState,
- "DlDownloadState");
-
- debugDownloadError(download,
- DlLastError,
- "DlLastError");
-
- debugDownloadStr(download,
- DlLastErrorString,
- "DlLastErrorString");
-
- debugDownloadStr(download,
- DlSourceUrl,
- "DlSourceUrl");
-
- debugDownloadStr(download,
- DlContentType,
- "DlContentType");
-
- debugDownloadStr(download,
- DlDestPath,
- "DlDestPath");
-
- debugDownloadStr(download,
- DlFileName,
- "DlFileName");
-
- debugDownloadInt(download,
- DlDownloadedSize,
- "DlDownloadedSize");
-
- debugDownloadInt(download,
- DlTotalSize,
- "DlTotalSize");
-
- debugDownloadInt(download,
- DlLastPausedSize,
- "DlLastPausedSize");
-
- debugDownloadInt(download,
- DlPercentage,
- "DlPercentage");
-
- debugDownloadStr(download,
- DlStartTime,
- "DlStartTime");
-
- debugDownloadStr(download,
- DlEndTime,
- "DlEndTime");
-
- debugDownloadUInt(download,
- DlElapsedTime,
- "DlElapsedTime");
-
- debugDownloadStr(download,
- DlRemainingTime,
- "DlRemainingTime");
-
- debugDownloadStr(download,
- DlSpeed,
- "DlSpeed");
-
- debugDownloadScope(download,
- DlDownloadScope,
- "DlDownloadScope");
-
- debugDownloadType(download,
- DlDownloadType,
- "DlDownloadType");
-
- debugDownloadPriority(download,
- DlPriority,
- "DlPriority");
-
- debugDownloadInt(download,
- DlProgressInterval,
- "DlProgressInterval");
-
- debugDownloadStr(download,
- OMADownloadDescriptorName,
- "OMADownloadDescriptorName");
-
- debugDownloadStr(download,
- OMADownloadDescriptorVersion,
- "OMADownloadDescriptorVersion");
-
- debugDownloadStr(download,
- OMADownloadDescriptorType,
- "OMADownloadDescriptorType");
-
- debugDownloadStr(download,
- OMADownloadDescriptorSize,
- "OMADownloadDescriptorSize");
-
- debugDownloadStr(download,
- OMADownloadDescriptorVendor,
- "OMADownloadDescriptorVendor");
-
- debugDownloadStr(download,
- OMADownloadDescriptorDescription,
- "OMADownloadDescriptorDescription");
-
- debugDownloadStr(download,
- OMADownloadDescriptorNextURL,
- "OMADownloadDescriptorNextURL");
-}
-
static void debugDownloadEvent(DEventType type)
{
const char * name = downloadEventToString(type);
@@ -475,6 +194,16 @@
return QString();
}
+void DownloadControllerPrivate::startDownload(const QUrl & url, const QFileInfo & info)
+{
+ Download * download = m_downloadManager->createDownload(url.toString());
+
+ download->setAttribute(DlDestPath, info.absolutePath());
+ download->setAttribute(DlFileName, info.fileName());
+
+ startDownload(download, url);
+}
+
void DownloadControllerPrivate::startDownload(QNetworkReply * reply)
{
QUrl url = reply->url();
@@ -508,9 +237,12 @@
// Start download.
- emit m_downloadController->downloadCreated(download);
+ DownloadProxy downloadProxy(new DownloadProxyData(download));
+
+ emit m_downloadController->downloadCreated(downloadProxy);
download->registerEventReceiver(this);
+
download->start();
}
@@ -526,6 +258,9 @@
return true;
case DownloadsCleared:
+ // ;;; In new DL mgr will have DownloadManager 'Removed' event instead.
+ // ;;; Looks like this will only be generated when all downloads are removed.
+ // ;;; In that case we can emit the same signal.
emit m_downloadController->downloadsCleared();
return true;
@@ -564,34 +299,36 @@
if (errorStr != 0)
error = errorStr;
+ DownloadProxy downloadProxy(new DownloadProxyData(download));
+
switch (type)
{
case Started:
- emit m_downloadController->downloadStarted(download);
+ emit m_downloadController->downloadStarted(downloadProxy);
return true;
case HeaderReceived:
- emit m_downloadController->downloadHeaderReceived(download);
+ emit m_downloadController->downloadHeaderReceived(downloadProxy);
return true;
case Progress:
- emit m_downloadController->downloadProgress(download);
+ emit m_downloadController->downloadProgress(downloadProxy);
return true;
case Completed:
- emit m_downloadController->downloadFinished(download);
+ emit m_downloadController->downloadFinished(downloadProxy);
return true;
case Paused:
- emit m_downloadController->downloadPaused(download, error);
+ emit m_downloadController->downloadPaused(downloadProxy, error);
return true;
case Cancelled:
- emit m_downloadController->downloadCancelled(download, error);
+ emit m_downloadController->downloadCancelled(downloadProxy, error);
return true;
case Failed:
- emit m_downloadController->downloadFailed(download, error);
+ emit m_downloadController->downloadFailed(downloadProxy, error);
return true;
case DescriptorUpdated:
@@ -599,11 +336,11 @@
return true;
case NetworkLoss:
- emit m_downloadController->downloadNetworkLoss(download, error);
+ emit m_downloadController->downloadNetworkLoss(downloadProxy, error);
return true;
case Error:
- emit m_downloadController->downloadError(download, error);
+ emit m_downloadController->downloadError(downloadProxy, error);
return true;
case OMADownloadDescriptorReady:
@@ -671,24 +408,11 @@
delete d;
}
-bool DownloadController::handlePage(QWebPage * page)
+void DownloadController::startDownload(const QUrl & url, const QFileInfo & info)
{
- bool succeeded = true;
+ qDebug() << "Download URL" << url;
- // Handle click on link when the link type is not supported.
- page->setForwardUnsupportedContent(true);
- if (!connect(page, SIGNAL(unsupportedContent(QNetworkReply *)),
- this, SLOT(startDownload(QNetworkReply *)))) {
- succeeded = false;
- };
-
- // Handle Save Link and Save Image requests from the context menu.
- if (!connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)),
- this, SLOT(startDownload(const QNetworkRequest &)))) {
- succeeded = false;
- }
-
- return succeeded;
+ d->startDownload(url, info);
}
void DownloadController::startDownload(QNetworkReply * reply)
@@ -721,15 +445,46 @@
DownloadController::~DownloadController()
{}
-bool DownloadController::handlePage(QWebPage * page)
+void DownloadController::startDownload(const QUrl & url, const QFileInfo & info)
{
- return true;
+ Q_UNUSED(info)
+
+ emit unsupportedDownload(url);
}
void DownloadController::startDownload(QNetworkReply * reply)
-{}
+{
+ QUrl url = reply->url();
+
+ emit unsupportedDownload(url);
+}
void DownloadController::startDownload(const QNetworkRequest & request)
-{}
+{
+ QUrl url = request.url();
+
+ emit unsupportedDownload(url);
+}
#endif // USE_DOWNLOAD_MANAGER
+
+bool DownloadController::handlePage(QWebPage * page)
+{
+ bool succeeded = true;
+
+ // Handle click on link when the link type is not supported.
+ page->setForwardUnsupportedContent(true);
+ if (!connect(page, SIGNAL(unsupportedContent(QNetworkReply *)),
+ this, SLOT(startDownload(QNetworkReply *)))) {
+ succeeded = false;
+ };
+
+ // Handle Save Link and Save Image requests from the context menu.
+ if (!connect(page, SIGNAL(downloadRequested(const QNetworkRequest &)),
+ this, SLOT(startDownload(const QNetworkRequest &)))) {
+ succeeded = false;
+ }
+
+ return succeeded;
+}
+