12#include <QDirIterator>
30 QScopedPointer<KoResourceBundle>
bundle;
44 Q_FOREACH(
const QString &tagname, resourceReference.
tagList) {
45 if (!
m_tags.contains(tagname)){
47 tag->setName(tagname);
48 tag->setComment(tagname);
50 tag->setResourceType(resourceType);
55 m_tags[tagname]->setDefaultResources(
m_tags[tagname]->defaultResources()
56 << QFileInfo(resourceReference.
resourcePath).fileName());
87 if (!
d->bundle->load()) {
88 qWarning() <<
"Could not load bundle" <<
location;
100 QStringList parts = url.split(
'/', Qt::SkipEmptyParts);
101 Q_ASSERT(parts.size() == 2);
104 item.
lastModified = QFileInfo(
d->bundle->filename()).lastModified();
110 bool foundVersionedFile =
false;
112 const QString resourceType =
resource->resourceType().first;
113 const QString resourceUrl = resourceType +
"/" +
resource->filename();
115 const QString bundleSaveLocation =
location() +
"_modified" +
"/" + resourceType;
117 if (QDir(bundleSaveLocation).exists()) {
118 const QString fn = bundleSaveLocation +
"/" +
resource->filename();
119 const QFileInfo fi(fn);
121 foundVersionedFile =
true;
124 if (!f.open(QFile::ReadOnly)) {
125 qWarning() <<
"Could not open resource file for reading" << fn;
129 qWarning() <<
"Could not reload resource file" << fn;
137 QImage img(bundleSaveLocation +
"/" +
'/' +
resource->thumbnailPath());
145 if (!foundVersionedFile) {
156 QFile modifiedFile(
location() +
"_modified" +
"/" + url);
157 if (modifiedFile.exists() && modifiedFile.open(QIODevice::ReadOnly)) {
160 result =
d->bundle->resourceMd5(url);
171 d->bundle->manifest().files(resourceType);
173 for (
auto it = references.begin(); it != references.end(); ++it) {
179 QString path = QDir::fromNativeSeparators(it->resourcePath);
180 int folderEndIdx = path.indexOf(
"/");
181 QString properFilenameWithSubfolders = path.right(path.length() - folderEndIdx - 1);
183 entry.
filename = properFilenameWithSubfolders;
187 entries.append(entry);
190 const QString bundleSaveLocation =
location() +
"_modified" +
"/" + resourceType;
192 QDirIterator it(bundleSaveLocation,
194 QDir::Files | QDir::Readable,
195 QDirIterator::Subdirectories);;
197 while (it.hasNext()) {
199 QFileInfo info(it.fileInfo());
206 entries.append(entry);
221 return d->bundle->image();
244 return d->bundle->metaData(key);
249 QString bundleSaveLocation =
location() +
"_modified" +
"/" + resourceType;
251 if (!QDir(bundleSaveLocation).exists()) {
252 QDir().mkpath(bundleSaveLocation);
260 QStringList parts = url.split(
'/', Qt::SkipEmptyParts);
261 Q_ASSERT(parts.size() == 2);
263 const QString resourceType = parts[0];
264 const QString resourceFileName = parts[1];
266 bool foundVersionedFile =
false;
268 const QString bundleSaveLocation =
location() +
"_modified" +
"/" + resourceType;
270 if (QDir(bundleSaveLocation).exists()) {
271 const QString fn = bundleSaveLocation +
"/" + resourceFileName;
272 if (QFileInfo(fn).exists()) {
273 foundVersionedFile =
true;
276 if (!f.open(QFile::ReadOnly)) {
277 qWarning() <<
"Could not open resource file for reading" << fn;
281 device->write(f.readAll());
285 if (!foundVersionedFile) {
286 d->bundle->exportResource(resourceType, resourceFileName, device);
QList< QString > QStringList
QScopedPointer< QListIterator< KisTagSP > > m_tagIterator
KisTagSP tag() const override
A tag object on which we can set properties and which we can save.
QHash< QString, KisTagSP > m_tags
bool hasNext() const override
void next() override
The iterator is only valid if next() has been called at least once.
BundleTagIterator(KoResourceBundle *bundle, const QString &resourceType)
KoResourceBundle * m_bundle
QScopedPointer< KoResourceBundle > bundle
Private(KisBundleStorage *_q)
KisBundleStorage(const QString &location)
QVariant metaData(const QString &key) const override
QStringList metaDataKeys() const override
bool loadVersionedResource(KoResourceSP resource) override
Note: this should find resources in a folder that override a resource in the bundle first.
bool exportResource(const QString &url, QIODevice *device) override
virtual ~KisBundleStorage()
QImage thumbnail() const override
QScopedPointer< Private > d
QSharedPointer< KisResourceStorage::ResourceIterator > resources(const QString &resourceType) override
QString resourceMd5(const QString &url) override
bool saveAsNewVersion(const QString &resourceType, KoResourceSP resource) override
KisResourceStorage::ResourceItem resourceItem(const QString &url) override
QSharedPointer< KisResourceStorage::TagIterator > tags(const QString &resourceType) override
static KisResourcesInterfaceSP instance()
static KisResourceLoaderRegistry * instance()
static const QString s_meta_author
static const QString s_meta_title
static const QString s_meta_user_defined
static const QString s_meta_creation_date
static const QString s_meta_value
static const QString s_meta_description
static const QString s_meta_dc_date
static const QString s_meta_generator
static const QString s_meta_version
static const QString s_meta_name
static const QString s_meta_initial_creator
static const QString s_meta_creator
virtual KoResourceSP resource(const QString &url)
void sanitizeResourceFileNameCase(KoResourceSP resource, const QDir &parentDir)
static void detectFileVersions(QVector< VersionedResourceEntry > &allFiles)
static bool addVersionedResource(const QString &saveLocation, KoResourceSP resource, int minVersion)
The KisTag loads a tag from a .tag file. A .tag file is a .desktop file. The following fields are imp...
static QString generateHash(const QString &filename)
generateHash reads the given file and generates a hex-encoded md5sum for the file.
QList< ResourceReference > files(const QString &type=QString()) const
A KoResourceBundle is a zip file that contains resources, some metadata about the creator of the bund...
KoResourceBundleManifest & manifest()
QSharedPointer< T > toQShared(T *ptr)
A resource item is simply an entry in the storage,.