Commit b11525db authored by Boudewijn Rempt's avatar Boudewijn Rempt

Rename KisTagLoader to KisTag

It can also save...
parent 7ce7a21c
......@@ -13,7 +13,7 @@ set(kritaresources_LIB_SRCS
KisBundleStorage.cpp
KisFolderStorage.cpp
KisTagLoader.cpp
KisTag.cpp
KoResource.cpp
KoMD5Generator.cpp
......
......@@ -34,7 +34,7 @@ public:
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
QSharedPointer<KisTag> tag() const override { return 0; }
private:
QString m_location;
......
......@@ -35,6 +35,7 @@ public:
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
QSharedPointer<KisTag> tag() const override { return 0; }
private:
......
......@@ -36,7 +36,7 @@ public:
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
QSharedPointer<KisTag> tag() const override { return 0; }
private:
......
......@@ -22,6 +22,7 @@
#include <QDirIterator>
#include <KisMimeDatabase.h>
#include <kis_debug.h>
#include <KisTag.h>
#include <KisResourceLoaderRegistry.h>
......@@ -40,18 +41,42 @@ public:
}
bool hasNext() const override { return m_dirIterator->hasNext(); }
void next() const override { m_dirIterator->next(); }
void next() const override
{
m_dirIterator->next();
load(const_cast<KisTag*>(&m_tag));
}
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
QString url() const override { return m_tag.url(); }
QString name() const override { return m_tag.name(); }
QString comment() const override {return m_tag.comment(); }
QSharedPointer<KisTag> tag() const
{
QSharedPointer<KisTag> t(new KisTag());
load(t.data());
return t;
}
private:
bool load(KisTag *tag) const
{
QFile f(m_dirIterator->filePath());
if (f.exists()) {
f.open(QFile::ReadOnly);
if (!tag->load(f)) {
qWarning() << m_dirIterator << "is not a valid tag desktop file";
return false;
}
}
return true;
}
QScopedPointer<QDirIterator> m_dirIterator;
QString m_location;
QString m_resourceType;
KisTag m_tag;
};
......@@ -140,18 +165,18 @@ protected:
if (!m_resource || (m_resource && m_resource->filename() != m_dirIterator->filePath())) {
QFile f(m_dirIterator->filePath());
f.open(QFile::ReadOnly);
if (!m_loader) {
const_cast<FolderIterator*>(this)->m_loader = KisResourceLoaderRegistry::instance()->loader(m_resourceType, KisMimeDatabase::mimeTypeForFile(m_dirIterator->filePath()));
if (!m_tag) {
const_cast<FolderIterator*>(this)->m_tag = KisResourceLoaderRegistry::instance()->loader(m_resourceType, KisMimeDatabase::mimeTypeForFile(m_dirIterator->filePath()));
}
if (m_loader) {
const_cast<FolderIterator*>(this)->m_resource = m_loader->load(m_dirIterator->filePath(), f);
if (m_tag) {
const_cast<FolderIterator*>(this)->m_resource = m_tag->load(m_dirIterator->filePath(), f);
}
f.close();
}
return !m_resource.isNull();
}
KisResourceLoaderBase *m_loader {0};
KisResourceLoaderBase *m_tag {0};
KoResourceSP m_resource;
QScopedPointer<QDirIterator> m_dirIterator;
const QString m_location;
......
......@@ -27,6 +27,8 @@
#include <KoResource.h>
#include <KisTag.h>
#include <kritaresources_export.h>
......@@ -66,6 +68,9 @@ public:
virtual QString name() const = 0;
/// An extra, optional comment for the tag
virtual QString comment() const = 0;
/// A tag object on which we can set properties and which we can save
virtual QSharedPointer<KisTag> tag() const = 0;
};
class ResourceIterator
......
......@@ -17,7 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include "KisTagLoader.h"
#include "KisTag.h"
#include <QIODevice>
#include <QLocale>
......@@ -32,14 +32,14 @@
#include <kis_debug.h>
const QByteArray KisTagLoader::s_group {"Desktop Entry"};
const QByteArray KisTagLoader::s_type {"Type"};
const QByteArray KisTagLoader::s_tag {"Tag"};
const QByteArray KisTagLoader::s_name {"Name"};
const QByteArray KisTagLoader::s_url {"URL"};
const QByteArray KisTagLoader::s_comment {"Comment"};
const QByteArray KisTag::s_group {"Desktop Entry"};
const QByteArray KisTag::s_type {"Type"};
const QByteArray KisTag::s_tag {"Tag"};
const QByteArray KisTag::s_name {"Name"};
const QByteArray KisTag::s_url {"URL"};
const QByteArray KisTag::s_comment {"Comment"};
class KisTagLoader::Private {
class KisTag::Private {
public:
QString url;
QString name;
......@@ -135,50 +135,50 @@ public:
};
KisTagLoader::KisTagLoader()
KisTag::KisTag()
: d(new Private)
{
}
KisTagLoader::~KisTagLoader()
KisTag::~KisTag()
{
}
QString KisTagLoader::name() const
QString KisTag::name() const
{
return d->name;
}
void KisTagLoader::setName(const QString &name) const
void KisTag::setName(const QString &name) const
{
d->map.setEntry(s_group, s_name, name, KEntryMap::EntryDirty);
d->name = name;
}
QString KisTagLoader::url() const
QString KisTag::url() const
{
return d->url;
}
void KisTagLoader::setUrl(const QString &url) const
void KisTag::setUrl(const QString &url) const
{
d->map.setEntry(s_group, s_url, url, KEntryMap::EntryDirty);
d->url = url;
}
QString KisTagLoader::comment() const
QString KisTag::comment() const
{
return d->comment;
}
void KisTagLoader::setComment(const QString &comment) const
void KisTag::setComment(const QString &comment) const
{
d->map.setEntry(s_group, s_comment, comment, KEntryMap::EntryDirty);
d->comment = comment;
}
bool KisTagLoader::load(QIODevice &io)
bool KisTag::load(QIODevice &io)
{
if (!io.isOpen()) {
io.open(QIODevice::ReadOnly);
......@@ -205,7 +205,7 @@ bool KisTagLoader::load(QIODevice &io)
return true;
}
bool KisTagLoader::save(QIODevice &io)
bool KisTag::save(QIODevice &io)
{
KConfigIniBackend ini;
ini.writeEntries(QLocale().name().toUtf8(), io, d->map);
......
......@@ -23,7 +23,7 @@
#include <QString>
#include <QScopedPointer>
/**
* @brief The KisTagLoader loads a tag from a .tag file.
* @brief The KisTag loads a tag from a .tag file.
* A .tag file is a .desktop file. The following fields
* are important:
*
......@@ -36,11 +36,11 @@ class QIODevice;
#include "kritaresources_export.h"
class KRITARESOURCES_EXPORT KisTagLoader
class KRITARESOURCES_EXPORT KisTag
{
public:
KisTagLoader();
virtual ~KisTagLoader();
KisTag();
virtual ~KisTag();
QString name() const;
void setName(const QString &name) const;
......
......@@ -21,7 +21,7 @@
#include <QTest>
#include <QBuffer>
#include <KisTagLoader.h>
#include <KisTag.h>
#include <KisResourceLoader.h>
#include <KoResource.h>
#include <KisResourceLoaderRegistry.h>
......@@ -32,7 +32,7 @@
void TestTagLoader ::testLoadTag()
{
KisTagLoader tagLoader;
KisTag tagLoader;
QFile f(QString(FILES_DATA_DIR) + "paintoppresets/test.desktop");
QVERIFY(f.exists());
......@@ -66,7 +66,7 @@ void TestTagLoader ::testLoadTag()
void TestTagLoader::testSaveTag()
{
KisTagLoader tagLoader;
KisTag tagLoader;
QFile f(QString(FILES_DATA_DIR) + "paintoppresets/test.desktop");
QVERIFY(f.exists());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment