Commit 009ff9036fbca3346a71dd7204865dced3dd4f7d
1 parent
faf0f17f
implemented urlGallery and jsonGallery
Showing
1 changed file
with
59 additions
and
2 deletions
openbr/plugins/gallery.cpp
| ... | ... | @@ -14,8 +14,7 @@ |
| 14 | 14 | * limitations under the License. * |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | -#include <QCryptographicHash> | |
| 18 | -#include <QRegularExpression> | |
| 17 | +#include <QtCore> | |
| 19 | 18 | #include <QtConcurrentRun> |
| 20 | 19 | #ifndef BR_EMBEDDED |
| 21 | 20 | #include <QNetworkAccessManager> |
| ... | ... | @@ -264,6 +263,64 @@ BR_REGISTER(Gallery, utdGallery) |
| 264 | 263 | |
| 265 | 264 | /*! |
| 266 | 265 | * \ingroup galleries |
| 266 | + * \brief Newline-separated URLs. | |
| 267 | + * \author Josh Klontz \cite jklontz | |
| 268 | + */ | |
| 269 | +class urlGallery : public BinaryGallery | |
| 270 | +{ | |
| 271 | + Q_OBJECT | |
| 272 | + | |
| 273 | + Template readTemplate() | |
| 274 | + { | |
| 275 | + Template t; | |
| 276 | + t.file.set("URL", QString::fromLocal8Bit(gallery.readLine()).simplified()); | |
| 277 | + return t; | |
| 278 | + } | |
| 279 | + | |
| 280 | + void write(const Template &t) | |
| 281 | + { | |
| 282 | + const QString url = t.file.get<QString>("URL", ""); | |
| 283 | + if (!url.isEmpty()) { | |
| 284 | + gallery.write(qPrintable(url)); | |
| 285 | + gallery.write("\n"); | |
| 286 | + } | |
| 287 | + } | |
| 288 | +}; | |
| 289 | + | |
| 290 | +BR_REGISTER(Gallery, urlGallery) | |
| 291 | + | |
| 292 | +/*! | |
| 293 | + * \ingroup galleries | |
| 294 | + * \brief Newline-separated JSON objects. | |
| 295 | + * \author Josh Klontz \cite jklontz | |
| 296 | + */ | |
| 297 | +class jsonGallery : public BinaryGallery | |
| 298 | +{ | |
| 299 | + Q_OBJECT | |
| 300 | + | |
| 301 | + Template readTemplate() | |
| 302 | + { | |
| 303 | + QJsonParseError error; | |
| 304 | + File file = QJsonDocument::fromJson(gallery.readLine(), &error).object().toVariantMap(); | |
| 305 | + if (error.error != QJsonParseError::NoError) | |
| 306 | + qDebug() << error.errorString(); | |
| 307 | + return file; | |
| 308 | + } | |
| 309 | + | |
| 310 | + void write(const Template &t) | |
| 311 | + { | |
| 312 | + const QByteArray json = QJsonDocument(QJsonObject::fromVariantMap(t.file.localMetadata())).toJson(QJsonDocument::Compact); | |
| 313 | + if (!json.isEmpty()) { | |
| 314 | + gallery.write(json); | |
| 315 | + gallery.write("\n"); | |
| 316 | + } | |
| 317 | + } | |
| 318 | +}; | |
| 319 | + | |
| 320 | +BR_REGISTER(Gallery, jsonGallery) | |
| 321 | + | |
| 322 | +/*! | |
| 323 | + * \ingroup galleries | |
| 267 | 324 | * \brief Reads/writes templates to/from folders. |
| 268 | 325 | * \author Josh Klontz \cite jklontz |
| 269 | 326 | * \param regexp An optional regular expression to match against the files extension. | ... | ... |