From 38be0d13830efd2d98281c645c3a60afe05ffece Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 12:05:43 +0200 Subject: Initial import from the monolithic Qt. This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12 --- examples/xml/README | 40 + examples/xml/dombookmarks/dombookmarks.pro | 20 + examples/xml/dombookmarks/frank.xbel | 230 ++++ examples/xml/dombookmarks/jennifer.xbel | 93 ++ examples/xml/dombookmarks/main.cpp | 52 + examples/xml/dombookmarks/mainwindow.cpp | 145 ++ examples/xml/dombookmarks/mainwindow.h | 75 + examples/xml/dombookmarks/xbeltree.cpp | 186 +++ examples/xml/dombookmarks/xbeltree.h | 74 + examples/xml/htmlinfo/apache_org.html | 281 ++++ examples/xml/htmlinfo/htmlinfo.pro | 19 + examples/xml/htmlinfo/main.cpp | 118 ++ examples/xml/htmlinfo/nokia_com.html | 215 +++ examples/xml/htmlinfo/simpleexample.html | 11 + examples/xml/htmlinfo/trolltech_com.html | 955 +++++++++++++ examples/xml/htmlinfo/w3c_org.html | 507 +++++++ examples/xml/htmlinfo/youtube_com.html | 1585 ++++++++++++++++++++++ examples/xml/rsslisting/main.cpp | 63 + examples/xml/rsslisting/rsslisting.cpp | 247 ++++ examples/xml/rsslisting/rsslisting.h | 90 ++ examples/xml/rsslisting/rsslisting.pro | 12 + examples/xml/saxbookmarks/frank.xbel | 230 ++++ examples/xml/saxbookmarks/jennifer.xbel | 93 ++ examples/xml/saxbookmarks/main.cpp | 56 + examples/xml/saxbookmarks/mainwindow.cpp | 169 +++ examples/xml/saxbookmarks/mainwindow.h | 77 ++ examples/xml/saxbookmarks/saxbookmarks.pro | 28 + examples/xml/saxbookmarks/xbelgenerator.cpp | 114 ++ examples/xml/saxbookmarks/xbelgenerator.h | 68 + examples/xml/saxbookmarks/xbelhandler.cpp | 146 ++ examples/xml/saxbookmarks/xbelhandler.h | 78 ++ examples/xml/streambookmarks/frank.xbel | 230 ++++ examples/xml/streambookmarks/jennifer.xbel | 93 ++ examples/xml/streambookmarks/main.cpp | 54 + examples/xml/streambookmarks/mainwindow.cpp | 174 +++ examples/xml/streambookmarks/mainwindow.h | 79 ++ examples/xml/streambookmarks/streambookmarks.pro | 16 + examples/xml/streambookmarks/xbelreader.cpp | 175 +++ examples/xml/streambookmarks/xbelreader.h | 83 ++ examples/xml/streambookmarks/xbelwriter.cpp | 92 ++ examples/xml/streambookmarks/xbelwriter.h | 65 + examples/xml/xml.pro | 20 + examples/xml/xmlstreamlint/main.cpp | 127 ++ examples/xml/xmlstreamlint/xmlstreamlint.pro | 12 + 44 files changed, 7297 insertions(+) create mode 100644 examples/xml/README create mode 100644 examples/xml/dombookmarks/dombookmarks.pro create mode 100644 examples/xml/dombookmarks/frank.xbel create mode 100644 examples/xml/dombookmarks/jennifer.xbel create mode 100644 examples/xml/dombookmarks/main.cpp create mode 100644 examples/xml/dombookmarks/mainwindow.cpp create mode 100644 examples/xml/dombookmarks/mainwindow.h create mode 100644 examples/xml/dombookmarks/xbeltree.cpp create mode 100644 examples/xml/dombookmarks/xbeltree.h create mode 100644 examples/xml/htmlinfo/apache_org.html create mode 100644 examples/xml/htmlinfo/htmlinfo.pro create mode 100644 examples/xml/htmlinfo/main.cpp create mode 100644 examples/xml/htmlinfo/nokia_com.html create mode 100644 examples/xml/htmlinfo/simpleexample.html create mode 100644 examples/xml/htmlinfo/trolltech_com.html create mode 100644 examples/xml/htmlinfo/w3c_org.html create mode 100644 examples/xml/htmlinfo/youtube_com.html create mode 100644 examples/xml/rsslisting/main.cpp create mode 100644 examples/xml/rsslisting/rsslisting.cpp create mode 100644 examples/xml/rsslisting/rsslisting.h create mode 100644 examples/xml/rsslisting/rsslisting.pro create mode 100644 examples/xml/saxbookmarks/frank.xbel create mode 100644 examples/xml/saxbookmarks/jennifer.xbel create mode 100644 examples/xml/saxbookmarks/main.cpp create mode 100644 examples/xml/saxbookmarks/mainwindow.cpp create mode 100644 examples/xml/saxbookmarks/mainwindow.h create mode 100644 examples/xml/saxbookmarks/saxbookmarks.pro create mode 100644 examples/xml/saxbookmarks/xbelgenerator.cpp create mode 100644 examples/xml/saxbookmarks/xbelgenerator.h create mode 100644 examples/xml/saxbookmarks/xbelhandler.cpp create mode 100644 examples/xml/saxbookmarks/xbelhandler.h create mode 100644 examples/xml/streambookmarks/frank.xbel create mode 100644 examples/xml/streambookmarks/jennifer.xbel create mode 100644 examples/xml/streambookmarks/main.cpp create mode 100644 examples/xml/streambookmarks/mainwindow.cpp create mode 100644 examples/xml/streambookmarks/mainwindow.h create mode 100644 examples/xml/streambookmarks/streambookmarks.pro create mode 100644 examples/xml/streambookmarks/xbelreader.cpp create mode 100644 examples/xml/streambookmarks/xbelreader.h create mode 100644 examples/xml/streambookmarks/xbelwriter.cpp create mode 100644 examples/xml/streambookmarks/xbelwriter.h create mode 100644 examples/xml/xml.pro create mode 100644 examples/xml/xmlstreamlint/main.cpp create mode 100644 examples/xml/xmlstreamlint/xmlstreamlint.pro (limited to 'examples/xml') diff --git a/examples/xml/README b/examples/xml/README new file mode 100644 index 0000000000..a6d81bb58a --- /dev/null +++ b/examples/xml/README @@ -0,0 +1,40 @@ +XML parsing and handling is supported through SAX and DOM compliant APIs. + +Qt's SAX compliant classes allow you to parse XML incrementally; the DOM +classes enable more complex document-level operations to be performed on +XML files. + + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/xml/dombookmarks/dombookmarks.pro b/examples/xml/dombookmarks/dombookmarks.pro new file mode 100644 index 0000000000..d071ccd0ee --- /dev/null +++ b/examples/xml/dombookmarks/dombookmarks.pro @@ -0,0 +1,20 @@ +HEADERS = mainwindow.h \ + xbeltree.h +SOURCES = main.cpp \ + mainwindow.cpp \ + xbeltree.cpp +QT += xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/dombookmarks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dombookmarks.pro *.xbel +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/dombookmarks +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + +wince*: { + addFiles.files = frank.xbel jennifer.xbel + addFiles.path = "\\My Documents" + DEPLOYMENT += addFiles +} diff --git a/examples/xml/dombookmarks/frank.xbel b/examples/xml/dombookmarks/frank.xbel new file mode 100644 index 0000000000..6bd63b8b07 --- /dev/null +++ b/examples/xml/dombookmarks/frank.xbel @@ -0,0 +1,230 @@ + + + + + Literate Programming + + Synopsis of Literate Programming + + + Literate Programming: Propaganda and Tools + + + Literate Programming by Henrik Turbell + + + Literate Programming Library + + + Literate Programming Basics + + + Literate Programming Overview + + + POD is not Literate Programming + + + Computers That We Can Count On + + + Literate Programming - Issues and Problems + + + Literate Programming - Wiki Pages + + + What is well-commented code? + + + Bibliography on literate programming - A searchable bibliography + + + Program comprehension and code reading bibliography + + + Elucidative Programming + + + AVL Trees (TexiWeb) + + + Literate Programming on Wikiverse + + + Physically Based Rendering: From Theory to Implementation + + + + Useful C++ Links + + STL + + STL Reference Documentation + + + STL Tutorial + + + STL Reference + + + + Qt + + Qt 2.3 Reference + + + Qt 3.3 Reference + + + Qt 4.0 Reference + + + Qt Home Page + + + + IOStreams + + IO Stream Library + + + Binary I/O + + + I/O Stream FAQ + + + + gdb + + GDB Tutorial + + + Debugging with GDB + + + GDB Quick Reference Page (PDF) (Handy) + + + + Classes and Constructors + + Constructor FAQ + + + Organizing Classes + + + + + Software Documentation or System Documentation + + The Almighty Thud + + + Microsoft Coding Techniques and Programming Practices + + + Software and Documentation + + + The Source Code is the Design + + + What is Software Design? + + + How To Write Unmaintainable Code + + + Self Documenting Program Code Remains a Distant Goal + + + Place Tab A in Slot B + + + UML Reference Card + + + + TeX Resources + + The TeX User's Group + + + MikTeX website + + + MetaPost website + + + HEVEA is a quite complete and fast LATEX to HTML translator + + + + Portable Document Format (PDF) + + Adobe - The postscript and PDF standards + + + Reference Manual Portable Document Format + + + Adobe Acrobat Software Development Kit + + + + Literature Sites + + Guide to Special Collections (Columbia University) + + + Literary Criticism on the Web from the Internet Public Library + + + Victorian Web. + + + Voice of the Shuttle. + + + Modernist Journals Project + + + Museum of American Poetics + + + Modern American Poetry + + + FindArticles.com + + + Literary History + + + Literary Encyclopedia + + + + The University of California Press + + + Wright American Fiction, 1851-1875 + + + Documenting the American South: Beginnings to 1920 + + + Electronic Text Center at the University of Virginia + + + The Schomburg Center for Research in Black Culture + + + Alex Catalogue of Electronic Texts. + + + diff --git a/examples/xml/dombookmarks/jennifer.xbel b/examples/xml/dombookmarks/jennifer.xbel new file mode 100644 index 0000000000..36256fda0a --- /dev/null +++ b/examples/xml/dombookmarks/jennifer.xbel @@ -0,0 +1,93 @@ + + + + + Qt Resources + + Qt Partners + + Training Partners + + + Consultants and System Integrators + + + Technology Partners + + + Value Added Resellers (VARs) + + + + Community Resources + + QtForum.org + + + The Independent Qt Tutorial + + + French PROG.Qt + + + German Qt Forum + + + Korean Qt Community Site + + + Russian Qt Forum + + + Digitalfanatics: The QT 4 Resource Center + + + QtQuestions + + + + Qt Quarterly + + + Qt home page + + + Qt 4.0 documentation + + + Frequently Asked Questions + + + + Online Dictionaries + + Dictionary.com + + + Merriam-Webster Online + + + Cambridge Dictionaries Online + + + OneLook Dictionary Search + + + + The New English-German Dictionary + + + TU Chemnitz German-English Dictionary + + + + Trésor de la Langue Française informatisé + + + Dictionnaire de l'Académie Française + + + Dictionnaire des synonymes + + + diff --git a/examples/xml/dombookmarks/main.cpp b/examples/xml/dombookmarks/main.cpp new file mode 100644 index 0000000000..71ce6aec0b --- /dev/null +++ b/examples/xml/dombookmarks/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 + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; + mainWin.show(); + mainWin.open(); + return app.exec(); +} diff --git a/examples/xml/dombookmarks/mainwindow.cpp b/examples/xml/dombookmarks/mainwindow.cpp new file mode 100644 index 0000000000..b3bfe64e17 --- /dev/null +++ b/examples/xml/dombookmarks/mainwindow.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** 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 + +#include "mainwindow.h" +#include "xbeltree.h" + +MainWindow::MainWindow() +{ + xbelTree = new XbelTree; + setCentralWidget(xbelTree); + + createActions(); + createMenus(); + + statusBar()->showMessage(tr("Ready")); + + setWindowTitle(tr("DOM Bookmarks")); + resize(480, 320); +} + +void MainWindow::open() +{ + QString fileName = + QFileDialog::getOpenFileName(this, tr("Open Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("SAX Bookmarks"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + if (xbelTree->read(&file)) + statusBar()->showMessage(tr("File loaded"), 2000); +} + +void MainWindow::saveAs() +{ + QString fileName = + QFileDialog::getSaveFileName(this, tr("Save Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + QFile file(fileName); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, tr("SAX Bookmarks"), + tr("Cannot write file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + if (xbelTree->write(&file)) + statusBar()->showMessage(tr("File saved"), 2000); +} + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About DOM Bookmarks"), + tr("The DOM Bookmarks example demonstrates how to " + "use Qt's DOM classes to read and write XML " + "documents.")); +} + +void MainWindow::createActions() +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcuts(QKeySequence::Open); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAsAct = new QAction(tr("&Save As..."), this); + saveAsAct->setShortcuts(QKeySequence::SaveAs); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcuts(QKeySequence::Quit); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAct); + fileMenu->addAction(saveAsAct); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} diff --git a/examples/xml/dombookmarks/mainwindow.h b/examples/xml/dombookmarks/mainwindow.h new file mode 100644 index 0000000000..058f5cc221 --- /dev/null +++ b/examples/xml/dombookmarks/mainwindow.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 MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class XbelTree; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void open(); + void saveAs(); + void about(); + +private: + void createActions(); + void createMenus(); + + XbelTree *xbelTree; + + QMenu *fileMenu; + QMenu *helpMenu; + QAction *openAct; + QAction *saveAsAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; + +#endif diff --git a/examples/xml/dombookmarks/xbeltree.cpp b/examples/xml/dombookmarks/xbeltree.cpp new file mode 100644 index 0000000000..2a072b2d54 --- /dev/null +++ b/examples/xml/dombookmarks/xbeltree.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** 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 + +#include "xbeltree.h" + +XbelTree::XbelTree(QWidget *parent) + : QTreeWidget(parent) +{ + QStringList labels; + labels << tr("Title") << tr("Location"); + + header()->setResizeMode(QHeaderView::Stretch); + setHeaderLabels(labels); + + folderIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon), + QIcon::Normal, QIcon::Off); + folderIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon), + QIcon::Normal, QIcon::On); + bookmarkIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon)); +} + +bool XbelTree::read(QIODevice *device) +{ + QString errorStr; + int errorLine; + int errorColumn; + + if (!domDocument.setContent(device, true, &errorStr, &errorLine, + &errorColumn)) { + QMessageBox::information(window(), tr("DOM Bookmarks"), + tr("Parse error at line %1, column %2:\n%3") + .arg(errorLine) + .arg(errorColumn) + .arg(errorStr)); + return false; + } + + QDomElement root = domDocument.documentElement(); + if (root.tagName() != "xbel") { + QMessageBox::information(window(), tr("DOM Bookmarks"), + tr("The file is not an XBEL file.")); + return false; + } else if (root.hasAttribute("version") + && root.attribute("version") != "1.0") { + QMessageBox::information(window(), tr("DOM Bookmarks"), + tr("The file is not an XBEL version 1.0 " + "file.")); + return false; + } + + clear(); + + disconnect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), + this, SLOT(updateDomElement(QTreeWidgetItem*,int))); + + QDomElement child = root.firstChildElement("folder"); + while (!child.isNull()) { + parseFolderElement(child); + child = child.nextSiblingElement("folder"); + } + + connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), + this, SLOT(updateDomElement(QTreeWidgetItem*,int))); + + return true; +} + +bool XbelTree::write(QIODevice *device) +{ + const int IndentSize = 4; + + QTextStream out(device); + domDocument.save(out, IndentSize); + return true; +} + +void XbelTree::updateDomElement(QTreeWidgetItem *item, int column) +{ + QDomElement element = domElementForItem.value(item); + if (!element.isNull()) { + if (column == 0) { + QDomElement oldTitleElement = element.firstChildElement("title"); + QDomElement newTitleElement = domDocument.createElement("title"); + + QDomText newTitleText = domDocument.createTextNode(item->text(0)); + newTitleElement.appendChild(newTitleText); + + element.replaceChild(newTitleElement, oldTitleElement); + } else { + if (element.tagName() == "bookmark") + element.setAttribute("href", item->text(1)); + } + } +} + +void XbelTree::parseFolderElement(const QDomElement &element, + QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *item = createItem(element, parentItem); + + QString title = element.firstChildElement("title").text(); + if (title.isEmpty()) + title = QObject::tr("Folder"); + + item->setFlags(item->flags() | Qt::ItemIsEditable); + item->setIcon(0, folderIcon); + item->setText(0, title); + + bool folded = (element.attribute("folded") != "no"); + setItemExpanded(item, !folded); + + QDomElement child = element.firstChildElement(); + while (!child.isNull()) { + if (child.tagName() == "folder") { + parseFolderElement(child, item); + } else if (child.tagName() == "bookmark") { + QTreeWidgetItem *childItem = createItem(child, item); + + QString title = child.firstChildElement("title").text(); + if (title.isEmpty()) + title = QObject::tr("Folder"); + + childItem->setFlags(item->flags() | Qt::ItemIsEditable); + childItem->setIcon(0, bookmarkIcon); + childItem->setText(0, title); + childItem->setText(1, child.attribute("href")); + } else if (child.tagName() == "separator") { + QTreeWidgetItem *childItem = createItem(child, item); + childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable)); + childItem->setText(0, QString(30, 0xB7)); + } + child = child.nextSiblingElement(); + } +} + +QTreeWidgetItem *XbelTree::createItem(const QDomElement &element, + QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *item; + if (parentItem) { + item = new QTreeWidgetItem(parentItem); + } else { + item = new QTreeWidgetItem(this); + } + domElementForItem.insert(item, element); + return item; +} diff --git a/examples/xml/dombookmarks/xbeltree.h b/examples/xml/dombookmarks/xbeltree.h new file mode 100644 index 0000000000..ad30de520c --- /dev/null +++ b/examples/xml/dombookmarks/xbeltree.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 XBELTREE_H +#define XBELTREE_H + +#include +#include +#include +#include + +class XbelTree : public QTreeWidget +{ + Q_OBJECT + +public: + XbelTree(QWidget *parent = 0); + + bool read(QIODevice *device); + bool write(QIODevice *device); + +private slots: + void updateDomElement(QTreeWidgetItem *item, int column); + +private: + void parseFolderElement(const QDomElement &element, + QTreeWidgetItem *parentItem = 0); + QTreeWidgetItem *createItem(const QDomElement &element, + QTreeWidgetItem *parentItem = 0); + + QDomDocument domDocument; + QHash domElementForItem; + QIcon folderIcon; + QIcon bookmarkIcon; +}; + +#endif diff --git a/examples/xml/htmlinfo/apache_org.html b/examples/xml/htmlinfo/apache_org.html new file mode 100644 index 0000000000..9e5e4d3a68 --- /dev/null +++ b/examples/xml/htmlinfo/apache_org.html @@ -0,0 +1,281 @@ + + + + + + + + + + + + Welcome! - The Apache Software Foundation + + + +
+
+
+
+ +
+
+
+
+
+

+ Latest News +

+
+ +
+
+
+ +
+

If you would like to keep up with news and announcements from the +foundation and all its projects, you can subscribe to the +Apache +Announcements List.

+ +

+ Free Video Streams from ApacheCon Europe 2008 +

+
+ApacheCon Europe 2008 +

+ApacheCon Europe 2008 held in Amsterdam was a great success, and attracted higher +than ever attendance figures, with about 500 registered attendees. This +figure represents an increase of more than 40% over the previous year, +demonstrating the rapidly growing interest in Apache and Open Source software +amongst European businesses. + +If you have not been able to attend ApacheCon Europe, you can still watch +videos of all keynotes and select talks online. Keynote sessions +and the opening plenary are available free of charge:

+ +

The talks of the following select ApacheCon Europe tracks are +available for just 49 Euro: +System Administration, +Web Security, +Web Services and Web 2.0. +

+
+
+ +

+ ApacheCon US 2008 in New Orleans! +

+
+

+ ApacheCon US 2008 will be held 3 November through 7 November in + New Orleans, Louisiana. + The Call for Papers has already closed and the program and further + information will be made available soon on the ApacheCon US 2008 + Web site www.us.apachecon.com. + If you would like to receive information about ApacheCon US 2008, please + subscribe to + the ApacheCon announcement mailing list. +

+
+
+ +

+ Notice regarding open letter to Sun Microsystems +

+
+

+ The Apache Software Foundation has written an open letter + to Sun Microsystems regarding our inabillity to acquire an acceptable license for the test kit + for Java SE needed by Apache Harmony. For futher information + please see the FAQ and direct all questions to Apache's VP + for JCP issues, geirm at apache dot org, or our regular press inquiry address, press at apache dot org. +

+
+
+
+ + +
+
+ + + diff --git a/examples/xml/htmlinfo/htmlinfo.pro b/examples/xml/htmlinfo/htmlinfo.pro new file mode 100644 index 0000000000..ca64b346a7 --- /dev/null +++ b/examples/xml/htmlinfo/htmlinfo.pro @@ -0,0 +1,19 @@ +SOURCES += main.cpp +QT -= gui + +wince*|symbian:{ + htmlfiles.files = *.html + htmlfiles.path = . + DEPLOYMENT += htmlfiles +} + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/htmlinfo +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.html htmlinfo.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/htmlinfo +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000C609 + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +} diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp new file mode 100644 index 0000000000..cb7ac528f0 --- /dev/null +++ b/examples/xml/htmlinfo/main.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** 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 + +void parseHtmlFile(QTextStream &out, const QString &fileName) { + QFile file(fileName); + + out << "Analysis of HTML file: " << fileName << endl; + + if (!file.open(QIODevice::ReadOnly)) { + out << " Couldn't open the file." << endl << endl << endl; + return; + } + +//! [0] + QXmlStreamReader reader(&file); +//! [0] + +//! [1] + int paragraphCount = 0; + QStringList links; + QString title; + while (!reader.atEnd()) { + reader.readNext(); + if (reader.isStartElement()) { + if (reader.name() == "title") + title = reader.readElementText(); + else if(reader.name() == "a") + links.append(reader.attributes().value("href").toString()); + else if(reader.name() == "p") + ++paragraphCount; + } + } +//! [1] + +//! [2] + if (reader.hasError()) { + out << " The HTML file isn't well-formed: " << reader.errorString() + << endl << endl << endl; + return; + } +//! [2] + + out << " Title: \"" << title << "\"" << endl + << " Number of paragraphs: " << paragraphCount << endl + << " Number of links: " << links.size() << endl + << " Showing first few links:" << endl; + + while(links.size() > 5) + links.removeLast(); + + foreach(QString link, links) + out << " " << link << endl; + out << endl << endl; +} + +int main(int argc, char **argv) +{ + // initialize QtCore application + QCoreApplication app(argc, argv); + + // get a list of all html files in the current directory + QStringList filter; + filter << "*.htm"; + filter << "*.html"; + QStringList htmlFiles = QDir::current().entryList(filter, QDir::Files); + + QTextStream out(stdout); + + if (htmlFiles.isEmpty()) { + out << "No html files available."; + return 1; + } + + // parse each html file and write the result to file/stream + foreach(QString file, htmlFiles) + parseHtmlFile(out, file); + + return 0; +} diff --git a/examples/xml/htmlinfo/nokia_com.html b/examples/xml/htmlinfo/nokia_com.html new file mode 100644 index 0000000000..46d4c95ee6 --- /dev/null +++ b/examples/xml/htmlinfo/nokia_com.html @@ -0,0 +1,215 @@ + + + + + + + + + + Nokia - Nokia on the Web + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+
+ Nokia - Connecting people + +
+ +
+ + +
+

Welcome to Nokia

+
+

Where would you like to go?

+ +
+ +
+ + + +
+ + +
+ + + + + + + + + + + + + +
+ + + + + diff --git a/examples/xml/htmlinfo/simpleexample.html b/examples/xml/htmlinfo/simpleexample.html new file mode 100644 index 0000000000..83a55cf00a --- /dev/null +++ b/examples/xml/htmlinfo/simpleexample.html @@ -0,0 +1,11 @@ + + + + Qt is cute! Frans is too! + + +

A paragraph.

+

A second paragraph. Check out our developer blogs

+

And the last paragraph. Or our online documentation.

+ + diff --git a/examples/xml/htmlinfo/trolltech_com.html b/examples/xml/htmlinfo/trolltech_com.html new file mode 100644 index 0000000000..180eb74358 --- /dev/null +++ b/examples/xml/htmlinfo/trolltech_com.html @@ -0,0 +1,955 @@ + + + + + + + + + + + Code Less. Create More. Deploy Everywhere. + — + Trolltech + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ Skip to content. + + Skip to navigation + +
+ + + + +
+ + +
+

+ Trolltech +

+ +
+ +
+
+ + +
Sections
+
+
+ +
+
+ +
+
+ +
Personal tools
+ + +
+ +
+
+ + You +are here: + Home + + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

Trolltech provides cross-platform software solutions for:

+ + + + + + + + + + + + + + + + + + +
+ + + + + Software Development Managers + + + + + + + + + + Embedded Developers + + + + +
+ + + + + Consumer Electronics Vendors + + + + + + + + + + Mobile Application Developers + + + + +
+ + + + + Cross-Platform Developers + + + + + + + + + + Open Source Developers + + + + +
+ +
+ +
+ + + + + Code Less. Create More. Deploy Everywhere. + + + +
+ + + +
+
+

Download Qt Button: Grey BG

+

Qt

+

Qt is a cross-platform application framework.  It includes:

+ +

 

+

Learn More Buy Now

+

 

+

 

+

 

+
+
+
+

Qtopia Learn More button 90px

+

Qtopia

+

Qtopia is an application platform and UI for Linux-based mobile, consumer electronics and embedded devices. Qtopia offers:

+
  • Rich toolkit and intuitive API
  • Fully customizable user interface
  • Highly efficient development framework
+

 

+

Customer Devices Buy Now

+
+
+ + + + + + + + + + + + +
+ +
+ + +
+ +
+

Quick Links

+ + + + + + + + + + + + + + +
+ + +
+

Nokia Acquisition

+ + + + + + + + +
+ + +
+

News

+ + + + +

+ + Trolltech Releases Qt Jambi 4.3.5 + + + + (Jun 03) + + + + + + + + +

+

+ + Trolltech releases Qt 4.3.5 + + + + (May 28) + + + + + + + + +

+

+ + Award From Qt Developers Recognizes Best Open Source Development Tools + + + + (May 14) + + + + + + + + +

+

+ + Trolltech Delivered Revenues of NOK 55.6 Million + + + + (May 08) + + + + + + + + +

+ + + + + +
+ + +
+

Events

+ +
+

 

+
+ + +

+ + Qt Open Enrollment Training Class + + + + + + (Jun 09 - Jun 13) + + + + + +

+

+ + Israel Qt User Group + + + + + + (Jun 16) + + + + + +

+

+ + Webinar: Building Tomorrow’s Virtual Driver Control Center + + + + + + (Jun 24) + + + + + +

+ + + + + + + +
+ +
+ + +
+ + +
+ + + + + +
+ + + + Powered by Plone CMS, the Open Source Content Management System + + + + +

+ This site conforms to the following standards: +

+ + + +
+ +
+ + + + + + + diff --git a/examples/xml/htmlinfo/w3c_org.html b/examples/xml/htmlinfo/w3c_org.html new file mode 100644 index 0000000000..0fcce48e4a --- /dev/null +++ b/examples/xml/htmlinfo/w3c_org.html @@ -0,0 +1,507 @@ + + + + + + + + + +World Wide Web Consortium - Web Standards + + + + + + + + + + + + + + + + +

The World Wide Web Consortium (W3C)

+ +

Leading the Web to Its Full Potential...

+ + + +

The World Wide Web Consortium (W3C) develops interoperable +technologies (specifications, guidelines, software, and tools) to lead +the Web to its full potential. W3C is a forum for information, +commerce, communication, and collective understanding. On this page, +you'll find W3C news, links to W3C technologies and ways to get involved. New visitors can find help in +Finding Your Way at +W3C. We encourage organizations to learn more about W3C and about +W3C Membership.

+ + + +
+

News

+ + + +

New eGovernment Activity to Help Improve Government through Better Use of the Web

+

Crowd scene

+

2008-06-03: W3C launches today a new forum for governments, citizens, researchers, and other stakeholders to investigate how best to use Web technology for good governance and citizen participation. "Open Standards, and in particular Semantic Web Standards, can help lower the cost of government, make it easier for independent agencies to work together, and increase flexibility in the face of change," said Tim Berners-Lee, W3C Director. W3C invites participation in the new eGovernment Interest Group, which is open to the public. The group will identify best practices and guidelines in this area, document where current technology does not adequately address stakeholder needs, and suggest improvements via the standards process. Read the W3C eGovernment FAQ and press release, and learn more about the W3C eGovernment Activity. (Permalink)

+ +

Two Group Notes Published About Semantic Web and Life Sciences

2008-06-05: The Semantic Web Health Care and Life Sciences Interest Group has published two Group Notes: A Prototype Knowledge Base for the Life Sciences and Experiences with the conversion of SenseLab databases to RDF/OWL. The former describes a prototype of a biomedical knowledge base that integrates 15 distinct data sources using currently available Semantic Web technologies including RDF and OWL. The Note outlines which resources were integrated, how the knowledge base was constructed using free and open source triple store technology, how it can be queried using SPARQL, and what resources and inferences are involved in answering complex queries. While the utility of the knowledge base is illustrated by identifying a set of genes involved in Alzheimer's Disease, the approach described here can be applied to any use case that integrates data from multiple domains. The second document describe the experience of converting SenseLab databases into OWL, an important step towards realizing the benefits of Semantic Web in integrative neuroscience research. Learn more about the Semantic Web Activity. (Permalink)

+ +

Offline Web Applications Published as W3C Note

2008-06-03: The HTML Working Group has published the Offline Web Applications Group Note. HTML 5 contains several features that address the challenge of building Web applications that work while offline. This document highlights these features (SQL, offline application caching APIs as well as online/offline events, status, and the localStorage API) from HTML 5 and provides brief tutorials on how these features might be used to create Web applications that work offline. Learn more about the HTML Activity. (Permalink)

+ +

W3C Advisory Committee Elects Advisory Board

2008-06-02: The W3C Advisory Committee has filled six open seats on the W3C Advisory Board. Created in 1998, the Advisory Board provides guidance to the Team on issues of strategy, management, legal matters, process, and conflict resolution. Beginning 1 July, the nine Advisory Board participants are Jean-François Abramatic (ILOG), Ann Bassetti (The Boeing Company), Jim Bell (HP), Don Deutsch (Oracle), Eduardo Gutentag (Sun Microsystems), Steve Holbrook (IBM), Ken Laskey (MITRE), Ora Lassila (Nokia), and Arun Ranganathan (Mozilla Foundation). Steve Zilles continues as interim Advisory Board Chair. Read more about the Advisory Board. (Permalink)

+ +

W3C Talks in June

2008-06-02: Browse W3C presentations and events also available as an RSS channel. (Permalink)

+ +

W3C Launches Group to Help Bridge the Digital Divide

Phone bikes2008-05-27: As part of the growing set of W3C initiatives related to social development, W3C invites participation in the new Mobile Web for Development (MW4D) interest Group, chartered to explore the potential of mobile technology to help bridge the digital divide. "We need to solve important challenges, such as lack of standards in end-user devices, network constraints, service cost, issues of literacy, and an understanding of the real information needs of rural communities," said Ken Banks, kiwanja.net, who Chairs the group. "To do so requires an multidisciplinary approach, a step we take through the creation of this new group." Read more in the press release. This launch is part of W3C's Mobile Web Initiative (MWI), which aims to identify and resolve challenges and issues of accessing the Web when on the move. This work takes place under the auspices of the European Union's 7th Research Framework Programme (FP7), part of the Digital World Forum project. (Photo credit: Stéphane Boyera. Permalink)

+ +

Last Call: XHTML Access Module

2008-05-26: The XHTML 2 Working Group has published the Last Call Working Draft of XHTML Access Module. This document is intended to help make XHTML-family markup languages more effective at supporting the needs of the accessibility community. It does so by providing a generic mechanism for defining the relationship between document components and well-known accessibility taxonomies. Comments are welcome through 16 June. Learn more about the HTML Activity. (Permalink)

+ +

W3C Invites Implementations of CSS Namespaces Module (Candidate Recommendation)

2008-05-23: The Cascading Style Sheets (CSS) Working Group has published the Candidate Recommendation of CSS Namespaces Module. This CSS Namespaces module defines the syntax for using namespaces in CSS. It defines the @namespace rule for declaring the default namespace and binding namespaces to namespace prefixes, and it also defines a syntax that other specifications can adopt for using those prefixes in namespace-qualified names. Learn more about the Style Activity. (Permalink)

+ +

Progress Events 1.0

2008-05-22: The Web API Working Group has published a Working Draft of Progress Events 1.0.This document describes event types that can be used for monitoring the progress of an operation. It is primarily intended for contexts such as data transfer operations specified by XMLHTTPRequest, or Media Access Events. Learn more about the Rich Web Client Activity. (Permalink)

+ +

XML Security Working Group to Take Next Steps on XML Signature, Encryption

2008-05-21: W3C is pleased to announce the creation of the XML Security Working Group, whose mission is to evaluate and act on recommendations from the September 2007 Workshop on XML Signature and XML Encryption regarding next steps for XML Security specifications. The group's deliverables include new work on XML Signature Syntax and Processing and XML Encryption Syntax and Processing, as well as maintenance of related specifications. Frederick Hirsch (Nokia) will Chair the group, with Thomas Roessler (W3C) as Team Contact. Learn more about the W3C Security Activity. (Permalink)

+ +

Last Call: Cascading Style Sheets (CSS) Snapshot 2007

2008-05-16: The Cascading Style Sheets (CSS) Working Group has published the Last Call Working Draft of Cascading Style Sheets (CSS) Snapshot 2007. This document collects together into one definition all the specifications that together form the current state of Cascading Style Sheets (CSS). The primary audience is CSS implementors, not CSS authors, as this definition includes modules by specification stability, not Web browser adoption rate. Comments are welcome through 09 June. Learn more about the Style Activity. (Permalink)

+ +

W3C Invites Implementations of XQuery and XPath Full Text 1.0 (Candidate Recommendation); Requirements and Use Cases Drafts Available

2008-05-16: The W3C XML Query Working Group and the W3C XSL Working Group jointly published today a Candidate Recommendation of XQuery and XPath Full Text 1.0. This document defines the syntax and formal semantics of XQuery and XPath Full Text 1.0 which is a language that extends XQuery 1.0 [XQuery 1.0: An XML Query Language] and XPath 2.0 [XML Path Language (XPath) 2.0] with full-text search capabilities. Implementors are encouraged to run the groups' test suite and report their results. The Groups also published Working Drafts of XQuery and XPath Full Text 1.0 Requirements and Use Cases. Learn more about the XML Activity. (Permalink)

+ +

State Chart XML (SCXML) Working Draft Published

2008-05-16: The Voice Browser Working Group has published an updated Working Draft of State Chart XML (SCXML): State Machine Notation for Control Abstraction. SCXML is an execution environment based on UML Harel State Tables and CCXML. The main differences from the previous draft are (1) the modularization of the language, (2) the introduction of profiles and (3) a revision of the algorithm for document interpretation; the document as a whole has changed significantly and the group welcomes review. Learn more about the Voice Browser Activity. (Permalink)

+ +

"Web Accessibility for Older Users: A Literature Review"; Comments Welcome on First Public Draft

2008-05-14: The Web Accessibility Initiative (WAI) Education and Outreach Working Group Working Group (EOWG) has published Web Accessibility for Older Users: A Literature Review as a First Public Working Draft. The document includes reviews and analysis of guidelines and articles covering the requirements of people with Web accessibility needs related to ageing. This literature review will inform WAI efforts to promote accessibility solutions for older Web users and potentially to develop profiles or extensions to WAI guidelines. The literature review is a deliverable of the WAI-AGE Project (Ageing Education and Harmonisation). See the call for review and participation for an introduction to the project and an invitation to contribute to the literature review and other WAI-AGE work; and about the Web Accessibility Initiative. (Permalink)

+ +

Last Call: CURIE Syntax 1.0

2008-05-08: The XHTML2 Working Group has published the Last Call Working Draft of CURIE Syntax 1.0, which outlines a syntax for expressing URIs in a generic, abbreviated syntax ("Compact URI"). The specification targets language designers who need a mechanism to permit the use of extensible value collections. Any language designer considering the use of QNames in attribute values should consider instead using CURIEs, since CURIEs are designed for this purpose, while QNames are not. Comments are welcome through 10 June. Learn more about the HTML Activity. (Permalink)

+ + + +

Past News

+
+ + +
+ +

W3C would like to thank the Supporters who have contributed +financially or through a donation of goods to W3C.

+ +

Read about the layout and send comments +about this page. Syndicate +this page with RSS 1.0, an +RDF vocabulary used for site summaries.

+ +
+Webmaster · Last modified: + $Date: 2008/06/05 17:06:19 $ + |
+Valid XHTML 1.0! | Valid CSS! | Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0 + | +
+ + + + diff --git a/examples/xml/htmlinfo/youtube_com.html b/examples/xml/htmlinfo/youtube_com.html new file mode 100644 index 0000000000..1de65a3aa5 --- /dev/null +++ b/examples/xml/htmlinfo/youtube_com.html @@ -0,0 +1,1585 @@ + + + + + + + + + YouTube - Broadcast Yourself. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ + + +
+ +
+ +
+
Loading...
+
+ +
+
+
+ + + + + + +
+
+
+ +
+ +
+
Promoted Videos
+
+
+
+
+
+
+
+ + +
+ beggars +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+ + +
+ Jr0canest +
+
+
+
+
+
+
+
+ + + +
+
+
+
+ + + + + + + + +
+
+ + + + +
+ +
video
+ +
+ + +
+ + + + Michael Greiner who is a neighbor and good friend of mine asked me to upload several Marim + + + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 3,853
+ +
+ + +
+ + 4.84814814815 + + + +
+ + + +
01:46
+
+ +
+
+ More in Entertainment +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + Check out the book "Sharp Teeth" on Amazon:
http://www.amazon.com/Sharp-Teeth-Toby-Barlow +
+ + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 67,438
+ +
+ + +
+ + 4.39928057554 + + + +
+ + + +
01:33
+
+ +
+
+ More in Film & Animation +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + This video is for Mrs. Aderman's 1st Period Environmental Science Class.

We are Mose Gi +
+ + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 122,748
+ +
+ + +
+ + 4.44329896907 + + + +
+ + + +
04:02
+
+ +
+
+ More in Education +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+
+
+ JCJC +
+
+ JCJC +
+
+ +
+ + + + His name is Okotanpe.
His mail addless is fuseloopa@hotmail.com

The name of this son +
+ + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 532,447
+ +
+ + +
+ + 4.83995523223 + + + +
+ + + +
05:26
+
+ +
+
+ More in Entertainment +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + I'm not a particularly political person, by which I mean I'd sooner just not get involved + + + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 136,222
+ +
+ + +
+ + 4.65044814341 + + + +
+ + + +
03:55
+
+ +
+
+ More in Music +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + for the taking. + + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 509,825
+ +
+ + +
+ + 3.91057134971 + + + +
+ + + +
05:15
+
+ +
+
+ More in Science & Technology +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + Want a chance to sing with Aimee Mann live? Go to http://www.youtube.com/group/aimeemannco + + + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 283,776
+ +
+ + +
+ + 3.79036827195 + + + +
+ + + +
02:22
+
+ +
+
+ More in Music +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + This is the first interactive video on YouTube!
Have fun and enjoy the show
you can see +
+ + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 3,155,063
+ +
+ + +
+ + 3.41263230956 + + + +
+ + + +
01:10
+
+ +
+
+ More in People & Blogs +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + making the biggest drawing in the world + + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 971,773
+ +
+ + +
+ + 4.54770783066 + + + +
+ + + +
04:04
+
+ +
+
+ More in Film & Animation +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+
+
+ Checkmate +
+
+ Checkmate +
+
+ +
+ + + + The Internets Celebrities Dallas Penn and Rafi Kam go in for an investigative report on Ch + + + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 412,830
+ +
+ + +
+ + 4.52936962751 + + + +
+ + + +
09:45
+
+ +
+
+ More in News & Politics +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + Stories from the men and women of the miltary, stationed in the Al Anbar Province. Right f + + + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 367,189
+ +
+ + +
+ + 4.2188365651 + + + +
+ + + +
10:35
+
+ +
+
+ More in News & Politics +
+
+ +
+ + + +
+ + + + + + +
+ +
video
+ +
+ + +
+ + + + Video from TornadoVideos.net Live Stream Unit 3 of several tornadoes from close range.. In + + + + (more) + + + + +
+
+ +
+ + +
+ +
+
+
+ +
+ Views: 797,370
+ +
+ + +
+ + 4.28912552436 + + + +
+ + + +
07:10
+
+ +
+
+ More in News & Politics +
+
+ +
+ + + +
+ + +
+
+ +
+ + +
+
+ + + + + + + + + + + +
+ + + + + + + +
+ + + + +
+ +
+
+
+ +
+ Login +
+
+
+ +
+ + + + + + + + + + + + + +
+
+ +
+
+ +
+ +
+
+ + +
+ + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + +
+ +
+
+
What's New
+ +
+
+
+ Video Annotations
Add interactive commentary and links to your videos +
+
+ +
+
+
+ New Address Book
Organizing your YouTube friends and contacts just got a lot simpler +
+
+ +
+
+
+ Updated Inbox
Manage your messages and invites with ease +
+
+ + +
+
+
+ YouTube Mobile
Watch and upload YouTube videos on your mobile device. +
+
+ +
+ Hear Ye, Hear Ye: Calling all Reporters
+ Today we announce the launch of a new type of YouTube account: the Reporter. Reporter channels are just like the other YouTube channel types, but are specifically intended for citizens and profess... + +

+
+
+ + +
+ + + + + + + + + + + + + + +
+ + +
+ +
+ + + +
+ + + + +
+ + + + + + + \ No newline at end of file diff --git a/examples/xml/rsslisting/main.cpp b/examples/xml/rsslisting/main.cpp new file mode 100644 index 0000000000..011569f2b6 --- /dev/null +++ b/examples/xml/rsslisting/main.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$ +** +****************************************************************************/ + +/* +main.cpp + +Provides the main function for the RSS news reader example. +*/ + +#include + +#include "rsslisting.h" + +/*! + Create an application and a main widget. Open the main widget for + user input, and exit with an appropriate return value when it is + closed. +*/ + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + RSSListing *rsslisting = new RSSListing; + rsslisting->show(); + return app.exec(); +} diff --git a/examples/xml/rsslisting/rsslisting.cpp b/examples/xml/rsslisting/rsslisting.cpp new file mode 100644 index 0000000000..5840f08d09 --- /dev/null +++ b/examples/xml/rsslisting/rsslisting.cpp @@ -0,0 +1,247 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/* +rsslisting.cpp + +Provides a widget for displaying news items from RDF news sources. +RDF is an XML-based format for storing items of information (see +http://www.w3.org/RDF/ for details). + +The widget itself provides a simple user interface for specifying +the URL of a news source, and controlling the downloading of news. + +The widget downloads and parses the XML asynchronously, feeding the +data to an XML reader in pieces. This allows the user to interrupt +its operation, and also allows very large data sources to be read. +*/ + + +#include +#include +#include + +#include "rsslisting.h" + + +/* + Constructs an RSSListing widget with a simple user interface, and sets + up the XML reader to use a custom handler class. + + The user interface consists of a line edit, a push button, and a + list view widget. The line edit is used for entering the URLs of news + sources; the push button starts the process of reading the + news. +*/ + +RSSListing::RSSListing(QWidget *parent) + : QWidget(parent), currentReply(0) +{ + lineEdit = new QLineEdit(this); + lineEdit->setText("http://labs.qt.nokia.com/blogs/feed"); + + fetchButton = new QPushButton(tr("Fetch"), this); + + treeWidget = new QTreeWidget(this); + connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), + this, SLOT(itemActivated(QTreeWidgetItem*))); + QStringList headerLabels; + headerLabels << tr("Title") << tr("Link"); + treeWidget->setHeaderLabels(headerLabels); + treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + + connect(&manager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(finished(QNetworkReply*))); + + connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch())); + connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch())); + + QVBoxLayout *layout = new QVBoxLayout(this); + + QHBoxLayout *hboxLayout = new QHBoxLayout; + + hboxLayout->addWidget(lineEdit); + hboxLayout->addWidget(fetchButton); + + layout->addLayout(hboxLayout); + layout->addWidget(treeWidget); + + setWindowTitle(tr("RSS listing example")); + resize(640,480); +} + +/* + Starts the network request and connects the needed signals +*/ +void RSSListing::get(const QUrl &url) +{ + QNetworkRequest request(url); + if (currentReply) { + currentReply->disconnect(this); + currentReply->deleteLater(); + } + currentReply = manager.get(request); + connect(currentReply, SIGNAL(readyRead()), this, SLOT(readyRead())); + connect(currentReply, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged())); + connect(currentReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError))); +} + +/* + Starts fetching data from a news source specified in the line + edit widget. + + The line edit is made read only to prevent the user from modifying its + contents during the fetch; this is only for cosmetic purposes. + The fetch button is disabled, the list view is cleared, and we + define the last list view item to be 0, meaning that there are no + existing items in the list. + + A URL is created with the raw contents of the line edit and + a get is initiated. +*/ + +void RSSListing::fetch() +{ + lineEdit->setReadOnly(true); + fetchButton->setEnabled(false); + treeWidget->clear(); + + xml.clear(); + + QUrl url(lineEdit->text()); + get(url); +} + +void RSSListing::metaDataChanged() +{ + QUrl redirectionTarget = currentReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); + if (redirectionTarget.isValid()) { + get(redirectionTarget); + } +} + +/* + Reads data received from the RDF source. + + We read all the available data, and pass it to the XML + stream reader. Then we call the XML parsing function. +*/ + +void RSSListing::readyRead() +{ + int statusCode = currentReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if (statusCode >= 200 && statusCode < 300) { + QByteArray data = currentReply->readAll(); + xml.addData(data); + parseXml(); + } +} + +/* + Finishes processing an HTTP request. + + The default behavior is to keep the text edit read only. + + If an error has occurred, the user interface is made available + to the user for further input, allowing a new fetch to be + started. + + If the HTTP get request has finished, we make the + user interface available to the user for further input. +*/ + +void RSSListing::finished(QNetworkReply *reply) +{ + Q_UNUSED(reply); + lineEdit->setReadOnly(false); + fetchButton->setEnabled(true); +} + + +/* + Parses the XML data and creates treeWidget items accordingly. +*/ +void RSSListing::parseXml() +{ + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement()) { + if (xml.name() == "item") + linkString = xml.attributes().value("rss:about").toString(); + currentTag = xml.name().toString(); + } else if (xml.isEndElement()) { + if (xml.name() == "item") { + + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(0, titleString); + item->setText(1, linkString); + treeWidget->addTopLevelItem(item); + + titleString.clear(); + linkString.clear(); + } + + } else if (xml.isCharacters() && !xml.isWhitespace()) { + if (currentTag == "title") + titleString += xml.text().toString(); + else if (currentTag == "link") + linkString += xml.text().toString(); + } + } + if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) { + qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString(); + } +} + +/* + Open the link in the browser +*/ +void RSSListing::itemActivated(QTreeWidgetItem * item) +{ + QDesktopServices::openUrl(QUrl(item->text(1))); +} + +void RSSListing::error(QNetworkReply::NetworkError) +{ + qWarning("error retrieving RSS feed"); + currentReply->disconnect(this); + currentReply->deleteLater(); + currentReply = 0; +} diff --git a/examples/xml/rsslisting/rsslisting.h b/examples/xml/rsslisting/rsslisting.h new file mode 100644 index 0000000000..98254f839b --- /dev/null +++ b/examples/xml/rsslisting/rsslisting.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 RSSLISTING_H +#define RSSLISTING_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QLineEdit; +class QTreeWidget; +class QTreeWidgetItem; +class QPushButton; +QT_END_NAMESPACE + +class RSSListing : public QWidget +{ + Q_OBJECT +public: + RSSListing(QWidget *widget = 0); + +public slots: + void fetch(); + void finished(QNetworkReply *reply); + void readyRead(); + void metaDataChanged(); + void itemActivated(QTreeWidgetItem * item); + void error(QNetworkReply::NetworkError); + +private: + void parseXml(); + void get(const QUrl &url); + + QXmlStreamReader xml; + QString currentTag; + QString linkString; + QString titleString; + + QNetworkAccessManager manager; + QNetworkReply *currentReply; + + QLineEdit *lineEdit; + QTreeWidget *treeWidget; + QPushButton *fetchButton; +}; + +#endif + diff --git a/examples/xml/rsslisting/rsslisting.pro b/examples/xml/rsslisting/rsslisting.pro new file mode 100644 index 0000000000..01bc9e2ad6 --- /dev/null +++ b/examples/xml/rsslisting/rsslisting.pro @@ -0,0 +1,12 @@ +HEADERS += rsslisting.h +SOURCES += main.cpp rsslisting.cpp +QT += network xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/rsslisting +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS rsslisting.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/rsslisting +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + diff --git a/examples/xml/saxbookmarks/frank.xbel b/examples/xml/saxbookmarks/frank.xbel new file mode 100644 index 0000000000..6bd63b8b07 --- /dev/null +++ b/examples/xml/saxbookmarks/frank.xbel @@ -0,0 +1,230 @@ + + + + + Literate Programming + + Synopsis of Literate Programming + + + Literate Programming: Propaganda and Tools + + + Literate Programming by Henrik Turbell + + + Literate Programming Library + + + Literate Programming Basics + + + Literate Programming Overview + + + POD is not Literate Programming + + + Computers That We Can Count On + + + Literate Programming - Issues and Problems + + + Literate Programming - Wiki Pages + + + What is well-commented code? + + + Bibliography on literate programming - A searchable bibliography + + + Program comprehension and code reading bibliography + + + Elucidative Programming + + + AVL Trees (TexiWeb) + + + Literate Programming on Wikiverse + + + Physically Based Rendering: From Theory to Implementation + + + + Useful C++ Links + + STL + + STL Reference Documentation + + + STL Tutorial + + + STL Reference + + + + Qt + + Qt 2.3 Reference + + + Qt 3.3 Reference + + + Qt 4.0 Reference + + + Qt Home Page + + + + IOStreams + + IO Stream Library + + + Binary I/O + + + I/O Stream FAQ + + + + gdb + + GDB Tutorial + + + Debugging with GDB + + + GDB Quick Reference Page (PDF) (Handy) + + + + Classes and Constructors + + Constructor FAQ + + + Organizing Classes + + + + + Software Documentation or System Documentation + + The Almighty Thud + + + Microsoft Coding Techniques and Programming Practices + + + Software and Documentation + + + The Source Code is the Design + + + What is Software Design? + + + How To Write Unmaintainable Code + + + Self Documenting Program Code Remains a Distant Goal + + + Place Tab A in Slot B + + + UML Reference Card + + + + TeX Resources + + The TeX User's Group + + + MikTeX website + + + MetaPost website + + + HEVEA is a quite complete and fast LATEX to HTML translator + + + + Portable Document Format (PDF) + + Adobe - The postscript and PDF standards + + + Reference Manual Portable Document Format + + + Adobe Acrobat Software Development Kit + + + + Literature Sites + + Guide to Special Collections (Columbia University) + + + Literary Criticism on the Web from the Internet Public Library + + + Victorian Web. + + + Voice of the Shuttle. + + + Modernist Journals Project + + + Museum of American Poetics + + + Modern American Poetry + + + FindArticles.com + + + Literary History + + + Literary Encyclopedia + + + + The University of California Press + + + Wright American Fiction, 1851-1875 + + + Documenting the American South: Beginnings to 1920 + + + Electronic Text Center at the University of Virginia + + + The Schomburg Center for Research in Black Culture + + + Alex Catalogue of Electronic Texts. + + + diff --git a/examples/xml/saxbookmarks/jennifer.xbel b/examples/xml/saxbookmarks/jennifer.xbel new file mode 100644 index 0000000000..d6a5b41d05 --- /dev/null +++ b/examples/xml/saxbookmarks/jennifer.xbel @@ -0,0 +1,93 @@ + + + + + Qt Resources + + Qt Partners + + Training Partners + + + Consultants and System Integrators + + + Technology Partners + + + Value Added Resellers (VARs) + + + + Community Resources + + QtForum.org + + + The Independent Qt Tutorial + + + French PROG.Qt + + + German Qt Forum + + + Korean Qt Community Site + + + Russian Qt Forum + + + Digitalfanatics: The QT 4 Resource Center + + + QtQuestions + + + + Qt Quarterly + + + qt home page + + + Qt 4.0 documentation + + + Frequently Asked Questions + + + + Online Dictionaries + + Dictionary.com + + + Merriam-Webster Online + + + Cambridge Dictionaries Online + + + OneLook Dictionary Search + + + + The New English-German Dictionary + + + TU Chemnitz German-English Dictionary + + + + Trésor de la Langue Française informatisé + + + Dictionnaire de l'Académie Française + + + Dictionnaire des synonymes + + + diff --git a/examples/xml/saxbookmarks/main.cpp b/examples/xml/saxbookmarks/main.cpp new file mode 100644 index 0000000000..5d70ec89a5 --- /dev/null +++ b/examples/xml/saxbookmarks/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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 + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; +#if defined(Q_OS_SYMBIAN) + mainWin.showFullScreen(); +#else + mainWin.show(); +#endif + mainWin.open(); + return app.exec(); +} diff --git a/examples/xml/saxbookmarks/mainwindow.cpp b/examples/xml/saxbookmarks/mainwindow.cpp new file mode 100644 index 0000000000..e5300121e5 --- /dev/null +++ b/examples/xml/saxbookmarks/mainwindow.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** 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 + +#include "mainwindow.h" +#include "xbelgenerator.h" +#include "xbelhandler.h" + +MainWindow::MainWindow() +{ + QStringList labels; + labels << tr("Title") << tr("Location"); + + treeWidget = new QTreeWidget; + treeWidget->header()->setResizeMode(QHeaderView::Stretch); + treeWidget->setHeaderLabels(labels); + setCentralWidget(treeWidget); + + createActions(); + createMenus(); + + statusBar()->showMessage(tr("Ready")); + + setWindowTitle(tr("SAX Bookmarks")); + resize(480, 320); +} + +void MainWindow::open() +{ +#if defined(Q_OS_SYMBIAN) + // Look for bookmarks on the same drive where the application is installed to, + // if drive is not read only. QDesktopServices::DataLocation does this check, + // and returns writable drive. + QString bookmarksFolder = + QDesktopServices::storageLocation(QDesktopServices::DataLocation).left(1); + bookmarksFolder.append(":/Data/qt/saxbookmarks"); + QDir::setCurrent(bookmarksFolder); +#endif + QString fileName = + QFileDialog::getOpenFileName(this, tr("Open Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + treeWidget->clear(); + + XbelHandler handler(treeWidget); + QXmlSimpleReader reader; + reader.setContentHandler(&handler); + reader.setErrorHandler(&handler); + + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("SAX Bookmarks"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + QXmlInputSource xmlInputSource(&file); + if (reader.parse(xmlInputSource)) + statusBar()->showMessage(tr("File loaded"), 2000); +} + +void MainWindow::saveAs() +{ + QString fileName = + QFileDialog::getSaveFileName(this, tr("Save Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + QFile file(fileName); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, tr("SAX Bookmarks"), + tr("Cannot write file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + XbelGenerator generator(treeWidget); + if (generator.write(&file)) + statusBar()->showMessage(tr("File saved"), 2000); +} + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About SAX Bookmarks"), + tr("The SAX Bookmarks example demonstrates how to use Qt's " + "SAX classes to read XML documents and how to generate XML by " + "hand.")); +} + +void MainWindow::createActions() +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcuts(QKeySequence::Open); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAsAct = new QAction(tr("&Save As..."), this); + saveAsAct->setShortcuts(QKeySequence::SaveAs); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcuts(QKeySequence::Quit); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAct); + fileMenu->addAction(saveAsAct); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} diff --git a/examples/xml/saxbookmarks/mainwindow.h b/examples/xml/saxbookmarks/mainwindow.h new file mode 100644 index 0000000000..3313d8f574 --- /dev/null +++ b/examples/xml/saxbookmarks/mainwindow.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 + +QT_BEGIN_NAMESPACE +class QTreeWidget; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void open(); + void saveAs(); + void about(); + +private: + void createActions(); + void createMenus(); + + QTreeWidget *treeWidget; + + QMenu *fileMenu; + QMenu *helpMenu; + QAction *openAct; + QAction *saveAsAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; + +#endif diff --git a/examples/xml/saxbookmarks/saxbookmarks.pro b/examples/xml/saxbookmarks/saxbookmarks.pro new file mode 100644 index 0000000000..3091947afc --- /dev/null +++ b/examples/xml/saxbookmarks/saxbookmarks.pro @@ -0,0 +1,28 @@ +HEADERS = mainwindow.h \ + xbelgenerator.h \ + xbelhandler.h +SOURCES = main.cpp \ + mainwindow.cpp \ + xbelgenerator.cpp \ + xbelhandler.cpp +QT += xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/saxbookmarks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS saxbookmarks.pro *.xbel +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/saxbookmarks +INSTALLS += target sources + +wince*: { + addFiles.files = frank.xbel jennifer.xbel + addFiles.path = "\\My Documents" + DEPLOYMENT += addFiles +} + +symbian: { + TARGET.UID3 = 0xA000C60A + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + addFiles.files = frank.xbel jennifer.xbel + addFiles.path = /data/qt/saxbookmarks + DEPLOYMENT += addFiles +} diff --git a/examples/xml/saxbookmarks/xbelgenerator.cpp b/examples/xml/saxbookmarks/xbelgenerator.cpp new file mode 100644 index 0000000000..a0bfe67f69 --- /dev/null +++ b/examples/xml/saxbookmarks/xbelgenerator.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** 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 + +#include "xbelgenerator.h" + +XbelGenerator::XbelGenerator(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ +} + +bool XbelGenerator::write(QIODevice *device) +{ + out.setDevice(device); + out.setCodec("UTF-8"); + out << "\n" + << "\n" + << "\n"; + + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) + generateItem(treeWidget->topLevelItem(i), 1); + + out << "\n"; + return true; +} + +QString XbelGenerator::indent(int depth) +{ + const int IndentSize = 4; + return QString(IndentSize * depth, ' '); +} + +QString XbelGenerator::escapedText(const QString &str) +{ + QString result = str; + result.replace("&", "&"); + result.replace("<", "<"); + result.replace(">", ">"); + return result; +} + +QString XbelGenerator::escapedAttribute(const QString &str) +{ + QString result = escapedText(str); + result.replace("\"", """); + result.prepend("\""); + result.append("\""); + return result; +} + +void XbelGenerator::generateItem(QTreeWidgetItem *item, int depth) +{ + QString tagName = item->data(0, Qt::UserRole).toString(); + if (tagName == "folder") { + bool folded = !treeWidget->isItemExpanded(item); + out << indent(depth) << "\n" + << indent(depth + 1) << "" << escapedText(item->text(0)) + << "\n"; + + for (int i = 0; i < item->childCount(); ++i) + generateItem(item->child(i), depth + 1); + + out << indent(depth) << "\n"; + } else if (tagName == "bookmark") { + out << indent(depth) << "text(1).isEmpty()) + out << " href=" << escapedAttribute(item->text(1)); + out << ">\n" + << indent(depth + 1) << "" << escapedText(item->text(0)) + << "\n" + << indent(depth) << "\n"; + } else if (tagName == "separator") { + out << indent(depth) << "\n"; + } +} diff --git a/examples/xml/saxbookmarks/xbelgenerator.h b/examples/xml/saxbookmarks/xbelgenerator.h new file mode 100644 index 0000000000..84011a262f --- /dev/null +++ b/examples/xml/saxbookmarks/xbelgenerator.h @@ -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$ +** +****************************************************************************/ + +#ifndef XBELGENERATOR_H +#define XBELGENERATOR_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +class XbelGenerator +{ +public: + XbelGenerator(QTreeWidget *treeWidget); + + bool write(QIODevice *device); + +private: + static QString indent(int indentLevel); + static QString escapedText(const QString &str); + static QString escapedAttribute(const QString &str); + void generateItem(QTreeWidgetItem *item, int depth); + + QTreeWidget *treeWidget; + QTextStream out; +}; + +#endif diff --git a/examples/xml/saxbookmarks/xbelhandler.cpp b/examples/xml/saxbookmarks/xbelhandler.cpp new file mode 100644 index 0000000000..09874c9edc --- /dev/null +++ b/examples/xml/saxbookmarks/xbelhandler.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** 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 + +#include "xbelhandler.h" + +XbelHandler::XbelHandler(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ + item = 0; + metXbelTag = false; + + QStyle *style = treeWidget->style(); + + folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), + QIcon::Normal, QIcon::Off); + folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), + QIcon::Normal, QIcon::On); + bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); +} + +bool XbelHandler::startElement(const QString & /* namespaceURI */, + const QString & /* localName */, + const QString &qName, + const QXmlAttributes &attributes) +{ + if (!metXbelTag && qName != "xbel") { + errorStr = QObject::tr("The file is not an XBEL file."); + return false; + } + + if (qName == "xbel") { + QString version = attributes.value("version"); + if (!version.isEmpty() && version != "1.0") { + errorStr = QObject::tr("The file is not an XBEL version 1.0 file."); + return false; + } + metXbelTag = true; + } else if (qName == "folder") { + item = createChildItem(qName); + item->setFlags(item->flags() | Qt::ItemIsEditable); + item->setIcon(0, folderIcon); + item->setText(0, QObject::tr("Folder")); + bool folded = (attributes.value("folded") != "no"); + treeWidget->setItemExpanded(item, !folded); + } else if (qName == "bookmark") { + item = createChildItem(qName); + item->setFlags(item->flags() | Qt::ItemIsEditable); + item->setIcon(0, bookmarkIcon); + item->setText(0, QObject::tr("Unknown title")); + item->setText(1, attributes.value("href")); + } else if (qName == "separator") { + item = createChildItem(qName); + item->setFlags(item->flags() & ~Qt::ItemIsSelectable); + item->setText(0, QString(30, 0xB7)); + } + + currentText.clear(); + return true; +} + +bool XbelHandler::endElement(const QString & /* namespaceURI */, + const QString & /* localName */, + const QString &qName) +{ + if (qName == "title") { + if (item) + item->setText(0, currentText); + } else if (qName == "folder" || qName == "bookmark" + || qName == "separator") { + item = item->parent(); + } + return true; +} + +bool XbelHandler::characters(const QString &str) +{ + currentText += str; + return true; +} + +bool XbelHandler::fatalError(const QXmlParseException &exception) +{ + QMessageBox::information(treeWidget->window(), QObject::tr("SAX Bookmarks"), + QObject::tr("Parse error at line %1, column %2:\n" + "%3") + .arg(exception.lineNumber()) + .arg(exception.columnNumber()) + .arg(exception.message())); + return false; +} + +QString XbelHandler::errorString() const +{ + return errorStr; +} + +QTreeWidgetItem *XbelHandler::createChildItem(const QString &tagName) +{ + QTreeWidgetItem *childItem; + if (item) { + childItem = new QTreeWidgetItem(item); + } else { + childItem = new QTreeWidgetItem(treeWidget); + } + childItem->setData(0, Qt::UserRole, tagName); + return childItem; +} diff --git a/examples/xml/saxbookmarks/xbelhandler.h b/examples/xml/saxbookmarks/xbelhandler.h new file mode 100644 index 0000000000..cee1bafe48 --- /dev/null +++ b/examples/xml/saxbookmarks/xbelhandler.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 XBELHANDLER_H +#define XBELHANDLER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +class XbelHandler : public QXmlDefaultHandler +{ +public: + XbelHandler(QTreeWidget *treeWidget); + + bool startElement(const QString &namespaceURI, const QString &localName, + const QString &qName, const QXmlAttributes &attributes); + bool endElement(const QString &namespaceURI, const QString &localName, + const QString &qName); + bool characters(const QString &str); + bool fatalError(const QXmlParseException &exception); + QString errorString() const; + +private: + QTreeWidgetItem *createChildItem(const QString &tagName); + + QTreeWidget *treeWidget; + QTreeWidgetItem *item; + QString currentText; + QString errorStr; + bool metXbelTag; + + QIcon folderIcon; + QIcon bookmarkIcon; +}; + +#endif diff --git a/examples/xml/streambookmarks/frank.xbel b/examples/xml/streambookmarks/frank.xbel new file mode 100644 index 0000000000..6bd63b8b07 --- /dev/null +++ b/examples/xml/streambookmarks/frank.xbel @@ -0,0 +1,230 @@ + + + + + Literate Programming + + Synopsis of Literate Programming + + + Literate Programming: Propaganda and Tools + + + Literate Programming by Henrik Turbell + + + Literate Programming Library + + + Literate Programming Basics + + + Literate Programming Overview + + + POD is not Literate Programming + + + Computers That We Can Count On + + + Literate Programming - Issues and Problems + + + Literate Programming - Wiki Pages + + + What is well-commented code? + + + Bibliography on literate programming - A searchable bibliography + + + Program comprehension and code reading bibliography + + + Elucidative Programming + + + AVL Trees (TexiWeb) + + + Literate Programming on Wikiverse + + + Physically Based Rendering: From Theory to Implementation + + + + Useful C++ Links + + STL + + STL Reference Documentation + + + STL Tutorial + + + STL Reference + + + + Qt + + Qt 2.3 Reference + + + Qt 3.3 Reference + + + Qt 4.0 Reference + + + Qt Home Page + + + + IOStreams + + IO Stream Library + + + Binary I/O + + + I/O Stream FAQ + + + + gdb + + GDB Tutorial + + + Debugging with GDB + + + GDB Quick Reference Page (PDF) (Handy) + + + + Classes and Constructors + + Constructor FAQ + + + Organizing Classes + + + + + Software Documentation or System Documentation + + The Almighty Thud + + + Microsoft Coding Techniques and Programming Practices + + + Software and Documentation + + + The Source Code is the Design + + + What is Software Design? + + + How To Write Unmaintainable Code + + + Self Documenting Program Code Remains a Distant Goal + + + Place Tab A in Slot B + + + UML Reference Card + + + + TeX Resources + + The TeX User's Group + + + MikTeX website + + + MetaPost website + + + HEVEA is a quite complete and fast LATEX to HTML translator + + + + Portable Document Format (PDF) + + Adobe - The postscript and PDF standards + + + Reference Manual Portable Document Format + + + Adobe Acrobat Software Development Kit + + + + Literature Sites + + Guide to Special Collections (Columbia University) + + + Literary Criticism on the Web from the Internet Public Library + + + Victorian Web. + + + Voice of the Shuttle. + + + Modernist Journals Project + + + Museum of American Poetics + + + Modern American Poetry + + + FindArticles.com + + + Literary History + + + Literary Encyclopedia + + + + The University of California Press + + + Wright American Fiction, 1851-1875 + + + Documenting the American South: Beginnings to 1920 + + + Electronic Text Center at the University of Virginia + + + The Schomburg Center for Research in Black Culture + + + Alex Catalogue of Electronic Texts. + + + diff --git a/examples/xml/streambookmarks/jennifer.xbel b/examples/xml/streambookmarks/jennifer.xbel new file mode 100644 index 0000000000..36256fda0a --- /dev/null +++ b/examples/xml/streambookmarks/jennifer.xbel @@ -0,0 +1,93 @@ + + + + + Qt Resources + + Qt Partners + + Training Partners + + + Consultants and System Integrators + + + Technology Partners + + + Value Added Resellers (VARs) + + + + Community Resources + + QtForum.org + + + The Independent Qt Tutorial + + + French PROG.Qt + + + German Qt Forum + + + Korean Qt Community Site + + + Russian Qt Forum + + + Digitalfanatics: The QT 4 Resource Center + + + QtQuestions + + + + Qt Quarterly + + + Qt home page + + + Qt 4.0 documentation + + + Frequently Asked Questions + + + + Online Dictionaries + + Dictionary.com + + + Merriam-Webster Online + + + Cambridge Dictionaries Online + + + OneLook Dictionary Search + + + + The New English-German Dictionary + + + TU Chemnitz German-English Dictionary + + + + Trésor de la Langue Française informatisé + + + Dictionnaire de l'Académie Française + + + Dictionnaire des synonymes + + + diff --git a/examples/xml/streambookmarks/main.cpp b/examples/xml/streambookmarks/main.cpp new file mode 100644 index 0000000000..c44e921e82 --- /dev/null +++ b/examples/xml/streambookmarks/main.cpp @@ -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$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +//! [0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; + mainWin.show(); + mainWin.open(); + return app.exec(); +} +//! [0] diff --git a/examples/xml/streambookmarks/mainwindow.cpp b/examples/xml/streambookmarks/mainwindow.cpp new file mode 100644 index 0000000000..e9236e93e6 --- /dev/null +++ b/examples/xml/streambookmarks/mainwindow.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** 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 + +#include "mainwindow.h" +#include "xbelreader.h" +#include "xbelwriter.h" + +//! [0] +MainWindow::MainWindow() +{ + QStringList labels; + labels << tr("Title") << tr("Location"); + + treeWidget = new QTreeWidget; + treeWidget->header()->setResizeMode(QHeaderView::Stretch); + treeWidget->setHeaderLabels(labels); + setCentralWidget(treeWidget); + + createActions(); + createMenus(); + + statusBar()->showMessage(tr("Ready")); + + setWindowTitle(tr("QXmlStream Bookmarks")); + resize(480, 320); +} +//! [0] + +//! [1] +void MainWindow::open() +{ + QString fileName = + QFileDialog::getOpenFileName(this, tr("Open Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + treeWidget->clear(); + + + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("QXmlStream Bookmarks"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + XbelReader reader(treeWidget); + if (!reader.read(&file)) { + QMessageBox::warning(this, tr("QXmlStream Bookmarks"), + tr("Parse error in file %1:\n\n%2") + .arg(fileName) + .arg(reader.errorString())); + } else { + statusBar()->showMessage(tr("File loaded"), 2000); + } + +} +//! [1] + +//! [2] +void MainWindow::saveAs() +{ + QString fileName = + QFileDialog::getSaveFileName(this, tr("Save Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + QFile file(fileName); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, tr("QXmlStream Bookmarks"), + tr("Cannot write file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + XbelWriter writer(treeWidget); + if (writer.writeFile(&file)) + statusBar()->showMessage(tr("File saved"), 2000); +} +//! [2] + +//! [3] +void MainWindow::about() +{ + QMessageBox::about(this, tr("About QXmlStream Bookmarks"), + tr("The QXmlStream Bookmarks example demonstrates how to use Qt's " + "QXmlStream classes to read and write XML documents.")); +} +//! [3] + +//! [4] +void MainWindow::createActions() +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcuts(QKeySequence::Open); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAsAct = new QAction(tr("&Save As..."), this); + saveAsAct->setShortcuts(QKeySequence::SaveAs); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcuts(QKeySequence::Quit); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} +//! [4] + +//! [5] +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAct); + fileMenu->addAction(saveAsAct); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} +//! [5] diff --git a/examples/xml/streambookmarks/mainwindow.h b/examples/xml/streambookmarks/mainwindow.h new file mode 100644 index 0000000000..f27c4088bc --- /dev/null +++ b/examples/xml/streambookmarks/mainwindow.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 MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +QT_END_NAMESPACE + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void open(); + void saveAs(); + void about(); + +private: + void createActions(); + void createMenus(); + + QTreeWidget *treeWidget; + + QMenu *fileMenu; + QMenu *helpMenu; + QAction *openAct; + QAction *saveAsAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; +//! [0] + +#endif diff --git a/examples/xml/streambookmarks/streambookmarks.pro b/examples/xml/streambookmarks/streambookmarks.pro new file mode 100644 index 0000000000..febd3cd85f --- /dev/null +++ b/examples/xml/streambookmarks/streambookmarks.pro @@ -0,0 +1,16 @@ +HEADERS = mainwindow.h \ + xbelreader.h \ + xbelwriter.h +SOURCES = main.cpp \ + mainwindow.cpp \ + xbelreader.cpp \ + xbelwriter.cpp +QT += xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/streambookmarks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS streambookmarks.pro *.xbel +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/streambookmarks +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/xml/streambookmarks/xbelreader.cpp b/examples/xml/streambookmarks/xbelreader.cpp new file mode 100644 index 0000000000..e6d1c64e64 --- /dev/null +++ b/examples/xml/streambookmarks/xbelreader.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** 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 + +#include "xbelreader.h" + +//! [0] +XbelReader::XbelReader(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ + QStyle *style = treeWidget->style(); + + folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), + QIcon::Normal, QIcon::Off); + folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), + QIcon::Normal, QIcon::On); + bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); +} +//! [0] + +//! [1] +bool XbelReader::read(QIODevice *device) +{ + xml.setDevice(device); + + if (xml.readNextStartElement()) { + if (xml.name() == "xbel" && xml.attributes().value("version") == "1.0") + readXBEL(); + else + xml.raiseError(QObject::tr("The file is not an XBEL version 1.0 file.")); + } + + return !xml.error(); +} +//! [1] + +//! [2] +QString XbelReader::errorString() const +{ + return QObject::tr("%1\nLine %2, column %3") + .arg(xml.errorString()) + .arg(xml.lineNumber()) + .arg(xml.columnNumber()); +} +//! [2] + +//! [3] +void XbelReader::readXBEL() +{ + Q_ASSERT(xml.isStartElement() && xml.name() == "xbel"); + + while (xml.readNextStartElement()) { + if (xml.name() == "folder") + readFolder(0); + else if (xml.name() == "bookmark") + readBookmark(0); + else if (xml.name() == "separator") + readSeparator(0); + else + xml.skipCurrentElement(); + } +} +//! [3] + +//! [4] +void XbelReader::readTitle(QTreeWidgetItem *item) +{ + Q_ASSERT(xml.isStartElement() && xml.name() == "title"); + + QString title = xml.readElementText(); + item->setText(0, title); +} +//! [4] + +//! [5] +void XbelReader::readSeparator(QTreeWidgetItem *item) +{ + Q_ASSERT(xml.isStartElement() && xml.name() == "separator"); + + QTreeWidgetItem *separator = createChildItem(item); + separator->setFlags(item->flags() & ~Qt::ItemIsSelectable); + separator->setText(0, QString(30, 0xB7)); + xml.skipCurrentElement(); +} +//! [5] + +void XbelReader::readFolder(QTreeWidgetItem *item) +{ + Q_ASSERT(xml.isStartElement() && xml.name() == "folder"); + + QTreeWidgetItem *folder = createChildItem(item); + bool folded = (xml.attributes().value("folded") != "no"); + treeWidget->setItemExpanded(folder, !folded); + + while (xml.readNextStartElement()) { + if (xml.name() == "title") + readTitle(folder); + else if (xml.name() == "folder") + readFolder(folder); + else if (xml.name() == "bookmark") + readBookmark(folder); + else if (xml.name() == "separator") + readSeparator(folder); + else + xml.skipCurrentElement(); + } +} + +void XbelReader::readBookmark(QTreeWidgetItem *item) +{ + Q_ASSERT(xml.isStartElement() && xml.name() == "bookmark"); + + QTreeWidgetItem *bookmark = createChildItem(item); + bookmark->setFlags(bookmark->flags() | Qt::ItemIsEditable); + bookmark->setIcon(0, bookmarkIcon); + bookmark->setText(0, QObject::tr("Unknown title")); + bookmark->setText(1, xml.attributes().value("href").toString()); + + while (xml.readNextStartElement()) { + if (xml.name() == "title") + readTitle(bookmark); + else + xml.skipCurrentElement(); + } +} + +QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item) +{ + QTreeWidgetItem *childItem; + if (item) { + childItem = new QTreeWidgetItem(item); + } else { + childItem = new QTreeWidgetItem(treeWidget); + } + childItem->setData(0, Qt::UserRole, xml.name().toString()); + return childItem; +} diff --git a/examples/xml/streambookmarks/xbelreader.h b/examples/xml/streambookmarks/xbelreader.h new file mode 100644 index 0000000000..1ca1190235 --- /dev/null +++ b/examples/xml/streambookmarks/xbelreader.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 XBELREADER_H +#define XBELREADER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +//! [0] +class XbelReader +{ +public: +//! [1] + XbelReader(QTreeWidget *treeWidget); +//! [1] + + bool read(QIODevice *device); + + QString errorString() const; + +private: +//! [2] + void readXBEL(); + void readTitle(QTreeWidgetItem *item); + void readSeparator(QTreeWidgetItem *item); + void readFolder(QTreeWidgetItem *item); + void readBookmark(QTreeWidgetItem *item); + + QTreeWidgetItem *createChildItem(QTreeWidgetItem *item); + + QXmlStreamReader xml; + QTreeWidget *treeWidget; +//! [2] + + QIcon folderIcon; + QIcon bookmarkIcon; +}; +//! [0] + +#endif diff --git a/examples/xml/streambookmarks/xbelwriter.cpp b/examples/xml/streambookmarks/xbelwriter.cpp new file mode 100644 index 0000000000..bd5454c941 --- /dev/null +++ b/examples/xml/streambookmarks/xbelwriter.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 + +#include "xbelwriter.h" + +//! [0] +XbelWriter::XbelWriter(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ + xml.setAutoFormatting(true); +} +//! [0] + +//! [1] +bool XbelWriter::writeFile(QIODevice *device) +{ + xml.setDevice(device); + + xml.writeStartDocument(); + xml.writeDTD(""); + xml.writeStartElement("xbel"); + xml.writeAttribute("version", "1.0"); + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) + writeItem(treeWidget->topLevelItem(i)); + + xml.writeEndDocument(); + return true; +} +//! [1] + +//! [2] +void XbelWriter::writeItem(QTreeWidgetItem *item) +{ + QString tagName = item->data(0, Qt::UserRole).toString(); + if (tagName == "folder") { + bool folded = !treeWidget->isItemExpanded(item); + xml.writeStartElement(tagName); + xml.writeAttribute("folded", folded ? "yes" : "no"); + xml.writeTextElement("title", item->text(0)); + for (int i = 0; i < item->childCount(); ++i) + writeItem(item->child(i)); + xml.writeEndElement(); + } else if (tagName == "bookmark") { + xml.writeStartElement(tagName); + if (!item->text(1).isEmpty()) + xml.writeAttribute("href", item->text(1)); + xml.writeTextElement("title", item->text(0)); + xml.writeEndElement(); + } else if (tagName == "separator") { + xml.writeEmptyElement(tagName); + } +} +//! [2] diff --git a/examples/xml/streambookmarks/xbelwriter.h b/examples/xml/streambookmarks/xbelwriter.h new file mode 100644 index 0000000000..8160a87b52 --- /dev/null +++ b/examples/xml/streambookmarks/xbelwriter.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 XBELWRITER_H +#define XBELWRITER_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +//! [0] +class XbelWriter +{ +public: + XbelWriter(QTreeWidget *treeWidget); + bool writeFile(QIODevice *device); + +private: + void writeItem(QTreeWidgetItem *item); + QXmlStreamWriter xml; + QTreeWidget *treeWidget; +}; +//! [0] + +#endif diff --git a/examples/xml/xml.pro b/examples/xml/xml.pro new file mode 100644 index 0000000000..a6c8aa18b4 --- /dev/null +++ b/examples/xml/xml.pro @@ -0,0 +1,20 @@ +TEMPLATE = subdirs +SUBDIRS = htmlinfo \ + xmlstreamlint + +!contains(QT_CONFIG, no-gui) { + SUBDIRS += dombookmarks \ + rsslisting \ + saxbookmarks \ + streambookmarks +} + +symbian: SUBDIRS = htmlinfo saxbookmarks + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xml.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/xml/xmlstreamlint/main.cpp b/examples/xml/xmlstreamlint/main.cpp new file mode 100644 index 0000000000..78f40f64fa --- /dev/null +++ b/examples/xml/xmlstreamlint/main.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include + +/* + This class exists for the sole purpose of creating a translation context. +*/ +class XmlStreamLint +{ +public: + Q_DECLARE_TR_FUNCTIONS(XmlStreamLint) +}; + +int main(int argc, char *argv[]) +{ + enum ExitCode + { + Success, + ParseFailure, + ArgumentError, + WriteError, + FileFailure + }; + + QCoreApplication app(argc, argv); + + QTextStream errorStream(stderr); + + if (argc != 2) + { + errorStream << XmlStreamLint::tr( + "Usage: xmlstreamlint \n"); + return ArgumentError; + } + + QString inputFilePath(QCoreApplication::arguments().at(1)); + QFile inputFile(inputFilePath); + + if (!QFile::exists(inputFilePath)) + { + errorStream << XmlStreamLint::tr( + "File %1 does not exist.\n").arg(inputFilePath); + return FileFailure; + + } else if (!inputFile.open(QIODevice::ReadOnly)) { + errorStream << XmlStreamLint::tr( + "Failed to open file %1.\n").arg(inputFilePath); + return FileFailure; + } + + QFile outputFile; + if (!outputFile.open(stdout, QIODevice::WriteOnly)) + { + errorStream << XmlStreamLint::tr("Failed to open stdout."); + return WriteError; + } + +//! [0] + QXmlStreamReader reader(&inputFile); + QXmlStreamWriter writer(&outputFile); +//! [0] + +//! [1] + while (!reader.atEnd()) + { + reader.readNext(); + + if (reader.error()) + { + errorStream << XmlStreamLint::tr( + "Error: %1 in file %2 at line %3, column %4.\n").arg( + reader.errorString(), inputFilePath, + QString::number(reader.lineNumber()), + QString::number(reader.columnNumber())); + return ParseFailure; +//! [1] + +//! [2] + } else + writer.writeCurrentToken(reader); + } +//! [2] + + return Success; +} diff --git a/examples/xml/xmlstreamlint/xmlstreamlint.pro b/examples/xml/xmlstreamlint/xmlstreamlint.pro new file mode 100644 index 0000000000..838ef042ab --- /dev/null +++ b/examples/xml/xmlstreamlint/xmlstreamlint.pro @@ -0,0 +1,12 @@ +CONFIG += console +QT -= gui +QT += xml +SOURCES += main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/xmlstreamlint +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xmlstreamlint.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/xmlstreamlint +INSTALLS += target sources + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) -- cgit v1.2.3