File indexing completed on 2024-05-12 15:59:52
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISSTORAGEPLUGIN_H 0008 #define KISSTORAGEPLUGIN_H 0009 0010 #include <QScopedPointer> 0011 #include <QString> 0012 0013 #include <KisResourceStorage.h> 0014 #include "kritaresources_export.h" 0015 0016 class QDir; 0017 0018 /** 0019 * The KisStoragePlugin class is the base class 0020 * for storage plugins. A storage plugin is used by 0021 * KisResourceStorage to locate resources and tags in 0022 * a kind of storage, like a folder, a bundle or an adobe 0023 * resource library. 0024 */ 0025 class KRITARESOURCES_EXPORT KisStoragePlugin 0026 { 0027 public: 0028 KisStoragePlugin(const QString &location); 0029 virtual ~KisStoragePlugin(); 0030 0031 virtual KisResourceStorage::ResourceItem resourceItem(const QString &url) = 0; 0032 0033 /// Retrieve the given resource. The url is the unique identifier of the resource, 0034 /// for instance resourcetype plus filename. 0035 virtual KoResourceSP resource(const QString &url); 0036 virtual QString resourceMd5(const QString &url); 0037 virtual QString resourceFilePath(const QString &url); 0038 virtual bool loadVersionedResource(KoResourceSP resource) = 0; 0039 virtual bool supportsVersioning() const; 0040 virtual QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) = 0; 0041 virtual QSharedPointer<KisResourceStorage::TagIterator> tags(const QString &resourceType) = 0; 0042 0043 virtual bool saveAsNewVersion(const QString &resourceType, KoResourceSP resource) {Q_UNUSED(resourceType); Q_UNUSED(resource); return false;} 0044 virtual bool importResource(const QString &url, QIODevice *device) {Q_UNUSED(url); Q_UNUSED(device); return false;} 0045 virtual bool exportResource(const QString &url, QIODevice *device) {Q_UNUSED(url); Q_UNUSED(device); return false;} 0046 virtual bool addResource(const QString &resourceType, KoResourceSP resource) {Q_UNUSED(resourceType); Q_UNUSED(resource); return false;} 0047 virtual QImage thumbnail() const { return QImage(); } 0048 0049 virtual void setMetaData(const QString &key, const QVariant &value) {Q_UNUSED(key); Q_UNUSED(value);} 0050 virtual QStringList metaDataKeys() const { return QStringList(); } 0051 virtual QVariant metaData(const QString &key) const { Q_UNUSED(key); return QString(); } 0052 0053 QDateTime timestamp(); 0054 0055 virtual bool isValid() const; 0056 0057 protected: 0058 friend class TestBundleStorage; 0059 QString location() const; 0060 0061 /** 0062 * On some systems, e.g. Windows, the file names are case-insensitive, 0063 * therefore URLs will fetch the resource even when the casing is not 0064 * the same. The storage, when returning such a resource should make 0065 * sure that its filename is set to the **real** filename, not the one 0066 * with incorrect casing. 0067 */ 0068 void sanitizeResourceFileNameCase(KoResourceSP resource, const QDir &parentDir); 0069 0070 private: 0071 class Private; 0072 QScopedPointer<Private> d; 0073 }; 0074 0075 #endif // KISSTORAGEPLUGIN_H