11#include <QDomDocument>
14#include <QDomNodeList>
25 if (type.startsWith(
"ko_")) {
28 else if (type.startsWith(
"kis_")) {
56 if (!device->isOpen()) {
57 if (!device->open(QIODevice::ReadOnly)) {
62 QDomDocument manifestDocument;
66 if (!manifestDocument.setContent(device,
true, &errorMessage, &errorLine, &errorColumn)) {
67 warnKrita <<
"Error parsing manifest" << errorMessage
68 <<
"line" << errorLine
69 <<
"column" << errorColumn;
73 QDomElement root = manifestDocument.documentElement();
78 QDomElement e = root.firstChildElement(
"file-entry");
79 for (; !e.isNull(); e = e.nextSiblingElement(
"file-entry")) {
81 warnKrita <<
"Skipping invalid manifest entry"
82 <<
"line" << e.lineNumber();
100 if (fullPath ==
"/" && mediaType ==
"application/x-krita-resourcebundle") {
104 }
else if (fullPath.isNull() || mediaType.isNull() || md5sum.isNull()) {
109 QDomElement t = e.firstChildElement(
"tags")
110 .firstChildElement(
"tag");
111 for (; !t.isNull(); t = t.nextSiblingElement(
"tag")) {
112 QString tag = t.text();
118 addResource(mediaType, fullPath, tagList, QByteArray::fromHex(md5sum.toLatin1()), -1);
124 if (!device->isOpen()) {
125 if (!device->open(QIODevice::WriteOnly)) {
136 Q_FOREACH (QString resourceType,
m_resources.keys()) {
144 if (!resource.
tagList.isEmpty()) {
146 Q_FOREACH (
const QString tag, resource.
tagList) {
165 ResourceReference ref(fileName, fileTagList, fileTypeName, md5, resourceId, filenameInBundle);
167 m_resources[fileTypeName] = QMap<QString, ResourceReference>();
189 Q_FOREACH (
const QString &type,
m_resources.keys()) {
201 if (type.isEmpty()) {
203 Q_FOREACH (
const QString &type,
m_resources.keys()) {
216 Q_FOREACH (
const QString &type,
m_resources.keys()) {
QList< QString > QStringList
QString manifestTypeToResourceType(const QString &type)
QString resourceTypeToManifestType(const QString &type)
QStringList types() const
void removeFile(QString fileName)
removeFile : remove a file from the manifest
bool save(QIODevice *device)
save the ResourceBundleManifest to the given device
virtual ~KoResourceBundleManifest()
~ResourceBundleManifest : Dtor
bool parseFileEntry(const QDomElement &e)
KoResourceBundleManifest()
ResourceBundleManifest : Ctor.
bool load(QIODevice *device)
load the ResourceBundleManifest from the given device
QMap< QString, QMap< QString, ResourceReference > > m_resources
void removeResource(ResourceReference &resource)
void addResource(const QString &fileType, const QString &fileName, const QStringList &tagFileList, const QString &md5, const int resourceId=-1, const QString filenameInBundle="")
addTag : Add a file tag as a child of the fileType tag.
QList< ResourceReference > files(const QString &type=QString()) const
static const QString manifest
void addManifestEntry(const QString &fullPath, const QString &mediaType)
void startElement(const char *tagName, bool indentInside=true)
void endDocument()
Call this to terminate an XML document.
void startDocument(const char *rootElemName, const char *publicId=0, const char *systemId=0)
void addTextNode(const QString &str)
void addAttribute(const char *attrName, const QString &value)