lib

KoStore.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 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 __koStore_h_
21#define __koStore_h_
22
23#include <tqstring.h>
24#include <tqstringlist.h>
25#include <tqiodevice.h>
26#include <tqvaluestack.h>
27#include <koffice_export.h>
28
29class TQWidget;
30
31class KURL;
32
39class KOSTORE_EXPORT KoStore
40{
41public:
42
43 enum Mode { Read, Write };
44 enum Backend { Auto, Tar, Zip, Directory };
45
60 static KoStore* createStore( const TQString& fileName, Mode mode, const TQCString & appIdentification = "", Backend backend = Auto );
61
67 static KoStore* createStore( TQIODevice *device, Mode mode, const TQCString & appIdentification = "", Backend backend = Auto );
68
89 static KoStore* createStore( TQWidget* window, const KURL& url, Mode mode, const TQCString & appIdentification = "", Backend backend = Auto );
90
94 virtual ~KoStore();
95
102 bool open( const TQString & name );
103
109 bool isOpen() const;
110
115 bool close();
116
122 TQIODevice* device() const;
123
128 TQByteArray read( unsigned long int max );
129
134 TQ_LONG write( const TQByteArray& _data );
135
141 TQ_LONG read( char *_buffer, TQ_ULONG _len );
142
147 virtual TQ_LONG write( const char* _data, TQ_ULONG _len );
148
153 TQIODevice::Offset size() const;
154
158 bool bad() const { return !m_bGood; } // :)
159
163 Mode mode() const { return m_mode; }
164
174 bool enterDirectory( const TQString& directory );
175
181 bool leaveDirectory();
182
187 TQString currentPath() const;
188
193 TQString currentDirectory() const;
194
195
200 void pushDirectory();
201
206 void popDirectory();
207
212 bool hasFile( const TQString& fileName ) const;
213
219 bool addLocalFile( const TQString &fileName, const TQString &destName );
220
227 TQStringList addLocalDirectory( const TQString &dirPath, const TQString &dest );
228
229
235 bool extractFile( const TQString &srcName, const TQString &fileName );
236
238
239 bool at( TQIODevice::Offset pos );
240 TQIODevice::Offset at() const;
241 bool atEnd() const;
243
249 void disallowNameExpansion( void );
250
251protected:
252
253 KoStore() {}
254
259 virtual bool init( Mode mode );
266 virtual bool openWrite( const TQString& name ) = 0;
274 virtual bool openRead( const TQString& name ) = 0;
275
279 virtual bool closeRead() = 0;
283 virtual bool closeWrite() = 0;
284
289 virtual bool enterRelativeDirectory( const TQString& dirName ) = 0;
294 virtual bool enterAbsoluteDirectory( const TQString& path ) = 0;
295
300 virtual bool fileExists( const TQString& absPath ) const = 0;
301
302private:
303 static Backend determineBackend( TQIODevice* dev );
304
318 TQString toExternalNaming( const TQString & _internalNaming ) const;
319
323 TQString expandEncodedPath( TQString intern ) const;
324
329 TQString expandEncodedDirectory( TQString intern ) const;
330
331 mutable enum
332 {
333 NAMING_VERSION_2_1,
334 NAMING_VERSION_2_2,
335 NAMING_VERSION_RAW
336 } m_namingVersion;
337
342 bool enterDirectoryInternal( const TQString& directory );
343
344protected:
345
346 Mode m_mode;
347
349 TQStringList m_strFiles;
350
352 TQStringList m_currentPath;
353
355 TQValueStack<TQString> m_directoryStack;
356
358 TQString m_sName;
360 TQIODevice::Offset m_iSize;
361
363 TQIODevice * m_stream;
364
365 bool m_bIsOpen;
368
369 static const int s_area;
370
371private:
372 KoStore( const KoStore& store );
373 KoStore& operator=( const KoStore& store );
374
375 class Private;
376 Private * d;
377
378};
379
380#endif
Saves and loads KOffice documents using various backends.
Definition KoStore.h:40
virtual bool closeRead()=0
virtual bool openRead(const TQString &name)=0
Open the file name in the store, for reading.
virtual bool closeWrite()=0
virtual bool openWrite(const TQString &name)=0
Open the file name in the store, for writing On success, this method must set m_stream to a stream in...
TQStringList m_currentPath
The "current directory" (path)
Definition KoStore.h:352
bool m_bGood
Must be set by the constructor.
Definition KoStore.h:367
virtual bool fileExists(const TQString &absPath) const =0
Check if a file exists inside the store.
TQString m_sName
Current filename (between an open() and a close())
Definition KoStore.h:358
bool bad() const
Definition KoStore.h:158
TQIODevice::Offset m_iSize
Current size of the file named m_sName.
Definition KoStore.h:360
virtual bool enterRelativeDirectory(const TQString &dirName)=0
Enter a subdirectory of the current directory.
virtual bool enterAbsoluteDirectory(const TQString &path)=0
Enter a directory where we've been before.
Mode mode() const
Definition KoStore.h:163
TQValueStack< TQString > m_directoryStack
Used to push/pop directories to make it easy to save/restore the state.
Definition KoStore.h:355
TQIODevice * m_stream
The stream for the current read or write operation.
Definition KoStore.h:363
TQStringList m_strFiles
Store the filenames (with full path inside the archive) when writing, to avoid duplicates.
Definition KoStore.h:349