Commit 63823205 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add skeleton for specialized storage plugins

parent 309cce59
......@@ -7,6 +7,12 @@ set(kritaresources_LIB_SRCS
KisResourceLocator.cpp
KisResourceStorage.cpp
KisStoragePlugin.cpp
KisAbrStorage.cpp
KisAslStorage.cpp
KisBundleStorage.cpp
KisFolderStorage.cpp
KoResource.cpp
KoMD5Generator.cpp
KoHashGeneratorProvider.cpp
......
/*
* 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 "KisAbrStorage.h"
KisAbrStorage::KisAbrStorage(const QString &location)
: KisStoragePlugin(location)
{
}
KisAbrStorage::~KisAbrStorage()
{
}
KisResourceStorage::ResourceItem KisAbrStorage::resourceItem(const QString &url)
{
return KisResourceStorage::ResourceItem();
}
KisResourceStorage::ResourceItemIterator KisAbrStorage::resourceItems(const QString &resourceType)
{
return KisResourceStorage::ResourceItemIterator();
}
KoResourceSP KisAbrStorage::resource(const QString &url)
{
return 0;
}
KisResourceStorage::ResourceIterator KisAbrStorage::resources(const QString &resourceType)
{
return KisResourceStorage::ResourceIterator();
}
/*
* 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 KISABRSTORAGE_H
#define KISABRSTORAGE_H
#include <KisStoragePlugin.h>
class KisAbrStorage : public KisStoragePlugin
{
public:
KisAbrStorage(const QString &location);
virtual ~KisAbrStorage();
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KisResourceStorage::ResourceItemIterator resourceItems(const QString &resourceType) override;
KoResourceSP resource(const QString &url) override;
KisResourceStorage::ResourceIterator resources(const QString &resourceType) override;
};
#endif // KISABRSTORAGE_H
/*
* 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 "KisAslStorage.h"
KisAslStorage::KisAslStorage(const QString &location)
: KisStoragePlugin(location)
{
}
KisAslStorage::~KisAslStorage()
{
}
KisResourceStorage::ResourceItem KisAslStorage::resourceItem(const QString &url)
{
return KisResourceStorage::ResourceItem();
}
KisResourceStorage::ResourceItemIterator KisAslStorage::resourceItems(const QString &resourceType)
{
return KisResourceStorage::ResourceItemIterator();
}
KoResourceSP KisAslStorage::resource(const QString &url)
{
return 0;
}
KisResourceStorage::ResourceIterator KisAslStorage::resources(const QString &resourceType)
{
return KisResourceStorage::ResourceIterator();
}
/*
* 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 KISASLSTORAGE_H
#define KISASLSTORAGE_H
#include <KisStoragePlugin.h>
class KisAslStorage : public KisStoragePlugin
{
public:
KisAslStorage(const QString &location);
virtual ~KisAslStorage();
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KisResourceStorage::ResourceItemIterator resourceItems(const QString &resourceType) override;
KoResourceSP resource(const QString &url) override;
KisResourceStorage::ResourceIterator resources(const QString &resourceType) override;
};
#endif // KISASLSTORAGE_H
/*
* 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 "KisBundleStorage.h"
KisBundleStorage::KisBundleStorage(const QString &location)
: KisStoragePlugin(location)
{
}
KisBundleStorage::~KisBundleStorage()
{
}
KisResourceStorage::ResourceItem KisBundleStorage::resourceItem(const QString &url)
{
return KisResourceStorage::ResourceItem();
}
KisResourceStorage::ResourceItemIterator KisBundleStorage::resourceItems(const QString &resourceType)
{
return KisResourceStorage::ResourceItemIterator();
}
KoResourceSP KisBundleStorage::resource(const QString &url)
{
return 0;
}
KisResourceStorage::ResourceIterator KisBundleStorage::resources(const QString &resourceType)
{
return KisResourceStorage::ResourceIterator();
}
/*
* 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 KISBUNDLESTORAGE_H
#define KISBUNDLESTORAGE_H
#include <KisStoragePlugin.h>
class KisBundleStorage : public KisStoragePlugin
{
public:
KisBundleStorage(const QString &location);
virtual ~KisBundleStorage();
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KisResourceStorage::ResourceItemIterator resourceItems(const QString &resourceType) override;
KoResourceSP resource(const QString &url) override;
KisResourceStorage::ResourceIterator resources(const QString &resourceType) override;
};
#endif // KISBUNDLESTORAGE_H
/*
* 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 "KisFolderStorage.h"
KisFolderStorage::KisFolderStorage(const QString &location)
: KisStoragePlugin(location)
{
}
KisFolderStorage::~KisFolderStorage()
{
}
KisResourceStorage::ResourceItem KisFolderStorage::resourceItem(const QString &url)
{
return KisResourceStorage::ResourceItem();
}
KisResourceStorage::ResourceItemIterator KisFolderStorage::resourceItems(const QString &resourceType)
{
return KisResourceStorage::ResourceItemIterator();
}
KoResourceSP KisFolderStorage::resource(const QString &url)
{
return 0;
}
KisResourceStorage::ResourceIterator KisFolderStorage::resources(const QString &resourceType)
{
return KisResourceStorage::ResourceIterator();
}
/*
* 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 KISFOLDERSTORAGE_H
#define KISFOLDERSTORAGE_H
#include <KisStoragePlugin.h>
class KisFolderStorage : public KisStoragePlugin
{
public:
KisFolderStorage(const QString &location);
virtual ~KisFolderStorage();
KisResourceStorage::ResourceItem resourceItem(const QString &url) override;
KisResourceStorage::ResourceItemIterator resourceItems(const QString &resourceType) override;
KoResourceSP resource(const QString &url) override;
KisResourceStorage::ResourceIterator resources(const QString &resourceType) override;
};
#endif // KISFOLDERSTORAGE_H
......@@ -255,9 +255,23 @@ bool KisResourceCacheDb::initialize(const QString &location)
return s_valid;
}
bool KisResourceCacheDb::addResource(KoResourceSP resource)
{
// XXX
return false;
}
bool KisResourceCacheDb::addResources(KisResourceStorageSP storage, QString folder)
{
qDebug() << folder << storage->resources(folder).count();
KisResourceStorage::ResourceIterator iter = storage->resources(folder);
while(iter.hasNext()) {
iter.next();
KoResourceSP res = iter.resource();
if (!addResource(res)) {
qWarning() << "Could not add resource" << res->filename() << "to the database";
}
}
return true;
}
......
......@@ -66,6 +66,7 @@ private:
~KisResourceCacheDb();
KisResourceCacheDb operator=(const KisResourceCacheDb&);
static bool addResource(KoResourceSP resource);
static bool addResources(KisResourceStorageSP storage, QString folder);
static bool addStorage(KisResourceStorageSP storage, bool preinstalled);
static bool synchronize(KisResourceStorageSP storage);
......
......@@ -19,9 +19,15 @@
#include "KisResourceStorage.h"
#include <QFileInfo>
#include <kzip.h>
#include <QFileInfo>
#include "KisStoragePlugin.h"
#include "KisFolderStorage.h"
#include "KisBundleStorage.h"
#include "KisAbrStorage.h"
#include "KisAslStorage.h"
class KisResourceStorage::Private {
public:
......@@ -29,6 +35,7 @@ public:
QString location;
bool valid {false};
KisResourceStorage::StorageType storageType {KisResourceStorage::StorageType::Unknown};
QScopedPointer<KisStoragePlugin> storagePlugin;
};
......@@ -38,21 +45,25 @@ KisResourceStorage::KisResourceStorage(const QString &location)
d->location = location;
QFileInfo fi(d->location);
if (fi.isDir()) {
d->storagePlugin.reset(new KisFolderStorage(location));
d->name = location;
d->storageType = StorageType::Folder;
d->valid = fi.isWritable();
}
else {
if (d->location.endsWith(".bundle")) {
d->storagePlugin.reset(new KisBundleStorage(location));
d->storageType = StorageType::Bundle;
// XXX: should we also check whether there's a valid metadata entry? Or is this enough?
d->valid = (fi.isReadable() && KZip(d->location).open(QIODevice::ReadOnly));
}
else if (d->location.endsWith(".abr")) {
d->storagePlugin.reset(new KisAbrStorage(location));
d->storageType = StorageType::AdobeBrushLibrary;
d->valid = fi.isReadable();
}
else if (d->location.endsWith(".asl")) {
d->storagePlugin.reset(new KisAslStorage(location));
d->storageType = StorageType::AdobeStyleLibrary;
d->valid = fi.isReadable();
}
......@@ -83,14 +94,24 @@ QDateTime KisResourceStorage::timestamp() const
return QFileInfo(d->location).lastModified();
}
KisResourceStorage::ResourceItem KisResourceStorage::resourceItem(const QString &url)
{
return d->storagePlugin->resourceItem(url);
}
KisResourceStorage::ResourceItemIterator KisResourceStorage::resourceItems(const QString &resourceType)
{
return d->storagePlugin->resourceItems(resourceType);
}
KoResourceSP KisResourceStorage::resource(const QString &url)
{
return 0;
return d->storagePlugin->resource(url);
}
QVector<KoResourceSP> KisResourceStorage::resources(const QString &resourceType)
KisResourceStorage::ResourceIterator KisResourceStorage::resources(const QString &resourceType)
{
return QVector<KoResourceSP>();
return d->storagePlugin->resources(resourceType);
}
......
......@@ -30,6 +30,7 @@
#include <kritaresources_export.h>
/**
* The KisResourceStorage class is the base class for
* places where resources can be stored. Examples are
......@@ -40,9 +41,42 @@ class KRITARESOURCES_EXPORT KisResourceStorage
{
public:
/// XXX: replace the default implementations with = 0 when all iterators have been implemented
/// A resource item is simply an entry in the storage,
struct ResourceItem {
virtual ~ResourceItem() {}
QString url;
QString type;
QDateTime lastModified;
virtual QByteArray md5sum() const {return QByteArray();}
};
class ResourceItemIterator
{
public:
virtual ~ResourceItemIterator() {}
virtual bool hasNext() const {return false;};
virtual void next() const{};
virtual QString url() const {return QString();}
virtual QString type() const {return QString();}
virtual QDateTime lastModified() const {return QDateTime();}
virtual QByteArray md5sum() const {return QByteArray();}
};
class ResourceIterator : public ResourceItemIterator
{
public:
virtual ~ResourceIterator() {}
virtual KoResourceSP resource() const {return 0;}
};
enum class StorageType : int {
......@@ -62,8 +96,12 @@ public:
StorageType type() const;
QDateTime timestamp() const;
ResourceItem resourceItem(const QString &url);
ResourceItemIterator resourceItems(const QString &resourceType);
KoResourceSP resource(const QString &url);
QVector<KoResourceSP> resources(const QString &resourceType);
ResourceIterator resources(const QString &resourceType);
private:
class Private;
......
/*
* 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 "KisStoragePlugin.h"
class KisStoragePlugin::Private
{
public:
QString location;
};
KisStoragePlugin::KisStoragePlugin(const QString &location)
: d(new Private())
{
d->location = location;
}
KisStoragePlugin::~KisStoragePlugin()
{
}
QString KisStoragePlugin::location() const
{
return d->location;
}
/*
* 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 KISSTORAGEPLUGIN_H
#define KISSTORAGEPLUGIN_H
#include <QScopedPointer>
#include <QString>
#include <KisResourceStorage.h>
/**
* The KisResourceStoragePlugin class is the base class
* for storage plugins. A storage plugin is used by
* KisResourceStorage to locate resources and tags in
* a kind of storage, like a folder, a bundle or an adobe
* resource library.
*/
class KisStoragePlugin
{
public:
KisStoragePlugin(const QString &location);
virtual ~KisStoragePlugin();
virtual KisResourceStorage::ResourceItem resourceItem(const QString &url) = 0;
virtual KisResourceStorage::ResourceItemIterator resourceItems(const QString &resourceType) = 0;
virtual KoResourceSP resource(const QString &url) = 0;
virtual KisResourceStorage::ResourceIterator resources(const QString &resourceType) = 0;
protected:
QString location() const;
private:
class Private;
QScopedPointer<Private> d;
};
#endif // KISSTORAGEPLUGIN_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