00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00076
00077 bool closeSucceeded() const;
00078
00083 bool isOpened() const { return m_open; }
00084
00090 int mode() const { return m_mode; }
00091
00096 QIODevice * device() const { return m_dev; }
00097
00103 const KArchiveDirectory* directory() const;
00104
00115 bool addLocalFile( const QString& fileName, const QString& destName );
00116
00128 bool addLocalDirectory( const QString& path, const QString& destName );
00129
00142 virtual bool writeDir( const QString& name, const QString& user, const QString& group ) = 0;
00143
00161 bool writeDir( const QString& name, const QString& user, const QString& group,
00162 mode_t perm, time_t atime, time_t mtime, time_t ctime );
00163
00178 bool writeSymLink(const QString &name, const QString &target,
00179 const QString &user, const QString &group,
00180 mode_t perm, time_t atime, time_t mtime, time_t ctime);
00181
00195 virtual bool writeFile( const QString& name, const QString& user, const QString& group, uint size, const char* data );
00196
00218 bool writeFile( const QString& name, const QString& user, const QString& group,
00219 uint size, mode_t perm, time_t atime, time_t mtime,
00220 time_t ctime, const char* data );
00221
00238 virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size ) = 0;
00239
00261 bool prepareWriting( const QString& name, const QString& user,
00262 const QString& group, uint size, mode_t perm,
00263 time_t atime, time_t mtime, time_t ctime );
00264
00269 bool writeData( const char* data, uint size );
00270
00276 virtual bool doneWriting( uint size ) = 0;
00277
00278 protected:
00284 virtual bool openArchive( int mode ) = 0;
00285
00290 virtual bool closeArchive() = 0;
00291
00299 virtual KArchiveDirectory* rootDir();
00300
00307 KArchiveDirectory * findOrCreate( const QString & path );
00308
00312 void setDevice( QIODevice *dev );
00313
00317 void setRootDir( KArchiveDirectory *rootDir );
00318
00319 private:
00320 QIODevice * m_dev;
00321 bool m_open;
00322 char m_mode;
00323 protected:
00324 virtual void virtual_hook( int id, void* data );
00325
00326 enum { VIRTUAL_WRITE_DATA = 1, VIRTUAL_WRITE_SYMLINK, VIRTUAL_WRITE_DIR,
00327 VIRTUAL_WRITE_FILE, VIRTUAL_PREPARE_WRITING };
00328 bool prepareWriting_impl( const QString& name, const QString& user,
00329 const QString& group, uint size, mode_t perm,
00330 time_t atime, time_t mtime, time_t ctime );
00331 struct PrepareWritingParams {
00332 const QString *name;
00333 const QString *user;
00334 const QString *group;
00335 uint size;
00336 mode_t perm;
00337 time_t atime, mtime, ctime;
00338 bool retval;
00339 };
00340 bool writeFile_impl( const QString& name, const QString& user,
00341 const QString& group, uint size, mode_t perm,
00342 time_t atime, time_t mtime, time_t ctime,
00343 const char* data );
00344 struct WriteFileParams {
00345 const QString *name;
00346 const QString *user;
00347 const QString *group;
00348 uint size;
00349 mode_t perm;
00350 time_t atime, mtime, ctime;
00351 const char *data;
00352 bool retval;
00353 };
00354 bool writeDir_impl(const QString& name, const QString& user,
00355 const QString& group, mode_t perm,
00356 time_t atime, time_t mtime, time_t ctime);
00357 struct WriteDirParams {
00358 const QString *name;
00359 const QString *user;
00360 const QString *group;
00361 mode_t perm;
00362 time_t atime, mtime, ctime;
00363 bool retval;
00364 };
00365 bool writeSymLink_impl(const QString &name, const QString &target,
00366 const QString &user, const QString &group,
00367 mode_t perm, time_t atime, time_t mtime, time_t ctime);
00368 struct WriteSymlinkParams {
00369 const QString *name;
00370 const QString *target;
00371 const QString *user;
00372 const QString *group;
00373 mode_t perm;
00374 time_t atime, mtime, ctime;
00375 bool retval;
00376 };
00377 bool writeData_impl( const char* data, uint size );
00378 struct WriteDataParams {
00379 const char* data;
00380 uint size;
00381 bool retval;
00382 };
00383 private:
00384 class KArchivePrivate;
00385 KArchivePrivate * d;
00386 };
00387
00395 class KIO_EXPORT KArchiveEntry
00396 {
00397 public:
00408 KArchiveEntry( KArchive* archive, const QString& name, int access, int date,
00409 const QString& user, const QString& group,
00410 const QString &symlink );
00411
00412 virtual ~KArchiveEntry() { }
00413
00418 QDateTime datetime() const;
00419
00424 int date() const { return m_date; }
00425
00430 QString name() const { return m_name; }
00436 mode_t permissions() const { return m_access; }
00441 QString user() const { return m_user; }
00446 QString group() const { return m_group; }
00447
00452 QString symlink() const { return m_symlink; }
00453
00458 virtual bool isFile() const { return false; }
00459
00464 virtual bool isDirectory() const { return false; }
00465
00466 protected:
00467 KArchive* archive() const { return m_archive; }
00468
00469 private:
00470 QString m_name;
00471 int m_date;
00472 mode_t m_access;
00473 QString m_user;
00474 QString m_group;
00475 QString m_symlink;
00476 KArchive* m_archive;
00477 protected:
00478 virtual void virtual_hook( int id, void* data );
00479 private:
00480 class KArchiveEntryPrivate* d;
00481 };
00482
00490 class KIO_EXPORT KArchiveFile : public KArchiveEntry
00491 {
00492 public:
00505 KArchiveFile( KArchive* archive, const QString& name, int access, int date,
00506 const QString& user, const QString& group, const QString &symlink,
00507 int pos, int size );
00508
00509 virtual ~KArchiveFile() { }
00510
00515 int position() const;
00520 int size() const;
00525 void setSize( int s ) { m_size = s; }
00526
00532 virtual QByteArray data() const;
00533
00542 QIODevice *device() const;
00543
00548 virtual bool isFile() const { return true; }
00549
00555 void copyTo(const QString& dest) const;
00556
00557 private:
00558 int m_pos;
00559 int m_size;
00560 protected:
00561 virtual void virtual_hook( int id, void* data );
00562 private:
00563 class KArchiveFilePrivate* d;
00564 };
00565
00573 class KIO_EXPORT KArchiveDirectory : public KArchiveEntry
00574 {
00575 public:
00586 KArchiveDirectory( KArchive* archive, const QString& name, int access, int date,
00587 const QString& user, const QString& group,
00588 const QString& symlink);
00589
00590 virtual ~KArchiveDirectory() { }
00591
00596 QStringList entries() const;
00602 KArchiveEntry* entry( QString name );
00608 const KArchiveEntry* entry( QString name ) const;
00609
00614 void addEntry( KArchiveEntry* );
00615
00620 virtual bool isDirectory() const { return true; }
00621
00629 void copyTo(const QString& dest, bool recursive = true) const;
00630
00631 private:
00632 QDict<KArchiveEntry> m_entries;
00633 protected:
00634 virtual void virtual_hook( int id, void* data );
00635 private:
00636 class KArchiveDirectoryPrivate* d;
00637 };
00638
00639 #endif