Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/kdecore/CMakeLists.txt b/kdecore/CMakeLists.txt
- index 79645ea..650d9a0 100644
- --- a/kdecore/CMakeLists.txt
- +++ b/kdecore/CMakeLists.txt
- @@ -158,7 +158,6 @@ set(kdecore_LIB_SRCS
- io/kdebugdbusiface.cpp
- io/kdirwatch.cpp
- io/kfilesystemtype_p.cpp
- - io/klimitediodevice.cpp
- io/kmessage.cpp
- io/kmountpoint.cpp
- io/kprocess.cpp
- diff --git a/kdecore/io/kar.cpp b/kdecore/io/kar.cpp
- index 9ff9937..a733e20 100644
- --- a/kdecore/io/kar.cpp
- +++ b/kdecore/io/kar.cpp
- @@ -29,7 +29,6 @@
- #include <QtCore/QRegExp>
- #include "kfilterdev.h"
- -//#include "klimitediodevice_p.h"
- ////////////////////////////////////////////////////////////////////////
- /////////////////////////// KAr ///////////////////////////////////////
- diff --git a/kdecore/io/karchive.cpp b/kdecore/io/karchive.cpp
- index 2c2be42..403eec1 100644
- --- a/kdecore/io/karchive.cpp
- +++ b/kdecore/io/karchive.cpp
- @@ -20,7 +20,6 @@
- */
- #include "karchive.h"
- -#include "klimitediodevice_p.h"
- #include <config.h>
- @@ -651,7 +650,13 @@ QByteArray KArchiveFile::data() const
- QIODevice * KArchiveFile::createDevice() const
- {
- - return new KLimitedIODevice( archive()->device(), d->pos, d->size );
- + QIODevice* limitedDev = archive()->device();
- + if(limitedDev->isOpen()) {
- + limitedDev->seek( position() );
- + } else {
- + limitedDev->open( QIODevice::ReadOnly );
- + }
- + return limitedDev;
- }
- bool KArchiveFile::isFile() const
- diff --git a/kdecore/io/klimitediodevice.cpp b/kdecore/io/klimitediodevice.cpp
- deleted file mode 100644
- index b457350..0000000
- --- a/kdecore/io/klimitediodevice.cpp
- +++ /dev/null
- @@ -1,81 +0,0 @@
- -/* This file is part of the KDE libraries
- - Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org>
- -
- - This library is free software; you can redistribute it and/or
- - modify it under the terms of the GNU Library General Public
- - License version 2 as published by the Free Software Foundation.
- -
- - This library is distributed in the hope that it will be useful,
- - but WITHOUT ANY WARRANTY; without even the implied warranty of
- - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- - Library General Public License for more details.
- -
- - You should have received a copy of the GNU Library General Public License
- - along with this library; see the file COPYING.LIB. If not, write to
- - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- - Boston, MA 02110-1301, USA.
- -*/
- -
- -#include <kdebug.h>
- -#include "klimitediodevice_p.h"
- -
- -KLimitedIODevice::KLimitedIODevice( QIODevice *dev, qint64 start, qint64 length )
- - : m_dev( dev ), m_start( start ), m_length( length )
- -{
- - //kDebug(7005) << "start=" << start << "length=" << length;
- - open( QIODevice::ReadOnly ); //krazy:exclude=syscalls
- -}
- -
- -bool KLimitedIODevice::open( QIODevice::OpenMode m )
- -{
- - //kDebug(7005) << "m=" << m;
- - if ( m & QIODevice::ReadOnly ) {
- - /*bool ok = false;
- - if ( m_dev->isOpen() )
- - ok = ( m_dev->mode() == QIODevice::ReadOnly );
- - else
- - ok = m_dev->open( m );
- - if ( ok )*/
- - m_dev->seek( m_start ); // No concurrent access !
- - }
- - else
- - kWarning(7005) << "KLimitedIODevice::open only supports QIODevice::ReadOnly!";
- - setOpenMode( QIODevice::ReadOnly );
- - return true;
- -}
- -
- -void KLimitedIODevice::close()
- -{
- -}
- -
- -qint64 KLimitedIODevice::size() const
- -{
- - return m_length;
- -}
- -
- -qint64 KLimitedIODevice::readData( char * data, qint64 maxlen )
- -{
- - maxlen = qMin( maxlen, m_length - pos() ); // Apply upper limit
- - return m_dev->read( data, maxlen );
- -}
- -
- -bool KLimitedIODevice::seek( qint64 pos )
- -{
- - Q_ASSERT( pos <= m_length );
- - pos = qMin( pos, m_length ); // Apply upper limit
- - bool ret = m_dev->seek( m_start + pos );
- - if ( ret ) {
- - QIODevice::seek( pos );
- - }
- - return ret;
- -}
- -
- -qint64 KLimitedIODevice::bytesAvailable() const
- -{
- - return QIODevice::bytesAvailable();
- -}
- -
- -bool KLimitedIODevice::isSequential() const
- -{
- - return m_dev->isSequential();
- -}
- diff --git a/kdecore/io/klimitediodevice_p.h b/kdecore/io/klimitediodevice_p.h
- deleted file mode 100644
- index 853dd5d..0000000
- --- a/kdecore/io/klimitediodevice_p.h
- +++ /dev/null
- @@ -1,63 +0,0 @@
- -/* This file is part of the KDE libraries
- - Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org>
- -
- - This library is free software; you can redistribute it and/or
- - modify it under the terms of the GNU Library General Public
- - License version 2 as published by the Free Software Foundation.
- -
- - This library is distributed in the hope that it will be useful,
- - but WITHOUT ANY WARRANTY; without even the implied warranty of
- - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- - Library General Public License for more details.
- -
- - You should have received a copy of the GNU Library General Public License
- - along with this library; see the file COPYING.LIB. If not, write to
- - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- - Boston, MA 02110-1301, USA.
- -*/
- -
- -#ifndef KLIMITEDIODEVICE_P_H
- -#define KLIMITEDIODEVICE_P_H
- -
- -#include <QtCore/qiodevice.h>
- -/**
- - * A readonly device that reads from an underlying device
- - * from a given point to another (e.g. to give access to a single
- - * file inside an archive).
- - * @author David Faure <faure@kde.org>
- - * @internal - used by KArchive
- - */
- -class KLimitedIODevice : public QIODevice
- -{
- -public:
- - /**
- - * Creates a new KLimitedIODevice.
- - * @param dev the underlying device, opened or not
- - * This device itself auto-opens (in readonly mode), no need to open it.
- - * @param start where to start reading (position in bytes)
- - * @param length the length of the data to read (in bytes)
- - */
- - KLimitedIODevice( QIODevice *dev, qint64 start, qint64 length );
- - virtual ~KLimitedIODevice() {}
- -
- - virtual bool isSequential() const;
- -
- - virtual bool open( QIODevice::OpenMode m );
- - virtual void close();
- -
- - virtual qint64 size() const;
- -
- - virtual qint64 readData ( char * data, qint64 maxlen );
- - virtual qint64 writeData ( const char *, qint64 ) { return -1; } // unsupported
- - virtual int putChar( int ) { return -1; } // unsupported
- -
- - //virtual qint64 pos() const { return m_dev->pos() - m_start; }
- - virtual bool seek( qint64 pos );
- - virtual qint64 bytesAvailable() const;
- -private:
- - QIODevice* m_dev;
- - qint64 m_start;
- - qint64 m_length;
- -};
- -
- -#endif
- diff --git a/kdecore/io/kzip.cpp b/kdecore/io/kzip.cpp
- index 9e5c17b..0cd4a11 100644
- --- a/kdecore/io/kzip.cpp
- +++ b/kdecore/io/kzip.cpp
- @@ -19,15 +19,15 @@
- #include "kzip.h"
- #include "kfilterdev.h"
- -#include "klimitediodevice_p.h"
- #include <kdebug.h>
- #include <QtCore/QHash>
- #include <QtCore/QByteArray>
- #include <QtCore/QFile>
- #include <QtCore/QDir>
- -#include <QtCore/qdatetime.h>
- +#include <QtCore/QDateTime>
- #include <QtCore/QList>
- +#include <QtCore/QIODevice>
- #include <zlib.h>
- #include <time.h>
- @@ -1278,6 +1278,7 @@ public:
- encoding(0)
- {}
- unsigned long crc;
- + qint64 start;
- qint64 compressedSize;
- qint64 headerStart;
- int encoding;
- @@ -1294,6 +1295,7 @@ KZipFileEntry::KZipFileEntry(KZip* zip, const QString& name, int access, int dat
- d->path = path;
- d->encoding = encoding;
- d->compressedSize = compressedSize;
- + d->start = start;
- }
- KZipFileEntry::~KZipFileEntry()
- @@ -1306,6 +1308,11 @@ int KZipFileEntry::encoding() const
- return d->encoding;
- }
- +qint64 KZipFileEntry::start() const
- +{
- + return d->start;
- +}
- +
- qint64 KZipFileEntry::compressedSize() const
- {
- return d->compressedSize;
- @@ -1356,7 +1363,13 @@ QIODevice* KZipFileEntry::createDevice() const
- {
- //kDebug(7040) << "creating iodevice limited to pos=" << position() << ", csize=" << compressedSize();
- // Limit the reading to the appropriate part of the underlying device (e.g. file)
- - KLimitedIODevice* limitedDev = new KLimitedIODevice( archive()->device(), position(), compressedSize() );
- + QIODevice* limitedDev = archive()->device();
- + if(limitedDev->isOpen()) {
- + limitedDev->seek( start() );
- + } else {
- + limitedDev->open( QIODevice::ReadOnly );
- + }
- +
- if ( encoding() == 0 || compressedSize() == 0 ) // no compression (or even no data)
- return limitedDev;
- diff --git a/kdecore/io/kzip.h b/kdecore/io/kzip.h
- index 4644880..2fa6ad9 100644
- --- a/kdecore/io/kzip.h
- +++ b/kdecore/io/kzip.h
- @@ -182,6 +182,7 @@ public:
- int encoding() const;
- qint64 compressedSize() const;
- + qint64 start() const;
- /// Only used when writing
- void setCompressedSize(qint64 compressedSize);
- diff --git a/kdecore/sonnet/tests/CMakeLists.txt b/kdecore/sonnet/tests/CMakeLists.txt
- index 308db57..a91b5f0 100644
- --- a/kdecore/sonnet/tests/CMakeLists.txt
- +++ b/kdecore/sonnet/tests/CMakeLists.txt
- @@ -14,7 +14,7 @@ target_link_libraries(test_suggest ${KDE4_KDECORE_LIBS} )
- MACRO(SONNET_UNIT_TESTS)
- FOREACH(_testname ${ARGN})
- kde4_add_test(sonnet-${_testname} ${_testname}.cpp)
- - target_link_libraries(sonnet-${_testname} ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTXML_LIBRARY} ${KDEWIN_LIBRARIES})
- + target_link_libraries(sonnet-${_testname} ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTXML_LIBRARY})
- ENDFOREACH(_testname)
- ENDMACRO(SONNET_UNIT_TESTS)
- diff --git a/kdecore/tests/CMakeLists.txt b/kdecore/tests/CMakeLists.txt
- index 224322f..3c96748 100644
- --- a/kdecore/tests/CMakeLists.txt
- +++ b/kdecore/tests/CMakeLists.txt
- @@ -114,11 +114,6 @@ target_link_libraries(kdecore-kdatetimeformattertest ${KDE4_KDECORE_LIBS} ${QT_Q
- add_executable(kdecore-kdirwatchtest_gui kdirwatchtest_gui.cpp)
- target_link_libraries(kdecore-kdirwatchtest_gui ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY})
- -########### klimitediodevicetest ###############
- -
- -kde4_add_test(kdecore-klimitediodevicetest klimitediodevicetest.cpp ../io/klimitediodevice.cpp)
- -target_link_libraries(kdecore-klimitediodevicetest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY})
- -
- ########### kmimetypetest ###############
- # compile kmimemagicrule.cpp into the test since it's not exported and we call match().
- diff --git a/kdecore/tests/klimitediodevicetest.cpp b/kdecore/tests/klimitediodevicetest.cpp
- deleted file mode 100644
- index 989a523..0000000
- --- a/kdecore/tests/klimitediodevicetest.cpp
- +++ /dev/null
- @@ -1,79 +0,0 @@
- -/* This file is part of the KDE project
- - Copyright (C) 2009 Pino Toscano <pino@kde.org>
- -
- - This library is free software; you can redistribute it and/or
- - modify it under the terms of the GNU Library General Public
- - License as published by the Free Software Foundation; either
- - version 2 of the License, or (at your option) any later version.
- -
- - This library is distributed in the hope that it will be useful,
- - but WITHOUT ANY WARRANTY; without even the implied warranty of
- - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- - Library General Public License for more details.
- -
- - You should have received a copy of the GNU Library General Public License
- - along with this library; see the file COPYING.LIB. If not, write to
- - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- - Boston, MA 02110-1301, USA.
- -*/
- -
- -#include "klimitediodevicetest.h"
- -
- -#include "klimitediodevice_p.h"
- -
- -#include <qtest_kde.h>
- -
- -QTEST_KDEMAIN_CORE(KLimitedIODeviceTest)
- -
- -void KLimitedIODeviceTest::addChunk(const QByteArray &chunk)
- -{
- - ChunkData cd;
- - cd.data = chunk;
- - cd.offset = m_chunks.isEmpty() ? 0 : m_chunks.last().offset + m_chunks.last().data.size();
- - m_chunks.append(cd);
- - m_data.append(chunk);
- -}
- -
- -void KLimitedIODeviceTest::initTestCase()
- -{
- - addChunk("Test of string");
- - addChunk("second part of the large buffer");
- - addChunk("... which will be used to test the KLimitedIODevice");
- -
- - m_buffer.setBuffer(&m_data);
- - m_buffer.open(QIODevice::ReadOnly);
- -}
- -
- -void KLimitedIODeviceTest::testReadChunks_data()
- -{
- - QTest::addColumn<int>("index");
- -
- - for (int i = 0; i < m_chunks.count(); ++i) {
- - const ChunkData &d = m_chunks.at(i);
- - QTest::newRow(d.data.constData()) << i;
- - }
- -}
- -
- -void KLimitedIODeviceTest::testReadChunks()
- -{
- - QFETCH(int, index);
- -
- - const ChunkData &chunk = m_chunks.at(index);
- -
- - KLimitedIODevice dev(&m_buffer, chunk.offset, chunk.data.size());
- - QVERIFY(dev.isOpen());
- - QCOMPARE(dev.readAll(), chunk.data);
- -}
- -
- -void KLimitedIODeviceTest::testSeeking()
- -{
- - const ChunkData &chunk = m_chunks.at(2);
- -
- - KLimitedIODevice dev(&m_buffer, chunk.offset, chunk.data.size());
- - QVERIFY(dev.seek(dev.size() - 16));
- - QCOMPARE(dev.readAll(), chunk.data.right(16));
- - QVERIFY(dev.seek(0));
- - QCOMPARE(dev.readAll(), chunk.data);
- -}
- -
- -#include "moc_klimitediodevicetest.cpp"
- diff --git a/kdecore/tests/klimitediodevicetest.h b/kdecore/tests/klimitediodevicetest.h
- deleted file mode 100644
- index d9b7439..0000000
- --- a/kdecore/tests/klimitediodevicetest.h
- +++ /dev/null
- @@ -1,52 +0,0 @@
- -/* This file is part of the KDE project
- - Copyright (C) 2009 Pino Toscano <pino@kde.org>
- -
- - This library is free software; you can redistribute it and/or
- - modify it under the terms of the GNU Library General Public
- - License as published by the Free Software Foundation; either
- - version 2 of the License, or (at your option) any later version.
- -
- - This library is distributed in the hope that it will be useful,
- - but WITHOUT ANY WARRANTY; without even the implied warranty of
- - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- - Library General Public License for more details.
- -
- - You should have received a copy of the GNU Library General Public License
- - along with this library; see the file COPYING.LIB. If not, write to
- - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- - Boston, MA 02110-1301, USA.
- -*/
- -
- -#ifndef KLIMITEDIODEVICETEST_H
- -#define KLIMITEDIODEVICETEST_H
- -
- -#include <QByteArray>
- -#include <QBuffer>
- -#include <QList>
- -#include <QObject>
- -
- -struct ChunkData
- -{
- - QByteArray data;
- - int offset;
- -};
- -
- -class KLimitedIODeviceTest : public QObject
- -{
- -Q_OBJECT
- -private Q_SLOTS:
- - void initTestCase();
- -
- - void testReadChunks_data();
- - void testReadChunks();
- - void testSeeking();
- -
- -private:
- - void addChunk(const QByteArray &chunk);
- -
- - QByteArray m_data;
- - QBuffer m_buffer;
- - QList<ChunkData> m_chunks;
- -};
- -
- -#endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement