F:/KPlato/koffice/libs/store/KoStore.h

Aller à la documentation de ce fichier.
00001 // -*- c-basic-offset: 2 -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 1998, 1999 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef __koStore_h_
00022 #define __koStore_h_
00023 
00024 #include <QString>
00025 #include <QStringList>
00026 #include <QIODevice>
00027 #include <q3valuestack.h>
00028 #include <QByteArray>
00029 #include <koffice_export.h>
00030 
00031 class QWidget;
00032 
00033 class KUrl;
00034 
00041 class KOSTORE_EXPORT KoStore
00042 {
00043 public:
00044 
00045   enum Mode { Read, Write };
00046   enum Backend { Auto, Tar, Zip, Directory, Encrypted };
00047 
00062   static KoStore* createStore( const QString& fileName, Mode mode, const QByteArray & appIdentification = "", Backend backend = Auto );
00063 
00069   static KoStore* createStore( QIODevice *device, Mode mode, const QByteArray & appIdentification = "", Backend backend = Auto );
00070 
00091   static KoStore* createStore( QWidget* window, const KUrl& url, Mode mode, const QByteArray & appIdentification = "", Backend backend = Auto );
00092 
00096   virtual ~KoStore();
00097 
00104   bool open( const QString & name );
00105 
00111   bool isOpen() const;
00112 
00117   bool close();
00118 
00124   QIODevice* device() const;
00125 
00130   QByteArray read( qint64 max );
00131 
00136   qint64 write( const QByteArray& _data );
00137 
00143   qint64 read( char *_buffer, qint64 _len );
00144 
00149   virtual qint64 write( const char* _data, qint64 _len );
00150 
00155   qint64 size() const;
00156 
00160   bool bad() const { return !m_bGood; } // :)
00161 
00165   Mode mode() const { return m_mode; }
00166 
00176   bool enterDirectory( const QString& directory );
00177 
00183   bool leaveDirectory();
00184 
00189   QString currentPath() const;
00190 
00195   QString currentDirectory() const;
00196 
00197 
00202   void pushDirectory();
00203 
00208   void popDirectory();
00209 
00214   bool hasFile( const QString& fileName ) const;
00215 
00221   bool addLocalFile( const QString &fileName, const QString &destName );
00222 
00228   bool addDataToFile( QByteArray &buffer, const QString &destName );
00229 
00236   QStringList addLocalDirectory( const QString &dirPath, const QString &dest );
00237 
00238 
00244   bool extractFile( const QString &srcName, const QString &fileName );
00245 
00251   bool extractFile( const QString &srcName, QByteArray &data );
00252 
00254 
00255   bool seek( qint64 pos );
00256   qint64 pos() const;
00257   bool atEnd() const;
00259 
00265   void disallowNameExpansion( void );
00266 
00267 protected:
00268 
00269   KoStore() {}
00270 
00275   virtual bool init( Mode mode );
00282   virtual bool openWrite( const QString& name ) = 0;
00290   virtual bool openRead( const QString& name ) = 0;
00291 
00295   virtual bool closeRead() = 0;
00299   virtual bool closeWrite() = 0;
00300 
00305   virtual bool enterRelativeDirectory( const QString& dirName ) = 0;
00310   virtual bool enterAbsoluteDirectory( const QString& path ) = 0;
00311 
00316   virtual bool fileExists( const QString& absPath ) const = 0;
00317 
00318 private:
00319   static Backend determineBackend( QIODevice* dev );
00320 
00334   QString toExternalNaming( const QString & _internalNaming ) const;
00335 
00339   QString expandEncodedPath( QString intern ) const;
00340 
00345   QString expandEncodedDirectory( QString intern ) const;
00346 
00347   mutable enum
00348   {
00349       NAMING_VERSION_2_1,
00350       NAMING_VERSION_2_2,
00351       NAMING_VERSION_RAW  
00352   } m_namingVersion;
00353 
00358   bool enterDirectoryInternal( const QString& directory );
00359 
00360   bool extractFile( const QString &srcName, QIODevice &buffer );
00361 
00362 protected:
00363 
00364   Mode m_mode;
00365 
00367   QStringList m_strFiles;
00368 
00370   QStringList m_currentPath;
00371 
00373   QString m_sName;
00375   qint64 m_iSize;
00376 
00378   QIODevice * m_stream;
00379 
00380   bool m_bIsOpen;
00382   bool m_bGood;
00383 
00384   static const int s_area;
00385 
00386 private:
00388   Q3ValueStack<QString> m_directoryStack;
00389 
00390 private:
00391   KoStore( const KoStore& store );  
00392   KoStore& operator=( const KoStore& store );  
00393 
00394   class Private;
00395   Private * d;
00396 
00397 };
00398 
00399 #endif

Généré le Wed Nov 22 23:41:14 2006 pour KPlato par  doxygen 1.5.1-p1