libs/store

KoStore Class Reference

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

#include <KoStore.h>

Inheritance diagram for KoStore:

List of all members.

Public Types

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

Public Member Functions

virtual ~KoStore ()
bool addDataToFile (QByteArray &buffer, const QString &destName)
QStringList addLocalDirectory (const QString &dirPath, const QString &dest)
bool addLocalFile (const QString &fileName, const QString &destName)
bool bad () const
bool close ()
QString currentDirectory () const
QString currentPath () const
QIODevicedevice () const
void disallowNameExpansion (void)
bool enterDirectory (const QString &directory)
bool extractFile (const QString &srcName, QByteArray &data)
bool extractFile (const QString &srcName, const QString &fileName)
bool finalize ()
bool hasFile (const QString &fileName) const
virtual bool isEncrypted ()
bool isOpen () const
bool leaveDirectory ()
Mode mode () const
bool open (const QString &name)
virtual QString password ()
void popDirectory ()
void pushDirectory ()
qint64 read (char *_buffer, qint64 _len)
QByteArray read (qint64 max)
virtual bool setPassword (const QString &password)
qint64 size () const
virtual qint64 write (const char *_data, qint64 _len)
qint64 write (const QByteArray &_data)



bool atEnd () const
qint64 pos () const
bool seek (qint64 pos)

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

bool m_bFinalized
bool m_bGood
bool m_bIsOpen
QStringList m_currentPath
qint64 m_iSize
Mode m_mode
QString m_sName
QIODevicem_stream
QStringList m_strFiles

Static Protected Attributes

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


Member Enumeration Documentation

Enumerator:
Auto 
Tar 
Zip 
Directory 
Encrypted 

Definition at line 46 of file KoStore.h.

Enumerator:
Read 
Write 

Definition at line 45 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 210 of file KoStore.cpp.

KoStore::KoStore (  )  [protected]

Definition at line 194 of file KoStore.cpp.


Member Function Documentation

bool KoStore::addDataToFile ( QByteArray buffer,
const QString destName 
)

Imports data into a store.

Parameters:
buffer data
destName file in the store

Definition at line 443 of file KoStore.cpp.

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

bool KoStore::atEnd (  )  const

Definition at line 552 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 262 of file KoStore.cpp.

virtual bool KoStore::closeRead (  )  [protected, pure virtual]
Returns:
true on success

Implemented in KoDirectoryStore, KoEncryptedStore, KoTarStore, and KoZipStore.

virtual bool KoStore::closeWrite (  )  [protected, pure virtual]
Returns:
true on success

Implemented in KoDirectoryStore, KoEncryptedStore, KoTarStore, and KoZipStore.

KoStore * KoStore::createStore ( QWidget window,
const KUrl &  url,
Mode  mode,
const QByteArray 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 authentication)
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!

Bug:
saving not completely implemented (fixed temporary file)

Definition at line 139 of file KoStore.cpp.

KoStore * KoStore::createStore ( QIODevice device,
Mode  mode,
const QByteArray 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 101 of file KoStore.cpp.

KoStore * KoStore::createStore ( const QString fileName,
Mode  mode,
const QByteArray 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 58 of file KoStore.cpp.

QString KoStore::currentDirectory (  )  const

Returns the current directory.

Note: Returns a path in "internal name" style

Definition at line 383 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 388 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 280 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 637 of file KoStore.cpp.

virtual bool KoStore::doFinalize (  )  [inline, protected, virtual]

Finalize store - called by finalize.

Returns:
true on success

Reimplemented in KoEncryptedStore, KoTarStore, and KoZipStore.

Definition at line 324 of file KoStore.h.

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, KoEncryptedStore, 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 357 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, KoEncryptedStore, KoTarStore, and KoZipStore.

bool KoStore::extractFile ( const QString srcName,
QByteArray data 
)

Extracts a file out of the store to a buffer.

Parameters:
srcName file in the store
data memory buffer

Definition at line 478 of file KoStore.cpp.

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 471 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, KoEncryptedStore, KoTarStore, and KoZipStore.

bool KoStore::finalize (  ) 

Call this before destroying the store, to be able to catch errors (e.g.

from ksavefile)

Definition at line 647 of file KoStore.cpp.

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

bool KoStore::isEncrypted (  )  [virtual]

Returns whether a store opened for reading is encrypted or a store opened for saving will be encrypted.

Returns:
True if the store is encrypted.

Reimplemented in KoEncryptedStore.

Definition at line 654 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 257 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 373 of file KoStore.cpp.

Mode KoStore::mode (  )  const [inline]
Returns:
the mode used when opening, read or write

Definition at line 166 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 215 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, KoEncryptedStore, 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, KoEncryptedStore, KoTarStore, and KoZipStore.

QString KoStore::password (  )  [virtual]

Retrieves the password used to encrypt or decrypt the store.

Note that QString() will returned if no password has been given or the store is not encrypted.

Returns:
The password this store is encrypted with.

Reimplemented in KoEncryptedStore.

Definition at line 664 of file KoStore.cpp.

void KoStore::popDirectory (  ) 

Restores the previously pushed directory.

No-op if the stack is empty.

Definition at line 405 of file KoStore.cpp.

qint64 KoStore::pos (  )  const

Definition at line 547 of file KoStore.cpp.

void KoStore::pushDirectory (  ) 

Stacks the current directory.

Restore the current path using popDirectory .

Definition at line 400 of file KoStore.cpp.

qint64 KoStore::read ( char *  _buffer,
qint64  _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 310 of file KoStore.cpp.

QByteArray KoStore::read ( qint64  max  ) 

Read data from the currently opened file.

You can also use the streams for this.

Definition at line 289 of file KoStore.cpp.

bool KoStore::seek ( qint64  pos  ) 

See QIODevice.

Definition at line 542 of file KoStore.cpp.

bool KoStore::setPassword ( const QString password  )  [virtual]

Sets the password to be used for decryption or encryption of the store.

Use of this function is optional: an encryptable store should make a best effort in obtaining a password if it wasn't supplied.

This method only works before opening a file. It might fail when a file has already been opened before calling this method.

This method will not function for any store that is not encrypted or can't be encrypted when saving.

Parameters:
password A non-empty password.
Returns:
True if the password was set.

Reimplemented in KoEncryptedStore.

Definition at line 659 of file KoStore.cpp.

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

qint64 KoStore::write ( const char *  _data,
qint64  _len 
) [virtual]

Write data into the currently opened file.

You can also use the streams for this.

Reimplemented in KoZipStore.

Definition at line 324 of file KoStore.cpp.

qint64 KoStore::write ( const QByteArray _data  ) 

Write data into the currently opened file.

You can also use the streams for this.

Definition at line 305 of file KoStore.cpp.


Member Data Documentation

bool KoStore::m_bFinalized [protected]

Definition at line 434 of file KoStore.h.

bool KoStore::m_bGood [protected]

Must be set by the constructor.

Definition at line 433 of file KoStore.h.

bool KoStore::m_bIsOpen [protected]

Definition at line 431 of file KoStore.h.

The "current directory" (path).

Definition at line 421 of file KoStore.h.

qint64 KoStore::m_iSize [protected]

Current size of the file named m_sName.

Definition at line 426 of file KoStore.h.

Mode KoStore::m_mode [protected]

Definition at line 415 of file KoStore.h.

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

Definition at line 424 of file KoStore.h.

The stream for the current read or write operation.

Definition at line 429 of file KoStore.h.

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

Definition at line 418 of file KoStore.h.

const int KoStore::s_area = 30002 [static, protected]

Definition at line 436 of file KoStore.h.


The documentation for this class was generated from the following files: