Commit 7ba3ffcf authored by Boudewijn Rempt's avatar Boudewijn Rempt

Implement skeleton tag iterators

parent 6f3e934c
......@@ -20,6 +20,27 @@
#include "KisAbrStorage.h"
#include "KisResourceStorage.h"
class AbrTagIterator : public KisResourceStorage::TagIterator
{
public:
AbrTagIterator(const QString &location, const QString &resourceType)
: m_location(location)
, m_resourceType(resourceType)
{}
bool hasNext() const override {return false; }
void next() const override {}
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
private:
QString m_location;
QString m_resourceType;
};
class AbrIterator : public KisResourceStorage::ResourceIterator
{
public:
......@@ -61,3 +82,8 @@ QSharedPointer<KisResourceStorage::ResourceIterator> KisAbrStorage::resources(co
{
return QSharedPointer<KisResourceStorage::ResourceIterator>(new AbrIterator);
}
QSharedPointer<KisResourceStorage::TagIterator> KisAbrStorage::tags(const QString &resourceType)
{
return QSharedPointer<KisResourceStorage::TagIterator>(new AbrTagIterator(location(), resourceType));
}
......@@ -32,6 +32,7 @@ public:
KoResourceSP resource(const QString &url) override;
QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) override;
QSharedPointer<KisResourceStorage::TagIterator> tags(const QString &resourceType) override;
};
......
......@@ -20,6 +20,29 @@
#include "KisAslStorage.h"
#include <KisResourceStorage.h>
class AslTagIterator : public KisResourceStorage::TagIterator
{
public:
AslTagIterator(const QString &location, const QString &resourceType)
: m_location(location)
, m_resourceType(resourceType)
{}
bool hasNext() const override {return false; }
void next() const override {}
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
private:
QString m_location;
QString m_resourceType;
};
class AslIterator : public KisResourceStorage::ResourceIterator
{
public:
......@@ -60,3 +83,8 @@ QSharedPointer<KisResourceStorage::ResourceIterator> KisAslStorage::resources(co
{
return QSharedPointer<KisResourceStorage::ResourceIterator>(new AslIterator);
}
QSharedPointer<KisResourceStorage::TagIterator> KisAslStorage::tags(const QString &resourceType)
{
return QSharedPointer<KisResourceStorage::TagIterator>(new AslTagIterator(location(), resourceType));
}
......@@ -31,7 +31,7 @@ public:
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KoResourceSP resource(const QString &url) override;
QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) override;
QSharedPointer<KisResourceStorage::TagIterator> tags(const QString &resourceType) override;
};
#endif // KISASLSTORAGE_H
......@@ -21,6 +21,29 @@
#include "KisResourceStorage.h"
class BundleTagIterator : public KisResourceStorage::TagIterator
{
public:
BundleTagIterator(const QString &location, const QString &resourceType)
: m_location(location)
, m_resourceType(resourceType)
{}
bool hasNext() const override {return false; }
void next() const override {}
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
private:
QString m_location;
QString m_resourceType;
};
class BundleIterator : public KisResourceStorage::ResourceIterator
{
public:
......@@ -57,5 +80,11 @@ KoResourceSP KisBundleStorage::resource(const QString &url)
QSharedPointer<KisResourceStorage::ResourceIterator> KisBundleStorage::resources(const QString &resourceType)
{
return QSharedPointer<KisResourceStorage::ResourceIterator>(new BundleIterator);
return QSharedPointer<KisResourceStorage::ResourceIterator>(new BundleIterator);
}
QSharedPointer<KisResourceStorage::TagIterator> KisBundleStorage::tags(const QString &resourceType)
{
return QSharedPointer<KisResourceStorage::TagIterator>(new BundleTagIterator(location(), resourceType));
}
......@@ -31,6 +31,7 @@ public:
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KoResourceSP resource(const QString &url) override;
QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) override;
QSharedPointer<KisResourceStorage::TagIterator> tags(const QString &resourceType) override;
};
#endif // KISBUNDLESTORAGE_H
......@@ -25,6 +25,36 @@
#include <KisResourceLoaderRegistry.h>
class FolderTagIterator : public KisResourceStorage::TagIterator
{
public:
FolderTagIterator(const QString &location, const QString &resourceType)
: m_location(location)
, m_resourceType(resourceType)
{
m_dirIterator.reset(new QDirIterator(location + '/' + resourceType,
QStringList() << "*.tag",
QDir::Files | QDir::Readable,
QDirIterator::Subdirectories));
}
bool hasNext() const override {return false; }
void next() const override {}
QString url() const override { return QString(); }
QString name() const override { return QString(); }
QString comment() const override {return QString(); }
private:
QScopedPointer<QDirIterator> m_dirIterator;
QString m_location;
QString m_resourceType;
};
class FolderItem : public KisResourceStorage::ResourceItem
{
public:
......@@ -54,9 +84,9 @@ public:
, m_resourceType(resourceType)
{
m_dirIterator.reset(new QDirIterator(location + '/' + resourceType,
KisResourceLoaderRegistry::instance()->filters(resourceType),
QDir::Files | QDir::Readable,
QDirIterator::Subdirectories));
KisResourceLoaderRegistry::instance()->filters(resourceType),
QDir::Files | QDir::Readable,
QDirIterator::Subdirectories));
}
~FolderIterator() override {}
......@@ -164,3 +194,8 @@ QSharedPointer<KisResourceStorage::ResourceIterator> KisFolderStorage::resources
{
return QSharedPointer<KisResourceStorage::ResourceIterator>(new FolderIterator(location(), resourceType));
}
QSharedPointer<KisResourceStorage::TagIterator> KisFolderStorage::tags(const QString &resourceType)
{
return QSharedPointer<KisResourceStorage::TagIterator>(new FolderTagIterator(location(), resourceType));
}
......@@ -33,6 +33,8 @@ public:
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KoResourceSP resource(const QString &url) override;
QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) override;
QSharedPointer<KisResourceStorage::TagIterator> tags(const QString &resourceType) override;
};
......
......@@ -53,6 +53,20 @@ public:
virtual QByteArray md5sum() const {return QByteArray();}
};
class TagIterator
{
public:
virtual ~TagIterator() {}
virtual bool hasNext() const = 0;
virtual void next() const = 0;
/// The untranslated name of the tag, to be used for making connections to resources
virtual QString url() const = 0;
/// The translated name of the tag, to be shown in the GUI
virtual QString name() const = 0;
/// An extra, optional comment for the tag
virtual QString comment() const = 0;
};
class ResourceIterator
{
......
......@@ -41,6 +41,7 @@ public:
virtual KisResourceStorage::ResourceItem resourceItem(const QString &url) = 0;
virtual KoResourceSP resource(const QString &url) = 0;
virtual QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) = 0;
virtual QSharedPointer<KisResourceStorage::TagIterator> tags(const QString &resourceType) = 0;
protected:
QString location() const;
......
/*
* Copyright (C) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KisTagLoader.h"
KisTagLoader::KisTagLoader()
{
}
/*
* Copyright (C) 2018 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KISTAGLOADER_H
#define KISTAGLOADER_H
/**
* @brief The KisTagLoader loads a tag from a .tag file.
* A .tag file is a .desktop file. The following fields
* are important:
*
* name: the name of the tag, which can be translated
* comment: a tooltip for the tag, which can be translagted
* url: the untranslated name of the tag
*/
class KisTagLoader
{
public:
KisTagLoader();
};
#endif // KISTAGLOADER_H
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