karchive.h
/* This file is part of the KDE libraries
Copyright (C) 2000 David Faure <faure@kde.org>
Copyright (C) 2003 Leo Savernik <l.savernik@aon.at>
Moved from ktar.h by Roberto Teixeira <maragato@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __karchive_h
#define __karchive_h
#include <sys/stat.h>
#include <sys/types.h>
#include <qdatetime.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qdict.h>
#include <kdelibs_export.h>
class KArchiveDirectory;
class KArchiveFile;
class KIO_EXPORT KArchive
{
protected:
KArchive( QIODevice * dev );
public:
virtual ~KArchive();
virtual bool open( int mode );
virtual void close();
// TODO KDE4 merge with above
bool closeSucceeded() const;
bool isOpened() const { return m_open; }
int mode() const { return m_mode; }
QIODevice * device() const { return m_dev; }
const KArchiveDirectory* directory() const;
bool addLocalFile( const QString& fileName, const QString& destName );
bool addLocalDirectory( const QString& path, const QString& destName );
virtual bool writeDir( const QString& name, const QString& user, const QString& group ) = 0;
bool writeDir( const QString& name, const QString& user, const QString& group,
mode_t perm, time_t atime, time_t mtime, time_t ctime );
bool writeSymLink(const QString &name, const QString &target,
const QString &user, const QString &group,
mode_t perm, time_t atime, time_t mtime, time_t ctime);
virtual bool writeFile( const QString& name, const QString& user, const QString& group, uint size, const char* data );
bool writeFile( const QString& name, const QString& user, const QString& group,
uint size, mode_t perm, time_t atime, time_t mtime,
time_t ctime, const char* data );
virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size ) = 0;
bool prepareWriting( const QString& name, const QString& user,
const QString& group, uint size, mode_t perm,
time_t atime, time_t mtime, time_t ctime );
bool writeData( const char* data, uint size );
virtual bool doneWriting( uint size ) = 0;
protected:
virtual bool openArchive( int mode ) = 0;
virtual bool closeArchive() = 0;
virtual KArchiveDirectory* rootDir();
KArchiveDirectory * findOrCreate( const QString & path );
void setDevice( QIODevice *dev );
void setRootDir( KArchiveDirectory *rootDir );
private:
QIODevice * m_dev;
bool m_open;
char m_mode;
protected:
virtual void virtual_hook( int id, void* data );
/* @internal for virtual_hook */
enum { VIRTUAL_WRITE_DATA = 1, VIRTUAL_WRITE_SYMLINK, VIRTUAL_WRITE_DIR,
VIRTUAL_WRITE_FILE, VIRTUAL_PREPARE_WRITING };
bool prepareWriting_impl( const QString& name, const QString& user,
const QString& group, uint size, mode_t perm,
time_t atime, time_t mtime, time_t ctime );
struct PrepareWritingParams {
const QString *name;
const QString *user;
const QString *group;
uint size;
mode_t perm;
time_t atime, mtime, ctime;
bool retval;
};
bool writeFile_impl( const QString& name, const QString& user,
const QString& group, uint size, mode_t perm,
time_t atime, time_t mtime, time_t ctime,
const char* data );
struct WriteFileParams {
const QString *name;
const QString *user;
const QString *group;
uint size;
mode_t perm;
time_t atime, mtime, ctime;
const char *data;
bool retval;
};
bool writeDir_impl(const QString& name, const QString& user,
const QString& group, mode_t perm,
time_t atime, time_t mtime, time_t ctime);
struct WriteDirParams {
const QString *name;
const QString *user;
const QString *group;
mode_t perm;
time_t atime, mtime, ctime;
bool retval;
};
bool writeSymLink_impl(const QString &name, const QString &target,
const QString &user, const QString &group,
mode_t perm, time_t atime, time_t mtime, time_t ctime);
struct WriteSymlinkParams {
const QString *name;
const QString *target;
const QString *user;
const QString *group;
mode_t perm;
time_t atime, mtime, ctime;
bool retval;
};
bool writeData_impl( const char* data, uint size );
struct WriteDataParams {
const char* data;
uint size;
bool retval;
};
private:
class KArchivePrivate;
KArchivePrivate * d;
};
class KIO_EXPORT KArchiveEntry
{
public:
KArchiveEntry( KArchive* archive, const QString& name, int access, int date,
const QString& user, const QString& group,
const QString &symlink );
virtual ~KArchiveEntry() { }
QDateTime datetime() const;
int date() const { return m_date; }
QString name() const { return m_name; }
mode_t permissions() const { return m_access; }
QString user() const { return m_user; }
QString group() const { return m_group; }
QString symlink() const { return m_symlink; }
virtual bool isFile() const { return false; }
virtual bool isDirectory() const { return false; }
protected:
KArchive* archive() const { return m_archive; }
private:
QString m_name;
int m_date;
mode_t m_access;
QString m_user;
QString m_group;
QString m_symlink;
KArchive* m_archive;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KArchiveEntryPrivate* d;
};
class KIO_EXPORT KArchiveFile : public KArchiveEntry
{
public:
KArchiveFile( KArchive* archive, const QString& name, int access, int date,
const QString& user, const QString& group, const QString &symlink,
int pos, int size );
virtual ~KArchiveFile() { }
int position() const; // TODO use Q_LONG in KDE-4.0
int size() const; // TODO use Q_LONG in KDE-4.0
void setSize( int s ) { m_size = s; }
virtual QByteArray data() const;
QIODevice *device() const; // TODO make virtual
virtual bool isFile() const { return true; }
void copyTo(const QString& dest) const;
private:
int m_pos; // TODO use Q_LONG in KDE-4.0
int m_size; // TODO use Q_LONG in KDE-4.0
protected:
virtual void virtual_hook( int id, void* data );
private:
class KArchiveFilePrivate* d;
};
class KIO_EXPORT KArchiveDirectory : public KArchiveEntry
{
public:
KArchiveDirectory( KArchive* archive, const QString& name, int access, int date,
const QString& user, const QString& group,
const QString& symlink);
virtual ~KArchiveDirectory() { }
QStringList entries() const;
KArchiveEntry* entry( QString name );
const KArchiveEntry* entry( QString name ) const;
void addEntry( KArchiveEntry* );
virtual bool isDirectory() const { return true; }
void copyTo(const QString& dest, bool recursive = true) const;
private:
QDict<KArchiveEntry> m_entries;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KArchiveDirectoryPrivate* d;
};
#endif
KArchive
KArchive is a base class for reading and writing archives.
Definition: karchive.h:42
KArchiveFile::isFile
virtual bool isFile() const
Checks whether this entry is a file.
Definition: karchive.h:548
KArchiveEntry::group
QString group() const
Group of the user who created the file.
Definition: karchive.h:446
KArchiveEntry::symlink
QString symlink() const
Symlink if there is one.
Definition: karchive.h:452
KArchiveEntry
A base class for entries in an KArchive.
Definition: karchive.h:395
KArchiveEntry::user
QString user() const
User who created the file.
Definition: karchive.h:441
KArchive::mode
int mode() const
Returns the mode in which the archive was opened.
Definition: karchive.h:90
KArchiveDirectory::isDirectory
virtual bool isDirectory() const
Checks whether this entry is a directory.
Definition: karchive.h:620
KArchive::device
QIODevice * device() const
The underlying device.
Definition: karchive.h:96
KArchiveDirectory
Represents a directory entry in a KArchive.
Definition: karchive.h:573
KArchiveEntry::date
int date() const
Creation date of the file.
Definition: karchive.h:424
KArchive::isOpened
bool isOpened() const
Checks whether the archive is open.
Definition: karchive.h:83
KArchiveFile
Represents a file entry in a KArchive.
Definition: karchive.h:490
KArchiveEntry::name
QString name() const
Name of the file without path.
Definition: karchive.h:430
KArchiveEntry::isFile
virtual bool isFile() const
Checks whether the entry is a file.
Definition: karchive.h:458
KArchiveEntry::permissions
mode_t permissions() const
The permissions and mode flags as returned by the stat() function in st_mode.
Definition: karchive.h:436
KArchiveFile::setSize
void setSize(int s)
Set size of data, usually after writing the file.
Definition: karchive.h:525
KArchiveEntry::isDirectory
virtual bool isDirectory() const
Checks whether the entry is a directory.
Definition: karchive.h:464

KDE Home | KDE Accessibility Home | Description of Access Keys