diff options
Diffstat (limited to 'examples/webkit')
59 files changed, 2651 insertions, 12 deletions
diff --git a/examples/webkit/domtraversal/domtraversal.desktop b/examples/webkit/domtraversal/domtraversal.desktop new file mode 100644 index 0000000..e44d725 --- /dev/null +++ b/examples/webkit/domtraversal/domtraversal.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=DOM Traversal +Exec=/opt/usr/bin/domtraversal +Icon=domtraversal +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/domtraversal/domtraversal.pro b/examples/webkit/domtraversal/domtraversal.pro index ba5f2d8..2e1b3aa 100644 --- a/examples/webkit/domtraversal/domtraversal.pro +++ b/examples/webkit/domtraversal/domtraversal.pro @@ -1,5 +1,6 @@ QT += webkit network -FORMS = window.ui +FORMS = window.ui \ + window_mobiles.ui HEADERS = window.h SOURCES = main.cpp \ window.cpp @@ -12,5 +13,10 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000D7CB + TARGET.CAPABILITY = NetworkServices + TARGET.EPOCHEAPSIZE = 0x100000 0x2000000 + TARGET.EPOCSTACKSIZE = 0x14000 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + diff --git a/examples/webkit/domtraversal/main.cpp b/examples/webkit/domtraversal/main.cpp index c705bbc..6d5650c 100644 --- a/examples/webkit/domtraversal/main.cpp +++ b/examples/webkit/domtraversal/main.cpp @@ -45,7 +45,11 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); Window window; - window.show(); + #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + window.showMaximized(); + #else + window.show(); + #endif window.setUrl(QUrl("http://qt.nokia.com/")); return app.exec(); } diff --git a/examples/webkit/domtraversal/window.h b/examples/webkit/domtraversal/window.h index 6828783..eb3b4ea 100644 --- a/examples/webkit/domtraversal/window.h +++ b/examples/webkit/domtraversal/window.h @@ -50,7 +50,11 @@ class QTreeWidgetItem; QT_END_NAMESPACE //! [Window class definition] -#include "ui_window.h" +#if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + #include "ui_window_mobiles.h" +#else + #include "ui_window.h" +#endif class Window : public QMainWindow, private Ui::Window { diff --git a/examples/webkit/domtraversal/window_mobiles.ui b/examples/webkit/domtraversal/window_mobiles.ui new file mode 100644 index 0000000..d6b6d11 --- /dev/null +++ b/examples/webkit/domtraversal/window_mobiles.ui @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Window</class> + <widget class="QMainWindow" name="Window"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>404</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>Web Element DOM Traversal</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="topMargin"> + <number>4</number> + </property> + <property name="bottomMargin"> + <number>4</number> + </property> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Web View</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QWebView" name="webView"> + <property name="url"> + <url> + <string>http://qt.nokia.com/</string> + </url> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>Document Structure</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QTreeWidget" name="treeWidget"> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string notr="true">1</string> + </property> + </column> + </widget> + </item> + </layout> + <zorder>treeWidget</zorder> + <zorder>treeWidget</zorder> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>404</width> + <height>20</height> + </rect> + </property> + </widget> + </widget> + <customwidgets> + <customwidget> + <class>QWebView</class> + <extends>QWidget</extends> + <header>QtWebKit/QWebView</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/examples/webkit/fancybrowser/fancybrowser.desktop b/examples/webkit/fancybrowser/fancybrowser.desktop new file mode 100644 index 0000000..975eb0c --- /dev/null +++ b/examples/webkit/fancybrowser/fancybrowser.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Fancy Browser +Exec=/opt/usr/bin/fancybrowser +Icon=fancybrowser +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/fancybrowser/fancybrowser.pro b/examples/webkit/fancybrowser/fancybrowser.pro index df4dbe3..1ed212e 100644 --- a/examples/webkit/fancybrowser/fancybrowser.pro +++ b/examples/webkit/fancybrowser/fancybrowser.pro @@ -13,6 +13,8 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000CF6C TARGET.EPOCHEAPSIZE = 0×020000 0×4000000 - TARGET.CAPABILITY += Location NetworkServices + TARGET.CAPABILITY += NetworkServices include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + diff --git a/examples/webkit/fancybrowser/main.cpp b/examples/webkit/fancybrowser/main.cpp index bd5c236..b18d190 100644 --- a/examples/webkit/fancybrowser/main.cpp +++ b/examples/webkit/fancybrowser/main.cpp @@ -50,6 +50,10 @@ int main(int argc, char * argv[]) else url = QUrl("http://www.google.com/ncr"); MainWindow *browser = new MainWindow(url); - browser->show(); + #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + browser->showMaximized(); + #else + browser->show(); + #endif return app.exec(); } diff --git a/examples/webkit/formextractor/formextractor.cpp b/examples/webkit/formextractor/formextractor.cpp index c1417ba..4f2b25b 100644 --- a/examples/webkit/formextractor/formextractor.cpp +++ b/examples/webkit/formextractor/formextractor.cpp @@ -78,6 +78,11 @@ void FormExtractor::submit() ui.updatesEdit->setText("Yes"); else ui.updatesEdit->setText("No"); + + // In mobile devices, change the tab when the data has been submitted + #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + ui.tabWidget->setCurrentWidget(ui.tabData); + #endif } void FormExtractor::populateJavaScriptWindowObject() diff --git a/examples/webkit/formextractor/formextractor.desktop b/examples/webkit/formextractor/formextractor.desktop new file mode 100644 index 0000000..5c67097 --- /dev/null +++ b/examples/webkit/formextractor/formextractor.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Form Extractor +Exec=/opt/usr/bin/formextractor +Icon=formextractor +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/formextractor/formextractor.h b/examples/webkit/formextractor/formextractor.h index 9fd17b1..8958708 100644 --- a/examples/webkit/formextractor/formextractor.h +++ b/examples/webkit/formextractor/formextractor.h @@ -43,7 +43,11 @@ #include <QtGui/QWidget> #include <QWebFrame> -#include "ui_formextractor.h" +#if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + #include "ui_formextractor_mobiles.h" +#else + #include "ui_formextractor.h" +#endif class FormExtractor : public QWidget { diff --git a/examples/webkit/formextractor/formextractor.pro b/examples/webkit/formextractor/formextractor.pro index 51e0c45..a41ed0f 100644 --- a/examples/webkit/formextractor/formextractor.pro +++ b/examples/webkit/formextractor/formextractor.pro @@ -6,7 +6,8 @@ SOURCES += main.cpp \ mainwindow.cpp HEADERS += formextractor.h \ mainwindow.h -FORMS += formextractor.ui +FORMS += formextractor.ui \ + formextractor_mobiles.ui RESOURCES += formextractor.qrc # install @@ -18,4 +19,6 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000CF6D include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.CAPABILITY = NetworkServices } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) diff --git a/examples/webkit/formextractor/formextractor_mobiles.ui b/examples/webkit/formextractor/formextractor_mobiles.ui new file mode 100644 index 0000000..4b81bc7 --- /dev/null +++ b/examples/webkit/formextractor/formextractor_mobiles.ui @@ -0,0 +1,139 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>242</width> + <height>313</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tabWebForm"> + <attribute name="title"> + <string>Web Form</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QWebView" name="webView"> + <property name="minimumSize"> + <size> + <width>200</width> + <height>150</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>400</width> + <height>16777215</height> + </size> + </property> + <property name="url"> + <url> + <string>about:blank</string> + </url> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tabData"> + <attribute name="title"> + <string>Extracted Data</string> + </attribute> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="firstNameLabel"> + <property name="text"> + <string>First Name</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="firstNameEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="lastNameLabel"> + <property name="text"> + <string>Last Name</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="lastNameEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="genderLabel"> + <property name="text"> + <string>Gender</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="genderEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="updatesLabel"> + <property name="text"> + <string>Receive Updates</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="updatesEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="1"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QWebView</class> + <extends>QWidget</extends> + <header>QtWebKit/QWebView</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/examples/webkit/framecapture/framecapture.desktop b/examples/webkit/framecapture/framecapture.desktop new file mode 100644 index 0000000..14d74e4 --- /dev/null +++ b/examples/webkit/framecapture/framecapture.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=WebKit Frame Capture +Exec=/opt/usr/bin/framecapture +Icon=framecapture +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/framecapture/framecapture.pro b/examples/webkit/framecapture/framecapture.pro index 11960b9..f235224 100644 --- a/examples/webkit/framecapture/framecapture.pro +++ b/examples/webkit/framecapture/framecapture.pro @@ -9,3 +9,13 @@ target.path = $$[QT_INSTALL_EXAMPLES]/webkit/framecapture sources.files = $$SOURCES $$HEADERS sources.path = $$[QT_INSTALL_EXAMPLES]/webkit/framecapture INSTALLS += target sources + +symbian { + TARGET.CAPABILITY = NetworkServices + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} + +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +symbian: warning(This example does not work on Symbian platform) +simulator: warning(This example does not work on Simulator platform) diff --git a/examples/webkit/googlechat/googlechat.desktop b/examples/webkit/googlechat/googlechat.desktop new file mode 100644 index 0000000..b19b74b --- /dev/null +++ b/examples/webkit/googlechat/googlechat.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Google Chat +Exec=/opt/usr/bin/googlechat +Icon=googlechat +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/googlechat/googlechat.pro b/examples/webkit/googlechat/googlechat.pro index 3d32c1b..5d998f7 100644 --- a/examples/webkit/googlechat/googlechat.pro +++ b/examples/webkit/googlechat/googlechat.pro @@ -13,4 +13,10 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000CF6E include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.CAPABILITY = NetworkServices } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +symbian: warning(This example does not work on Symbian platform) +maemo5: warning(This example does not work on Maemo platform) +simulator: warning(This example does not work on Simulator platform) diff --git a/examples/webkit/previewer/main.cpp b/examples/webkit/previewer/main.cpp index 03aa831..89e9f39 100644 --- a/examples/webkit/previewer/main.cpp +++ b/examples/webkit/previewer/main.cpp @@ -46,7 +46,11 @@ int main(int argc, char * argv[]) { QApplication app(argc, argv); MainWindow mainWindow; - mainWindow.show(); + #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + mainWindow.showMaximized(); + #else + mainWindow.show(); + #endif return app.exec(); } //! [0] diff --git a/examples/webkit/previewer/previewer.cpp b/examples/webkit/previewer/previewer.cpp index 40c5da4..06cba16 100644 --- a/examples/webkit/previewer/previewer.cpp +++ b/examples/webkit/previewer/previewer.cpp @@ -60,5 +60,10 @@ void Previewer::on_previewButton_clicked() // Update the contents in web viewer QString text = plainTextEdit->toPlainText(); webView->setHtml(text, baseUrl); + + // In mobile devices, change the tab + #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + tabWidget->setCurrentWidget(tabHTMLPreview); + #endif } //! [1] diff --git a/examples/webkit/previewer/previewer.desktop b/examples/webkit/previewer/previewer.desktop new file mode 100644 index 0000000..51c570d --- /dev/null +++ b/examples/webkit/previewer/previewer.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Previewer +Exec=/opt/usr/bin/previewer +Icon=previewer +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/previewer/previewer.h b/examples/webkit/previewer/previewer.h index f59efbf..771b21f 100644 --- a/examples/webkit/previewer/previewer.h +++ b/examples/webkit/previewer/previewer.h @@ -41,7 +41,11 @@ #ifndef PREVIEWER_H #define PREVIEWER_H -#include "ui_previewer.h" +#if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + #include "ui_previewer_mobiles.h" +#else + #include "ui_previewer.h" +#endif //! [0] class Previewer : public QWidget, public Ui::Form diff --git a/examples/webkit/previewer/previewer.pro b/examples/webkit/previewer/previewer.pro index 525dbb2..371695e 100644 --- a/examples/webkit/previewer/previewer.pro +++ b/examples/webkit/previewer/previewer.pro @@ -4,7 +4,8 @@ HEADERS = previewer.h \ SOURCES = main.cpp \ previewer.cpp \ mainwindow.cpp -FORMS = previewer.ui +FORMS = previewer.ui \ + previewer_mobiles.ui # install target.path = $$[QT_INSTALL_EXAMPLES]/webkit/previewer @@ -15,4 +16,6 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000CF6F include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.CAPABILITY = NetworkServices } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) diff --git a/examples/webkit/previewer/previewer_mobiles.ui b/examples/webkit/previewer/previewer_mobiles.ui new file mode 100644 index 0000000..b65a88e --- /dev/null +++ b/examples/webkit/previewer/previewer_mobiles.ui @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>259</width> + <height>177</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tabHTMLPreview"> + <attribute name="title"> + <string>HTML Preview</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QWebView" name="webView"> + <property name="url"> + <url> + <string>about:blank</string> + </url> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tabHTMLEditor"> + <attribute name="title"> + <string>HTML Editor</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QPlainTextEdit" name="plainTextEdit"/> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="clearButton"> + <property name="text"> + <string>Clear</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="previewButton"> + <property name="text"> + <string>Preview</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QWebView</class> + <extends>QWidget</extends> + <header>QtWebKit/QWebView</header> + </customwidget> + </customwidgets> + <resources/> + <connections> + <connection> + <sender>clearButton</sender> + <signal>clicked()</signal> + <receiver>plainTextEdit</receiver> + <slot>clear()</slot> + <hints> + <hint type="sourcelabel"> + <x>56</x> + <y>653</y> + </hint> + <hint type="destinationlabel"> + <x>98</x> + <y>551</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/examples/webkit/simpleselector/main.cpp b/examples/webkit/simpleselector/main.cpp index 959f15d..cdd1123 100644 --- a/examples/webkit/simpleselector/main.cpp +++ b/examples/webkit/simpleselector/main.cpp @@ -47,7 +47,11 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); Window window; window.setUrl(QUrl("http://www.webkit.org")); - window.show(); + #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR + window.showMaximized(); + #else + window.show(); + #endif return app.exec(); } //! [main program] diff --git a/examples/webkit/simpleselector/simpleselector.desktop b/examples/webkit/simpleselector/simpleselector.desktop new file mode 100644 index 0000000..2f9fde1 --- /dev/null +++ b/examples/webkit/simpleselector/simpleselector.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=Simple Selector +Exec=/opt/usr/bin/simpleselector +Icon=simpleselector +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/webkit/simpleselector/simpleselector.pro b/examples/webkit/simpleselector/simpleselector.pro index 3ddd6db..f5c1018 100644 --- a/examples/webkit/simpleselector/simpleselector.pro +++ b/examples/webkit/simpleselector/simpleselector.pro @@ -13,4 +13,7 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000D7CC include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + TARGET.CAPABILITY = NetworkServices } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + 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..3d87daa --- /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/data/accounts.csv b/examples/webkit/simplewebplugin/data/accounts.csv new file mode 100644 index 0000000..2ea3bd6 --- /dev/null +++ b/examples/webkit/simplewebplugin/data/accounts.csv @@ -0,0 +1,11 @@ +"Name","Address","Quantity" +"Kristian Quan","123 Company Place, Big City","4" +"Matthew Rand","The Orchard, Little Village","2" +"Eirik Asaki","497 Park Skyway, Future City","29" +"Jarek Hanssen","1023 Riviera Drive, Southern Precinct","45" +"Carlos Hartmann","The Manor House, Country Estate","1" +"Bea King","Floor 201, Sun Tower, Central City","32" +"Stian Hinton","Mechanical workshop, Fishing Village, North River","0" +"Shane Bowland","P.O. Box 419, Beach Resort","1" +"Gavin Holm","19 Library Road, University Campus, near Large Town","16" +"Adrienna Randles","98 Tapestry Road, Market Town, The Shires","1" 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/pages/index.html b/examples/webkit/simplewebplugin/pages/index.html new file mode 100644 index 0000000..9581a8e --- /dev/null +++ b/examples/webkit/simplewebplugin/pages/index.html @@ -0,0 +1,27 @@ +<html> +<head> +<title>Simple Web Plugin</title> +</head> + +<body> +<h1>Simple Web Plugin</h1> + +<p> + This plugin displays comma-separated value (CSV) files in Web pages using + a subclass of Qt's + <a href="http://doc.trolltech.com/4.4/qtableview.html">QTableView</a> + widget. +</p> + +<!-- [embedded object] --> +<object type="text/csv;header=present;charset=utf8" + data="qrc:/data/accounts.csv" + width="100%" height="300"></object> +<!-- [embedded object] --> + +<p> + The above table shows some sample data rendered by the plugin. +</p> + +</body> +</html> diff --git a/examples/webkit/simplewebplugin/simplewebplugin.pro b/examples/webkit/simplewebplugin/simplewebplugin.pro new file mode 100644 index 0000000..c16302d --- /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 = simplewebplugin.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/simplewebplugin/simplewebplugin.qrc b/examples/webkit/simplewebplugin/simplewebplugin.qrc new file mode 100644 index 0000000..14f80e7 --- /dev/null +++ b/examples/webkit/simplewebplugin/simplewebplugin.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/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) +} diff --git a/examples/webkit/webkit.pro b/examples/webkit/webkit.pro index 62d3762..4ff2d91 100644 --- a/examples/webkit/webkit.pro +++ b/examples/webkit/webkit.pro @@ -6,6 +6,9 @@ SUBDIRS += domtraversal \ simpleselector \ imageanalyzer \ framecapture \ + simplewebplugin \ + webplugin \ + webftpclient contains(QT_CONFIG, openssl):SUBDIRS += googlechat @@ -15,4 +18,3 @@ sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS webkit.pro README sources.path = $$[QT_INSTALL_EXAMPLES]/webkit INSTALLS += target sources -symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) 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/csvview.cpp b/examples/webkit/webplugin/csvview.cpp new file mode 100644 index 0000000..0996f24 --- /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 ¤t) +{ + 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 ¤t); + +private: + void addRow(bool firstLine, QStandardItemModel *model, + const QList<QStandardItem *> &items); + + QString mimeType; +}; +//! [definition] + +#endif diff --git a/examples/webkit/webplugin/data/accounts.csv b/examples/webkit/webplugin/data/accounts.csv new file mode 100644 index 0000000..2ea3bd6 --- /dev/null +++ b/examples/webkit/webplugin/data/accounts.csv @@ -0,0 +1,11 @@ +"Name","Address","Quantity" +"Kristian Quan","123 Company Place, Big City","4" +"Matthew Rand","The Orchard, Little Village","2" +"Eirik Asaki","497 Park Skyway, Future City","29" +"Jarek Hanssen","1023 Riviera Drive, Southern Precinct","45" +"Carlos Hartmann","The Manor House, Country Estate","1" +"Bea King","Floor 201, Sun Tower, Central City","32" +"Stian Hinton","Mechanical workshop, Fishing Village, North River","0" +"Shane Bowland","P.O. Box 419, Beach Resort","1" +"Gavin Holm","19 Library Road, University Campus, near Large Town","16" +"Adrienna Randles","98 Tapestry Road, Market Town, The Shires","1" 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/pages/index.html b/examples/webkit/webplugin/pages/index.html new file mode 100644 index 0000000..fe38bba --- /dev/null +++ b/examples/webkit/webplugin/pages/index.html @@ -0,0 +1,64 @@ +<html> +<head> +<title>Web Plugin</title> +<!-- [script] --> +<script type="text/javascript"> +function fillInTable(name, address, quantity) +{ + var nameElement = document.getElementById("customers_name"); + var addressElement = document.getElementById("customers_address"); + var quantityElement = document.getElementById("customers_quantity"); + + nameElement.innerHTML = name; + addressElement.innerHTML = address; + quantityElement.innerHTML = quantity; +} +</script> +<!-- [script] --> +</head> + +<body> +<h1>Web Plugin</h1> + +<p> + This plugin displays comma-separated value (CSV) files in Web pages using + a table widget. +</p> + +<!-- [embedded object] --> +<object type="text/csv;header=present;charset=utf8" + data="qrc:/data/accounts.csv" + width="100%" height="300"> +</object> +<!-- [embedded object] --> + +<p> + The table above shows some sample data rendered by the plugin. It is exposed + to this page as the <tt>view</tt> JavaScript object. +</p> + +<p> + The fields shown below in an HTML table can be updated by selecting a row in + the table above. A signal in the view is connected to a JavaScript function + in this page which fills in the values. +</p> + +<div style="margin-left: 5%; width: 90%; background-color: lightgray"> +<!-- [table] --> +<table> +<tr> + <th>Name:</th> + <td id="customers_name"></td> +</tr><tr> + <th>Address:</th> + <td id="customers_address"></td> +</tr><tr> + <th>Quantity:</th> + <td id="customers_quantity"></td> +</tr> +</table> +<!-- [table] --> +</div> + +</body> +</html> diff --git a/examples/webkit/webplugin/webplugin.pro b/examples/webkit/webplugin/webplugin.pro new file mode 100644 index 0000000..48f48d1 --- /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 = webplugin.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) +} diff --git a/examples/webkit/webplugin/webplugin.qrc b/examples/webkit/webplugin/webplugin.qrc new file mode 100644 index 0000000..14f80e7 --- /dev/null +++ b/examples/webkit/webplugin/webplugin.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/" > + <file>pages/index.html</file> + <file>data/accounts.csv</file> + </qresource> +</RCC> |