summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2011-03-10 18:14:58 (GMT)
committerDavid Boddie <david.boddie@nokia.com>2011-03-10 18:14:58 (GMT)
commit0142d7fc89a5eecb542a5650c4864f7581f73d83 (patch)
treeecf499d9addd19d84cf9e212f1516f8fb345d2f0 /examples
parent17e19884dd3da255af0467d095076769fc7f480b (diff)
downloadQt-0142d7fc89a5eecb542a5650c4864f7581f73d83.zip
Qt-0142d7fc89a5eecb542a5650c4864f7581f73d83.tar.gz
Qt-0142d7fc89a5eecb542a5650c4864f7581f73d83.tar.bz2
Doc: Added QtWebKit examples from Qt Quarterly 26 and 32.
Diffstat (limited to 'examples')
-rw-r--r--examples/webkit/simplewebplugin/csvfactory.cpp91
-rw-r--r--examples/webkit/simplewebplugin/csvfactory.h67
-rw-r--r--examples/webkit/simplewebplugin/csvview.cpp176
-rw-r--r--examples/webkit/simplewebplugin/csvview.h71
-rw-r--r--examples/webkit/simplewebplugin/main.cpp52
-rw-r--r--examples/webkit/simplewebplugin/mainwindow.cpp63
-rw-r--r--examples/webkit/simplewebplugin/mainwindow.h54
-rw-r--r--examples/webkit/simplewebplugin/simplecsvplugin.qrc6
-rw-r--r--examples/webkit/simplewebplugin/simplewebplugin.pro23
-rw-r--r--examples/webkit/webftpclient/downloader.cpp96
-rw-r--r--examples/webkit/webftpclient/downloader.h75
-rw-r--r--examples/webkit/webftpclient/ftpreply.cpp237
-rw-r--r--examples/webkit/webftpclient/ftpreply.h81
-rw-r--r--examples/webkit/webftpclient/ftpview.cpp68
-rw-r--r--examples/webkit/webftpclient/ftpview.h58
-rw-r--r--examples/webkit/webftpclient/main.cpp57
-rw-r--r--examples/webkit/webftpclient/networkaccessmanager.cpp71
-rw-r--r--examples/webkit/webftpclient/networkaccessmanager.h57
-rw-r--r--examples/webkit/webftpclient/webftpclient.pro22
-rw-r--r--examples/webkit/webkit.pro5
-rw-r--r--examples/webkit/webplugin/csvfactory.cpp98
-rw-r--r--examples/webkit/webplugin/csvfactory.h67
-rw-r--r--examples/webkit/webplugin/csvplugin.qrc6
-rw-r--r--examples/webkit/webplugin/csvview.cpp190
-rw-r--r--examples/webkit/webplugin/csvview.h79
-rw-r--r--examples/webkit/webplugin/main.cpp50
-rw-r--r--examples/webkit/webplugin/mainwindow.cpp59
-rw-r--r--examples/webkit/webplugin/mainwindow.h54
-rw-r--r--examples/webkit/webplugin/webplugin.pro23
29 files changed, 2055 insertions, 1 deletions
diff --git a/examples/webkit/simplewebplugin/csvfactory.cpp b/examples/webkit/simplewebplugin/csvfactory.cpp
new file mode 100644
index 0000000..56b4558
--- /dev/null
+++ b/examples/webkit/simplewebplugin/csvfactory.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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 <QtNetwork>
+#include <QWebPluginFactory>
+#include "csvfactory.h"
+#include "csvview.h"
+
+//! [constructor]
+CSVFactory::CSVFactory(QObject *parent)
+ : QWebPluginFactory(parent)
+{
+ manager = new QNetworkAccessManager(this);
+};
+//! [constructor]
+
+//! [begin create]
+QObject *CSVFactory::create(const QString &mimeType, const QUrl &url,
+ const QStringList &argumentNames,
+ const QStringList &argumentValues) const
+{
+ if (mimeType != "text/csv")
+ return 0;
+
+ CSVView *view = new CSVView(argumentValues[argumentNames.indexOf("type")]);
+//! [begin create]
+
+//! [submit request]
+ QNetworkRequest request(url);
+ QNetworkReply *reply = manager->get(request);
+ connect(reply, SIGNAL(finished()), view, SLOT(updateModel()));
+ connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
+
+ return view;
+}
+//! [submit request]
+
+//! [plugins]
+QList<QWebPluginFactory::Plugin> CSVFactory::plugins() const
+{
+ QWebPluginFactory::MimeType mimeType;
+ mimeType.name = "text/csv";
+ mimeType.description = "Comma-separated values";
+ mimeType.fileExtensions = QStringList() << "csv";
+
+ QWebPluginFactory::Plugin plugin;
+ plugin.name = "CSV file viewer";
+ plugin.description = "A CSV file Web plugin.";
+ plugin.mimeTypes = QList<MimeType>() << mimeType;
+
+ return QList<QWebPluginFactory::Plugin>() << plugin;
+}
+//! [plugins]
diff --git a/examples/webkit/simplewebplugin/csvfactory.h b/examples/webkit/simplewebplugin/csvfactory.h
new file mode 100644
index 0000000..0b046c5
--- /dev/null
+++ b/examples/webkit/simplewebplugin/csvfactory.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** 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 CSVFACTORY_H
+#define CSVFACTORY_H
+
+#include <QNetworkRequest>
+#include <QWebPluginFactory>
+
+class QNetworkAccessManager;
+class QNetworkReply;
+
+//! [plugin factory]
+class CSVFactory : public QWebPluginFactory
+{
+ Q_OBJECT
+
+public:
+ CSVFactory(QObject *parent = 0);
+ QObject *create(const QString &mimeType, const QUrl &url,
+ const QStringList &argumentNames,
+ const QStringList &argumentValues) const;
+ QList<QWebPluginFactory::Plugin> plugins() const;
+
+private:
+ QNetworkAccessManager *manager;
+};
+//! [plugin factory]
+
+#endif
diff --git a/examples/webkit/simplewebplugin/csvview.cpp b/examples/webkit/simplewebplugin/csvview.cpp
new file mode 100644
index 0000000..0a3eff7
--- /dev/null
+++ b/examples/webkit/simplewebplugin/csvview.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** 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 <QtNetwork>
+#include "csvview.h"
+
+//! [constructor]
+CSVView::CSVView(const QString &mimeType, QWidget *parent)
+ : QTableView(parent)
+{
+ this->mimeType = mimeType;
+}
+//! [constructor]
+
+//! [update model begin]
+void CSVView::updateModel()
+{
+ QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
+
+ if (reply->error() != QNetworkReply::NoError)
+ return;
+
+ bool hasHeader = false;
+ QString charset = "latin1";
+//! [update model begin]
+
+ foreach (QString piece, mimeType.split(";")) {
+ piece = piece.trimmed();
+ if (piece.contains("=")) {
+ int index = piece.indexOf("=");
+ QString left = piece.left(index).trimmed();
+ QString right = piece.mid(index + 1).trimmed();
+ if (left == "header")
+ hasHeader = (right == "present");
+ else if (left == "charset")
+ charset = right;
+ }
+ }
+
+//! [read data begin]
+ QTextStream stream(reply);
+ stream.setCodec(QTextCodec::codecForName(charset.toLatin1()));
+
+ QStandardItemModel *model = new QStandardItemModel(this);
+//! [read data begin]
+ QList<QStandardItem *> items;
+ bool firstLine = hasHeader;
+ bool wasQuote = false;
+ bool wasCR = false;
+ bool quoted = false;
+ QString text;
+
+ while (!stream.atEnd()) {
+
+ QString ch = stream.read(1);
+
+ if (wasQuote) {
+ if (ch == "\"") {
+ if (quoted) {
+ text += ch; // quoted "" are inserted as "
+ wasQuote = false; // no quotes are pending
+ } else {
+ quoted = true; // unquoted "" starts quoting
+ wasQuote = true; // with a pending quote
+ }
+ continue; // process the next character
+
+ } else {
+ quoted = !quoted; // process the pending quote
+ wasQuote = false; // no quotes are pending
+ } // process the current character
+
+ } else if (wasCR) {
+ wasCR = false;
+
+ if (ch == "\n") { // CR LF represents the end of a row
+ if (!text.isEmpty())
+ items.append(new QStandardItem(QString(text)));
+
+ addRow(firstLine, model, items);
+ items.clear();
+ text = "";
+ firstLine = false;
+ continue; // process the next character
+ } else
+ text += "\r"; // CR on its own is inserted
+ } // process the current character
+
+ // wasQuote is never true here.
+ // wasCR is never true here.
+
+ if (ch == "\"")
+ wasQuote = true; // handle the pending quote later
+
+ else if (ch == ",") {
+ if (quoted)
+ text += ch;
+ else {
+ items.append(new QStandardItem(QString(text)));
+ text = "";
+ }
+ }
+
+ else if (ch == "\r") {
+ if (!quoted)
+ wasCR = true;
+ else
+ text += ch;
+ }
+
+ else if (ch == "\n")
+ text += ch;
+ else
+ text += ch;
+
+ }
+
+ if (items.count() > 0)
+ addRow(firstLine, model, items);
+
+//! [update model]
+ reply->close();
+
+ setModel(model);
+ resizeColumnsToContents();
+ horizontalHeader()->setStretchLastSection(true);
+}
+//! [update model]
+
+void CSVView::addRow(bool firstLine, QStandardItemModel *model,
+ const QList<QStandardItem *> &items)
+{
+ if (firstLine) {
+ for (int j = 0; j < items.count(); ++j)
+ model->setHorizontalHeaderItem(j, items[j]);
+ } else
+ model->appendRow(items);
+}
diff --git a/examples/webkit/simplewebplugin/csvview.h b/examples/webkit/simplewebplugin/csvview.h
new file mode 100644
index 0000000..0a136f3
--- /dev/null
+++ b/examples/webkit/simplewebplugin/csvview.h
@@ -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$
+**
+****************************************************************************/
+
+#ifndef CSVVIEW_H
+#define CSVVIEW_H
+
+#include <QNetworkRequest>
+#include <QStandardItemModel>
+#include <QTableView>
+#include <QWebPluginFactory>
+
+class QNetworkAccessManager;
+class QNetworkReply;
+
+//! [definition]
+class CSVView : public QTableView
+{
+ Q_OBJECT
+
+public:
+ CSVView(const QString &mimeType, QWidget *parent = 0);
+
+public slots:
+ void updateModel();
+
+private:
+ void addRow(bool firstLine, QStandardItemModel *model,
+ const QList<QStandardItem *> &items);
+
+ QString mimeType;
+};
+//! [definition]
+
+#endif
diff --git a/examples/webkit/simplewebplugin/main.cpp b/examples/webkit/simplewebplugin/main.cpp
new file mode 100644
index 0000000..8e823b1
--- /dev/null
+++ b/examples/webkit/simplewebplugin/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** 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 <QApplication>
+#include "mainwindow.h"
+
+//! [main]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [main]
diff --git a/examples/webkit/simplewebplugin/mainwindow.cpp b/examples/webkit/simplewebplugin/mainwindow.cpp
new file mode 100644
index 0000000..60bdd8b
--- /dev/null
+++ b/examples/webkit/simplewebplugin/mainwindow.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 <QFile>
+#include <QWebView>
+#include "csvfactory.h"
+#include "mainwindow.h"
+
+//! [constructor]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ QWebSettings::globalSettings()->setAttribute(
+ QWebSettings::PluginsEnabled, true);
+
+ QWebView *webView = new QWebView;
+ CSVFactory *factory = new CSVFactory(this);
+ webView->page()->setPluginFactory(factory);
+ QFile file(":/pages/index.html");
+ file.open(QFile::ReadOnly);
+ webView->setHtml(file.readAll());
+
+ setCentralWidget(webView);
+ setWindowTitle(tr("Simple Web Plugin Example"));
+}
+//! [constructor]
diff --git a/examples/webkit/simplewebplugin/mainwindow.h b/examples/webkit/simplewebplugin/mainwindow.h
new file mode 100644
index 0000000..12c8306
--- /dev/null
+++ b/examples/webkit/simplewebplugin/mainwindow.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** 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 MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+};
+
+#endif
diff --git a/examples/webkit/simplewebplugin/simplecsvplugin.qrc b/examples/webkit/simplewebplugin/simplecsvplugin.qrc
new file mode 100644
index 0000000..14f80e7
--- /dev/null
+++ b/examples/webkit/simplewebplugin/simplecsvplugin.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>pages/index.html</file>
+ <file>data/accounts.csv</file>
+ </qresource>
+</RCC>
diff --git a/examples/webkit/simplewebplugin/simplewebplugin.pro b/examples/webkit/simplewebplugin/simplewebplugin.pro
new file mode 100644
index 0000000..c3f5a9b
--- /dev/null
+++ b/examples/webkit/simplewebplugin/simplewebplugin.pro
@@ -0,0 +1,23 @@
+QT += webkit network
+
+HEADERS = csvfactory.h \
+ csvview.h \
+ mainwindow.h
+
+SOURCES = csvfactory.cpp \
+ csvview.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+RESOURCES = simplecsvplugin.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit/simplewebplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/simplewebplugin
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000EFFF
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
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..abbd231
--- /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..6b73680
--- /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..784bf01
--- /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)
+}
diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro
index 6a1d8f8..c2d96f4 100644
--- a/examples/webkit/webkit.pro
+++ b/examples/webkit/webkit.pro
@@ -5,7 +5,10 @@ SUBDIRS += domtraversal \
fancybrowser \
simpleselector \
imageanalyzer \
- framecapture
+ framecapture \
+ simplewebplugin \
+ webplugin \
+ webftpclient
contains(QT_CONFIG, openssl):SUBDIRS += googlechat
diff --git a/examples/webkit/webplugin/csvfactory.cpp b/examples/webkit/webplugin/csvfactory.cpp
new file mode 100644
index 0000000..b605a76
--- /dev/null
+++ b/examples/webkit/webplugin/csvfactory.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** 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 <QtNetwork>
+#include <QtWebKit>
+#include "csvfactory.h"
+#include "csvview.h"
+
+CSVFactory::CSVFactory(QWebView *webView, QObject *parent)
+ : QWebPluginFactory(parent)
+{
+ manager = new QNetworkAccessManager(this);
+ this->webView = webView;
+};
+
+//! [begin create]
+QObject *CSVFactory::create(const QString &mimeType, const QUrl &url,
+ const QStringList &argumentNames,
+ const QStringList &argumentValues) const
+{
+ if (mimeType != "text/csv")
+ return 0;
+
+ QHash<QString, QString> arguments;
+ for (int i = 0; i < argumentNames.count(); ++i)
+ arguments[argumentNames[i]] = argumentValues[i];
+
+ CSVView *view = new CSVView(arguments["type"]);
+//! [begin create]
+
+//! [create connection]
+ QWebFrame *frame = webView->page()->mainFrame();
+ frame->addToJavaScriptWindowObject("view", view);
+ frame->evaluateJavaScript("view.rowSelected.connect(fillInTable);\n");
+//! [create connection]
+
+//! [submit request]
+ QNetworkRequest request(url);
+ QNetworkReply *reply = manager->get(request);
+ connect(reply, SIGNAL(finished()), view, SLOT(updateModel()));
+ connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
+
+ return view;
+}
+//! [submit request]
+
+QList<QWebPluginFactory::Plugin> CSVFactory::plugins() const
+{
+ QWebPluginFactory::MimeType mimeType;
+ mimeType.name = "text/csv";
+ mimeType.description = "Comma-separated values";
+ mimeType.fileExtensions = QStringList() << "csv";
+
+ QWebPluginFactory::Plugin plugin;
+ plugin.name = "CSV file viewer";
+ plugin.description = "A CSV file Web plugin.";
+ plugin.mimeTypes = QList<MimeType>() << mimeType;
+
+ return QList<QWebPluginFactory::Plugin>() << plugin;
+}
diff --git a/examples/webkit/webplugin/csvfactory.h b/examples/webkit/webplugin/csvfactory.h
new file mode 100644
index 0000000..5a44c50
--- /dev/null
+++ b/examples/webkit/webplugin/csvfactory.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** 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 CSVFACTORY_H
+#define CSVFACTORY_H
+
+#include <QNetworkRequest>
+#include <QWebPluginFactory>
+
+class QNetworkAccessManager;
+class QNetworkReply;
+class QWebView;
+
+class CSVFactory : public QWebPluginFactory
+{
+ Q_OBJECT
+
+public:
+ CSVFactory(QWebView *webView, QObject *parent = 0);
+ QObject *create(const QString &mimeType, const QUrl &url,
+ const QStringList &argumentNames,
+ const QStringList &argumentValues) const;
+ QList<QWebPluginFactory::Plugin> plugins() const;
+
+private:
+ QNetworkAccessManager *manager;
+ QWebView *webView;
+};
+
+#endif
diff --git a/examples/webkit/webplugin/csvplugin.qrc b/examples/webkit/webplugin/csvplugin.qrc
new file mode 100644
index 0000000..14f80e7
--- /dev/null
+++ b/examples/webkit/webplugin/csvplugin.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>pages/index.html</file>
+ <file>data/accounts.csv</file>
+ </qresource>
+</RCC>
diff --git a/examples/webkit/webplugin/csvview.cpp b/examples/webkit/webplugin/csvview.cpp
new file mode 100644
index 0000000..90a1206
--- /dev/null
+++ b/examples/webkit/webplugin/csvview.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** 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 <QtNetwork>
+#include "csvview.h"
+
+//! [constructor]
+CSVView::CSVView(const QString &mimeType, QWidget *parent)
+ : QTableView(parent)
+{
+ this->mimeType = mimeType;
+
+ setEditTriggers(NoEditTriggers);
+ setSelectionBehavior(SelectRows);
+ setSelectionMode(SingleSelection);
+}
+//! [constructor]
+
+void CSVView::updateModel()
+{
+ QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
+
+ if (reply->error() != QNetworkReply::NoError)
+ return;
+
+ bool hasHeader = false;
+ QString charset = "latin1";
+
+ foreach (QString piece, mimeType.split(";")) {
+ piece = piece.trimmed();
+ if (piece.contains("=")) {
+ int index = piece.indexOf("=");
+ QString left = piece.left(index).trimmed();
+ QString right = piece.mid(index + 1).trimmed();
+ if (left == "header")
+ hasHeader = (right == "present");
+ else if (left == "charset")
+ charset = right;
+ }
+ }
+
+ QTextStream stream(reply);
+ stream.setCodec(QTextCodec::codecForName(charset.toLatin1()));
+
+ QStandardItemModel *model = new QStandardItemModel(this);
+ QList<QStandardItem *> items;
+ bool firstLine = hasHeader;
+ bool wasQuote = false;
+ bool wasCR = false;
+ bool quoted = false;
+ QString text;
+
+ while (!stream.atEnd()) {
+
+ QString ch = stream.read(1);
+
+ if (wasQuote) {
+ if (ch == "\"") {
+ if (quoted) {
+ text += ch; // quoted "" are inserted as "
+ wasQuote = false; // no quotes are pending
+ } else {
+ quoted = true; // unquoted "" starts quoting
+ wasQuote = true; // with a pending quote
+ }
+ continue; // process the next character
+
+ } else {
+ quoted = !quoted; // process the pending quote
+ wasQuote = false; // no quotes are pending
+ } // process the current character
+
+ } else if (wasCR) {
+ wasCR = false;
+
+ if (ch == "\n") { // CR LF represents the end of a row
+ if (!text.isEmpty())
+ items.append(new QStandardItem(QString(text)));
+
+ addRow(firstLine, model, items);
+ items.clear();
+ text = "";
+ firstLine = false;
+ continue; // process the next character
+ } else
+ text += "\r"; // CR on its own is inserted
+ } // process the current character
+
+ // wasQuote is never true here.
+ // wasCR is never true here.
+
+ if (ch == "\"")
+ wasQuote = true; // handle the pending quote later
+
+ else if (ch == ",") {
+ if (quoted)
+ text += ch;
+ else {
+ items.append(new QStandardItem(QString(text)));
+ text = "";
+ }
+ }
+
+ else if (ch == "\r") {
+ if (!quoted)
+ wasCR = true;
+ else
+ text += ch;
+ }
+
+ else if (ch == "\n")
+ text += ch;
+ else
+ text += ch;
+
+ }
+
+ if (items.count() > 0)
+ addRow(firstLine, model, items);
+
+ reply->close();
+
+ setModel(model);
+
+ connect(selectionModel(),
+ SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+ this, SLOT(exportRow(const QModelIndex &)));
+
+ resizeColumnsToContents();
+ horizontalHeader()->setStretchLastSection(true);
+}
+
+void CSVView::addRow(bool firstLine, QStandardItemModel *model,
+ const QList<QStandardItem *> &items)
+{
+ if (firstLine) {
+ for (int j = 0; j < items.count(); ++j)
+ model->setHorizontalHeaderItem(j, items[j]);
+ } else
+ model->appendRow(items);
+}
+
+//! [export row]
+void CSVView::exportRow(const QModelIndex &current)
+{
+ QString name = model()->index(current.row(), 0).data().toString();
+ QString address = model()->index(current.row(), 1).data().toString();
+ QString quantity = model()->index(current.row(), 2).data().toString();
+
+ emit rowSelected(name, address, quantity);
+}
+//! [export row]
diff --git a/examples/webkit/webplugin/csvview.h b/examples/webkit/webplugin/csvview.h
new file mode 100644
index 0000000..bf8918b
--- /dev/null
+++ b/examples/webkit/webplugin/csvview.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** 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 CSVVIEW_H
+#define CSVVIEW_H
+
+#include <QNetworkRequest>
+#include <QStandardItemModel>
+#include <QTableView>
+#include <QWebPluginFactory>
+
+class QNetworkAccessManager;
+class QNetworkReply;
+class QWebFrame;
+
+//! [definition]
+class CSVView : public QTableView
+{
+ Q_OBJECT
+
+public:
+ CSVView(const QString &mimeType, QWidget *parent = 0);
+
+signals:
+ void rowSelected(const QString &name, const QString &address,
+ const QString &quantity);
+
+public slots:
+ void updateModel();
+
+private slots:
+ void exportRow(const QModelIndex &current);
+
+private:
+ void addRow(bool firstLine, QStandardItemModel *model,
+ const QList<QStandardItem *> &items);
+
+ QString mimeType;
+};
+//! [definition]
+
+#endif
diff --git a/examples/webkit/webplugin/main.cpp b/examples/webkit/webplugin/main.cpp
new file mode 100644
index 0000000..fd2b233
--- /dev/null
+++ b/examples/webkit/webplugin/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** 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 <QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/webkit/webplugin/mainwindow.cpp b/examples/webkit/webplugin/mainwindow.cpp
new file mode 100644
index 0000000..188e08f
--- /dev/null
+++ b/examples/webkit/webplugin/mainwindow.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** 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 <QFile>
+#include <QWebView>
+#include "csvfactory.h"
+#include "mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ QWebSettings::globalSettings()->setAttribute(
+ QWebSettings::PluginsEnabled, true);
+
+ QWebView *webView = new QWebView;
+ CSVFactory *factory = new CSVFactory(webView, this);
+ webView->page()->setPluginFactory(factory);
+ webView->setUrl(QUrl("qrc:/pages/index.html"));
+
+ setCentralWidget(webView);
+ setWindowTitle(tr("Web Plugin Example"));
+}
diff --git a/examples/webkit/webplugin/mainwindow.h b/examples/webkit/webplugin/mainwindow.h
new file mode 100644
index 0000000..12c8306
--- /dev/null
+++ b/examples/webkit/webplugin/mainwindow.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** 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 MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+};
+
+#endif
diff --git a/examples/webkit/webplugin/webplugin.pro b/examples/webkit/webplugin/webplugin.pro
new file mode 100644
index 0000000..cb5ebf3
--- /dev/null
+++ b/examples/webkit/webplugin/webplugin.pro
@@ -0,0 +1,23 @@
+QT += webkit network
+
+HEADERS = csvfactory.h \
+ csvview.h \
+ mainwindow.h
+
+SOURCES = csvfactory.cpp \
+ csvview.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+RESOURCES = csvplugin.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/webkit/webplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/webplugin
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000EFFE
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}