kio Library: karchive.h Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# karchive.h

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2000 David Faure <faure@kde.org>
    00003    Copyright (C) 2003 Leo Savernik <l.savernik@aon.at>
    00004
    00005    Moved from ktar.h by Roberto Teixeira <maragato@kde.org>
    00006
    00007    This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Library General Public
    00009    License version 2 as published by the Free Software Foundation.
    00010
    00011    This library is distributed in the hope that it will be useful,
    00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014    Library General Public License for more details.
    00015
    00016    You should have received a copy of the GNU Library General Public License
    00017    along with this library; see the file COPYING.LIB.  If not, write to
    00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019    Boston, MA 02111-1307, USA.
    00020 */
    00021 #ifndef __karchive_h
    00022 #define __karchive_h
    00023
    00024 #include <sys/stat.h>
    00025 #include <sys/types.h>
    00026
    00027 #include <qdatetime.h>
    00028 #include <qstring.h>
    00029 #include <qstringlist.h>
    00030 #include <qdict.h>
    00031
    00032 #include <kdelibs_export.h>
    00033
    00034 class KArchiveDirectory;
    00035 class KArchiveFile;
    00036
    00042 class KIO_EXPORT KArchive
    00043 {
    00044 protected:
    00050     KArchive( QIODevice * dev );
    00051
    00052 public:
    00053     virtual ~KArchive();
    00054
    00061     virtual bool open( int mode );
    00062
    00069     virtual void close();
    00070
    00075     bool isOpened() const { return m_open; }
    00076
    00082     int mode() const { return m_mode; }
    00083
    00088     QIODevice * device() const { return m_dev; }
    00089
    00095     const KArchiveDirectory* directory() const;
    00096
    00107     bool addLocalFile( const QString& fileName, const QString& destName );
    00108
    00120     bool addLocalDirectory( const QString& path, const QString& destName );
    00121
    00133     virtual bool writeDir( const QString& name, const QString& user, const QString& group ) = 0;
    00134
    00152     bool writeDir( const QString& name, const QString& user, const QString& group,
    00153                 mode_t perm, time_t atime, time_t mtime, time_t ctime );
    00154
    00169     bool writeSymLink(const QString &name, const QString &target,
    00170                 const QString &user, const QString &group,
    00171                 mode_t perm, time_t atime, time_t mtime, time_t ctime);
    00172
    00186     virtual bool writeFile( const QString& name, const QString& user, const QString& group, uint size, const char* data );
    00187
    00209     bool writeFile( const QString& name, const QString& user, const QString& group,
    00210                 uint size, mode_t perm, time_t atime, time_t mtime,
    00211                 time_t ctime, const char* data );
    00212
    00227     virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size ) = 0;
    00228
    00250     bool prepareWriting( const QString& name, const QString& user,
    00251                 const QString& group, uint size, mode_t perm,
    00252                 time_t atime, time_t mtime, time_t ctime );
    00253
    00258     bool writeData( const char* data, uint size );
    00259
    00265     virtual bool doneWriting( uint size ) = 0;
    00266
    00267 protected:
    00273     virtual bool openArchive( int mode ) = 0;
    00274
    00279     virtual bool closeArchive() = 0;
    00280
    00288     virtual KArchiveDirectory* rootDir();
    00289
    00296     KArchiveDirectory * findOrCreate( const QString & path );
    00297
    00301     void setDevice( QIODevice *dev );
    00302
    00306     void setRootDir( KArchiveDirectory *rootDir );
    00307
    00308 private:
    00309     QIODevice * m_dev;
    00310     bool m_open;
    00311     char m_mode;
    00312 protected:
    00313     virtual void virtual_hook( int id, void* data );
    00314     /* @internal for virtual_hook */
    00315     enum { VIRTUAL_WRITE_DATA = 1, VIRTUAL_WRITE_SYMLINK, VIRTUAL_WRITE_DIR,
    00316         VIRTUAL_WRITE_FILE, VIRTUAL_PREPARE_WRITING };
    00317     bool prepareWriting_impl( const QString& name, const QString& user,
    00318                 const QString& group, uint size, mode_t perm,
    00319                 time_t atime, time_t mtime, time_t ctime );
    00320     struct PrepareWritingParams {
    00321     const QString *name;
    00322     const QString *user;
    00323     const QString *group;
    00324     uint size;
    00325     mode_t perm;
    00326     time_t atime, mtime, ctime;
    00327     bool retval;
    00328     };
    00329     bool writeFile_impl( const QString& name, const QString& user,
    00330                 const QString& group, uint size, mode_t perm,
    00331                 time_t atime, time_t mtime, time_t ctime,
    00332                 const char* data );
    00333     struct WriteFileParams {
    00334     const QString *name;
    00335     const QString *user;
    00336     const QString *group;
    00337     uint size;
    00338     mode_t perm;
    00339     time_t atime, mtime, ctime;
    00340     const char *data;
    00341     bool retval;
    00342     };
    00343     bool writeDir_impl(const QString& name, const QString& user,
    00344                 const QString& group, mode_t perm,
    00345                 time_t atime, time_t mtime, time_t ctime);
    00346     struct WriteDirParams {
    00347     const QString *name;
    00348     const QString *user;
    00349     const QString *group;
    00350     mode_t perm;
    00351     time_t atime, mtime, ctime;
    00352     bool retval;
    00353     };
    00354     bool writeSymLink_impl(const QString &name, const QString &target,
    00355                 const QString &user, const QString &group,
    00356                 mode_t perm, time_t atime, time_t mtime, time_t ctime);
    00357     struct WriteSymlinkParams {
    00358     const QString *name;
    00359     const QString *target;
    00360     const QString *user;
    00361     const QString *group;
    00362     mode_t perm;
    00363     time_t atime, mtime, ctime;
    00364     bool retval;
    00365     };
    00366     bool writeData_impl( const char* data, uint size );
    00367     struct WriteDataParams {
    00368         const char* data;
    00369         uint size;
    00370         bool retval;
    00371     };
    00372 private:
    00373     class KArchivePrivate;
    00374     KArchivePrivate * d;
    00375 };
    00376
    00384 class KIO_EXPORT KArchiveEntry
    00385 {
    00386 public:
    00397     KArchiveEntry( KArchive* archive, const QString& name, int access, int date,
    00398                const QString& user, const QString& group,
    00399                const QString &symlink );
    00400
    00401     virtual ~KArchiveEntry() { }
    00402
    00407     QDateTime datetime() const;
    00408
    00413     int date() const { return m_date; }
    00414
    00419     QString name() const { return m_name; }
    00425     mode_t permissions() const { return m_access; }
    00430     QString user() const { return m_user; }
    00435     QString group() const { return m_group; }
    00436
    00441     QString symlink() const { return m_symlink; }
    00442
    00447     virtual bool isFile() const { return false; }
    00448
    00453     virtual bool isDirectory() const { return false; }
    00454
    00455 protected:
    00456     KArchive* archive() const { return m_archive; }
    00457
    00458 private:
    00459     QString m_name;
    00460     int m_date;
    00461     mode_t m_access;
    00462     QString m_user;
    00463     QString m_group;
    00464     QString m_symlink;
    00465     KArchive* m_archive;
    00466 protected:
    00467     virtual void virtual_hook( int id, void* data );
    00468 private:
    00469     class KArchiveEntryPrivate* d;
    00470 };
    00471
    00479 class KIO_EXPORT KArchiveFile : public KArchiveEntry
    00480 {
    00481 public:
    00494     KArchiveFile( KArchive* archive, const QString& name, int access, int date,
    00495               const QString& user, const QString& group, const QString &symlink,
    00496               int pos, int size );
    00497
    00498     virtual ~KArchiveFile() { }
    00499
    00504     int position() const; // TODO use Q_LONG in KDE-4.0
    00509     int size() const; // TODO use Q_LONG in KDE-4.0
    00514     void setSize( int s ) { m_size = s; }
    00515
    00521     virtual QByteArray data() const;
    00522
    00531     QIODevice *device() const; // TODO make virtual
    00532
    00537     virtual bool isFile() const { return true; }
    00538
    00544     void copyTo(const QString& dest) const;
    00545
    00546 private:
    00547     int m_pos; // TODO use Q_LONG in KDE-4.0
    00548     int m_size; // TODO use Q_LONG in KDE-4.0
    00549 protected:
    00550     virtual void virtual_hook( int id, void* data );
    00551 private:
    00552     class KArchiveFilePrivate* d;
    00553 };
    00554
    00562 class KIO_EXPORT KArchiveDirectory : public KArchiveEntry
    00563 {
    00564 public:
    00575     KArchiveDirectory( KArchive* archive, const QString& name, int access, int date,
    00576                    const QString& user, const QString& group,
    00577                    const QString& symlink);
    00578
    00579     virtual ~KArchiveDirectory() { }
    00580
    00585     QStringList entries() const;
    00591     KArchiveEntry* entry( QString name );
    00597     const KArchiveEntry* entry( QString name ) const;
    00598
    00603     void addEntry( KArchiveEntry* );
    00604
    00609     virtual bool isDirectory() const { return true; }
    00610
    00618      void copyTo(const QString& dest, bool recursive = true) const;
    00619
    00620 private:
    00621     QDict<KArchiveEntry> m_entries;
    00622 protected:
    00623     virtual void virtual_hook( int id, void* data );
    00624 private:
    00625     class KArchiveDirectoryPrivate* d;
    00626 };
    00627
    00628 #endif

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:23:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003