Krita Source Code Documentation
Loading...
Searching...
No Matches
KisResourceLocator.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef KISRESOURCELOCATOR_H
8#define KISRESOURCELOCATOR_H
9
10#include <QObject>
11#include <QScopedPointer>
12#include <QStringList>
13#include <QString>
14
15#include "kritaresources_export.h"
16
17#include <KisResourceStorage.h>
18
19
32class KRITARESOURCES_EXPORT KisResourceLocator : public QObject
33{
34 Q_OBJECT
35public:
36
37 // The configuration key that holds the resource location
38 // for this installation of Krita. The location is
39 // QStandardPaths::AppDataLocation by default, but that
40 // can be changed.
41 static const QString resourceLocationKey;
42
44
47 enum class LocatorError {
48 Ok,
49 LocationReadOnly,
50 CannotCreateLocation,
51 CannotInitializeDb,
52 CannotSynchronizeDb
53 };
54
61 LocatorError initialize(const QString &installationResourcesLocation);
62
67 QStringList errorMessages() const;
68
74 QString resourceLocationBase() const;
75
79 void purge(const QString &storageLocation);
80
89 bool addStorage(const QString &storageLocation, KisResourceStorageSP storage);
90
96 bool removeStorage(const QString &storageLocation);
97
103 bool hasStorage(const QString &storageLocation);
104
105
109 static void saveTags();
110
114 void purgeTag(const QString tagUrl, const QString resourceType);
115
120 QString filePathForResource(KoResourceSP resource);
121
123 void updateFontStorage();
124
125Q_SIGNALS:
126
127 void progressMessage(const QString&);
128
130 void storageAdded(const QString &location);
131
133 void storageRemoved(const QString &location);
134
136 void beginExternalResourceImport(const QString &resourceType, int numResources);
137
139 void endExternalResourceImport(const QString &resourceType);
140
142 void beginExternalResourceRemove(const QString &resourceType, const QVector<int> resourceIds);
143
145 void endExternalResourceRemove(const QString &resourceType);
146
148 void resourceActiveStateChanged(const QString &resourceType, int resourceId);
149
155 void storageResynchronized(const QString &storage, bool isBulkResynchronization);
156
161
162private:
163
164 friend class KisAllTagsModel;
168 friend class KisStorageModel;
169 friend class TestResourceLocator;
170 friend class TestResourceModel;
171 friend class Resource;
172 friend class KisResourceCacheDb;
178
180 bool resourceCached(QString storageLocation, const QString &resourceType, const QString &filename) const;
181
195 KoResourceSP resource(QString storageLocation, const QString &resourceType, const QString &filename);
196
202 KoResourceSP resourceForId(int resourceId);
203
210 bool setResourceActive(int resourceId, bool active);
211
219 KoResourceSP importResourceFromFile(const QString &resourceType, const QString &fileName, const bool allowOverwrite, const QString &storageLocation = QString());
220
229 KoResourceSP importResource(const QString &resourceType, const QString &fileName, QIODevice *device, const bool allowOverwrite, const QString &storageLocation = QString());
230
237 bool importWillOverwriteResource(const QString &resourceType, const QString &fileName, const QString &storageLocation = QString()) const;
238
245 bool exportResource(KoResourceSP resource, QIODevice *device);
246
254 bool addResource(const QString &resourceType, const KoResourceSP resource, const QString &storageLocation = QString());
255
262 bool updateResource(const QString &resourceType, const KoResourceSP resource);
263
271 bool reloadResource(const QString &resourceType, const KoResourceSP resource);
272
278 QMap<QString, QVariant> metaDataForResource(int id) const;
279
286 bool setMetaDataForResource(int id, QMap<QString, QVariant> map) const;
287
293 QMap<QString, QVariant> metaDataForStorage(const QString &storageLocation) const;
294
300 void setMetaDataForStorage(const QString &storageLocation, QMap<QString, QVariant> map) const;
301
308 void loadRequiredResources(KoResourceSP resource);
309
315 KisTagSP tagForUrl(const QString &tagUrl, const QString resourceType);
316
323 static KisTagSP tagForUrlNoCache(const QString &tagUrl, const QString resourceType);
324
325 KisResourceLocator(QObject *parent);
328
330 Unknown, // We don't know whether Krita has run on this system for this resource location yet
331 Initialized, // Everything is ready to start synchronizing the database
332 FirstRun, // Krita hasn't run for this resource location yet
333 FirstUpdate, // Krita was installed, but it's a version from before the resource locator existed, only user-defined resources are present
334 Updating // Krita is updating from an older version with resource locator
335 };
336
337 LocatorError firstTimeInstallation(InitializationStatus initializationStatus, const QString &installationResourcesLocation);
338
339 // Synchronize on restarting Krita to see whether the user has added any storages or resources to the resources location
340 bool synchronizeDb();
341
342 void findStorages();
343 QList<KisResourceStorageSP> storages() const;
344
345 KisResourceStorageSP storageByLocation(const QString &location) const;
346 KisResourceStorageSP folderStorage() const;
347 KisResourceStorageSP memoryStorage() const;
348 KisResourceStorageSP fontStorage() const;
349
355
357
358 ResourceStorage getResourceStorage(int resourceId) const;
359 QString makeStorageLocationAbsolute(QString storageLocation) const;
360 QString makeStorageLocationRelative(QString location) const;
361
362 class Private;
363 QScopedPointer<Private> d;
364};
365
366#endif // KISRESOURCELOCATOR_H
PythonPluginManager * instance
The KisAllresourcesModel class provides access to the cache database for a particular resource type....
The KisResourceCacheDb class encapsulates the database that caches information about the resources av...
void progressMessage(const QString &)
QScopedPointer< Private > d
void endExternalResourceRemove(const QString &resourceType)
Emitted when the locator finished importing the embedded resource.
void storageRemoved(const QString &location)
Emitted whenever a storage is removed.
KisResourceLocator operator=(const KisResourceLocator &)
void storageAdded(const QString &location)
Emitted whenever a storage is added.
void storagesBulkSynchronizationFinished()
KisResourceLocator(const KisResourceLocator &)
void beginExternalResourceImport(const QString &resourceType, int numResources)
Emitted when the locator needs to add an embedded resource.
void beginExternalResourceRemove(const QString &resourceType, const QVector< int > resourceIds)
Emitted when the locator needs to add an embedded resource.
void endExternalResourceImport(const QString &resourceType)
Emitted when the locator finished importing the embedded resource.
void storageResynchronized(const QString &storage, bool isBulkResynchronization)
void resourceActiveStateChanged(const QString &resourceType, int resourceId)
Emitted when a resource changes its active state.
The KisTagResourceModel class makes it possible to retrieve the resources for certain tags or the tag...
@ Unknown
Definition psd.h:44