lib

#include <KoStore.h>

Inheritance diagram for KoStore:
KoStoreBase

Public Types

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

Public Member Functions

virtual ~KoStore ()
 
bool open (const TQString &name)
 
bool isOpen () const
 
bool close ()
 
TQIODevice * device () const
 
TQByteArray read (unsigned long int max)
 
TQ_LONG write (const TQByteArray &_data)
 
TQ_LONG read (char *_buffer, TQ_ULONG _len)
 
virtual TQ_LONG write (const char *_data, TQ_ULONG _len)
 
TQIODevice::Offset size () const
 
bool bad () const
 
Mode mode () const
 
bool enterDirectory (const TQString &directory)
 
bool leaveDirectory ()
 
TQString currentPath () const
 
TQString currentDirectory () const
 
void pushDirectory ()
 
void popDirectory ()
 
bool hasFile (const TQString &fileName) const
 
bool addLocalFile (const TQString &fileName, const TQString &destName)
 
TQStringList addLocalDirectory (const TQString &dirPath, const TQString &dest)
 
bool extractFile (const TQString &srcName, const TQString &fileName)
 
bool at (TQIODevice::Offset pos)
 
TQIODevice::Offset at () const
 
bool atEnd () const
 
void disallowNameExpansion (void)
 

Static Public Member Functions

static KoStore * createStore (const TQString &fileName, Mode mode, const TQCString &appIdentification="", Backend backend=Auto)
 
static KoStore * createStore (TQIODevice *device, Mode mode, const TQCString &appIdentification="", Backend backend=Auto)
 
static KoStore * createStore (TQWidget *window, const KURL &url, Mode mode, const TQCString &appIdentification="", Backend backend=Auto)
 

Protected Member Functions

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

Protected Attributes

Mode m_mode
 
TQStringList m_strFiles
 
TQStringList m_currentPath
 
TQValueStack< TQString > m_directoryStack
 
TQString m_sName
 
TQIODevice::Offset m_iSize
 
TQIODevice * m_stream
 
bool m_bIsOpen
 
bool m_bGood
 

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

Member Enumeration Documentation

◆ Backend

enum KoStore::Backend

Definition at line 44 of file KoStore.h.

◆ Mode

enum KoStore::Mode

Definition at line 43 of file KoStore.h.

Constructor & Destructor Documentation

◆ ~KoStore()

KoStore::~KoStore ( )
virtual

Destroys the store (i.e.

closes the file on the hard disk)

Definition at line 183 of file KoStore.cpp.

◆ KoStore()

KoStore::KoStore ( )
inlineprotected

Definition at line 253 of file KoStore.h.

Member Function Documentation

◆ addLocalDirectory()

TQStringList KoStore::addLocalDirectory ( const TQString &  dirPath,
const TQString &  dest 
)

Imports a local directory.

Parameters
dirPathpath to the directory on a disk
destpath in the store where the directory should get saved
Returns
the directory index

Definition at line 491 of file KoStore.cpp.

◆ addLocalFile()

bool KoStore::addLocalFile ( const TQString &  fileName,
const TQString &  destName 
)

Imports a local file into a store.

Parameters
fileNamefile on hard disk
destNamefile in the store

Definition at line 429 of file KoStore.cpp.

◆ at() [1/2]

TQIODevice::Offset KoStore::at ( ) const

Definition at line 531 of file KoStore.cpp.

◆ at() [2/2]

bool KoStore::at ( TQIODevice::Offset  pos)

See TQIODevice.

Definition at line 526 of file KoStore.cpp.

◆ atEnd()

bool KoStore::atEnd ( ) const

Definition at line 536 of file KoStore.cpp.

◆ bad()

bool KoStore::bad ( ) const
inline
Returns
true if an error occurred

Definition at line 158 of file KoStore.h.

◆ close()

bool KoStore::close ( )

Close the file inside the store.

Returns
true on success.

Definition at line 242 of file KoStore.cpp.

◆ closeRead()

virtual bool KoStore::closeRead ( )
protectedpure virtual
Returns
true on success

◆ closeWrite()

virtual bool KoStore::closeWrite ( )
protectedpure virtual
Returns
true on success

◆ createStore() [1/3]

KoStore * KoStore::createStore ( const TQString &  fileName,
Mode  mode,
const TQCString &  appIdentification = "",
Backend  backend = Auto 
)
static

Open a store (i.e.

the representation on disk of a KOffice document).

Parameters
fileNamethe name of the file to open
modeif KoStore::Read, open an existing store to read it. if KoStore::Write, create or replace a store.
backendthe backend to use for the data storage. Auto means automatically-determined for reading, and the current format (now Zip) for writing.
appIdentificationthe 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.

◆ createStore() [2/3]

KoStore * KoStore::createStore ( TQIODevice *  device,
Mode  mode,
const TQCString &  appIdentification = "",
Backend  backend = Auto 
)
static

Create a store for any kind of TQIODevice: file, memory buffer... KoStore will take care of opening the TQIODevice.

This method doesn't support the Directory store!

Definition at line 92 of file KoStore.cpp.

◆ createStore() [3/3]

KoStore * KoStore::createStore ( TQWidget *  window,
const KURL &  url,
Mode  mode,
const TQCString &  appIdentification = "",
Backend  backend = Auto 
)
static

Open a store (i.e.

the representation on disk of a KOffice document).

Parameters
windowassociated window (for the progress bar dialog and authentification)
urlURL of the file to open
modeif KoStore::Read, open an existing store to read it. if KoStore::Write, create or replace a store.
backendthe backend to use for the data storage. Auto means automatically-determined for reading, and the current format (now Zip) for writing.
appIdentificationthe 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 120 of file KoStore.cpp.

◆ currentDirectory()

TQString KoStore::currentDirectory ( ) const

Returns the current directory.

Note: Returns a path in "internal name" style

Definition at line 400 of file KoStore.cpp.

◆ currentPath()

TQString KoStore::currentPath ( ) const

Returns the current path including a trailing slash.

Note: Returns a path in "internal name" style

Definition at line 405 of file KoStore.cpp.

◆ device()

TQIODevice * 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 261 of file KoStore.cpp.

◆ disallowNameExpansion()

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

◆ enterAbsoluteDirectory()

virtual bool KoStore::enterAbsoluteDirectory ( const TQString &  path)
protectedpure virtual

Enter a directory where we've been before.

It is guaranteed to always exist.

◆ enterDirectory()

bool KoStore::enterDirectory ( const TQString &  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 374 of file KoStore.cpp.

◆ enterRelativeDirectory()

virtual bool KoStore::enterRelativeDirectory ( const TQString &  dirName)
protectedpure virtual

Enter a subdirectory of the current directory.

The directory might not exist yet in Write mode.

◆ extractFile()

bool KoStore::extractFile ( const TQString &  srcName,
const TQString &  fileName 
)

Extracts a file out of the store.

Parameters
srcNamefile in the store
fileNamefile on a disk

Definition at line 462 of file KoStore.cpp.

◆ fileExists()

virtual bool KoStore::fileExists ( const TQString &  absPath) const
protectedpure virtual

Check if a file exists inside the store.

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

◆ hasFile()

bool KoStore::hasFile ( const TQString &  fileName) const
Returns
true if the given file exists in the current directory, i.e. if open(fileName) will work.

Definition at line 625 of file KoStore.cpp.

◆ init()

bool KoStore::init ( Mode  mode)
protectedvirtual

Init store - called by constructor.

Returns
true on success

Definition at line 171 of file KoStore.cpp.

◆ isOpen()

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

◆ leaveDirectory()

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

◆ mode()

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

Definition at line 163 of file KoStore.h.

◆ open()

bool KoStore::open ( const TQString &  name)

Open a new file inside the store.

Parameters
nameThe 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 188 of file KoStore.cpp.

◆ openRead()

virtual bool KoStore::openRead ( const TQString &  name)
protectedpure 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

◆ openWrite()

virtual bool KoStore::openWrite ( const TQString &  name)
protectedpure 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

◆ popDirectory()

void KoStore::popDirectory ( )

Restores the previously pushed directory.

No-op if the stack is empty.

Definition at line 422 of file KoStore.cpp.

◆ pushDirectory()

void KoStore::pushDirectory ( )

Stacks the current directory.

Restore the current path using popDirectory .

Definition at line 417 of file KoStore.cpp.

◆ read() [1/2]

TQ_LONG KoStore::read ( char *  _buffer,
TQ_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 313 of file KoStore.cpp.

◆ read() [2/2]

TQByteArray KoStore::read ( unsigned long int  max)

Read data from the currently opened file.

You can also use the streams for this.

Definition at line 270 of file KoStore.cpp.

◆ size()

TQIODevice::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 359 of file KoStore.cpp.

◆ write() [1/2]

TQ_LONG KoStore::write ( const char *  _data,
TQ_ULONG  _len 
)
virtual

Write data into the currently opened file.

You can also use the streams for this.

Definition at line 337 of file KoStore.cpp.

◆ write() [2/2]

TQ_LONG KoStore::write ( const TQByteArray &  _data)

Write data into the currently opened file.

You can also use the streams for this.

Definition at line 308 of file KoStore.cpp.

Member Data Documentation

◆ m_bGood

bool KoStore::m_bGood
protected

Must be set by the constructor.

Definition at line 367 of file KoStore.h.

◆ m_bIsOpen

bool KoStore::m_bIsOpen
protected

Definition at line 365 of file KoStore.h.

◆ m_currentPath

TQStringList KoStore::m_currentPath
protected

The "current directory" (path)

Definition at line 352 of file KoStore.h.

◆ m_directoryStack

TQValueStack<TQString> KoStore::m_directoryStack
protected

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

Definition at line 355 of file KoStore.h.

◆ m_iSize

TQIODevice::Offset KoStore::m_iSize
protected

Current size of the file named m_sName.

Definition at line 360 of file KoStore.h.

◆ m_mode

Mode KoStore::m_mode
protected

Definition at line 346 of file KoStore.h.

◆ m_sName

TQString KoStore::m_sName
protected

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

Definition at line 358 of file KoStore.h.

◆ m_stream

TQIODevice* KoStore::m_stream
protected

The stream for the current read or write operation.

Definition at line 363 of file KoStore.h.

◆ m_strFiles

TQStringList KoStore::m_strFiles
protected

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

Definition at line 349 of file KoStore.h.

◆ s_area

const int KoStore::s_area = 30002
staticprotected

Definition at line 369 of file KoStore.h.


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