Warning, file /office/calligra/libs/store/KoStoreDevice.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2000 David Faure <faure@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef koStoreDevice_h
0021 #define koStoreDevice_h
0022 
0023 #include "KoStore.h"
0024 
0025 /**
0026  * This class implements a QIODevice around KoStore, so that
0027  * it can be used to create a QDomDocument from it, to be written or read
0028  * using QDataStream or to be written using QTextStream
0029  */
0030 class KOSTORE_EXPORT KoStoreDevice : public QIODevice
0031 {
0032 Q_OBJECT
0033 public:
0034     /// Note: KoStore::open() should be called before calling this.
0035     explicit KoStoreDevice(KoStore * store) : m_store(store) {
0036         // calligra-1.x behavior compat: a KoStoreDevice is automatically open
0037         setOpenMode(m_store->mode() == KoStore::Read ? QIODevice::ReadOnly : QIODevice::WriteOnly);
0038     }
0039     ~KoStoreDevice() override;
0040 
0041     bool isSequential() const override {
0042         return true;
0043     }
0044 
0045     bool open(OpenMode m) override {
0046         setOpenMode(m);
0047         if (m & QIODevice::ReadOnly)
0048             return (m_store->mode() == KoStore::Read);
0049         if (m & QIODevice::WriteOnly)
0050             return (m_store->mode() == KoStore::Write);
0051         return false;
0052     }
0053     void close() override {}
0054 
0055     qint64 size() const override {
0056         if (m_store->mode() == KoStore::Read)
0057             return m_store->size();
0058         else
0059             return 0xffffffff;
0060     }
0061 
0062     // See QIODevice
0063     qint64 pos() const override {
0064         return m_store->pos();
0065     }
0066     bool seek(qint64 pos) override {
0067         return m_store->seek(pos);
0068     }
0069     bool atEnd() const override {
0070         return m_store->atEnd();
0071     }
0072 
0073 protected:
0074     KoStore *m_store;
0075 
0076     qint64 readData(char *data, qint64 maxlen) override {
0077         return m_store->read(data, maxlen);
0078     }
0079 
0080     qint64 writeData(const char *data, qint64 len) override {
0081         return m_store->write(data, len);
0082     }
0083 
0084 };
0085 
0086 #endif