85476431f47b2dcb8b1e8f0280cf92f48ad5d847
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / qt / qwebdownloaditem.cpp
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #include "config.h"
22 #include "qwebdownloaditem_p.h"
23
24 #include "DownloadProxy.h"
25 #include "qwebdownloaditem_p_p.h"
26
27 QWebDownloadItemPrivate::QWebDownloadItemPrivate(QWebDownloadItem* qq)
28     : q(qq)
29     , downloadProxy(0)
30     , expectedContentLength(0)
31     , totalBytesReceived(0)
32 {
33 }
34
35 QWebDownloadItem::QWebDownloadItem(QObject* parent)
36     : QObject(parent)
37     , d(new QWebDownloadItemPrivate(this))
38 {
39 }
40
41 QWebDownloadItem::~QWebDownloadItem()
42 {
43     delete d;
44 }
45
46 QUrl QWebDownloadItem::url() const
47 {
48     return d->sourceUrl;
49 }
50
51 QString QWebDownloadItem::destinationPath() const
52 {
53     return d->destinationPath;
54 }
55
56 void QWebDownloadItem::setDestinationPath(const QString& destination)
57 {
58     d->destinationPath = destination;
59 }
60
61 QString QWebDownloadItem::suggestedFilename() const
62 {
63     return d->suggestedFilename;
64 }
65
66 QString QWebDownloadItem::mimeType() const
67 {
68     return d->mimeType;
69 }
70
71 quint64 QWebDownloadItem::expectedContentLength() const
72 {
73     return d->expectedContentLength;
74 }
75
76 quint64 QWebDownloadItem::totalBytesReceived() const
77 {
78     return d->totalBytesReceived;
79 }
80
81 void QWebDownloadItem::cancel()
82 {
83     ASSERT(d->downloadProxy);
84     d->downloadProxy->cancel();
85 }
86
87 void QWebDownloadItem::start()
88 {
89     ASSERT(!d->suggestedFilename.isEmpty());
90
91     if (d->destinationPath.isEmpty())
92         d->destinationPath = d->suggestedFilename;
93
94     d->downloadProxy->startTransfer(d->destinationPath);
95 }
96