lib Library API Documentation

KoStore Class Reference

Saves and loads KOffice documents using various backends. More...

#include <koStore.h>

List of all members.

Public Types

enum  Mode { Read, Write }
enum  Backend { Auto, Tar, Zip, Directory }

Public Member Functions

virtual ~KoStore ()
bool open (const QString &name)
bool isOpen () const
bool close ()
QIODevicedevice () const
QByteArray read (long unsigned int max)
Q_LONG write (const QByteArray &_data)
Q_LONG read (char *_buffer, Q_ULONG _len)
virtual Q_LONG write (const char *_data, Q_ULONG _len)
QIODevice::Offset size () const
bool bad () const
Mode mode () const
bool enterDirectory (const QString &directory)
bool leaveDirectory ()
QString currentPath () const
void pushDirectory ()
void popDirectory ()
bool addLocalFile (const QString &fileName, const QString &destName)
QStringList addLocalDirectory (const QString &dirPath, const QString &dest)
bool extractFile (const QString &srcName, const QString &fileName)
bool at (QIODevice::Offset pos)
QIODevice::Offset at () const
bool atEnd () const

Static Public Member Functions

KoStorecreateStore (const QString &fileName, Mode mode, const QCString &appIdentification="", Backend backend=Auto)
KoStorecreateStore (QIODevice *device, Mode mode, const QCString &appIdentification="", Backend backend=Auto)

Protected Member Functions

virtual bool init (Mode mode)
virtual bool openWrite (const QString &name)=0
virtual bool openRead (const QString &name)=0
virtual bool closeRead ()=0
virtual bool closeWrite ()=0
virtual bool enterRelativeDirectory (const QString &dirName)=0
virtual bool enterAbsoluteDirectory (const QString &path)=0
virtual bool fileExists (const QString &absPath)=0

Protected Attributes

Mode m_mode
QStringList m_strFiles
QStringList m_currentPath
QValueStack< QStringm_directoryStack
QString m_sName
QIODevice::Offset m_iSize
QIODevicem_stream
bool m_bIsOpen
bool m_bGood

Static Protected Attributes

const int s_area = 30002


Detailed Description

Saves and loads KOffice documents using various backends.

Currently supported backends are ZIP, tar and directory. We call a "store" the file on the hard disk (the one the users sees) and call a "file" a file inside the store.

Definition at line 35 of file koStore.h.


Constructor & Destructor Documentation

KoStore::~KoStore  )  [virtual]
 

Destroys the store (i.e.

closes the file on the hard disk)

Definition at line 133 of file koStore.cc.

References m_stream.


Member Function Documentation

KoStore * KoStore::createStore const QString fileName,
Mode  mode,
const QCString appIdentification = "",
Backend  backend = Auto
[static]
 

Open a store (i.e.

the representation on disk of a KOffice document).

Parameters:
fileName the name of the file to open
mode if KoStore::Read, open an existing store to read it. if KoStore::Write, create or replace a store.
backend the backend to use for the data storage. Auto means automatically-determined for reading, and the current format (now Zip) for writing.
appIdentification the application's mimetype, to be written in the file for "mime-magic" identification. Only meaningful if mode is Write, and if backend!=Directory.

Definition at line 54 of file koStore.cc.

References createStore().

Referenced by createStore().

KoStore * KoStore::createStore QIODevice device,
Mode  mode,
const QCString appIdentification = "",
Backend  backend = Auto
[static]
 

Create a store for any kind of iodevice: file, memory buffer...

This method doesn't support the Directory store!

Definition at line 88 of file koStore.cc.

References createStore().

bool KoStore::open const QString name  ) 
 

Open a new file inside the store.

Parameters:
name The filename, internal representation ("root", "tar:/0"... ). If the tar:/ prefix is missing it's assumed to be a relative URI.
Returns:
true on success.

Definition at line 138 of file koStore.cc.

References m_iSize, m_sName, m_strFiles, open(), openRead(), and openWrite().

Referenced by addLocalFile(), extractFile(), KoDocument::loadFromStore(), KoDocument::loadNativeFormat(), open(), KoPictureCollection::readFromStore(), KoDocument::saveNativeFormat(), and KoDocument::saveToStore().

bool KoStore::isOpen  )  const
 

Allows to check for an open storage.

Definition at line 187 of file koStore.cc.

bool KoStore::close  ) 
 

Close the file inside the store.

Returns:
true on success.

Definition at line 192 of file koStore.cc.

References closeRead(), closeWrite(), and m_stream.

Referenced by addLocalFile(), extractFile(), KoDocument::loadFromStore(), KoDocument::loadNativeFormat(), KoPictureCollection::readFromStore(), KoDocument::saveNativeFormat(), and KoDocument::saveToStore().

QIODevice * KoStore::device  )  const
 

Get a device for reading a file from the store directly (slightly faster than read() calls) You need to call open first, and close afterwards.

Definition at line 211 of file koStore.cc.

References m_stream.

Referenced by KoDocument::loadFromStore(), and KoDocument::loadNativeFormat().

QByteArray KoStore::read long unsigned int  max  ) 
 

Read data from the currently opened file.

You can also use the streams for this.

Referenced by extractFile(), and read().

Q_LONG KoStore::write const QByteArray _data  ) 
 

Write data into the currently opened file.

You can also use the streams for this.

Definition at line 258 of file koStore.cc.

References write().

Referenced by addLocalFile(), and write().

Q_LONG KoStore::read char *  _buffer,
Q_ULONG  _len
 

Read data from the currently opened file.

You can also use the streams for this.

Returns:
size of data read, -1 on error

Definition at line 263 of file koStore.cc.

References m_iSize, m_stream, and read().

Q_LONG KoStore::write const char *  _data,
Q_ULONG  _len
[virtual]
 

Write data into the currently opened file.

You can also use the streams for this.

Definition at line 287 of file koStore.cc.

References m_iSize, m_stream, and write().

QIODevice::Offset KoStore::size  )  const
 

Returns:
the size of the currently opened file, -1 on error. Can be used as an argument for the read methods, for instance

Definition at line 309 of file koStore.cc.

References m_iSize.

Referenced by addLocalFile(), and extractFile().

bool KoStore::bad  )  const [inline]
 

Returns:
true if an error occurred

Definition at line 129 of file koStore.h.

References m_bGood.

Referenced by KoDocument::loadNativeFormat(), and KoDocument::saveNativeFormat().

Mode KoStore::mode  )  const [inline]
 

Returns:
the mode used when opening, read or write

Definition at line 134 of file koStore.h.

Referenced by KoFilterChain::storageFile().

bool KoStore::enterDirectory const QString directory  ) 
 

Enters one or multiple directories.

In Read mode this actually checks whether the specified directories exist and returns false if they don't. In Write mode we don't create the directory, we just use the "current directory" to generate the absolute path if you pass a relative path (one not starting with tar:/) when opening a stream. Note: Operates on internal names

Definition at line 324 of file koStore.cc.

References enterDirectory().

Referenced by enterDirectory(), KoDocument::loadFromStore(), popDirectory(), and KoDocument::saveToStore().

bool KoStore::leaveDirectory  ) 
 

Leaves a directory.

Equivalent to "cd .."

Returns:
true on success, false if we were at the root already to make it possible to "loop to the root"

Definition at line 340 of file koStore.cc.

References currentPath(), enterAbsoluteDirectory(), and m_currentPath.

QString KoStore::currentPath  )  const
 

Returns the current path including a trailing slash.

Note: Returns a path in "internal name" style

Definition at line 350 of file koStore.cc.

References m_currentPath.

Referenced by leaveDirectory(), and pushDirectory().

void KoStore::pushDirectory  ) 
 

Stacks the current directory.

Restore the current path using popDirectory .

Definition at line 362 of file koStore.cc.

References currentPath(), and m_directoryStack.

Referenced by KoDocument::loadFromStore(), and KoDocument::saveToStore().

void KoStore::popDirectory  ) 
 

Restores the previously pushed directory.

No-op if the stack is empty.

Definition at line 367 of file koStore.cc.

References enterAbsoluteDirectory(), enterDirectory(), m_currentPath, and m_directoryStack.

Referenced by KoDocument::loadFromStore(), and KoDocument::saveToStore().

bool KoStore::addLocalFile const QString fileName,
const QString destName
 

Imports a local file into a store.

Parameters:
fileName file on hard disk
destName file in the store

Definition at line 374 of file koStore.cc.

References addLocalFile(), close(), open(), size(), and write().

Referenced by addLocalDirectory(), and addLocalFile().

QStringList KoStore::addLocalDirectory const QString dirPath,
const QString dest
 

Imports a local directory.

Parameters:
dirPath path to the directory on a disk
dest path in the store where the directory should get saved
Returns:
the directory index

Definition at line 436 of file koStore.cc.

References addLocalDirectory(), and addLocalFile().

Referenced by addLocalDirectory().

bool KoStore::extractFile const QString srcName,
const QString fileName
 

Extracts a file out of the store.

Parameters:
srcName file in the store
fileName file on a disk

Definition at line 407 of file koStore.cc.

References close(), extractFile(), open(), read(), and size().

Referenced by extractFile().

bool KoStore::at QIODevice::Offset  pos  ) 
 

See QIODevice.

Definition at line 471 of file koStore.cc.

References m_stream.

QIODevice::Offset KoStore::at  )  const
 

See QIODevice.

Definition at line 476 of file koStore.cc.

References m_stream.

bool KoStore::atEnd  )  const
 

See QIODevice.

Definition at line 481 of file koStore.cc.

References m_stream.

bool KoStore::init Mode  mode  )  [protected, virtual]
 

Init store - called by constructor.

Returns:
true on success

Definition at line 121 of file koStore.cc.

References init(), and m_stream.

Referenced by init().

virtual bool KoStore::openWrite const QString name  )  [protected, pure virtual]
 

Open the file name in the store, for writing On success, this method must set m_stream to a stream in which we can write.

Parameters:
name "absolute path" (in the archive) to the file to open
Returns:
true on success

Referenced by open().

virtual bool KoStore::openRead const QString name  )  [protected, pure virtual]
 

Open the file name in the store, for reading.

On success, this method must set m_stream to a stream from which we can read, as well as setting m_iSize to the size of the file.

Parameters:
name "absolute path" (in the archive) to the file to open
Returns:
true on success

Referenced by open().

virtual bool KoStore::closeRead  )  [protected, pure virtual]
 

Returns:
true on success

Referenced by close().

virtual bool KoStore::closeWrite  )  [protected, pure virtual]
 

Returns:
true on success

Referenced by close().

virtual bool KoStore::enterRelativeDirectory const QString dirName  )  [protected, pure virtual]
 

Enter a subdirectory of the current directory.

The directory might not exist yet in Write mode.

virtual bool KoStore::enterAbsoluteDirectory const QString path  )  [protected, pure virtual]
 

Enter a directory where we've been before.

It is guaranteed to always exist.

Referenced by leaveDirectory(), and popDirectory().


Member Data Documentation

QStringList KoStore::m_strFiles [protected]
 

Store the filenames (with full path inside the archive) when writing, to avoid duplicates.

Definition at line 296 of file koStore.h.

Referenced by open().

QStringList KoStore::m_currentPath [protected]
 

The "current directory" (path).

Definition at line 299 of file koStore.h.

Referenced by currentPath(), leaveDirectory(), and popDirectory().

QValueStack<QString> KoStore::m_directoryStack [protected]
 

Used to push/pop directories to make it easy to save/restore the state.

Definition at line 302 of file koStore.h.

Referenced by popDirectory(), and pushDirectory().

QString KoStore::m_sName [protected]
 

Current filename (between an open() and a close()).

Definition at line 305 of file koStore.h.

Referenced by open().

QIODevice::Offset KoStore::m_iSize [protected]
 

Current size of the file named m_sName.

Definition at line 307 of file koStore.h.

Referenced by open(), read(), size(), and write().

QIODevice* KoStore::m_stream [protected]
 

The stream for the current read or write operation.

Definition at line 310 of file koStore.h.

Referenced by at(), atEnd(), close(), device(), init(), read(), write(), and ~KoStore().

bool KoStore::m_bGood [protected]
 

Must be set by the constructor.

Definition at line 314 of file koStore.h.

Referenced by bad().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 24 18:22:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003