lib

KoStoreDevice.h
1/* This file is part of the KDE project
2 Copyright (C) 2000 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef koStoreDevice_h
21#define koStoreDevice_h
22
23#include <KoStore.h>
24
30class KoStoreDevice : public TQIODevice
31{
32public:
34 KoStoreDevice( KoStore * store ) : m_store(store) {
35 setType( IO_Direct );
36 }
38
39 bool open( int m ) {
40 if ( m & IO_ReadOnly )
41 return ( m_store->mode() == KoStore::Read );
42 if ( m & IO_WriteOnly )
43 return ( m_store->mode() == KoStore::Write );
44 return false;
45 }
46 void close() { }
47 void flush() { }
48
49 Offset size() const {
50 if ( m_store->mode() == KoStore::Read )
51 return m_store->size();
52 else
53 return 0xffffffff;
54 }
55
56 virtual TQ_LONG readBlock( char *data, TQ_ULONG maxlen ) { return m_store->read(data, maxlen); }
57 virtual TQ_LONG writeBlock( const char *data, TQ_ULONG len ) { return m_store->write( data, len ); }
58 // Not virtual, only to uncover shadow
59 TQ_LONG writeBlock( const TQByteArray& data ) { return TQIODevice::writeBlock( data ); }
60
61 int getch() {
62 char c[2];
63 if ( m_store->read(c, 1) == -1)
64 return -1;
65 else
66 return c[0];
67 }
68 int putch( int _c ) {
69 char c[2];
70 c[0] = _c;
71 c[1] = 0;
72 if (m_store->write( c, 1 ) == 1)
73 return _c;
74 else
75 return -1;
76 }
77 int ungetch( int ) { return -1; } // unsupported
78
79 // See TQIODevice
80 virtual bool at( Offset pos ) { return m_store->at(pos); }
81 virtual Offset at() const { return m_store->at(); }
82 virtual bool atEnd() const { return m_store->atEnd(); }
83
84protected:
85 KoStore * m_store;
86};
87
88#endif
This class implements a TQIODevice around KoStore, so that it can be used to create a TQDomDocument f...
KoStoreDevice(KoStore *store)
Note: KoStore::open() should be called before calling this.
Saves and loads KOffice documents using various backends.
Definition KoStore.h:40