lib

KoStore Class Reference

#include <KoStore.h>

Inheritance diagram for KoStore:

KoStoreBase KoDirectoryStore KoTarStore KoZipStore List of all members.

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 40 of file KoStore.h.


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 ()
QIODevice * device () const
QByteArray read (unsigned long 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
QString currentDirectory () const
void pushDirectory ()
void popDirectory ()
bool hasFile (const QString &fileName) const
bool addLocalFile (const QString &fileName, const QString &destName)
QStringList addLocalDirectory (const QString &dirPath, const QString &dest)
bool extractFile (const QString &srcName, const QString &fileName)
void disallowNameExpansion (void)
bool at (QIODevice::Offset pos)
QIODevice::Offset at () const
bool atEnd () const

Static Public Member Functions

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

Protected Member Functions

 KoStore ()
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) const =0

Protected Attributes

Mode m_mode
QStringList m_strFiles
QStringList m_currentPath
QValueStack< QString > m_directoryStack
QString m_sName
QIODevice::Offset m_iSize
QIODevice * m_stream
bool m_bIsOpen
bool m_bGood

Static Protected Attributes

static const int s_area = 30002

Constructor & Destructor Documentation

KoStore::~KoStore  )  [virtual]
 

Destroys the store (i.e.

closes the file on the hard disk)

Definition at line 184 of file KoStore.cpp.


Member Function Documentation

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 492 of file KoStore.cpp.

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 430 of file KoStore.cpp.

bool KoStore::at QIODevice::Offset  pos  ) 
 

See QIODevice.

Definition at line 527 of file KoStore.cpp.

bool KoStore::bad  )  const [inline]
 

Returns:
true if an error occurred

Definition at line 159 of file KoStore.h.

bool KoStore::close  ) 
 

Close the file inside the store.

Returns:
true on success.

Definition at line 243 of file KoStore.cpp.

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

Returns:
true on success

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

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

Returns:
true on success

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

KoStore * KoStore::createStore QWidget *  window,
const KURL &  url,
Mode  mode,
const QCString &  appIdentification = "",
Backend  backend = Auto
[static]
 

Open a store (i.e.

the representation on disk of a KOffice document).

Parameters:
window associated window (for the progress bar dialog and authentification)
url URL 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.
If the file is remote, the backend Directory cannot be used!

Since:
1.4
Bug:
saving not completely implemented (fixed temporary file)

Definition at line 121 of file KoStore.cpp.

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

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

.. KoStore will take care of opening the QIODevice. This method doesn't support the Directory store!

Definition at line 93 of file KoStore.cpp.

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 59 of file KoStore.cpp.

QString KoStore::currentDirectory  )  const
 

Returns the current directory.

Note: Returns a path in "internal name" style

Definition at line 401 of file KoStore.cpp.

QString KoStore::currentPath  )  const
 

Returns the current path including a trailing slash.

Note: Returns a path in "internal name" style

Definition at line 406 of file KoStore.cpp.

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 262 of file KoStore.cpp.

void KoStore::disallowNameExpansion void   ) 
 

Do not expand file and directory names Useful when using KoStore on non-KOffice files.

(This method should be called just after the constructor)

Definition at line 621 of file KoStore.cpp.

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

Enter a directory where we've been before.

It is guaranteed to always exist.

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

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 375 of file KoStore.cpp.

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.

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

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 463 of file KoStore.cpp.

virtual bool KoStore::fileExists const QString &  absPath  )  const [protected, pure virtual]
 

Check if a file exists inside the store.

Parameters:
absPath the absolute path inside the store, i.e. not relative to the current directory

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

bool KoStore::hasFile const QString &  fileName  )  const
 

Returns:
true if the given file exists in the current directory, i.e. if open(fileName) will work.

Definition at line 626 of file KoStore.cpp.

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

Init store - called by constructor.

Returns:
true on success

Reimplemented in KoDirectoryStore, and KoTarStore.

Definition at line 172 of file KoStore.cpp.

bool KoStore::isOpen  )  const
 

Check whether a file inside the store is currently opened with open(), ready to be read or written.

Returns:
true if a file is currently opened.

Definition at line 238 of file KoStore.cpp.

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 391 of file KoStore.cpp.

Mode KoStore::mode  )  const [inline]
 

Returns:
the mode used when opening, read or write

Definition at line 164 of file KoStore.h.

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 189 of file KoStore.cpp.

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

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

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

Implemented in KoDirectoryStore, KoTarStore, and KoZipStore.

void KoStore::popDirectory  ) 
 

Restores the previously pushed directory.

No-op if the stack is empty.

Definition at line 423 of file KoStore.cpp.

void KoStore::pushDirectory  ) 
 

Stacks the current directory.

Restore the current path using popDirectory .

Definition at line 418 of file KoStore.cpp.

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 314 of file KoStore.cpp.

QByteArray KoStore::read unsigned long int  max  ) 
 

Read data from the currently opened file.

You can also use the streams for this.

Definition at line 271 of file KoStore.cpp.

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 360 of file KoStore.cpp.

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.

Reimplemented in KoZipStore.

Definition at line 338 of file KoStore.cpp.

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 309 of file KoStore.cpp.


Member Data Documentation

bool KoStore::m_bGood [protected]
 

Must be set by the constructor.

Definition at line 368 of file KoStore.h.

QStringList KoStore::m_currentPath [protected]
 

The "current directory" (path).

Definition at line 353 of file KoStore.h.

QValueStack<QString> KoStore::m_directoryStack [protected]
 

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

Definition at line 356 of file KoStore.h.

QIODevice::Offset KoStore::m_iSize [protected]
 

Current size of the file named m_sName.

Definition at line 361 of file KoStore.h.

QString KoStore::m_sName [protected]
 

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

Definition at line 359 of file KoStore.h.

QIODevice* KoStore::m_stream [protected]
 

The stream for the current read or write operation.

Definition at line 364 of file KoStore.h.

QStringList KoStore::m_strFiles [protected]
 

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

Definition at line 350 of file KoStore.h.


The documentation for this class was generated from the following files:
KDE Home | KDE Accessibility Home | Description of Access Keys