2
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 2 or (at your option)
7
* version 3 of the License.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "LayeredStream.h"
20
LayeredStream::LayeredStream(QIODevice* baseDevice)
21
: QIODevice(baseDevice)
22
, m_baseDevice(baseDevice)
24
connect(baseDevice, SIGNAL(aboutToClose()), SLOT(closeStream()));
27
LayeredStream::~LayeredStream()
32
bool LayeredStream::isSequential() const
37
bool LayeredStream::open(QIODevice::OpenMode mode)
40
qWarning("LayeredStream::open: Device is already open.");
44
bool readMode = (mode & QIODevice::ReadOnly);
45
bool writeMode = (mode & QIODevice::WriteOnly);
47
if (readMode && writeMode) {
48
qWarning("LayeredStream::open: Reading and writing at the same time is not supported.");
50
} else if (!readMode && !writeMode) {
51
qWarning("LayeredStream::open: Must be opened in read or write mode.");
53
} else if ((readMode && !m_baseDevice->isReadable()) || (writeMode && !m_baseDevice->isWritable())) {
54
qWarning("LayeredStream::open: Base device is not opened correctly.");
57
if (mode & QIODevice::Append) {
58
qWarning("LayeredStream::open: QIODevice::Append is not supported.");
59
mode = mode & ~QIODevice::Append;
61
if (mode & QIODevice::Truncate) {
62
qWarning("LayeredStream::open: QIODevice::Truncate is not supported.");
63
mode = mode & ~QIODevice::Truncate;
66
mode = mode | QIODevice::Unbuffered;
68
return QIODevice::open(mode);
72
qint64 LayeredStream::readData(char* data, qint64 maxSize)
74
return m_baseDevice->read(data, maxSize);
77
qint64 LayeredStream::writeData(const char* data, qint64 maxSize)
79
return m_baseDevice->write(data, maxSize);
82
void LayeredStream::closeStream()