diff options
author | Alexis Menard <alexis.menard@trolltech.com> | 2011-06-22 15:00:09 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@trolltech.com> | 2011-06-22 15:00:09 (GMT) |
commit | 1b46b28ddac18fd0f5edc250218dfb15ac05e652 (patch) | |
tree | 57b0fe3414941d5deda54a7b658c7b3d2b0f2268 /examples/webkit/webftpclient | |
parent | 20ec7b41ac600fe670c3c8e6305cc12b10440c30 (diff) | |
parent | e4cce8849bf45be9a111072e3fca7bdf67364e8a (diff) | |
download | Qt-1b46b28ddac18fd0f5edc250218dfb15ac05e652.zip Qt-1b46b28ddac18fd0f5edc250218dfb15ac05e652.tar.gz Qt-1b46b28ddac18fd0f5edc250218dfb15ac05e652.tar.bz2 |
Merge branch '4.8' of git://gitorious.org/qt/qt into 4.8
Diffstat (limited to 'examples/webkit/webftpclient')
-rw-r--r-- | examples/webkit/webftpclient/downloader.cpp | 96 | ||||
-rw-r--r-- | examples/webkit/webftpclient/downloader.h | 75 | ||||
-rw-r--r-- | examples/webkit/webftpclient/ftpreply.cpp | 237 | ||||
-rw-r--r-- | examples/webkit/webftpclient/ftpreply.h | 81 | ||||
-rw-r--r-- | examples/webkit/webftpclient/ftpview.cpp | 68 | ||||
-rw-r--r-- | examples/webkit/webftpclient/ftpview.h | 58 | ||||
-rw-r--r-- | examples/webkit/webftpclient/main.cpp | 57 | ||||
-rw-r--r-- | examples/webkit/webftpclient/networkaccessmanager.cpp | 71 | ||||
-rw-r--r-- | examples/webkit/webftpclient/networkaccessmanager.h | 57 | ||||
-rw-r--r-- | examples/webkit/webftpclient/webftpclient.pro | 22 |
10 files changed, 822 insertions, 0 deletions
diff --git a/examples/webkit/webftpclient/downloader.cpp b/examples/webkit/webftpclient/downloader.cpp new file mode 100644 index 0000000..7185852 --- /dev/null +++ b/examples/webkit/webftpclient/downloader.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QFileDialog> +#include <QMessageBox> +#include <QNetworkRequest> +#include <QNetworkReply> +#include "downloader.h" + +Downloader::Downloader(QWidget *parentWidget, QNetworkAccessManager *manager) + : QObject(parentWidget), manager(manager), parentWidget(parentWidget) +{ +} + +QString Downloader::chooseSaveFile(const QUrl &url) +{ + QString fileName = url.path().split("/").last(); + if (!path.isEmpty()) + fileName = QDir(path).filePath(fileName); + + return QFileDialog::getSaveFileName(parentWidget, tr("Save File"), fileName); +} + +void Downloader::startDownload(const QNetworkRequest &request) +{ + downloads[request.url().toString()] = chooseSaveFile(request.url()); + + QNetworkReply *reply = manager->get(request); + connect(reply, SIGNAL(finished()), this, SLOT(finishDownload())); +} + +void Downloader::saveFile(QNetworkReply *reply) +{ + QString newPath = downloads[reply->url().toString()]; + + if (newPath.isEmpty()) + newPath = chooseSaveFile(reply->url()); + + if (!newPath.isEmpty()) { + QFile file(newPath); + if (file.open(QIODevice::WriteOnly)) { + file.write(reply->readAll()); + file.close(); + path = QDir(newPath).dirName(); + QMessageBox::information(parentWidget, tr("Download Completed"), + tr("Saved '%1'.").arg(newPath)); + } else + QMessageBox::warning(parentWidget, tr("Download Failed"), + tr("Failed to save the file.")); + } +} + +void Downloader::finishDownload() +{ + QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); + saveFile(reply); + downloads.remove(reply->url().toString()); + reply->deleteLater(); +} diff --git a/examples/webkit/webftpclient/downloader.h b/examples/webkit/webftpclient/downloader.h new file mode 100644 index 0000000..8201cea --- /dev/null +++ b/examples/webkit/webftpclient/downloader.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DOWNLOADER_H +#define DOWNLOADER_H + +#include <QDir> +#include <QHash> +#include <QObject> +#include <QUrl> + +class QNetworkAccessManager; +class QNetworkRequest; +class QNetworkReply; +class QWidget; + +class Downloader : public QObject +{ + Q_OBJECT + +public: + Downloader(QWidget *parentWidget, QNetworkAccessManager *manager); + +public slots: + QString chooseSaveFile(const QUrl &url); + void startDownload(const QNetworkRequest &request); + void saveFile(QNetworkReply *reply); + void finishDownload(); + +private: + QNetworkAccessManager *manager; + QNetworkReply *reply; + QHash<QString, QString> downloads; + QString path; + QWidget *parentWidget; +}; + +#endif diff --git a/examples/webkit/webftpclient/ftpreply.cpp b/examples/webkit/webftpclient/ftpreply.cpp new file mode 100644 index 0000000..d3b7aa7 --- /dev/null +++ b/examples/webkit/webftpclient/ftpreply.cpp @@ -0,0 +1,237 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QTextDocument> +#include <QtNetwork> +#include "ftpreply.h" + +//! [constructor] +FtpReply::FtpReply(const QUrl &url) + : QNetworkReply() +{ + ftp = new QFtp(this); + connect(ftp, SIGNAL(listInfo(QUrlInfo)), this, SLOT(processListInfo(QUrlInfo))); + connect(ftp, SIGNAL(readyRead()), this, SLOT(processData())); + connect(ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(processCommand(int, bool))); + + offset = 0; + units = QStringList() << tr("bytes") << tr("K") << tr("M") << tr("G") + << tr("Ti") << tr("Pi") << tr("Ei") << tr("Zi") + << tr("Yi"); + + setUrl(url); + ftp->connectToHost(url.host()); +} +//! [constructor] + +//! [process command] +void FtpReply::processCommand(int, bool err) +{ + if (err) { + setError(ContentNotFoundError, tr("Unknown command")); + emit error(ContentNotFoundError); + return; + } + + switch (ftp->currentCommand()) { + case QFtp::ConnectToHost: + ftp->login(); + break; + + case QFtp::Login: + ftp->list(url().path()); + break; + + case QFtp::List: + if (items.size() == 1) + ftp->get(url().path()); + else + setListContent(); + break; + + case QFtp::Get: + setContent(); + + default: + ; + } +} +//! [process command] + +//! [process list info] +void FtpReply::processListInfo(const QUrlInfo &urlInfo) +{ + items.append(urlInfo); +} +//! [process list info] + +//! [process data] +void FtpReply::processData() +{ + content += ftp->readAll(); +} +//! [process data] + +//! [set content] +void FtpReply::setContent() +{ + open(ReadOnly | Unbuffered); + setHeader(QNetworkRequest::ContentLengthHeader, QVariant(content.size())); + emit readyRead(); + emit finished(); + ftp->close(); +} +//! [set content] + +//! [set list content] +void FtpReply::setListContent() +{ + QUrl u = url(); + if (!u.path().endsWith("/")) + u.setPath(u.path() + "/"); + + QString base_url = url().toString(); + QString base_path = u.path(); + + open(ReadOnly | Unbuffered); + QString content( + "<html>\n" + "<head>\n" + " <title>" + Qt::escape(base_url) + "</title>\n" + " <style type=\"text/css\">\n" + " th { background-color: #aaaaaa; color: black }\n" + " table { border: solid 1px #aaaaaa }\n" + " tr.odd { background-color: #dddddd; color: black\n }\n" + " tr.even { background-color: white; color: black\n }\n" + " </style>\n" + "</head>\n\n" + "<body>\n" + "<h1>" + tr("Listing for %1").arg(base_path) + "</h1>\n\n" + "<table align=\"center\" cellspacing=\"0\" width=\"90%\">\n" + "<tr><th>Name</th><th>Size</th></tr>\n"); + + QUrl parent = u.resolved(QUrl("..")); + + if (parent.isParentOf(u)) + + content += QString("<tr><td><strong><a href=\"" + parent.toString() + "\">" + + tr("Parent directory") + "</a></strong></td><td></td></tr>\n"); + + int i = 0; + foreach (const QUrlInfo &item, items) { + + QUrl child = u.resolved(QUrl(item.name())); + + if (i == 0) + content += QString("<tr class=\"odd\">"); + else + content += QString("<tr class=\"even\">"); + + content += QString("<td><a href=\"" + child.toString() + "\">" + + Qt::escape(item.name()) + "</a></td>"); + + qint64 size = item.size(); + int unit = 0; + while (size) { + qint64 new_size = size/1024; + if (new_size && unit < units.size()) { + size = new_size; + unit += 1; + } else + break; + } + + if (item.isFile()) + content += QString("<td>" + QString::number(size) + " " + + units[unit] + "</td></tr>\n"); + else + content += QString("<td></td></tr>\n"); + + i = 1 - i; + } + + content += QString("</table>\n" + "</body>\n" + "</html>\n"); + + this->content = content.toUtf8(); + + setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/html; charset=UTF-8")); + setHeader(QNetworkRequest::ContentLengthHeader, QVariant(this->content.size())); + emit readyRead(); + emit finished(); + ftp->close(); +} +//! [set list content] + +// QIODevice methods + +//! [abort] +void FtpReply::abort() +{ +} +//! [abort] + +//! [bytes available] +qint64 FtpReply::bytesAvailable() const +{ + return content.size() - offset; +} +//! [bytes available] + +//! [is sequential] +bool FtpReply::isSequential() const +{ + return true; +} +//! [is sequential] + +//! [read data] +qint64 FtpReply::readData(char *data, qint64 maxSize) +{ + if (offset < content.size()) { + qint64 number = qMin(maxSize, content.size() - offset); + memcpy(data, content.constData() + offset, number); + offset += number; + return number; + } else + return -1; +} +//! [read data] diff --git a/examples/webkit/webftpclient/ftpreply.h b/examples/webkit/webftpclient/ftpreply.h new file mode 100644 index 0000000..becd4e4 --- /dev/null +++ b/examples/webkit/webftpclient/ftpreply.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FTPREPLY_H +#define FTPREPLY_H + +#include <QNetworkReply> +#include <QStringList> +#include <QUrlInfo> + +class QFtp; + +//! [class definition] +class FtpReply : public QNetworkReply +{ + Q_OBJECT + +public: + FtpReply(const QUrl &url); + void abort(); + qint64 bytesAvailable() const; + bool isSequential() const; + +protected: + qint64 readData(char *data, qint64 maxSize); + +private slots: + void processCommand(int command, bool error); + void processListInfo(const QUrlInfo &urlInfo); + void processData(); + +private: + void setContent(); + void setListContent(); + + QFtp *ftp; + QList<QUrlInfo> items; + QByteArray content; + qint64 offset; + QStringList units; +}; +//! [class definition] + +#endif diff --git a/examples/webkit/webftpclient/ftpview.cpp b/examples/webkit/webftpclient/ftpview.cpp new file mode 100644 index 0000000..dd3fc8a --- /dev/null +++ b/examples/webkit/webftpclient/ftpview.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "downloader.h" +#include "ftpview.h" +#include "networkaccessmanager.h" + +//! [constructor] +FtpView::FtpView() +{ + QNetworkAccessManager *oldManager = page()->networkAccessManager(); + NetworkAccessManager *newManager = new NetworkAccessManager(oldManager, this); + page()->setNetworkAccessManager(newManager); + + page()->setForwardUnsupportedContent(true); + downloader = new Downloader(this, newManager); + + connect(page(), SIGNAL(unsupportedContent(QNetworkReply *)), + downloader, SLOT(saveFile(QNetworkReply *))); + connect(page(), SIGNAL(downloadRequested(const QNetworkRequest &)), + downloader, SLOT(startDownload(const QNetworkRequest &))); + + connect(this, SIGNAL(urlChanged(const QUrl &)), + this, SLOT(updateWindowTitle(const QUrl &))); +} +//! [constructor] + +void FtpView::updateWindowTitle(const QUrl &url) +{ + setWindowTitle(tr("FTP Client - %1").arg(url.toString())); +} diff --git a/examples/webkit/webftpclient/ftpview.h b/examples/webkit/webftpclient/ftpview.h new file mode 100644 index 0000000..2538812 --- /dev/null +++ b/examples/webkit/webftpclient/ftpview.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QWebView> + +class Downloader; +class QNetworkAccessManager; + +class FtpView : public QWebView +{ + Q_OBJECT + +public: + FtpView(); + +private slots: + void updateWindowTitle(const QUrl &url); + +private: + Downloader *downloader; +}; diff --git a/examples/webkit/webftpclient/main.cpp b/examples/webkit/webftpclient/main.cpp new file mode 100644 index 0000000..ac42e36 --- /dev/null +++ b/examples/webkit/webftpclient/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <QtWebKit> + +#include "ftpview.h" + +//! [main] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + FtpView view; + view.setUrl(QUrl("ftp://ftp.qt.nokia.com")); + view.show(); + + return app.exec(); +} +//! [main] diff --git a/examples/webkit/webftpclient/networkaccessmanager.cpp b/examples/webkit/webftpclient/networkaccessmanager.cpp new file mode 100644 index 0000000..e52c7fe --- /dev/null +++ b/examples/webkit/webftpclient/networkaccessmanager.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtNetwork> +#include "networkaccessmanager.h" +#include "ftpreply.h" + +//! [constructor] +NetworkAccessManager::NetworkAccessManager(QNetworkAccessManager *manager, QObject *parent) + : QNetworkAccessManager(parent) +{ + setCache(manager->cache()); + setCookieJar(manager->cookieJar()); + setProxy(manager->proxy()); + setProxyFactory(manager->proxyFactory()); +} +//! [constructor] + +//! [create request] +QNetworkReply *NetworkAccessManager::createRequest( + QNetworkAccessManager::Operation operation, const QNetworkRequest &request, + QIODevice *device) +{ + if (request.url().scheme() != "ftp") + return QNetworkAccessManager::createRequest(operation, request, device); + + if (operation == GetOperation) + // Handle ftp:// URLs separately by creating custom QNetworkReply + // objects. + return new FtpReply(request.url()); + else + return QNetworkAccessManager::createRequest(operation, request, device); +} +//! [create request] diff --git a/examples/webkit/webftpclient/networkaccessmanager.h b/examples/webkit/webftpclient/networkaccessmanager.h new file mode 100644 index 0000000..256ae82 --- /dev/null +++ b/examples/webkit/webftpclient/networkaccessmanager.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef NETWORKACCESSMANAGER_H +#define NETWORKACCESSMANAGER_H + +#include <QNetworkAccessManager> + +class NetworkAccessManager : public QNetworkAccessManager +{ + Q_OBJECT + +public: + NetworkAccessManager(QNetworkAccessManager *oldManager, QObject *parent = 0); + +protected: + QNetworkReply *createRequest(Operation operation, const QNetworkRequest &request, QIODevice *device); +}; + +#endif diff --git a/examples/webkit/webftpclient/webftpclient.pro b/examples/webkit/webftpclient/webftpclient.pro new file mode 100644 index 0000000..6c17410 --- /dev/null +++ b/examples/webkit/webftpclient/webftpclient.pro @@ -0,0 +1,22 @@ +HEADERS = downloader.h \ + ftpreply.h \ + ftpview.h \ + networkaccessmanager.h +SOURCES = downloader.cpp \ + ftpreply.cpp \ + ftpview.cpp \ + main.cpp \ + networkaccessmanager.cpp + +QT += network webkit + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/webkit/webftpclient +sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/webftpclient +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000EFEF + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} |