From 009ff9036fbca3346a71dd7204865dced3dd4f7d Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Fri, 13 Jun 2014 11:18:12 -0400 Subject: [PATCH] implemented urlGallery and jsonGallery --- openbr/plugins/gallery.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/openbr/plugins/gallery.cpp b/openbr/plugins/gallery.cpp index f964187..ae7aa93 100644 --- a/openbr/plugins/gallery.cpp +++ b/openbr/plugins/gallery.cpp @@ -14,8 +14,7 @@ * limitations under the License. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include -#include +#include #include #ifndef BR_EMBEDDED #include @@ -264,6 +263,64 @@ BR_REGISTER(Gallery, utdGallery) /*! * \ingroup galleries + * \brief Newline-separated URLs. + * \author Josh Klontz \cite jklontz + */ +class urlGallery : public BinaryGallery +{ + Q_OBJECT + + Template readTemplate() + { + Template t; + t.file.set("URL", QString::fromLocal8Bit(gallery.readLine()).simplified()); + return t; + } + + void write(const Template &t) + { + const QString url = t.file.get("URL", ""); + if (!url.isEmpty()) { + gallery.write(qPrintable(url)); + gallery.write("\n"); + } + } +}; + +BR_REGISTER(Gallery, urlGallery) + +/*! + * \ingroup galleries + * \brief Newline-separated JSON objects. + * \author Josh Klontz \cite jklontz + */ +class jsonGallery : public BinaryGallery +{ + Q_OBJECT + + Template readTemplate() + { + QJsonParseError error; + File file = QJsonDocument::fromJson(gallery.readLine(), &error).object().toVariantMap(); + if (error.error != QJsonParseError::NoError) + qDebug() << error.errorString(); + return file; + } + + void write(const Template &t) + { + const QByteArray json = QJsonDocument(QJsonObject::fromVariantMap(t.file.localMetadata())).toJson(QJsonDocument::Compact); + if (!json.isEmpty()) { + gallery.write(json); + gallery.write("\n"); + } + } +}; + +BR_REGISTER(Gallery, jsonGallery) + +/*! + * \ingroup galleries * \brief Reads/writes templates to/from folders. * \author Josh Klontz \cite jklontz * \param regexp An optional regular expression to match against the files extension. -- libgit2 0.21.4