diff --git a/libs/odf/KoEncryptionChecker.cpp b/libs/odf/KoEncryptionChecker.cpp deleted file mode 100644 index 6900976ef4..0000000000 --- a/libs/odf/KoEncryptionChecker.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2009 Boudewijn Rempt - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "KoEncryptionChecker.h" - -#ifdef QCA2 - -// QCA headers have "slots" and "signals", which QT_NO_SIGNALS_SLOTS_KEYWORDS does not like -#define slots Q_SLOTS -#define signals Q_SIGNALS -#include -#undef slots -#undef signals -#include - -bool KoEncryptionChecker::isEncryptionSupported() -{ - QCA::Initializer* initializer = new QCA::Initializer(); - bool supported = QCA::isSupported("sha1") && QCA::isSupported("pbkdf2(sha1)") && QCA::isSupported("blowfish-cfb"); - if (!supported) { - warnOdf << "QCA is enabled but sha1, pbkdf2(sha1) or blowfish-cfb are not supported. Encryption is disabled."; - } - delete initializer; - return supported; -} -#else -bool KoEncryptionChecker::isEncryptionSupported() -{ - - return false; -} -#endif diff --git a/libs/odf/KoEncryptionChecker.h b/libs/odf/KoEncryptionChecker.h deleted file mode 100644 index a31f9bbe44..0000000000 --- a/libs/odf/KoEncryptionChecker.h +++ /dev/null @@ -1,31 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2009 Boudewijn Rempt - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef KO_ENCRYPTION_CHECKER -#define KO_ENCRYPTION_CHECKER - -#include "kritaodf_export.h" - -namespace KoEncryptionChecker -{ - -KRITAODF_EXPORT bool isEncryptionSupported(); - -} - -#endif diff --git a/libs/odf/tests/TestStorage.cpp b/libs/odf/tests/TestStorage.cpp index 5ea955e1f4..13d6faf6cb 100644 --- a/libs/odf/tests/TestStorage.cpp +++ b/libs/odf/tests/TestStorage.cpp @@ -1,257 +1,250 @@ /* This file is part of the KDE project Copyright (C) 2002 Werner Trobin Copyright (C) 2008 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include -#include #include #include #include #include class TestStorage : public QObject { Q_OBJECT private Q_SLOTS: void storage_data(); void storage(); void storage2_data(); void storage2(); private: char getch(QIODevice * dev); }; char TestStorage::getch(QIODevice * dev) { char c = 0; dev->getChar(&c); return c; } void TestStorage::storage_data() { QTest::addColumn("type"); QTest::addColumn("testFile"); QTest::newRow("directory") << (int) KoStore::Directory << "testdir"; QTest::newRow("zip") << (int) KoStore::Zip <<"test.zip"; } void TestStorage::storage() { const char test1[] = "This test checks whether we're able to write to some arbitrary directory.\n"; const char testDir[] = "0"; const char testDirResult[] = "0/"; const char test2[] = "This time we try to append the given relative path to the current dir.\n"; const char test3[] = "Hello World"; const char testDir2[] = "test2/with/a"; const char testDir2Result[] = "0/test2/with/a/"; const char test4[] = "Heureka, it works"; QFETCH(int, type); QFETCH(QString, testFile); KoStore::Backend backend = static_cast(type); if (QFile::exists(testFile)) QFile::remove(testFile); QDir dirTest(testFile); if (dirTest.exists()) { #ifdef Q_OS_UNIX QByteArray ba = QByteArray("rm -rf ") + QFile::encodeName(testFile); Q_UNUSED(system(ba.constData())); // QDir::rmdir isn't recursive! #else QFAIL("build dir not empty"); #endif } KoStore* store = KoStore::createStore(testFile, KoStore::Write, "", backend); QVERIFY(store); QVERIFY(store->bad() == false); - if (store->isEncrypted()) - store->setPassword("password"); - QVERIFY(store->open("test1/with/a/relative/dir.txt")); for (int i = 0; i < 100; ++i) store->write(test1, strlen(test1)); store->close(); store->enterDirectory(testDir); QCOMPARE(store->currentPath(), QString(testDirResult)); QVERIFY(store->open("test2/with/a/relative/dir.txt")); for (int i = 0; i < 100; ++i) store->write(test2, strlen(test2)); store->close(); QVERIFY(store->open("root")); store->write(test3, strlen(test3)); store->close(); store->enterDirectory(testDir2); QCOMPARE(store->currentPath(), QString(testDir2Result)); QVERIFY(store->open("root")); store->write(test4, strlen(test4)); store->close(); if (store->isOpen()) store->close(); delete store; store = KoStore::createStore(testFile, KoStore::Read, "", backend); QVERIFY(store->bad() == false); - if (store->isEncrypted()) - store->setPassword("password"); - QVERIFY (store->open("test1/with/a/relative/dir.txt")); QIODevice* dev = store->device(); int i = 0, lim = strlen(test1), count = 0; while (static_cast(getch(dev)) == test1[i++]) { if (i == lim) { i = 0; ++count; } } store->close(); QCOMPARE(count, 100); store->enterDirectory(testDir); QCOMPARE (store->currentPath(), QString(testDirResult)); QVERIFY (store->open("test2/with/a/relative/dir.txt")); dev = store->device(); i = 0; lim = strlen(test2); count = 0; while (static_cast(getch(dev)) == test2[i++]) { if (i == lim) { i = 0; ++count; } } store->close(); QCOMPARE(count, 100); store->enterDirectory(testDir2); store->pushDirectory(); while (store->leaveDirectory()) { ; } store->enterDirectory(testDir); QCOMPARE (store->currentPath(), QString(testDirResult)); QVERIFY (store->open("root")); QCOMPARE (store->size(), (qint64) 22); dev = store->device(); QByteArray dataReadBack = dev->read(strlen(test3)); store->close(); QCOMPARE (dataReadBack, QByteArray(test3)); store->popDirectory(); QCOMPARE(store->currentPath(), QString(testDir2Result)); QVERIFY (store->hasFile("relative/dir.txt")); QVERIFY (store->open("root")); char buf[29]; store->read(buf, 28); buf[28] = '\0'; store->close(); QVERIFY(strncmp(buf, test4, 28) == 0); if (store->isOpen()) store->close(); delete store; QFile::remove(testFile); } #define DATALEN 64 void TestStorage::storage2_data() { QTest::addColumn("type"); QTest::addColumn("testFile"); QTest::newRow("directory") << (int) KoStore::Directory << "testdir"; QTest::newRow("zip") << (int) KoStore::Zip <<"test.zip"; } void TestStorage::storage2() { QFETCH(int, type); QFETCH(QString, testFile); KoStore::Backend backend = static_cast(type); if (QFile::exists(testFile)) QFile::remove(testFile); QDir dirTest(testFile); if (dirTest.exists()) { #ifdef Q_OS_UNIX QByteArray ba = QByteArray("rm -rf ") + QFile::encodeName(testFile); Q_UNUSED(system(ba.constData())); // QDir::rmdir isn't recursive! #else QFAIL("build dir not empty"); #endif } KoStore* store = KoStore::createStore(testFile, KoStore::Write, "", backend); QVERIFY(store->bad() == false); // Write QVERIFY (store->open("layer")); char str[DATALEN]; sprintf(str, "1,2,3,4\n"); store->write(str, strlen(str)); memset(str, '\0', DATALEN); store->write(str, DATALEN); store->close(); delete store; store = KoStore::createStore(testFile, KoStore::Read, "", backend); QVERIFY(store->bad() == false); // Read back QVERIFY (store->open("layer")); char str2[DATALEN]; QIODevice *stream = store->device(); // << Possible suspect! stream->readLine(str2, DATALEN); // << as is this qint64 len = store->read(str2, DATALEN); QCOMPARE(len, (qint64) DATALEN); store->close(); delete store; QFile::remove(testFile); } QTEST_GUILESS_MAIN(TestStorage) #include diff --git a/libs/store/KoStore.cpp b/libs/store/KoStore.cpp index ecde07531e..7561da0315 100644 --- a/libs/store/KoStore.cpp +++ b/libs/store/KoStore.cpp @@ -1,457 +1,442 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 Torben Weis Copyright (C) 2000-2002 David Faure , Werner Trobin Copyright (C) 2010 C. Boemann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KoStore.h" #include "KoStore_p.h" #include "KoQuaZipStore.h" #include "KoDirectoryStore.h" #include #include #include #include #include #include #include #include #define DefaultFormat KoStore::Zip static KoStore::Backend determineBackend(QIODevice *dev) { unsigned char buf[5]; if (dev->read((char *)buf, 4) < 4) return DefaultFormat; // will create a "bad" store (bad()==true) if (buf[0] == 'P' && buf[1] == 'K' && buf[2] == 3 && buf[3] == 4) return KoStore::Zip; return DefaultFormat; // fallback } KoStore* KoStore::createStore(const QString& fileName, Mode mode, const QByteArray & appIdentification, Backend backend, bool writeMimetype) { if (backend == Auto) { if (mode == KoStore::Write) backend = DefaultFormat; else { QFileInfo inf(fileName); if (inf.isDir()) backend = Directory; else { QFile file(fileName); if (file.open(QIODevice::ReadOnly)) backend = determineBackend(&file); else backend = DefaultFormat; // will create a "bad" store (bad()==true) } } } switch (backend) { case Zip: return new KoQuaZipStore(fileName, mode, appIdentification, writeMimetype); case Directory: return new KoDirectoryStore(fileName /* should be a dir name.... */, mode, writeMimetype); default: warnStore << "Unsupported backend requested for KoStore : " << backend; return 0; } } KoStore* KoStore::createStore(QIODevice *device, Mode mode, const QByteArray & appIdentification, Backend backend, bool writeMimetype) { if (backend == Auto) { if (mode == KoStore::Write) backend = DefaultFormat; else { if (device->open(QIODevice::ReadOnly)) { backend = determineBackend(device); device->close(); } } } switch (backend) { case Directory: errorStore << "Can't create a Directory store for a memory buffer!" << endl; return 0; case Zip: return new KoQuaZipStore(device, mode, appIdentification, writeMimetype); default: warnStore << "Unsupported backend requested for KoStore : " << backend; return 0; } } namespace { const char ROOTPART[] = "root"; const char MAINNAME[] = "maindoc.xml"; } KoStore::KoStore(Mode mode, bool writeMimetype) : d_ptr(new KoStorePrivate(this, mode, writeMimetype)) {} KoStore::~KoStore() { Q_D(KoStore); delete d->stream; delete d_ptr; } bool KoStore::open(const QString & _name) { Q_D(KoStore); // This also converts from relative to absolute, i.e. merges the currentPath() d->fileName = d->toExternalNaming(_name); debugStore << "KOStore" << _name << d->fileName; if (d->isOpen) { warnStore << "Store is already opened, missing close"; return false; } if (d->fileName.length() > 512) { errorStore << "KoStore: Filename " << d->fileName << " is too long" << endl; return false; } if (d->mode == Write) { debugStore << "opening for writing" << d->fileName; if (d->filesList.contains(d->fileName)) { warnStore << "KoStore: Duplicate filename" << d->fileName; return false; } d->filesList.append(d->fileName); d->size = 0; if (!openWrite(d->fileName)) return false; } else if (d->mode == Read) { debugStore << "Opening for reading" << d->fileName; if (!openRead(d->fileName)) return false; } else return false; d->isOpen = true; return true; } bool KoStore::isOpen() const { Q_D(const KoStore); return d->isOpen; } bool KoStore::close() { Q_D(KoStore); if (!d->isOpen) { warnStore << "You must open before closing"; return false; } bool ret = d->mode == Write ? closeWrite() : closeRead(); delete d->stream; d->stream = 0; d->isOpen = false; return ret; } QIODevice* KoStore::device() const { Q_D(const KoStore); if (!d->isOpen) warnStore << "You must open before asking for a device"; if (d->mode != Read) warnStore << "Can not get device from store that is opened for writing"; return d->stream; } QByteArray KoStore::read(qint64 max) { Q_D(KoStore); QByteArray data; if (!d->isOpen) { warnStore << "You must open before reading"; return data; } if (d->mode != Read) { errorStore << "KoStore: Can not read from store that is opened for writing" << endl; return data; } return d->stream->read(max); } qint64 KoStore::write(const QByteArray& data) { return write(data.constData(), data.size()); // see below } qint64 KoStore::read(char *_buffer, qint64 _len) { Q_D(KoStore); if (!d->isOpen) { errorStore << "KoStore: You must open before reading" << endl; return -1; } if (d->mode != Read) { errorStore << "KoStore: Can not read from store that is opened for writing" << endl; return -1; } return d->stream->read(_buffer, _len); } qint64 KoStore::write(const char* _data, qint64 _len) { Q_D(KoStore); if (_len == 0) return 0; if (!d->isOpen) { errorStore << "KoStore: You must open before writing" << endl; return 0; } if (d->mode != Write) { errorStore << "KoStore: Can not write to store that is opened for reading" << endl; return 0; } int nwritten = d->stream->write(_data, _len); Q_ASSERT(nwritten == (int)_len); d->size += nwritten; return nwritten; } qint64 KoStore::size() const { Q_D(const KoStore); if (!d->isOpen) { warnStore << "You must open before asking for a size"; return static_cast(-1); } if (d->mode != Read) { warnStore << "Can not get size from store that is opened for writing"; return static_cast(-1); } return d->size; } bool KoStore::enterDirectory(const QString &directory) { Q_D(KoStore); //debugStore <<"enterDirectory" << directory; int pos; bool success = true; QString tmp(directory); while ((pos = tmp.indexOf('/')) != -1 && (success = d->enterDirectoryInternal(tmp.left(pos)))) tmp.remove(0, pos + 1); if (success && !tmp.isEmpty()) return d->enterDirectoryInternal(tmp); return success; } bool KoStore::leaveDirectory() { Q_D(KoStore); if (d->currentPath.isEmpty()) return false; d->currentPath.pop_back(); return enterAbsoluteDirectory(currentPath()); } QString KoStore::currentPath() const { Q_D(const KoStore); QString path; QStringList::ConstIterator it = d->currentPath.begin(); QStringList::ConstIterator end = d->currentPath.end(); for (; it != end; ++it) { path += *it; path += '/'; } return path; } void KoStore::pushDirectory() { Q_D(KoStore); d->directoryStack.push(currentPath()); } void KoStore::popDirectory() { Q_D(KoStore); d->currentPath.clear(); enterAbsoluteDirectory(QString()); enterDirectory(d->directoryStack.pop()); } bool KoStore::extractFile(const QString &srcName, QByteArray &data) { Q_D(KoStore); QBuffer buffer(&data); return d->extractFile(srcName, buffer); } bool KoStorePrivate::extractFile(const QString &srcName, QIODevice &buffer) { if (!q->open(srcName)) return false; if (!buffer.open(QIODevice::WriteOnly)) { q->close(); return false; } QByteArray data; data.resize(8 * 1024); uint total = 0; for (int block = 0; (block = q->read(data.data(), data.size())) > 0; total += block) { buffer.write(data.data(), block); } if (q->size() != static_cast(-1)) Q_ASSERT(total == q->size()); buffer.close(); q->close(); return true; } bool KoStore::seek(qint64 pos) { Q_D(KoStore); return d->stream->seek(pos); } qint64 KoStore::pos() const { Q_D(const KoStore); return d->stream->pos(); } bool KoStore::atEnd() const { Q_D(const KoStore); return d->stream->atEnd(); } // See the specification for details of what this function does. QString KoStorePrivate::toExternalNaming(const QString & _internalNaming) const { if (_internalNaming == ROOTPART) return q->currentPath() + MAINNAME; QString intern; if (_internalNaming.startsWith("tar:/")) // absolute reference intern = _internalNaming.mid(5); // remove protocol else intern = q->currentPath() + _internalNaming; return intern; } bool KoStorePrivate::enterDirectoryInternal(const QString &directory) { if (q->enterRelativeDirectory(directory)) { currentPath.append(directory); return true; } return false; } bool KoStore::hasFile(const QString& fileName) const { Q_D(const KoStore); return fileExists(d->toExternalNaming(fileName)); } bool KoStore::hasDirectory(const QString &directoryName) { return enterAbsoluteDirectory(directoryName); } bool KoStore::finalize() { Q_D(KoStore); Q_ASSERT(!d->finalized); // call this only once! d->finalized = true; return doFinalize(); } void KoStore::setCompressionEnabled(bool /*e*/) { } void KoStore::setSubstitution(const QString &name, const QString &substitution) { Q_D(KoStore); d->substituteThis = name; d->substituteWith = substitution; } -bool KoStore::isEncrypted() -{ - return false; -} - -bool KoStore::setPassword(const QString& /*password*/) -{ - return false; -} - -QString KoStore::password() -{ - return QString(); -} - bool KoStore::bad() const { Q_D(const KoStore); return !d->good; } KoStore::Mode KoStore::mode() const { Q_D(const KoStore); return d->mode; } QStringList KoStore::directoryList() const { return QStringList(); } diff --git a/libs/store/KoStore.h b/libs/store/KoStore.h index d847edd9b6..7c8c20f7a8 100644 --- a/libs/store/KoStore.h +++ b/libs/store/KoStore.h @@ -1,335 +1,301 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999 David Faure Copyright (C) 2010 C. Boemann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef __koStore_h_ #define __koStore_h_ #include #include #include "kritastore_export.h" class QWidget; class QUrl; class KoStorePrivate; /** * Saves and loads Krita documents using various backends. Currently supported * backends are zip 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. */ class KRITASTORE_EXPORT KoStore { public: enum Mode { Read, Write }; enum Backend { Auto, Zip, Directory }; /** * Open a store (i.e. the representation on disk of a Krita document). * * @param fileName the name of the file to open * @param mode if KoStore::Read, open an existing store to read it. * if KoStore::Write, create or replace a store. * @param backend the backend to use for the data storage. * Auto means automatically-determined for reading, * and the current format (now Zip) for writing. * * @param 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. * * @param writeMimetype If true, some backends (notably the Zip * store) will write a file called 'mimetype' automatically and * fill it with data from the appIdentification. This is only * applicable if Mode is set to Write. */ static KoStore *createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification = QByteArray(), Backend backend = Auto, bool writeMimetype = true); /** * 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! */ static KoStore *createStore(QIODevice *device, Mode mode, const QByteArray &appIdentification = QByteArray(), Backend backend = Auto, bool writeMimetype = true); /** * Destroys the store (i.e. closes the file on the hard disk) */ virtual ~KoStore(); /** * Open a new file inside the store * @param name The filename, internal representation ("root", "tar:/0"... ). * If the tar:/ prefix is missing it's assumed to be a relative URI. * @return true on success. */ bool open(const QString &name); /** * Check whether a file inside the store is currently opened with open(), * ready to be read or written. * @return true if a file is currently opened. */ bool isOpen() const; /** * Close the file inside the store * @return true on success. */ bool close(); /** * Get a device for reading a file from the store directly * (slightly faster than read() calls) * You need to call @ref open first, and @ref close afterwards. */ QIODevice *device() const; /** * Read data from the currently opened file. You can also use the streams * for this. */ QByteArray read(qint64 max); /** * Write data into the currently opened file. You can also use the streams * for this. */ qint64 write(const QByteArray &data); /** * Read data from the currently opened file. You can also use the streams * for this. * @return size of data read, -1 on error */ qint64 read(char *buffer, qint64 length); /** * Write data into the currently opened file. You can also use the streams * for this. */ virtual qint64 write(const char* data, qint64 length); /** * @return the size of the currently opened file, -1 on error. * Can be used as an argument for the read methods, for instance */ qint64 size() const; /** * @return true if an error occurred */ bool bad() const; /** * @return the mode used when opening, read or write */ Mode mode() const; /** * If an store is opened for reading, then the directories * of the store can be accessed via this function. * * @return a stringlist with all directories found */ virtual QStringList directoryList() const; /** * 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 */ virtual bool enterDirectory(const QString &directory); /** * Leaves a directory. Equivalent to "cd .." * @return true on success, false if we were at the root already to * make it possible to "loop to the root" */ bool leaveDirectory(); /** * Returns the current path including a trailing slash. * Note: Returns a path in "internal name" style */ QString currentPath() const; /** * Stacks the current directory. Restore the current path using * @ref popDirectory . */ void pushDirectory(); /** * Restores the previously pushed directory. No-op if the stack is * empty. */ void popDirectory(); /** * @return true if the given file exists in the current directory, * i.e. if open(fileName) will work. */ bool hasFile(const QString &fileName) const; /** *@return true if the given directory exists in the archive */ bool hasDirectory(const QString &directoryName); /** * Extracts a file out of the store to a buffer * @param sourceName file in the store * @param data memory buffer */ bool extractFile(const QString &sourceName, QByteArray &data); //@{ /// See QIODevice bool seek(qint64 pos); qint64 pos() const; bool atEnd() const; //@} /** * Call this before destroying the store, to be able to catch errors * (e.g. from ksavefile) */ bool finalize(); - /** - * 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. - * - * @param password A non-empty password. - * - * @return True if the password was set. - */ - virtual bool setPassword(const QString &password); - - /** - * 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. - * - * @return The password this store is encrypted with. - */ - virtual QString password(); - - /** - * Returns whether a store opened for reading is encrypted or a store opened - * for saving will be encrypted. - * - * @return True if the store is encrypted. - */ - virtual bool isEncrypted(); - /** * Allow to enable or disable compression of the files. Only supported by the * ZIP backend. */ virtual void setCompressionEnabled(bool e); /// When reading, in the paths in the store where name occurs, substitution is used. void setSubstitution(const QString &name, const QString &substitution); protected: KoStore(Mode mode, bool writeMimetype = true); /** * Finalize store - called by finalize. * @return true on success */ virtual bool doFinalize() { return true; } /** * Open the file @p name in the store, for writing * On success, this method must set m_stream to a stream in which we can write. * @param name "absolute path" (in the archive) to the file to open * @return true on success */ virtual bool openWrite(const QString &name) = 0; /** * Open the file @p 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. * @param name "absolute path" (in the archive) to the file to open * @return true on success */ virtual bool openRead(const QString &name) = 0; /** * @return true on success */ virtual bool closeRead() = 0; /** * @return true on success */ virtual bool closeWrite() = 0; /** * Enter a subdirectory of the current directory. * The directory might not exist yet in Write mode. */ virtual bool enterRelativeDirectory(const QString &dirName) = 0; /** * Enter a directory where we've been before. * It is guaranteed to always exist. */ virtual bool enterAbsoluteDirectory(const QString &path) = 0; /** * Check if a file exists inside the store. * @param absPath the absolute path inside the store, i.e. not relative to the current directory */ virtual bool fileExists(const QString &absPath) const = 0; protected: KoStorePrivate *d_ptr; private: Q_DECLARE_PRIVATE(KoStore) private: KoStore(const KoStore& store); ///< don't copy KoStore& operator=(const KoStore& store); ///< don't assign }; #endif