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

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2000 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef koStoreDevice_h
00021 #define koStoreDevice_h
00022 
00023 #include <KoStore.h>
00024 
00030 class KoStoreDevice : public QIODevice
00031 {
00032 public:
00034   KoStoreDevice( KoStore * store ) : m_store(store) {
00035       // koffice-1.x behavior compat: a KoStoreDevice is automatically open
00036       setOpenMode( m_store->mode() == KoStore::Read ? QIODevice::ReadOnly : QIODevice::WriteOnly );
00037   }
00038   ~KoStoreDevice() {}
00039 
00040   virtual bool isSequential() const { return true; }
00041 
00042   virtual bool open( OpenMode m ) {
00043     setOpenMode(m);
00044     if ( m & QIODevice::ReadOnly )
00045       return ( m_store->mode() == KoStore::Read );
00046     if ( m & QIODevice::WriteOnly )
00047       return ( m_store->mode() == KoStore::Write );
00048     return false;
00049   }
00050   virtual void close() {}
00051 
00052   qint64 size() const {
00053     if ( m_store->mode() == KoStore::Read )
00054       return m_store->size();
00055     else
00056       return 0xffffffff;
00057   }
00058 
00059   virtual qint64 readData( char *data, qint64 maxlen ) { return m_store->read(data, maxlen); }
00060   virtual qint64 writeData( const char *data, qint64 len ) { return m_store->write( data, len ); }
00061 
00062 #if 0
00063   int getch() {
00064     char c[2];
00065     if ( m_store->read(c, 1) == -1)
00066       return -1;
00067     else
00068       return c[0];
00069   }
00070   int putch( int _c ) {
00071     char c[2];
00072     c[0] = _c;
00073     c[1] = 0;
00074     if (m_store->write( c, 1 ) == 1)
00075       return _c;
00076     else
00077       return -1;
00078   }
00079   int ungetch( int ) { return -1; } // unsupported
00080 #endif
00081 
00082   // See QIODevice
00083   virtual qint64 pos() const { return m_store->pos(); }
00084   virtual bool seek( qint64 pos ) { return m_store->seek(pos); }
00085   virtual bool atEnd() const { return m_store->atEnd(); }
00086 
00087 protected:
00088   KoStore * m_store;
00089 };
00090 
00091 #endif

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