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

#include <KisResourceStorage.h>

Classes

class  Private
 
struct  ResourceItem
 A resource item is simply an entry in the storage,. More...
 
class  ResourceIterator
 
class  TagIterator
 

Public Types

enum class  StorageType : int {
  Unknown = 1 , Folder = 2 , Bundle = 3 , AdobeBrushLibrary = 4 ,
  AdobeStyleLibrary = 5 , Memory = 6 , FontStorage = 7
}
 

Public Member Functions

bool addResource (KoResourceSP resource)
 
bool addTag (const QString &resourceType, KisTagSP tag)
 
KisResourceStorageSP clone () const
 
bool exportResource (const QString &url, QIODevice *device)
 
bool importResource (const QString &url, QIODevice *device)
 
 KisResourceStorage (const KisResourceStorage &rhs)
 
 KisResourceStorage (const QString &location)
 
 KisResourceStorage (const QString &location, KisResourceStorage::StorageType storageType)
 
bool loadVersionedResource (KoResourceSP resource)
 Reloads the given resource from the persistent storage.
 
QString location () const
 The absolute location of the storage.
 
QVariant metaData (const QString &key) const
 
QStringList metaDataKeys () const
 
QString name () const
 
KisResourceStorageoperator= (const KisResourceStorage &rhs)
 
KoResourceSP resource (const QString &url)
 The loaded resource for an entry in the storage.
 
QString resourceFilePath (const QString &url)
 
ResourceItem resourceItem (const QString &url)
 And entry in the storage; this is not the loaded resource.
 
QString resourceMd5 (const QString &url)
 The MD5 checksum of the resource in the storage.
 
QSharedPointer< ResourceIteratorresources (const QString &resourceType) const
 An iterator over all the resources in the storage.
 
bool saveAsNewVersion (KoResourceSP resource)
 Creates a new version of the given resource.
 
void setMetaData (const QString &key, const QVariant &value)
 
bool supportsVersioning () const
 
QSharedPointer< TagIteratortags (const QString &resourceType) const
 An iterator over all the tags in the resource.
 
QImage thumbnail () const
 The icond for the storage.
 
QDateTime timestamp () const
 
QDateTime timeStampForResource (const QString &resourceType, const QString &filename) const
 
StorageType type () const
 The type of the storage.
 
bool valid () const
 true if the storage exists and can be used
 
 ~KisResourceStorage ()
 

Static Public Member Functions

static QString storageTypeToString (StorageType storageType)
 
static QString storageTypeToUntranslatedString (StorageType storageType)
 

Static Public Attributes

static const QString s_meta_author
 
static const QString s_meta_creation_date
 
static const QString s_meta_creator
 
static const QString s_meta_dc_date
 
static const QString s_meta_description
 
static const QString s_meta_email
 
static const QString s_meta_generator
 
static const QString s_meta_initial_creator
 
static const QString s_meta_license
 
static const QString s_meta_name
 
static const QString s_meta_title
 
static const QString s_meta_user_defined
 
static const QString s_meta_value
 
static const QString s_meta_version
 
static const QString s_meta_website
 
static const QString s_xmlns_dc
 
static const QString s_xmlns_meta
 

Private Member Functions

void setStorageId (int storageId)
 
int storageId ()
 
KisStoragePlugintestingGetStoragePlugin ()
 

Private Attributes

QScopedPointer< Privated
 

Friends

class KisResourceCacheDb
 
class KisResourceLocator
 
class KisStorageModel
 
class TestResourceLocator
 

Detailed Description

The KisResourceStorage class is the base class for places where resources can be stored. Examples are folders, bundles or Adobe resource libraries like ABR files.

Definition at line 51 of file KisResourceStorage.h.

Member Enumeration Documentation

◆ StorageType

enum class KisResourceStorage::StorageType : int
strong
Enumerator
Unknown 
Folder 
Bundle 
AdobeBrushLibrary 
AdobeStyleLibrary 
Memory 
FontStorage 

Definition at line 104 of file KisResourceStorage.h.

Constructor & Destructor Documentation

◆ KisResourceStorage() [1/3]

KisResourceStorage::KisResourceStorage ( const QString & location,
KisResourceStorage::StorageType storageType )

Definition at line 109 of file KisResourceStorage.cpp.

110 : d(new Private())
111{
112 d->location = location;
113
114 auto createMemoryStorage = [this] (const QString &location, bool isValid) {
115 d->name = location;
116 d->storageType = StorageType::Memory;
118 d->valid = isValid;
119 };
120
121 switch (storageType) {
122 case StorageType::Folder: {
123 QFileInfo fi(d->location);
124 if (fi.isDir()) {
125 d->name = fi.fileName();
126 d->storageType = StorageType::Folder;
127 d->storagePlugin.reset(KisStoragePluginRegistry::instance()->m_storageFactoryMap[StorageType::Folder]->create(location));
128 d->valid = fi.isWritable();
129 } else {
130 createMemoryStorage(location, false);
131 }
132 break;
133 }
134 case StorageType::Bundle: {
135 QFileInfo fi(d->location);
136 d->name = fi.fileName();
137 d->storageType = StorageType::Bundle;
138 d->storagePlugin.reset(KisStoragePluginRegistry::instance()->m_storageFactoryMap[StorageType::Bundle]->create(location));
139 // XXX: should we also check whether there's a valid metadata entry? Or is this enough?
140 d->valid = (fi.isReadable() && QuaZip(d->location).open(QuaZip::mdUnzip));
141 break;
142 }
144 QFileInfo fi(d->location);
145 d->name = fi.fileName();
146 d->storageType = StorageType::AdobeBrushLibrary;
147 d->storagePlugin.reset(KisStoragePluginRegistry::instance()->m_storageFactoryMap[StorageType::AdobeBrushLibrary]->create(location));
148 d->valid = fi.isReadable();
149 break;
150 }
152 QFileInfo fi(d->location);
153 d->name = fi.fileName();
154 d->storageType = StorageType::AdobeStyleLibrary;
155 d->storagePlugin.reset(KisStoragePluginRegistry::instance()->m_storageFactoryMap[StorageType::AdobeStyleLibrary]->create(location));
156 d->valid = d->storagePlugin->isValid();
157 break;
158 }
160 createMemoryStorage(location, false);
161 break;
163 createMemoryStorage(location, true);
164 break;
167 if (factory) {
168 d->name = location;
169 d->storageType = StorageType::FontStorage;
170 d->storagePlugin.reset(factory->create(location));
171 d->valid = true;
172 } else {
173 createMemoryStorage(location, false);
174 }
175 break;
176 }
177 }
178}
QString location() const
The absolute location of the storage.
QScopedPointer< Private > d
static KisStoragePluginRegistry * instance()
QMap< KisResourceStorage::StorageType, KisStoragePluginFactoryBase * > m_storageFactoryMap
QPainterPath create(const char32_t codepoint, double height)
Creates a tofu missing glyph indicator representing the provided Unicode codepoint.

References AdobeBrushLibrary, AdobeStyleLibrary, Bundle, d, Folder, FontStorage, KisStoragePluginRegistry::instance(), location(), KisStoragePluginRegistry::m_storageFactoryMap, Memory, and Unknown.

◆ KisResourceStorage() [2/3]

KisResourceStorage::KisResourceStorage ( const QString & location)

Definition at line 180 of file KisResourceStorage.cpp.

181 : KisResourceStorage(location, autoDetectStorageType(location))
182{
183}
KisResourceStorage(const QString &location, KisResourceStorage::StorageType storageType)

◆ ~KisResourceStorage()

KisResourceStorage::~KisResourceStorage ( )

Definition at line 185 of file KisResourceStorage.cpp.

186{
187}

◆ KisResourceStorage() [3/3]

KisResourceStorage::KisResourceStorage ( const KisResourceStorage & rhs)

Definition at line 189 of file KisResourceStorage.cpp.

190 : d(new Private)
191{
192 *this = rhs;
193}

Member Function Documentation

◆ addResource()

bool KisResourceStorage::addResource ( KoResourceSP resource)

Adds the given resource to the storage. If there is already a resource with the given filename of the given type, this should return false and saveAsNewVersion should be used.

Definition at line 295 of file KisResourceStorage.cpp.

296{
297 if (!resource) return false;
298
299 return d->storagePlugin->addResource(resource->resourceType().first, resource);
300}
KoResourceSP resource(const QString &url)
The loaded resource for an entry in the storage.

References d, and resource().

◆ addTag()

bool KisResourceStorage::addTag ( const QString & resourceType,
KisTagSP tag )

Adds a tag to the storage, however, it does not store the links between tags and resources.

◆ clone()

KisResourceStorageSP KisResourceStorage::clone ( ) const

Definition at line 214 of file KisResourceStorage.cpp.

215{
216 return KisResourceStorageSP(new KisResourceStorage(*this));
217}
QSharedPointer< KisResourceStorage > KisResourceStorageSP

References KisResourceStorage().

◆ exportResource()

bool KisResourceStorage::exportResource ( const QString & url,
QIODevice * device )

Copies the given resource from the storage into device

Parameters
urlis the URL of the resource inside the storage, which is usually resource_type/resource_filename.ext

Definition at line 307 of file KisResourceStorage.cpp.

308{
309 return d->storagePlugin->exportResource(url, device);
310}

References d.

◆ importResource()

bool KisResourceStorage::importResource ( const QString & url,
QIODevice * device )

Copies the given file into this storage. Implementations should not overwrite an existing resource with the same filename, but return false.

Parameters
urlis the URL of the resource inside the storage, which is usually resource_type/resource_filename.ext

Definition at line 302 of file KisResourceStorage.cpp.

303{
304 return d->storagePlugin->importResource(url, device);
305}

References d.

◆ loadVersionedResource()

bool KisResourceStorage::loadVersionedResource ( KoResourceSP resource)

Reloads the given resource from the persistent storage.

Definition at line 317 of file KisResourceStorage.cpp.

318{
319 return d->storagePlugin->loadVersionedResource(resource);
320}

References d, and resource().

◆ location()

QString KisResourceStorage::location ( ) const

The absolute location of the storage.

Definition at line 224 of file KisResourceStorage.cpp.

225{
226 return d->location;
227}

References d.

◆ metaData()

QVariant KisResourceStorage::metaData ( const QString & key) const

Definition at line 337 of file KisResourceStorage.cpp.

338{
339 return d->storagePlugin->metaData(key);
340}

References d.

◆ metaDataKeys()

QStringList KisResourceStorage::metaDataKeys ( ) const

Definition at line 332 of file KisResourceStorage.cpp.

333{
334 return d->storagePlugin->metaDataKeys();
335}

References d.

◆ name()

QString KisResourceStorage::name ( ) const

The filename of the storage if it's a bundle or Adobe Library. This can also be empty (for the folder storage) or "memory" for the storage for temporary resources, a UUID for storages associated with documents.

Definition at line 219 of file KisResourceStorage.cpp.

220{
221 return d->name;
222}

References d.

◆ operator=()

KisResourceStorage & KisResourceStorage::operator= ( const KisResourceStorage & rhs)

Definition at line 195 of file KisResourceStorage.cpp.

196{
197 if (this != &rhs) {
198 d->name = rhs.d->name;
199 d->location = rhs.d->location;
200 d->storageType = rhs.d->storageType;
201 if (d->storageType == StorageType::Memory) {
202 const QSharedPointer<KisMemoryStorage> memoryStorage = rhs.d->storagePlugin.dynamicCast<KisMemoryStorage>();
203 KIS_ASSERT(memoryStorage);
204 d->storagePlugin = QSharedPointer<KisMemoryStorage>(new KisMemoryStorage(*memoryStorage));
205 }
206 else {
207 d->storagePlugin = rhs.d->storagePlugin;
208 }
209 d->valid = false;
210 }
211 return *this;
212}
The KisMemoryStorage class stores the temporary resources that are not saved to disk or bundle....
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References d, KIS_ASSERT, Memory, and name().

◆ resource()

KoResourceSP KisResourceStorage::resource ( const QString & url)

The loaded resource for an entry in the storage.

Definition at line 263 of file KisResourceStorage.cpp.

264{
265 return d->storagePlugin->resource(url);
266}

References d.

◆ resourceFilePath()

QString KisResourceStorage::resourceFilePath ( const QString & url)

If the resource is present on the filesystem as a distinct fine, returns the full file path of it, otherwise returns an empty string.

Never manipulate the file in any way directly! It will destroy the resources database. Use this file path only for informational purposes.

Definition at line 273 of file KisResourceStorage.cpp.

274{
275 return d->storagePlugin->resourceFilePath(url);
276}

References d.

◆ resourceItem()

KisResourceStorage::ResourceItem KisResourceStorage::resourceItem ( const QString & url)

And entry in the storage; this is not the loaded resource.

Definition at line 258 of file KisResourceStorage.cpp.

259{
260 return d->storagePlugin->resourceItem(url);
261}

References d.

◆ resourceMd5()

QString KisResourceStorage::resourceMd5 ( const QString & url)

The MD5 checksum of the resource in the storage.

Definition at line 268 of file KisResourceStorage.cpp.

269{
270 return d->storagePlugin->resourceMd5(url);
271}

References d.

◆ resources()

QSharedPointer< KisResourceStorage::ResourceIterator > KisResourceStorage::resources ( const QString & resourceType) const

An iterator over all the resources in the storage.

Definition at line 278 of file KisResourceStorage.cpp.

279{
280 return d->storagePlugin->resources(resourceType);
281}

References d.

◆ saveAsNewVersion()

bool KisResourceStorage::saveAsNewVersion ( KoResourceSP resource)

Creates a new version of the given resource.

Definition at line 288 of file KisResourceStorage.cpp.

289{
290 if (!resource) return false;
291
292 return d->storagePlugin->saveAsNewVersion(resource->resourceType().first, resource);
293}

References d, and resource().

◆ setMetaData()

void KisResourceStorage::setMetaData ( const QString & key,
const QVariant & value )

Definition at line 322 of file KisResourceStorage.cpp.

323{
324 d->storagePlugin->setMetaData(key, value);
325}
float value(const T *src, size_t ch)

References d, and value().

◆ setStorageId()

void KisResourceStorage::setStorageId ( int storageId)
private

Definition at line 342 of file KisResourceStorage.cpp.

343{
344 d->storageId = storageId;
345}

References d, and storageId().

◆ storageId()

int KisResourceStorage::storageId ( )
private

Definition at line 347 of file KisResourceStorage.cpp.

348{
349 return d->storageId;
350}

References d.

◆ storageTypeToString()

static QString KisResourceStorage::storageTypeToString ( StorageType storageType)
inlinestatic

Definition at line 114 of file KisResourceStorage.h.

114 {
115 switch (storageType) {
117 return i18n("Unknown");
119 return i18n("Folder");
121 return i18n("Bundle");
123 return i18n("Adobe Brush Library");
125 return i18n("Adobe Style Library");
127 return i18n("Font Storage");
129 return i18n("Memory");
130 default:
131 return i18n("Invalid");
132 }
133 }

◆ storageTypeToUntranslatedString()

static QString KisResourceStorage::storageTypeToUntranslatedString ( StorageType storageType)
inlinestatic

Definition at line 136 of file KisResourceStorage.h.

136 {
137 switch (storageType) {
139 return ("Unknown");
141 return ("Folder");
143 return ("Bundle");
145 return ("Adobe Brush Library");
147 return ("Adobe Style Library");
149 return ("Font Storage");
151 return ("Memory");
152 default:
153 return ("Invalid");
154 }
155 }

◆ supportsVersioning()

bool KisResourceStorage::supportsVersioning ( ) const

Returns true if the storage supports versioning of the resources. It enables loadVersionedResource() call.

Definition at line 312 of file KisResourceStorage.cpp.

313{
314 return d->storagePlugin->supportsVersioning();
315}

References d.

◆ tags()

QSharedPointer< KisResourceStorage::TagIterator > KisResourceStorage::tags ( const QString & resourceType) const

An iterator over all the tags in the resource.

Definition at line 283 of file KisResourceStorage.cpp.

284{
285 return d->storagePlugin->tags(resourceType);
286}

References d.

◆ testingGetStoragePlugin()

KisStoragePlugin * KisResourceStorage::testingGetStoragePlugin ( )
private

Definition at line 352 of file KisResourceStorage.cpp.

353{
354 return d->storagePlugin.data();
355}

References d.

◆ thumbnail()

QImage KisResourceStorage::thumbnail ( ) const

The icond for the storage.

Definition at line 234 of file KisResourceStorage.cpp.

235{
236 return d->storagePlugin->thumbnail();
237}

References d.

◆ timestamp()

QDateTime KisResourceStorage::timestamp ( ) const

The time and date when the storage was last modified, or created for memory storages.

Definition at line 239 of file KisResourceStorage.cpp.

240{
241 return d->storagePlugin->timestamp();
242}

References d.

◆ timeStampForResource()

QDateTime KisResourceStorage::timeStampForResource ( const QString & resourceType,
const QString & filename ) const

The time and date when the resource was last modified For filestorage

Definition at line 244 of file KisResourceStorage.cpp.

245{
246 QFileInfo li(d->location);
247 if (li.suffix().toLower() == "bundle") {
248 QFileInfo bf(d->location + "_modified/" + resourceType + "/" + filename);
249 if (bf.exists()) {
250 return bf.lastModified();
251 }
252 } else if (QFileInfo(d->location + "/" + resourceType + "/" + filename).exists()) {
253 return QFileInfo(d->location + "/" + resourceType + "/" + filename).lastModified();
254 }
255 return this->timestamp();
256}
QDateTime timestamp() const

References d, and timestamp().

◆ type()

KisResourceStorage::StorageType KisResourceStorage::type ( ) const

The type of the storage.

Definition at line 229 of file KisResourceStorage.cpp.

230{
231 return d->storageType;
232}

References d.

◆ valid()

bool KisResourceStorage::valid ( ) const

true if the storage exists and can be used

Definition at line 327 of file KisResourceStorage.cpp.

328{
329 return d->valid;
330}

References d.

Friends And Related Symbol Documentation

◆ KisResourceCacheDb

friend class KisResourceCacheDb
friend

Definition at line 275 of file KisResourceStorage.h.

◆ KisResourceLocator

friend class KisResourceLocator
friend

Definition at line 274 of file KisResourceStorage.h.

◆ KisStorageModel

friend class KisStorageModel
friend

Definition at line 273 of file KisResourceStorage.h.

◆ TestResourceLocator

friend class TestResourceLocator
friend

Definition at line 276 of file KisResourceStorage.h.

Member Data Documentation

◆ d

QScopedPointer<Private> KisResourceStorage::d
private

Definition at line 284 of file KisResourceStorage.h.

◆ s_meta_author

const QString KisResourceStorage::s_meta_author
static

Definition at line 252 of file KisResourceStorage.h.

◆ s_meta_creation_date

const QString KisResourceStorage::s_meta_creation_date
static

Definition at line 257 of file KisResourceStorage.h.

◆ s_meta_creator

const QString KisResourceStorage::s_meta_creator
static

Definition at line 256 of file KisResourceStorage.h.

◆ s_meta_dc_date

const QString KisResourceStorage::s_meta_dc_date
static

Definition at line 258 of file KisResourceStorage.h.

◆ s_meta_description

const QString KisResourceStorage::s_meta_description
static

Definition at line 254 of file KisResourceStorage.h.

◆ s_meta_email

const QString KisResourceStorage::s_meta_email
static

Definition at line 264 of file KisResourceStorage.h.

◆ s_meta_generator

const QString KisResourceStorage::s_meta_generator
static

Definition at line 251 of file KisResourceStorage.h.

◆ s_meta_initial_creator

const QString KisResourceStorage::s_meta_initial_creator
static

Definition at line 255 of file KisResourceStorage.h.

◆ s_meta_license

const QString KisResourceStorage::s_meta_license
static

Definition at line 263 of file KisResourceStorage.h.

◆ s_meta_name

const QString KisResourceStorage::s_meta_name
static

Definition at line 260 of file KisResourceStorage.h.

◆ s_meta_title

const QString KisResourceStorage::s_meta_title
static

Definition at line 253 of file KisResourceStorage.h.

◆ s_meta_user_defined

const QString KisResourceStorage::s_meta_user_defined
static

Definition at line 259 of file KisResourceStorage.h.

◆ s_meta_value

const QString KisResourceStorage::s_meta_value
static

Definition at line 261 of file KisResourceStorage.h.

◆ s_meta_version

const QString KisResourceStorage::s_meta_version
static

Definition at line 262 of file KisResourceStorage.h.

◆ s_meta_website

const QString KisResourceStorage::s_meta_website
static

Definition at line 265 of file KisResourceStorage.h.

◆ s_xmlns_dc

const QString KisResourceStorage::s_xmlns_dc
static

Definition at line 249 of file KisResourceStorage.h.

◆ s_xmlns_meta

const QString KisResourceStorage::s_xmlns_meta
static

Definition at line 248 of file KisResourceStorage.h.


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