Qt 4.8
qiodevicedelegate.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <QtDebug>
43 
44 #include "qpatternistlocale_p.h"
45 
46 #include "qiodevicedelegate_p.h"
47 
49 
50 using namespace QPatternist;
51 
52 QIODeviceDelegate::QIODeviceDelegate(QIODevice *const source) : m_source(source)
53 {
55 
59  connect(source, SIGNAL(readyRead()), SIGNAL(readyRead()));
60 
61  /* According to Thiago these two signals are very similar, but QtNetworkAccess uses finished()
62  * instead for a minor but significant reason. */
64 
65  /* For instance QFile emits no signals, so how do we know if the device has all data available
66  * and it therefore is safe and correct to emit finished()? isSequential() tells us whether it's
67  * not random access, and whether it's safe to emit finished(). */
68  if(m_source->isSequential())
70  else
72 
74 
75  /* Set up the timeout timer. */
76  connect(&m_timeout, SIGNAL(timeout()), SLOT(networkTimeout()));
77 
80 }
81 
83 {
84  setErrorString(QtXmlPatterns::tr("Network timeout."));
86 }
87 
89 {
90  /* Do nothing, just to please QNetworkReply's pure virtual. */
91 }
92 
94 {
95  return m_source->atEnd();
96 }
97 
99 {
100  return m_source->bytesAvailable();
101 }
102 
104 {
105  return m_source->bytesToWrite();
106 }
107 
109 {
110  return m_source->canReadLine();
111 }
112 
114 {
115  return m_source->close();
116 }
117 
119 {
120  return m_source->isSequential();
121 }
122 
123 bool QIODeviceDelegate::open(OpenMode mode)
124 {
125  const bool success = m_source->open(mode);
127  return success;
128 }
129 
131 {
132  return m_source->pos();
133 }
134 
136 {
137  return m_source->reset();
138 }
139 
141 {
142  return m_source->seek(pos);
143 }
144 
146 {
147  return m_source->size();
148 }
149 
151 {
152  return m_source->waitForBytesWritten(msecs);
153 }
154 
156 {
157  return m_source->waitForReadyRead(msecs);
158 }
159 
161 {
162  return m_source->read(data, maxSize);
163 }
164 
166 
void setSingleShot(bool singleShot)
Definition: qtimer.h:108
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
NetworkError error() const
Returns the error that was found during the processing of this request.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
void setOpenMode(OpenMode openMode)
Sets the OpenMode of the device to openMode.
Definition: qiodevice.cpp:477
virtual bool waitForReadyRead(int msecs)
Blocks until new data is available for reading and the readyRead() signal has been emitted...
Definition: qiodevice.cpp:1616
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
Definition: qiodevice.cpp:590
virtual qint64 readData(char *data, qint64 maxSize)
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
void readChannelFinished()
This signal is emitted when the input (reading) stream is closed in this device.
void aboutToClose()
This signal is emitted when the device is about to close.
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
QIODeviceDelegate(QIODevice *const source)
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
Definition: qiodevice.cpp:711
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
#define SIGNAL(a)
Definition: qobjectdefs.h:227
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
Definition: qiodevice.cpp:767
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void close()
Closes this device for reading.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
The namespace for the internal API of QtXmlPatterns.
static const char * data(const QByteArray &arr)
virtual bool waitForReadyRead(int msecs)
Blocks until new data is available for reading and the readyRead() signal has been emitted...
__int64 qint64
Definition: qglobal.h:942
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
void finished()
This signal is emitted when the reply has finished processing.
Contains functions used for formatting arguments, such as keywords and paths, in translated strings...
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
Definition: qiodevice.cpp:465
void setErrorString(const QString &errorString)
Sets the human readable description of the last device error that occurred to str.
Definition: qiodevice.cpp:1660
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
virtual bool reset()
Seeks to the start of input for random-access devices.
Definition: qiodevice.cpp:732
virtual bool waitForBytesWritten(int msecs)
For buffered devices, this function waits until a payload of buffered written data has been written t...
Definition: qiodevice.cpp:1648
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
virtual bool reset()
Seeks to the start of input for random-access devices.
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
Definition: qiodevice.cpp:1330
void readyRead()
This signal is emitted once every time new data is available for reading from the device...
virtual bool waitForBytesWritten(int msecs)
For buffered devices, this function waits until a payload of buffered written data has been written t...
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
Definition: qtimer.cpp:249
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659
virtual void abort()
Aborts the operation immediately and close down any network connections still open.