Commit f756d65d23cfb60301b85e711615a1b49e7e2469
1 parent
c4c4e5ad
first draft of new jsonGallery
Showing
2 changed files
with
74 additions
and
2 deletions
openbr/plugins/gallery/binary.cpp
| ... | ... | @@ -261,7 +261,7 @@ BR_REGISTER(Gallery, urlGallery) |
| 261 | 261 | * \brief Newline-separated JSON objects. |
| 262 | 262 | * \author Josh Klontz \cite jklontz |
| 263 | 263 | */ |
| 264 | -class jsonGallery : public BinaryGallery | |
| 264 | +class jsonObjectGallery : public BinaryGallery | |
| 265 | 265 | { |
| 266 | 266 | Q_OBJECT |
| 267 | 267 | |
| ... | ... | @@ -289,7 +289,7 @@ class jsonGallery : public BinaryGallery |
| 289 | 289 | } |
| 290 | 290 | }; |
| 291 | 291 | |
| 292 | -BR_REGISTER(Gallery, jsonGallery) | |
| 292 | +BR_REGISTER(Gallery, jsonObjectGallery) | |
| 293 | 293 | |
| 294 | 294 | } // namespace br |
| 295 | 295 | ... | ... |
openbr/plugins/gallery/json.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2017 Rank One Computing Corporation * | |
| 3 | + * * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 5 | + * you may not use this file except in compliance with the License. * | |
| 6 | + * You may obtain a copy of the License at * | |
| 7 | + * * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 9 | + * * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software * | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 13 | + * See the License for the specific language governing permissions and * | |
| 14 | + * limitations under the License. * | |
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 16 | + | |
| 17 | +#include <QJsonArray> | |
| 18 | +#include <QJsonDocument> | |
| 19 | +#include <QJsonObject> | |
| 20 | +#include <openbr/plugins/openbr_internal.h> | |
| 21 | + | |
| 22 | +namespace br | |
| 23 | +{ | |
| 24 | + | |
| 25 | +/*! | |
| 26 | + * \ingroup galleries | |
| 27 | + * \brief Treats the file as a JSON document. | |
| 28 | + * \author Josh Klontz \cite jklontz | |
| 29 | + */ | |
| 30 | +class jsonGallery : public FileGallery | |
| 31 | +{ | |
| 32 | + Q_OBJECT | |
| 33 | + Q_PROPERTY(QString label READ get_label WRITE set_label RESET reset_label STORED false) | |
| 34 | + BR_PROPERTY(QString, label, "PersonID") | |
| 35 | + | |
| 36 | + TemplateList readBlock(bool *done) | |
| 37 | + { | |
| 38 | + *done = true; | |
| 39 | + | |
| 40 | + if (!readOpen()) | |
| 41 | + qFatal("Failed to open JSON file!"); | |
| 42 | + | |
| 43 | + QJsonParseError jsonParseError; | |
| 44 | + const QJsonDocument jsonDocument = QJsonDocument::fromJson(f.readAll(), &jsonParseError); | |
| 45 | + if (jsonParseError.error != QJsonParseError::NoError) | |
| 46 | + qFatal("%s", qPrintable(jsonParseError.error)); | |
| 47 | + | |
| 48 | + if (!jsonDocument.isArray()) | |
| 49 | + qFatal("Expected JSON document to be an array!"); | |
| 50 | + | |
| 51 | + TemplateList result; | |
| 52 | + foreach (const QJsonValue &value, jsonDocument.array()) { | |
| 53 | + File file(value.toObject().toVariantMap()); | |
| 54 | + if (!label.isEmpty() && file.contains(label)) | |
| 55 | + file.set("Label", file.get<QString>(label)); | |
| 56 | + result.append(file); | |
| 57 | + } | |
| 58 | + | |
| 59 | + return result; | |
| 60 | + } | |
| 61 | + | |
| 62 | + void write(const Template &) | |
| 63 | + { | |
| 64 | + qFatal("Not implemented!"); | |
| 65 | + } | |
| 66 | +}; | |
| 67 | + | |
| 68 | +BR_REGISTER(Gallery, jsonGallery) | |
| 69 | + | |
| 70 | +} // namespace br | |
| 71 | + | |
| 72 | +#include "gallery/json.moc" | ... | ... |