Advertisement
Guest User

Untitled

a guest
Oct 20th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.28 KB | None | 0 0
  1. diff --git a/kdecore/CMakeLists.txt b/kdecore/CMakeLists.txt
  2. index 79645ea..650d9a0 100644
  3. --- a/kdecore/CMakeLists.txt
  4. +++ b/kdecore/CMakeLists.txt
  5. @@ -158,7 +158,6 @@ set(kdecore_LIB_SRCS
  6. io/kdebugdbusiface.cpp
  7. io/kdirwatch.cpp
  8. io/kfilesystemtype_p.cpp
  9. - io/klimitediodevice.cpp
  10. io/kmessage.cpp
  11. io/kmountpoint.cpp
  12. io/kprocess.cpp
  13. diff --git a/kdecore/io/kar.cpp b/kdecore/io/kar.cpp
  14. index 9ff9937..a733e20 100644
  15. --- a/kdecore/io/kar.cpp
  16. +++ b/kdecore/io/kar.cpp
  17. @@ -29,7 +29,6 @@
  18. #include <QtCore/QRegExp>
  19.  
  20. #include "kfilterdev.h"
  21. -//#include "klimitediodevice_p.h"
  22.  
  23. ////////////////////////////////////////////////////////////////////////
  24. /////////////////////////// KAr ///////////////////////////////////////
  25. diff --git a/kdecore/io/karchive.cpp b/kdecore/io/karchive.cpp
  26. index 2c2be42..403eec1 100644
  27. --- a/kdecore/io/karchive.cpp
  28. +++ b/kdecore/io/karchive.cpp
  29. @@ -20,7 +20,6 @@
  30. */
  31.  
  32. #include "karchive.h"
  33. -#include "klimitediodevice_p.h"
  34.  
  35. #include <config.h>
  36.  
  37. @@ -651,7 +650,13 @@ QByteArray KArchiveFile::data() const
  38.  
  39. QIODevice * KArchiveFile::createDevice() const
  40. {
  41. - return new KLimitedIODevice( archive()->device(), d->pos, d->size );
  42. + QIODevice* limitedDev = archive()->device();
  43. + if(limitedDev->isOpen()) {
  44. + limitedDev->seek( position() );
  45. + } else {
  46. + limitedDev->open( QIODevice::ReadOnly );
  47. + }
  48. + return limitedDev;
  49. }
  50.  
  51. bool KArchiveFile::isFile() const
  52. diff --git a/kdecore/io/klimitediodevice.cpp b/kdecore/io/klimitediodevice.cpp
  53. deleted file mode 100644
  54. index b457350..0000000
  55. --- a/kdecore/io/klimitediodevice.cpp
  56. +++ /dev/null
  57. @@ -1,81 +0,0 @@
  58. -/* This file is part of the KDE libraries
  59. - Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org>
  60. -
  61. - This library is free software; you can redistribute it and/or
  62. - modify it under the terms of the GNU Library General Public
  63. - License version 2 as published by the Free Software Foundation.
  64. -
  65. - This library is distributed in the hope that it will be useful,
  66. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  67. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  68. - Library General Public License for more details.
  69. -
  70. - You should have received a copy of the GNU Library General Public License
  71. - along with this library; see the file COPYING.LIB. If not, write to
  72. - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  73. - Boston, MA 02110-1301, USA.
  74. -*/
  75. -
  76. -#include <kdebug.h>
  77. -#include "klimitediodevice_p.h"
  78. -
  79. -KLimitedIODevice::KLimitedIODevice( QIODevice *dev, qint64 start, qint64 length )
  80. - : m_dev( dev ), m_start( start ), m_length( length )
  81. -{
  82. - //kDebug(7005) << "start=" << start << "length=" << length;
  83. - open( QIODevice::ReadOnly ); //krazy:exclude=syscalls
  84. -}
  85. -
  86. -bool KLimitedIODevice::open( QIODevice::OpenMode m )
  87. -{
  88. - //kDebug(7005) << "m=" << m;
  89. - if ( m & QIODevice::ReadOnly ) {
  90. - /*bool ok = false;
  91. - if ( m_dev->isOpen() )
  92. - ok = ( m_dev->mode() == QIODevice::ReadOnly );
  93. - else
  94. - ok = m_dev->open( m );
  95. - if ( ok )*/
  96. - m_dev->seek( m_start ); // No concurrent access !
  97. - }
  98. - else
  99. - kWarning(7005) << "KLimitedIODevice::open only supports QIODevice::ReadOnly!";
  100. - setOpenMode( QIODevice::ReadOnly );
  101. - return true;
  102. -}
  103. -
  104. -void KLimitedIODevice::close()
  105. -{
  106. -}
  107. -
  108. -qint64 KLimitedIODevice::size() const
  109. -{
  110. - return m_length;
  111. -}
  112. -
  113. -qint64 KLimitedIODevice::readData( char * data, qint64 maxlen )
  114. -{
  115. - maxlen = qMin( maxlen, m_length - pos() ); // Apply upper limit
  116. - return m_dev->read( data, maxlen );
  117. -}
  118. -
  119. -bool KLimitedIODevice::seek( qint64 pos )
  120. -{
  121. - Q_ASSERT( pos <= m_length );
  122. - pos = qMin( pos, m_length ); // Apply upper limit
  123. - bool ret = m_dev->seek( m_start + pos );
  124. - if ( ret ) {
  125. - QIODevice::seek( pos );
  126. - }
  127. - return ret;
  128. -}
  129. -
  130. -qint64 KLimitedIODevice::bytesAvailable() const
  131. -{
  132. - return QIODevice::bytesAvailable();
  133. -}
  134. -
  135. -bool KLimitedIODevice::isSequential() const
  136. -{
  137. - return m_dev->isSequential();
  138. -}
  139. diff --git a/kdecore/io/klimitediodevice_p.h b/kdecore/io/klimitediodevice_p.h
  140. deleted file mode 100644
  141. index 853dd5d..0000000
  142. --- a/kdecore/io/klimitediodevice_p.h
  143. +++ /dev/null
  144. @@ -1,63 +0,0 @@
  145. -/* This file is part of the KDE libraries
  146. - Copyright (C) 2001, 2002, 2007 David Faure <faure@kde.org>
  147. -
  148. - This library is free software; you can redistribute it and/or
  149. - modify it under the terms of the GNU Library General Public
  150. - License version 2 as published by the Free Software Foundation.
  151. -
  152. - This library is distributed in the hope that it will be useful,
  153. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  154. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  155. - Library General Public License for more details.
  156. -
  157. - You should have received a copy of the GNU Library General Public License
  158. - along with this library; see the file COPYING.LIB. If not, write to
  159. - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  160. - Boston, MA 02110-1301, USA.
  161. -*/
  162. -
  163. -#ifndef KLIMITEDIODEVICE_P_H
  164. -#define KLIMITEDIODEVICE_P_H
  165. -
  166. -#include <QtCore/qiodevice.h>
  167. -/**
  168. - * A readonly device that reads from an underlying device
  169. - * from a given point to another (e.g. to give access to a single
  170. - * file inside an archive).
  171. - * @author David Faure <faure@kde.org>
  172. - * @internal - used by KArchive
  173. - */
  174. -class KLimitedIODevice : public QIODevice
  175. -{
  176. -public:
  177. - /**
  178. - * Creates a new KLimitedIODevice.
  179. - * @param dev the underlying device, opened or not
  180. - * This device itself auto-opens (in readonly mode), no need to open it.
  181. - * @param start where to start reading (position in bytes)
  182. - * @param length the length of the data to read (in bytes)
  183. - */
  184. - KLimitedIODevice( QIODevice *dev, qint64 start, qint64 length );
  185. - virtual ~KLimitedIODevice() {}
  186. -
  187. - virtual bool isSequential() const;
  188. -
  189. - virtual bool open( QIODevice::OpenMode m );
  190. - virtual void close();
  191. -
  192. - virtual qint64 size() const;
  193. -
  194. - virtual qint64 readData ( char * data, qint64 maxlen );
  195. - virtual qint64 writeData ( const char *, qint64 ) { return -1; } // unsupported
  196. - virtual int putChar( int ) { return -1; } // unsupported
  197. -
  198. - //virtual qint64 pos() const { return m_dev->pos() - m_start; }
  199. - virtual bool seek( qint64 pos );
  200. - virtual qint64 bytesAvailable() const;
  201. -private:
  202. - QIODevice* m_dev;
  203. - qint64 m_start;
  204. - qint64 m_length;
  205. -};
  206. -
  207. -#endif
  208. diff --git a/kdecore/io/kzip.cpp b/kdecore/io/kzip.cpp
  209. index 9e5c17b..0cd4a11 100644
  210. --- a/kdecore/io/kzip.cpp
  211. +++ b/kdecore/io/kzip.cpp
  212. @@ -19,15 +19,15 @@
  213.  
  214. #include "kzip.h"
  215. #include "kfilterdev.h"
  216. -#include "klimitediodevice_p.h"
  217. #include <kdebug.h>
  218.  
  219. #include <QtCore/QHash>
  220. #include <QtCore/QByteArray>
  221. #include <QtCore/QFile>
  222. #include <QtCore/QDir>
  223. -#include <QtCore/qdatetime.h>
  224. +#include <QtCore/QDateTime>
  225. #include <QtCore/QList>
  226. +#include <QtCore/QIODevice>
  227.  
  228. #include <zlib.h>
  229. #include <time.h>
  230. @@ -1278,6 +1278,7 @@ public:
  231. encoding(0)
  232. {}
  233. unsigned long crc;
  234. + qint64 start;
  235. qint64 compressedSize;
  236. qint64 headerStart;
  237. int encoding;
  238. @@ -1294,6 +1295,7 @@ KZipFileEntry::KZipFileEntry(KZip* zip, const QString& name, int access, int dat
  239. d->path = path;
  240. d->encoding = encoding;
  241. d->compressedSize = compressedSize;
  242. + d->start = start;
  243. }
  244.  
  245. KZipFileEntry::~KZipFileEntry()
  246. @@ -1306,6 +1308,11 @@ int KZipFileEntry::encoding() const
  247. return d->encoding;
  248. }
  249.  
  250. +qint64 KZipFileEntry::start() const
  251. +{
  252. + return d->start;
  253. +}
  254. +
  255. qint64 KZipFileEntry::compressedSize() const
  256. {
  257. return d->compressedSize;
  258. @@ -1356,7 +1363,13 @@ QIODevice* KZipFileEntry::createDevice() const
  259. {
  260. //kDebug(7040) << "creating iodevice limited to pos=" << position() << ", csize=" << compressedSize();
  261. // Limit the reading to the appropriate part of the underlying device (e.g. file)
  262. - KLimitedIODevice* limitedDev = new KLimitedIODevice( archive()->device(), position(), compressedSize() );
  263. + QIODevice* limitedDev = archive()->device();
  264. + if(limitedDev->isOpen()) {
  265. + limitedDev->seek( start() );
  266. + } else {
  267. + limitedDev->open( QIODevice::ReadOnly );
  268. + }
  269. +
  270. if ( encoding() == 0 || compressedSize() == 0 ) // no compression (or even no data)
  271. return limitedDev;
  272.  
  273. diff --git a/kdecore/io/kzip.h b/kdecore/io/kzip.h
  274. index 4644880..2fa6ad9 100644
  275. --- a/kdecore/io/kzip.h
  276. +++ b/kdecore/io/kzip.h
  277. @@ -182,6 +182,7 @@ public:
  278.  
  279. int encoding() const;
  280. qint64 compressedSize() const;
  281. + qint64 start() const;
  282.  
  283. /// Only used when writing
  284. void setCompressedSize(qint64 compressedSize);
  285. diff --git a/kdecore/sonnet/tests/CMakeLists.txt b/kdecore/sonnet/tests/CMakeLists.txt
  286. index 308db57..a91b5f0 100644
  287. --- a/kdecore/sonnet/tests/CMakeLists.txt
  288. +++ b/kdecore/sonnet/tests/CMakeLists.txt
  289. @@ -14,7 +14,7 @@ target_link_libraries(test_suggest ${KDE4_KDECORE_LIBS} )
  290. MACRO(SONNET_UNIT_TESTS)
  291. FOREACH(_testname ${ARGN})
  292. kde4_add_test(sonnet-${_testname} ${_testname}.cpp)
  293. - target_link_libraries(sonnet-${_testname} ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTXML_LIBRARY} ${KDEWIN_LIBRARIES})
  294. + target_link_libraries(sonnet-${_testname} ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} ${QT_QTXML_LIBRARY})
  295. ENDFOREACH(_testname)
  296. ENDMACRO(SONNET_UNIT_TESTS)
  297.  
  298. diff --git a/kdecore/tests/CMakeLists.txt b/kdecore/tests/CMakeLists.txt
  299. index 224322f..3c96748 100644
  300. --- a/kdecore/tests/CMakeLists.txt
  301. +++ b/kdecore/tests/CMakeLists.txt
  302. @@ -114,11 +114,6 @@ target_link_libraries(kdecore-kdatetimeformattertest ${KDE4_KDECORE_LIBS} ${QT_Q
  303. add_executable(kdecore-kdirwatchtest_gui kdirwatchtest_gui.cpp)
  304. target_link_libraries(kdecore-kdirwatchtest_gui ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY})
  305.  
  306. -########### klimitediodevicetest ###############
  307. -
  308. -kde4_add_test(kdecore-klimitediodevicetest klimitediodevicetest.cpp ../io/klimitediodevice.cpp)
  309. -target_link_libraries(kdecore-klimitediodevicetest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY})
  310. -
  311. ########### kmimetypetest ###############
  312.  
  313. # compile kmimemagicrule.cpp into the test since it's not exported and we call match().
  314. diff --git a/kdecore/tests/klimitediodevicetest.cpp b/kdecore/tests/klimitediodevicetest.cpp
  315. deleted file mode 100644
  316. index 989a523..0000000
  317. --- a/kdecore/tests/klimitediodevicetest.cpp
  318. +++ /dev/null
  319. @@ -1,79 +0,0 @@
  320. -/* This file is part of the KDE project
  321. - Copyright (C) 2009 Pino Toscano <pino@kde.org>
  322. -
  323. - This library is free software; you can redistribute it and/or
  324. - modify it under the terms of the GNU Library General Public
  325. - License as published by the Free Software Foundation; either
  326. - version 2 of the License, or (at your option) any later version.
  327. -
  328. - This library is distributed in the hope that it will be useful,
  329. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  330. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  331. - Library General Public License for more details.
  332. -
  333. - You should have received a copy of the GNU Library General Public License
  334. - along with this library; see the file COPYING.LIB. If not, write to
  335. - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  336. - Boston, MA 02110-1301, USA.
  337. -*/
  338. -
  339. -#include "klimitediodevicetest.h"
  340. -
  341. -#include "klimitediodevice_p.h"
  342. -
  343. -#include <qtest_kde.h>
  344. -
  345. -QTEST_KDEMAIN_CORE(KLimitedIODeviceTest)
  346. -
  347. -void KLimitedIODeviceTest::addChunk(const QByteArray &chunk)
  348. -{
  349. - ChunkData cd;
  350. - cd.data = chunk;
  351. - cd.offset = m_chunks.isEmpty() ? 0 : m_chunks.last().offset + m_chunks.last().data.size();
  352. - m_chunks.append(cd);
  353. - m_data.append(chunk);
  354. -}
  355. -
  356. -void KLimitedIODeviceTest::initTestCase()
  357. -{
  358. - addChunk("Test of string");
  359. - addChunk("second part of the large buffer");
  360. - addChunk("... which will be used to test the KLimitedIODevice");
  361. -
  362. - m_buffer.setBuffer(&m_data);
  363. - m_buffer.open(QIODevice::ReadOnly);
  364. -}
  365. -
  366. -void KLimitedIODeviceTest::testReadChunks_data()
  367. -{
  368. - QTest::addColumn<int>("index");
  369. -
  370. - for (int i = 0; i < m_chunks.count(); ++i) {
  371. - const ChunkData &d = m_chunks.at(i);
  372. - QTest::newRow(d.data.constData()) << i;
  373. - }
  374. -}
  375. -
  376. -void KLimitedIODeviceTest::testReadChunks()
  377. -{
  378. - QFETCH(int, index);
  379. -
  380. - const ChunkData &chunk = m_chunks.at(index);
  381. -
  382. - KLimitedIODevice dev(&m_buffer, chunk.offset, chunk.data.size());
  383. - QVERIFY(dev.isOpen());
  384. - QCOMPARE(dev.readAll(), chunk.data);
  385. -}
  386. -
  387. -void KLimitedIODeviceTest::testSeeking()
  388. -{
  389. - const ChunkData &chunk = m_chunks.at(2);
  390. -
  391. - KLimitedIODevice dev(&m_buffer, chunk.offset, chunk.data.size());
  392. - QVERIFY(dev.seek(dev.size() - 16));
  393. - QCOMPARE(dev.readAll(), chunk.data.right(16));
  394. - QVERIFY(dev.seek(0));
  395. - QCOMPARE(dev.readAll(), chunk.data);
  396. -}
  397. -
  398. -#include "moc_klimitediodevicetest.cpp"
  399. diff --git a/kdecore/tests/klimitediodevicetest.h b/kdecore/tests/klimitediodevicetest.h
  400. deleted file mode 100644
  401. index d9b7439..0000000
  402. --- a/kdecore/tests/klimitediodevicetest.h
  403. +++ /dev/null
  404. @@ -1,52 +0,0 @@
  405. -/* This file is part of the KDE project
  406. - Copyright (C) 2009 Pino Toscano <pino@kde.org>
  407. -
  408. - This library is free software; you can redistribute it and/or
  409. - modify it under the terms of the GNU Library General Public
  410. - License as published by the Free Software Foundation; either
  411. - version 2 of the License, or (at your option) any later version.
  412. -
  413. - This library is distributed in the hope that it will be useful,
  414. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  415. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  416. - Library General Public License for more details.
  417. -
  418. - You should have received a copy of the GNU Library General Public License
  419. - along with this library; see the file COPYING.LIB. If not, write to
  420. - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  421. - Boston, MA 02110-1301, USA.
  422. -*/
  423. -
  424. -#ifndef KLIMITEDIODEVICETEST_H
  425. -#define KLIMITEDIODEVICETEST_H
  426. -
  427. -#include <QByteArray>
  428. -#include <QBuffer>
  429. -#include <QList>
  430. -#include <QObject>
  431. -
  432. -struct ChunkData
  433. -{
  434. - QByteArray data;
  435. - int offset;
  436. -};
  437. -
  438. -class KLimitedIODeviceTest : public QObject
  439. -{
  440. -Q_OBJECT
  441. -private Q_SLOTS:
  442. - void initTestCase();
  443. -
  444. - void testReadChunks_data();
  445. - void testReadChunks();
  446. - void testSeeking();
  447. -
  448. -private:
  449. - void addChunk(const QByteArray &chunk);
  450. -
  451. - QByteArray m_data;
  452. - QBuffer m_buffer;
  453. - QList<ChunkData> m_chunks;
  454. -};
  455. -
  456. -#endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement