467 lines
29 KiB
HTML
467 lines
29 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>Qt 4.8: rsslisting.cpp Example File (xml/rsslisting/rsslisting.cpp)</title>
|
|
<link rel="stylesheet" type="text/css" href="style/style.css" />
|
|
<script src="scripts/jquery.js" type="text/javascript"></script>
|
|
<script src="scripts/functions.js" type="text/javascript"></script>
|
|
<link rel="stylesheet" type="text/css" href="style/superfish.css" />
|
|
<link rel="stylesheet" type="text/css" href="style/narrow.css" />
|
|
<!--[if IE]>
|
|
<meta name="MSSmartTagsPreventParsing" content="true">
|
|
<meta http-equiv="imagetoolbar" content="no">
|
|
<![endif]-->
|
|
<!--[if lt IE 7]>
|
|
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
|
|
<![endif]-->
|
|
<!--[if IE 7]>
|
|
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
|
|
<![endif]-->
|
|
<!--[if IE 8]>
|
|
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
|
|
<![endif]-->
|
|
|
|
<script src="scripts/superfish.js" type="text/javascript"></script>
|
|
<script src="scripts/narrow.js" type="text/javascript"></script>
|
|
|
|
</head>
|
|
<body class="" onload="CheckEmptyAndLoadList();">
|
|
<div class="header" id="qtdocheader">
|
|
<div class="content">
|
|
<div id="nav-logo">
|
|
<a href="index.html">Home</a></div>
|
|
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
|
|
<div id="narrowsearch"></div>
|
|
<div id="nav-topright">
|
|
<ul>
|
|
<li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
|
|
<li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
|
|
<li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
|
|
DOC</a></li>
|
|
<li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="shortCut">
|
|
<ul>
|
|
<li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
|
|
<li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS </a></li>
|
|
</ul>
|
|
</div>
|
|
<ul class="sf-menu" id="narrowmenu">
|
|
<li><a href="#">API Lookup</a>
|
|
<ul>
|
|
<li><a href="classes.html">Class index</a></li>
|
|
<li><a href="functions.html">Function index</a></li>
|
|
<li><a href="modules.html">Modules</a></li>
|
|
<li><a href="namespaces.html">Namespaces</a></li>
|
|
<li><a href="qtglobal.html">Global Declarations</a></li>
|
|
<li><a href="qdeclarativeelements.html">QML elements</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#">Qt Topics</a>
|
|
<ul>
|
|
<li><a href="qt-basic-concepts.html">Programming with Qt</a></li>
|
|
<li><a href="qtquick.html">Device UIs & Qt Quick</a></li>
|
|
<li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>
|
|
<li><a href="supported-platforms.html">Supported Platforms</a></li>
|
|
<li><a href="technology-apis.html">Qt and Key Technologies</a></li>
|
|
<li><a href="best-practices.html">How-To's and Best Practices</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#">Examples</a>
|
|
<ul>
|
|
<li><a href="all-examples.html">Examples</a></li>
|
|
<li><a href="tutorials.html">Tutorials</a></li>
|
|
<li><a href="demos.html">Demos</a></li>
|
|
<li><a href="qdeclarativeexamples.html">QML Examples</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="wrapper">
|
|
<div class="hd">
|
|
<span></span>
|
|
</div>
|
|
<div class="bd group">
|
|
<div class="sidebar">
|
|
<div class="searchlabel">
|
|
Search index:</div>
|
|
<div class="search" id="sidebarsearch">
|
|
<form id="qtdocsearch" action="" onsubmit="return false;">
|
|
<fieldset>
|
|
<input type="text" name="searchstring" id="pageType" value="" />
|
|
<div id="resultdialog">
|
|
<a href="#" id="resultclose">Close</a>
|
|
<p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p>
|
|
<p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span> results:</p>
|
|
<ul id="resultlist" class="all">
|
|
</ul>
|
|
</div>
|
|
</fieldset>
|
|
</form>
|
|
</div>
|
|
<div class="box first bottombar" id="lookup">
|
|
<h2 title="API Lookup"><span></span>
|
|
API Lookup</h2>
|
|
<div id="list001" class="list">
|
|
<ul id="ul001" >
|
|
<li class="defaultLink"><a href="classes.html">Class index</a></li>
|
|
<li class="defaultLink"><a href="functions.html">Function index</a></li>
|
|
<li class="defaultLink"><a href="modules.html">Modules</a></li>
|
|
<li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
|
|
<li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
|
|
<li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="box bottombar" id="topics">
|
|
<h2 title="Qt Topics"><span></span>
|
|
Qt Topics</h2>
|
|
<div id="list002" class="list">
|
|
<ul id="ul002" >
|
|
<li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li>
|
|
<li class="defaultLink"><a href="qtquick.html">Device UIs & Qt Quick</a></li>
|
|
<li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li>
|
|
<li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>
|
|
<li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li>
|
|
<li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="box" id="examples">
|
|
<h2 title="Examples"><span></span>
|
|
Examples</h2>
|
|
<div id="list003" class="list">
|
|
<ul id="ul003">
|
|
<li class="defaultLink"><a href="all-examples.html">Examples</a></li>
|
|
<li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
|
|
<li class="defaultLink"><a href="demos.html">Demos</a></li>
|
|
<li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="wrap">
|
|
<div class="toolbar">
|
|
<div class="breadcrumb toolblock">
|
|
<ul>
|
|
<li class="first"><a href="index.html">Home</a></li>
|
|
<!-- Breadcrumbs go here -->
|
|
</ul>
|
|
</div>
|
|
<div class="toolbuttons toolblock">
|
|
<ul>
|
|
<li id="smallA" class="t_button">A</li>
|
|
<li id="medA" class="t_button active">A</li>
|
|
<li id="bigA" class="t_button">A</li>
|
|
<li id="print" class="t_button"><a href="javascript:this.print();">
|
|
<span>Print</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="content mainContent">
|
|
<h1 class="title">rsslisting.cpp Example File</h1>
|
|
<span class="small-subtitle">xml/rsslisting/rsslisting.cpp</span>
|
|
<!-- $$$xml/rsslisting/rsslisting.cpp-description -->
|
|
<div class="descr"> <a name="details"></a>
|
|
<pre class="cpp"> <span class="comment">/****************************************************************************
|
|
**
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
** Contact: http://www.qt.io/licensing/
|
|
**
|
|
** 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 The Qt Company Ltd 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$
|
|
**
|
|
****************************************************************************/</span>
|
|
|
|
<span class="comment">/*
|
|
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.
|
|
*/</span>
|
|
|
|
<span class="preprocessor">#include <QtCore></span>
|
|
<span class="preprocessor">#include <QtGui></span>
|
|
<span class="preprocessor">#include <QtNetwork></span>
|
|
|
|
<span class="preprocessor">#include "rsslisting.h"</span>
|
|
|
|
<span class="comment">/*
|
|
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.
|
|
*/</span>
|
|
|
|
RSSListing<span class="operator">::</span>RSSListing(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
|
|
: <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)<span class="operator">,</span> currentReply(<span class="number">0</span>)
|
|
{
|
|
<span class="preprocessor">#ifdef Q_OS_SYMBIAN</span>
|
|
<span class="comment">// Set Internet Access Point</span>
|
|
<span class="type"><a href="qnetworkconfigurationmanager.html">QNetworkConfigurationManager</a></span> manager;
|
|
<span class="keyword">const</span> <span class="type">bool</span> canStartIAP <span class="operator">=</span> manager<span class="operator">.</span>capabilities() <span class="operator">&</span> <span class="type"><a href="qnetworkconfigurationmanager.html">QNetworkConfigurationManager</a></span><span class="operator">::</span>CanStartAndStopInterfaces;
|
|
|
|
<span class="comment">// Is there default access point, use it</span>
|
|
<span class="type"><a href="qnetworkconfiguration.html">QNetworkConfiguration</a></span> cfg <span class="operator">=</span> manager<span class="operator">.</span>defaultConfiguration();
|
|
<span class="keyword">if</span> (<span class="operator">!</span>cfg<span class="operator">.</span>isValid() <span class="operator">|</span><span class="operator">|</span> <span class="operator">!</span>canStartIAP) {
|
|
<span class="comment">// Available Access Points not found</span>
|
|
<span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>warning(<span class="keyword">this</span><span class="operator">,</span> <span class="string">"Error"</span><span class="operator">,</span> <span class="string">"No access point"</span>);
|
|
<span class="keyword">return</span>;
|
|
}
|
|
|
|
m_session <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qnetworksession.html">QNetworkSession</a></span>(cfg);
|
|
m_session<span class="operator">-</span><span class="operator">></span>open();
|
|
m_session<span class="operator">-</span><span class="operator">></span>waitForOpened();
|
|
<span class="preprocessor">#endif</span>
|
|
|
|
lineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>(<span class="keyword">this</span>);
|
|
lineEdit<span class="operator">-</span><span class="operator">></span>setText(<span class="string">"http://labs.qt.nokia.com/blogs/feed"</span>);
|
|
|
|
fetchButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"Fetch"</span>)<span class="operator">,</span> <span class="keyword">this</span>);
|
|
|
|
treeWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtreewidget.html">QTreeWidget</a></span>(<span class="keyword">this</span>);
|
|
connect(treeWidget<span class="operator">,</span> SIGNAL(itemActivated(<span class="type"><a href="qtreewidgetitem.html">QTreeWidgetItem</a></span><span class="operator">*</span><span class="operator">,</span><span class="type">int</span>))<span class="operator">,</span>
|
|
<span class="keyword">this</span><span class="operator">,</span> SLOT(itemActivated(<span class="type"><a href="qtreewidgetitem.html">QTreeWidgetItem</a></span><span class="operator">*</span>)));
|
|
<span class="type"><a href="qstringlist.html">QStringList</a></span> headerLabels;
|
|
headerLabels <span class="operator"><</span><span class="operator"><</span> tr(<span class="string">"Title"</span>) <span class="operator"><</span><span class="operator"><</span> tr(<span class="string">"Link"</span>);
|
|
treeWidget<span class="operator">-</span><span class="operator">></span>setHeaderLabels(headerLabels);
|
|
treeWidget<span class="operator">-</span><span class="operator">></span>header()<span class="operator">-</span><span class="operator">></span>setResizeMode(<span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>ResizeToContents);
|
|
|
|
connect(<span class="operator">&</span>manager<span class="operator">,</span> SIGNAL(finished(<span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span><span class="operator">*</span>))<span class="operator">,</span>
|
|
<span class="keyword">this</span><span class="operator">,</span> SLOT(finished(<span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span><span class="operator">*</span>)));
|
|
|
|
connect(lineEdit<span class="operator">,</span> SIGNAL(returnPressed())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(fetch()));
|
|
connect(fetchButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(fetch()));
|
|
|
|
<span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(<span class="keyword">this</span>);
|
|
|
|
<span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>hboxLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
|
|
|
|
hboxLayout<span class="operator">-</span><span class="operator">></span>addWidget(lineEdit);
|
|
hboxLayout<span class="operator">-</span><span class="operator">></span>addWidget(fetchButton);
|
|
|
|
layout<span class="operator">-</span><span class="operator">></span>addLayout(hboxLayout);
|
|
layout<span class="operator">-</span><span class="operator">></span>addWidget(treeWidget);
|
|
|
|
setWindowTitle(tr(<span class="string">"RSS listing example"</span>));
|
|
<span class="preprocessor">#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5)</span>
|
|
resize(<span class="number">640</span><span class="operator">,</span><span class="number">480</span>);
|
|
<span class="preprocessor">#endif</span>
|
|
}
|
|
|
|
<span class="comment">/*
|
|
Starts the network request and connects the needed signals
|
|
*/</span>
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>get(<span class="keyword">const</span> <span class="type"><a href="qurl.html">QUrl</a></span> <span class="operator">&</span>url)
|
|
{
|
|
<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span> request(url);
|
|
<span class="keyword">if</span> (currentReply) {
|
|
currentReply<span class="operator">-</span><span class="operator">></span>disconnect(<span class="keyword">this</span>);
|
|
currentReply<span class="operator">-</span><span class="operator">></span>deleteLater();
|
|
}
|
|
currentReply <span class="operator">=</span> manager<span class="operator">.</span>get(request);
|
|
connect(currentReply<span class="operator">,</span> SIGNAL(readyRead())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(readyRead()));
|
|
connect(currentReply<span class="operator">,</span> SIGNAL(metaDataChanged())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(metaDataChanged()));
|
|
connect(currentReply<span class="operator">,</span> SIGNAL(error(<span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span><span class="operator">::</span>NetworkError))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(error(<span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span><span class="operator">::</span>NetworkError)));
|
|
}
|
|
|
|
<span class="comment">/*
|
|
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.
|
|
*/</span>
|
|
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>fetch()
|
|
{
|
|
lineEdit<span class="operator">-</span><span class="operator">></span>setReadOnly(<span class="keyword">true</span>);
|
|
fetchButton<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">false</span>);
|
|
treeWidget<span class="operator">-</span><span class="operator">></span>clear();
|
|
|
|
xml<span class="operator">.</span>clear();
|
|
|
|
<span class="type"><a href="qurl.html">QUrl</a></span> url(lineEdit<span class="operator">-</span><span class="operator">></span>text());
|
|
get(url);
|
|
}
|
|
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>metaDataChanged()
|
|
{
|
|
<span class="type"><a href="qurl.html">QUrl</a></span> redirectionTarget <span class="operator">=</span> currentReply<span class="operator">-</span><span class="operator">></span>attribute(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">::</span>RedirectionTargetAttribute)<span class="operator">.</span>toUrl();
|
|
<span class="keyword">if</span> (redirectionTarget<span class="operator">.</span>isValid()) {
|
|
get(redirectionTarget);
|
|
}
|
|
}
|
|
|
|
<span class="comment">/*
|
|
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.
|
|
*/</span>
|
|
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>readyRead()
|
|
{
|
|
<span class="type">int</span> statusCode <span class="operator">=</span> currentReply<span class="operator">-</span><span class="operator">></span>attribute(<span class="type"><a href="qnetworkrequest.html">QNetworkRequest</a></span><span class="operator">::</span>HttpStatusCodeAttribute)<span class="operator">.</span>toInt();
|
|
<span class="keyword">if</span> (statusCode <span class="operator">></span><span class="operator">=</span> <span class="number">200</span> <span class="operator">&</span><span class="operator">&</span> statusCode <span class="operator"><</span> <span class="number">300</span>) {
|
|
<span class="type"><a href="qbytearray.html">QByteArray</a></span> data <span class="operator">=</span> currentReply<span class="operator">-</span><span class="operator">></span>readAll();
|
|
xml<span class="operator">.</span>addData(data);
|
|
parseXml();
|
|
}
|
|
}
|
|
|
|
<span class="comment">/*
|
|
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.
|
|
*/</span>
|
|
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>finished(<span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span> <span class="operator">*</span>reply)
|
|
{
|
|
Q_UNUSED(reply);
|
|
lineEdit<span class="operator">-</span><span class="operator">></span>setReadOnly(<span class="keyword">false</span>);
|
|
fetchButton<span class="operator">-</span><span class="operator">></span>setEnabled(<span class="keyword">true</span>);
|
|
}
|
|
|
|
<span class="comment">/*
|
|
Parses the XML data and creates treeWidget items accordingly.
|
|
*/</span>
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>parseXml()
|
|
{
|
|
<span class="keyword">while</span> (<span class="operator">!</span>xml<span class="operator">.</span>atEnd()) {
|
|
xml<span class="operator">.</span>readNext();
|
|
<span class="keyword">if</span> (xml<span class="operator">.</span>isStartElement()) {
|
|
<span class="keyword">if</span> (xml<span class="operator">.</span>name() <span class="operator">=</span><span class="operator">=</span> <span class="string">"item"</span>)
|
|
linkString <span class="operator">=</span> xml<span class="operator">.</span>attributes()<span class="operator">.</span>value(<span class="string">"rss:about"</span>)<span class="operator">.</span>toString();
|
|
currentTag <span class="operator">=</span> xml<span class="operator">.</span>name()<span class="operator">.</span>toString();
|
|
} <span class="keyword">else</span> <span class="keyword">if</span> (xml<span class="operator">.</span>isEndElement()) {
|
|
<span class="keyword">if</span> (xml<span class="operator">.</span>name() <span class="operator">=</span><span class="operator">=</span> <span class="string">"item"</span>) {
|
|
|
|
<span class="type"><a href="qtreewidgetitem.html">QTreeWidgetItem</a></span> <span class="operator">*</span>item <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtreewidgetitem.html">QTreeWidgetItem</a></span>;
|
|
item<span class="operator">-</span><span class="operator">></span>setText(<span class="number">0</span><span class="operator">,</span> titleString);
|
|
item<span class="operator">-</span><span class="operator">></span>setText(<span class="number">1</span><span class="operator">,</span> linkString);
|
|
treeWidget<span class="operator">-</span><span class="operator">></span>addTopLevelItem(item);
|
|
|
|
titleString<span class="operator">.</span>clear();
|
|
linkString<span class="operator">.</span>clear();
|
|
}
|
|
|
|
} <span class="keyword">else</span> <span class="keyword">if</span> (xml<span class="operator">.</span>isCharacters() <span class="operator">&</span><span class="operator">&</span> <span class="operator">!</span>xml<span class="operator">.</span>isWhitespace()) {
|
|
<span class="keyword">if</span> (currentTag <span class="operator">=</span><span class="operator">=</span> <span class="string">"title"</span>)
|
|
titleString <span class="operator">+</span><span class="operator">=</span> xml<span class="operator">.</span>text()<span class="operator">.</span>toString();
|
|
<span class="keyword">else</span> <span class="keyword">if</span> (currentTag <span class="operator">=</span><span class="operator">=</span> <span class="string">"link"</span>)
|
|
linkString <span class="operator">+</span><span class="operator">=</span> xml<span class="operator">.</span>text()<span class="operator">.</span>toString();
|
|
}
|
|
}
|
|
<span class="keyword">if</span> (xml<span class="operator">.</span>error() <span class="operator">&</span><span class="operator">&</span> xml<span class="operator">.</span>error() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="qxmlstreamreader.html">QXmlStreamReader</a></span><span class="operator">::</span>PrematureEndOfDocumentError) {
|
|
<a href="qtglobal.html#qWarning">qWarning</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"XML ERROR:"</span> <span class="operator"><</span><span class="operator"><</span> xml<span class="operator">.</span>lineNumber() <span class="operator"><</span><span class="operator"><</span> <span class="string">": "</span> <span class="operator"><</span><span class="operator"><</span> xml<span class="operator">.</span>errorString();
|
|
}
|
|
}
|
|
|
|
<span class="comment">/*
|
|
Open the link in the browser
|
|
*/</span>
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>itemActivated(<span class="type"><a href="qtreewidgetitem.html">QTreeWidgetItem</a></span> <span class="operator">*</span> item)
|
|
{
|
|
<span class="type"><a href="qdesktopservices.html">QDesktopServices</a></span><span class="operator">::</span>openUrl(<span class="type"><a href="qurl.html">QUrl</a></span>(item<span class="operator">-</span><span class="operator">></span>text(<span class="number">1</span>)));
|
|
}
|
|
|
|
<span class="type">void</span> RSSListing<span class="operator">::</span>error(<span class="type"><a href="qnetworkreply.html">QNetworkReply</a></span><span class="operator">::</span>NetworkError)
|
|
{
|
|
<a href="qtglobal.html#qWarning">qWarning</a>(<span class="string">"error retrieving RSS feed"</span>);
|
|
currentReply<span class="operator">-</span><span class="operator">></span>disconnect(<span class="keyword">this</span>);
|
|
currentReply<span class="operator">-</span><span class="operator">></span>deleteLater();
|
|
currentReply <span class="operator">=</span> <span class="number">0</span>;
|
|
}</pre>
|
|
</div>
|
|
<!-- @@@xml/rsslisting/rsslisting.cpp -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="ft">
|
|
<span></span>
|
|
</div>
|
|
</div>
|
|
<div class="footer">
|
|
<p>
|
|
<acronym title="Copyright">©</acronym> 2015 The Qt Company Ltd.
|
|
Documentation contributions included herein are the copyrights of
|
|
their respective owners.</p>
|
|
<br />
|
|
<p>
|
|
The documentation provided herein is licensed under the terms of the
|
|
<a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
|
|
License version 1.3</a> as published by the Free Software Foundation.</p>
|
|
<p>
|
|
Documentation sources may be obtained from <a href="http://www.qt-project.org">
|
|
www.qt-project.org</a>.</p>
|
|
<br />
|
|
<p>
|
|
Qt and respective logos are trademarks of The Qt Company Ltd
|
|
in Finland and/or other countries worldwide. All other trademarks are property
|
|
of their respective owners. <a title="Privacy Policy"
|
|
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
|
|
</div>
|
|
|
|
<script src="scripts/functions.js" type="text/javascript"></script>
|
|
</body>
|
|
</html>
|