Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDirectoryStore Class Reference

#include <KoDirectoryStore.h>

+ Inheritance diagram for KoDirectoryStore:

Public Member Functions

 KoDirectoryStore (const QString &path, Mode _mode, bool writeMimetype)
 
 ~KoDirectoryStore () override
 
- Public Member Functions inherited from KoStore
bool atEnd () const
 
bool bad () const
 
bool close ()
 
QString currentPath () const
 
QIODevice * device () const
 
virtual QStringList directoryList () const
 
virtual bool enterDirectory (const QString &directory)
 
bool extractFile (const QString &sourceName, QByteArray &data)
 
bool finalize ()
 
bool hasDirectory (const QString &directoryName)
 
bool hasFile (const QString &fileName) const
 
bool isOpen () const
 
bool leaveDirectory ()
 
Mode mode () const
 
bool open (const QString &name)
 
void popDirectory ()
 
qint64 pos () const
 
void pushDirectory ()
 
qint64 read (char *buffer, qint64 length)
 
QByteArray read (qint64 max)
 
bool seek (qint64 pos)
 See QIODevice.
 
virtual void setCompressionEnabled (bool e)
 
void setSubstitution (const QString &name, const QString &substitution)
 When reading, in the paths in the store where name occurs, substitution is used.
 
qint64 size () const
 
virtual qint64 write (const char *data, qint64 length)
 
qint64 write (const QByteArray &data)
 
virtual ~KoStore ()
 

Protected Member Functions

bool closeRead () override
 
bool closeWrite () override
 
bool enterAbsoluteDirectory (const QString &path) override
 
bool enterRelativeDirectory (const QString &dirName) override
 
bool fileExists (const QString &absPath) const override
 
void init ()
 
bool openRead (const QString &name) override
 
bool openReadOrWrite (const QString &name, QIODevice::OpenModeFlag ioMode)
 
bool openWrite (const QString &name) override
 
- Protected Member Functions inherited from KoStore
virtual bool doFinalize ()
 
 KoStore (Mode mode, bool writeMimetype=true)
 

Private Attributes

QString m_basePath
 
QString m_currentPath
 
QFile * m_file
 

Additional Inherited Members

- Public Types inherited from KoStore
enum  Backend { Auto , Zip , Directory }
 
enum  Mode { Read , Write }
 
- Static Public Member Functions inherited from KoStore
static KoStorecreateStore (const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
 
static KoStorecreateStore (QIODevice *device, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
 
- Protected Attributes inherited from KoStore
KoStorePrivated_ptr
 

Detailed Description

Definition at line 14 of file KoDirectoryStore.h.

Constructor & Destructor Documentation

◆ KoDirectoryStore()

KoDirectoryStore::KoDirectoryStore ( const QString & path,
Mode _mode,
bool writeMimetype )

Definition at line 16 of file KoDirectoryStore.cpp.

17 : KoStore(mode, writeMimetype)
18 , m_basePath(path)
19{
20 //debugStore << "path:" << path
21
22
23 //debugStore << "base path:" << m_basePath;
24
25 init();
26}
Mode mode() const
Definition KoStore.cpp:420
KoStore(Mode mode, bool writeMimetype=true)
Definition KoStore.cpp:98

References init().

◆ ~KoDirectoryStore()

KoDirectoryStore::~KoDirectoryStore ( )
override

Definition at line 28 of file KoDirectoryStore.cpp.

29{
30}

Member Function Documentation

◆ closeRead()

bool KoDirectoryStore::closeRead ( )
inlineoverrideprotectedvirtual
Returns
true on success

Implements KoStore.

Definition at line 27 of file KoDirectoryStore.h.

27 {
28 return true;
29 }

◆ closeWrite()

bool KoDirectoryStore::closeWrite ( )
inlineoverrideprotectedvirtual
Returns
true on success

Implements KoStore.

Definition at line 30 of file KoDirectoryStore.h.

30 {
31 return true;
32 }

◆ enterAbsoluteDirectory()

bool KoDirectoryStore::enterAbsoluteDirectory ( const QString & path)
overrideprotectedvirtual

Enter a directory where we've been before. It is guaranteed to always exist.

Implements KoStore.

Definition at line 95 of file KoDirectoryStore.cpp.

96{
98 //debugStore <<"KoDirectoryStore::enterAbsoluteDirectory" << m_currentPath;
99 QDir newDir(m_currentPath);
100 Q_ASSERT(newDir.exists()); // We've been there before, therefore it must exist.
101 return newDir.exists();
102}

References m_basePath, and m_currentPath.

◆ enterRelativeDirectory()

bool KoDirectoryStore::enterRelativeDirectory ( const QString & dirName)
overrideprotectedvirtual

Enter a subdirectory of the current directory. The directory might not exist yet in Write mode.

Implements KoStore.

Definition at line 77 of file KoDirectoryStore.cpp.

78{
79 QDir origDir(m_currentPath);
80 m_currentPath += dirName;
81 if (!m_currentPath.endsWith('/'))
82 m_currentPath += '/';
83 //debugStore <<"KoDirectoryStore::enterRelativeDirectory m_currentPath now" << m_currentPath;
84 QDir newDir(m_currentPath);
85 if (newDir.exists())
86 return true;
87 // Dir doesn't exist. If reading -> error. If writing -> create.
88 if (mode() == Write && origDir.mkdir(dirName)) {
89 debugStore << "Created" << dirName << " under" << origDir.absolutePath();
90 return true;
91 }
92 return false;
93}
#define debugStore
Definition StoreDebug.h:15
@ Write
Definition KoStore.h:29

References debugStore, m_currentPath, KoStore::mode(), and KoStore::Write.

◆ fileExists()

bool KoDirectoryStore::fileExists ( const QString & absPath) const
overrideprotectedvirtual

Check if a file exists inside the store.

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

Implements KoStore.

Definition at line 104 of file KoDirectoryStore.cpp.

105{
106 debugStore << "KoDirectoryStore::fileExists" << m_basePath + absPath;
107 return QFile::exists(m_basePath + absPath);
108}

References debugStore, and m_basePath.

◆ init()

void KoDirectoryStore::init ( )
protected

Definition at line 32 of file KoDirectoryStore.cpp.

33{
34 Q_D(KoStore);
35
36 if (!m_basePath.endsWith('/'))
37 m_basePath += '/';
39
40 QDir dir(m_basePath);
41 if (dir.exists()) {
42 d->good = true;
43 return;
44 }
45 // Dir doesn't exist. If reading -> error. If writing -> create.
46 if (d->mode == Write && dir.mkpath(m_basePath)) {
47 debugStore << "KoDirectoryStore::init Directory created:" << m_basePath;
48 d->good = true;
49 }
50}

References debugStore, m_basePath, m_currentPath, and KoStore::Write.

◆ openRead()

bool KoDirectoryStore::openRead ( const QString & name)
inlineoverrideprotectedvirtual

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

Implements KoStore.

Definition at line 24 of file KoDirectoryStore.h.

24 {
25 return openReadOrWrite(name, QIODevice::ReadOnly);
26 }
bool openReadOrWrite(const QString &name, QIODevice::OpenModeFlag ioMode)

References openReadOrWrite().

◆ openReadOrWrite()

bool KoDirectoryStore::openReadOrWrite ( const QString & name,
QIODevice::OpenModeFlag ioMode )
protected

Definition at line 52 of file KoDirectoryStore.cpp.

53{
54 Q_D(KoStore);
55 //debugStore <<"KoDirectoryStore::openReadOrWrite m_currentPath=" << m_currentPath <<" name=" << name;
56 int pos = name.lastIndexOf('/');
57 if (pos != -1) { // there are subdirs in the name -> maybe need to create them, when writing
58 pushDirectory(); // remember where we were
59 enterAbsoluteDirectory(QString());
60 //debugStore <<"KoDirectoryStore::openReadOrWrite entering" << name.left(pos);
61 bool ret = enterDirectory(name.left(pos));
63 if (!ret)
64 return false;
65 }
66 d->stream = new QFile(m_basePath + name);
67 if (!d->stream->open(iomode)) {
68 delete d->stream;
69 d->stream = 0;
70 return false;
71 }
72 if (iomode == QIODevice::ReadOnly)
73 d->size = d->stream->size();
74 return true;
75}
bool enterAbsoluteDirectory(const QString &path) override
void pushDirectory()
Definition KoStore.cpp:294
void popDirectory()
Definition KoStore.cpp:300
virtual bool enterDirectory(const QString &directory)
Definition KoStore.cpp:253
qint64 pos() const
Definition KoStore.cpp:347
const char * name(StandardAction id)

References enterAbsoluteDirectory(), KoStore::enterDirectory(), m_basePath, KoStore::popDirectory(), KoStore::pos(), and KoStore::pushDirectory().

◆ openWrite()

bool KoDirectoryStore::openWrite ( const QString & name)
inlineoverrideprotectedvirtual

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

Implements KoStore.

Definition at line 21 of file KoDirectoryStore.h.

21 {
22 return openReadOrWrite(name, QIODevice::WriteOnly);
23 }

References openReadOrWrite().

Member Data Documentation

◆ m_basePath

QString KoDirectoryStore::m_basePath
private

Definition at line 40 of file KoDirectoryStore.h.

◆ m_currentPath

QString KoDirectoryStore::m_currentPath
private

Definition at line 43 of file KoDirectoryStore.h.

◆ m_file

QFile* KoDirectoryStore::m_file
private

Definition at line 46 of file KoDirectoryStore.h.


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