Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/examples/xml/rsslisting/main.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    77** This file is part of the examples of the Qt Toolkit.
    88**
    9 ** $QT_BEGIN_LICENSE:LGPL$
    10 ** Commercial Usage
    11 ** Licensees holding valid Qt Commercial licenses may use this file in
    12 ** accordance with the Qt Commercial License Agreement provided with the
    13 ** Software or, alternatively, in accordance with the terms contained in
    14 ** a written agreement between you and Nokia.
     9** $QT_BEGIN_LICENSE:BSD$
     10** You may use this file under the terms of the BSD license as follows:
    1511**
    16 ** GNU Lesser General Public License Usage
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
    18 ** General Public License version 2.1 as published by the Free Software
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
    20 ** packaging of this file.  Please review the following information to
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     12** "Redistribution and use in source and binary forms, with or without
     13** modification, are permitted provided that the following conditions are
     14** met:
     15**   * Redistributions of source code must retain the above copyright
     16**     notice, this list of conditions and the following disclaimer.
     17**   * Redistributions in binary form must reproduce the above copyright
     18**     notice, this list of conditions and the following disclaimer in
     19**     the documentation and/or other materials provided with the
     20**     distribution.
     21**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
     22**     the names of its contributors may be used to endorse or promote
     23**     products derived from this software without specific prior written
     24**     permission.
    2325**
    24 ** In addition, as a special exception, Nokia gives you certain additional
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    27 **
    28 ** GNU General Public License Usage
    29 ** Alternatively, this file may be used under the terms of the GNU
    30 ** General Public License version 3.0 as published by the Free Software
    31 ** Foundation and appearing in the file LICENSE.GPL included in the
    32 ** packaging of this file.  Please review the following information to
    33 ** ensure the GNU General Public License version 3.0 requirements will be
    34 ** met: http://www.gnu.org/copyleft/gpl.html.
    35 **
    36 ** If you have questions regarding the use of this file, please contact
    37 ** Nokia at [email protected].
     26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    3837** $QT_END_LICENSE$
    3938**
     
    5958{
    6059    QApplication app(argc, argv);
    61     qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager.");
    6260    RSSListing *rsslisting = new RSSListing;
    6361    rsslisting->show();
  • trunk/examples/xml/rsslisting/rsslisting.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    77** This file is part of the examples of the Qt Toolkit.
    88**
    9 ** $QT_BEGIN_LICENSE:LGPL$
    10 ** Commercial Usage
    11 ** Licensees holding valid Qt Commercial licenses may use this file in
    12 ** accordance with the Qt Commercial License Agreement provided with the
    13 ** Software or, alternatively, in accordance with the terms contained in
    14 ** a written agreement between you and Nokia.
    15 **
    16 ** GNU Lesser General Public License Usage
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
    18 ** General Public License version 2.1 as published by the Free Software
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
    20 ** packaging of this file.  Please review the following information to
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    23 **
    24 ** In addition, as a special exception, Nokia gives you certain additional
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    27 **
    28 ** GNU General Public License Usage
    29 ** Alternatively, this file may be used under the terms of the GNU
    30 ** General Public License version 3.0 as published by the Free Software
    31 ** Foundation and appearing in the file LICENSE.GPL included in the
    32 ** packaging of this file.  Please review the following information to
    33 ** ensure the GNU General Public License version 3.0 requirements will be
    34 ** met: http://www.gnu.org/copyleft/gpl.html.
    35 **
    36 ** If you have questions regarding the use of this file, please contact
    37 ** Nokia at [email protected].
     9** $QT_BEGIN_LICENSE:BSD$
     10** You may use this file under the terms of the BSD license as follows:
     11**
     12** "Redistribution and use in source and binary forms, with or without
     13** modification, are permitted provided that the following conditions are
     14** met:
     15**   * Redistributions of source code must retain the above copyright
     16**     notice, this list of conditions and the following disclaimer.
     17**   * Redistributions in binary form must reproduce the above copyright
     18**     notice, this list of conditions and the following disclaimer in
     19**     the documentation and/or other materials provided with the
     20**     distribution.
     21**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
     22**     the names of its contributors may be used to endorse or promote
     23**     products derived from this software without specific prior written
     24**     permission.
     25**
     26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    3837** $QT_END_LICENSE$
    3938**
     
    6766    up the XML reader to use a custom handler class.
    6867
    69     The user interface consists of a line edit, two push buttons, and a
     68    The user interface consists of a line edit, , and a
    7069    list view widget. The line edit is used for entering the URLs of news
    71     sources; the push buttons start and abort the process of reading the
     70    sources; the push button the process of reading the
    7271    news.
    7372*/
    7473
    7574RSSListing::RSSListing(QWidget *parent)
    76     : QWidget(parent)
     75    : QWidget(parent)
    7776{
    7877    lineEdit = new QLineEdit(this);
     
    8079
    8180    fetchButton = new QPushButton(tr("Fetch"), this);
    82     abortButton = new QPushButton(tr("Abort"), this);
    83     abortButton->setEnabled(false);
    8481
    8582    treeWidget = new QTreeWidget(this);
     
    9188    treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
    9289
    93     connect(&http, SIGNAL(readyRead(QHttpResponseHeader)),
    94              this, SLOT(readData(QHttpResponseHeader)));
    95 
    96     connect(&http, SIGNAL(requestFinished(int,bool)),
    97              this, SLOT(finished(int,bool)));
     90    connect(&manager, SIGNAL(finished(QNetworkReply*)),
     91             this, SLOT(finished(QNetworkReply*)));
    9892
    9993    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
    10094    connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));
    101     connect(abortButton, SIGNAL(clicked()), &http, SLOT(abort()));
    10295
    10396    QVBoxLayout *layout = new QVBoxLayout(this);
     
    107100    hboxLayout->addWidget(lineEdit);
    108101    hboxLayout->addWidget(fetchButton);
    109     hboxLayout->addWidget(abortButton);
    110102
    111103    layout->addLayout(hboxLayout);
     
    117109
    118110/*
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
    119127    Starts fetching data from a news source specified in the line
    120128    edit widget.
     
    122130    The line edit is made read only to prevent the user from modifying its
    123131    contents during the fetch; this is only for cosmetic purposes.
    124     The fetch button is disabled, and the abort button is enabled to allow
    125     the user to interrupt processing. The list view is cleared, and we
     132    The fetch button is disabled, the list view is cleared, and we
    126133    define the last list view item to be 0, meaning that there are no
    127134    existing items in the list.
    128135
    129     The HTTP handler is supplied with the raw contents of the line edit and
    130     a fetch is initiated. We keep the ID value returned by the HTTP handler
    131     for future reference.
     136    A URL is created with the raw contents of the line edit and
     137    a get is initiated.
    132138*/
    133139
     
    136142    lineEdit->setReadOnly(true);
    137143    fetchButton->setEnabled(false);
    138     abortButton->setEnabled(true);
    139144    treeWidget->clear();
    140145
     
    142147
    143148    QUrl url(lineEdit->text());
    144 
    145     http.setHost(url.host());
    146     connectionId = http.get(url.path());
     149    get(url);
     150}
     151
     152void RSSListing::metaDataChanged()
     153{
     154    QUrl redirectionTarget = currentReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
     155    if (redirectionTarget.isValid()) {
     156        get(redirectionTarget);
     157    }
    147158}
    148159
     
    152163    We read all the available data, and pass it to the XML
    153164    stream reader. Then we call the XML parsing function.
    154 
    155     If parsing fails for any reason, we abort the fetch.
    156 */
    157 
    158 void RSSListing::readData(const QHttpResponseHeader &resp)
    159 {
    160     if (resp.statusCode() != 200)
    161         http.abort();
    162     else {
    163         xml.addData(http.readAll());
     165*/
     166
     167void RSSListing::readyRead()
     168{
     169    int statusCode = currentReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
     170    if (statusCode >= 200 && statusCode < 300) {
     171        QByteArray data = currentReply->readAll();
     172        xml.addData(data);
    164173        parseXml();
    165174    }
     
    179188*/
    180189
    181 void RSSListing::finished(int id, bool error)
    182 {
    183     if (error) {
    184         qWarning("Received error during HTTP fetch.");
    185         lineEdit->setReadOnly(false);
    186         abortButton->setEnabled(false);
    187         fetchButton->setEnabled(true);
    188     }
    189     else if (id == connectionId) {
    190         lineEdit->setReadOnly(false);
    191         abortButton->setEnabled(false);
    192         fetchButton->setEnabled(true);
    193     }
     190void RSSListing::finished(QNetworkReply *reply)
     191{
     192    Q_UNUSED(reply);
     193    lineEdit->setReadOnly(false);
     194    fetchButton->setEnabled(true);
    194195}
    195196
     
    227228    if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
    228229        qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString();
    229         http.abort();
    230230    }
    231231}
     
    238238    QDesktopServices::openUrl(QUrl(item->text(1)));
    239239}
     240
     241
     242
     243
     244
     245
     246
     247
  • trunk/examples/xml/rsslisting/rsslisting.h

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    77** This file is part of the examples of the Qt Toolkit.
    88**
    9 ** $QT_BEGIN_LICENSE:LGPL$
    10 ** Commercial Usage
    11 ** Licensees holding valid Qt Commercial licenses may use this file in
    12 ** accordance with the Qt Commercial License Agreement provided with the
    13 ** Software or, alternatively, in accordance with the terms contained in
    14 ** a written agreement between you and Nokia.
     9** $QT_BEGIN_LICENSE:BSD$
     10** You may use this file under the terms of the BSD license as follows:
    1511**
    16 ** GNU Lesser General Public License Usage
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
    18 ** General Public License version 2.1 as published by the Free Software
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
    20 ** packaging of this file.  Please review the following information to
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
     12** "Redistribution and use in source and binary forms, with or without
     13** modification, are permitted provided that the following conditions are
     14** met:
     15**   * Redistributions of source code must retain the above copyright
     16**     notice, this list of conditions and the following disclaimer.
     17**   * Redistributions in binary form must reproduce the above copyright
     18**     notice, this list of conditions and the following disclaimer in
     19**     the documentation and/or other materials provided with the
     20**     distribution.
     21**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
     22**     the names of its contributors may be used to endorse or promote
     23**     products derived from this software without specific prior written
     24**     permission.
    2325**
    24 ** In addition, as a special exception, Nokia gives you certain additional
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    27 **
    28 ** GNU General Public License Usage
    29 ** Alternatively, this file may be used under the terms of the GNU
    30 ** General Public License version 3.0 as published by the Free Software
    31 ** Foundation and appearing in the file LICENSE.GPL included in the
    32 ** packaging of this file.  Please review the following information to
    33 ** ensure the GNU General Public License version 3.0 requirements will be
    34 ** met: http://www.gnu.org/copyleft/gpl.html.
    35 **
    36 ** If you have questions regarding the use of this file, please contact
    37 ** Nokia at [email protected].
     26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
    3837** $QT_END_LICENSE$
    3938**
     
    4342#define RSSLISTING_H
    4443
    45 #include <QHttp>
     44#include <QNetworkAccessManager>
     45#include <QNetworkReply>
    4646#include <QWidget>
    4747#include <QBuffer>
    4848#include <QXmlStreamReader>
     49
    4950
    5051QT_BEGIN_NAMESPACE
     
    6364public slots:
    6465    void fetch();
    65     void finished(int id, bool error);
    66     void readData(const QHttpResponseHeader &);
     66    void finished(QNetworkReply *reply);
     67    void readyRead();
     68    void metaDataChanged();
    6769    void itemActivated(QTreeWidgetItem * item);
     70
    6871
    6972private:
    7073    void parseXml();
     74
    7175
    7276    QXmlStreamReader xml;
     
    7579    QString titleString;
    7680
    77     QHttp http;
    78     int connectionId;
     81    Q;
     82    ;
    7983
    8084    QLineEdit *lineEdit;
    8185    QTreeWidget *treeWidget;
    82     QPushButton *abortButton;
    8386    QPushButton *fetchButton;
    8487};
Note: See TracChangeset for help on using the changeset viewer.