GUI: allow indented JSON via environment variable

This commit is contained in:
Moritz Bunkus 2015-08-11 21:57:09 +02:00
parent cfa061bb0c
commit bbc429c1ae

View File

@ -8,11 +8,24 @@
#include <QJsonValue>
#include <QSettings>
#include <QStack>
#include <QtGlobal>
#include "common/qt.h"
#include "mkvtoolnix-gui/util/json_config_file.h"
namespace mtx { namespace gui { namespace Util {
static QJsonDocument::JsonFormat
jsonFormat() {
static boost::optional<QJsonDocument::JsonFormat> s_jsonFormat;
if (!s_jsonFormat)
s_jsonFormat.reset( QString::fromUtf8(qgetenv("MTX_JSON_FORMAT")).toLower() == Q("indented") ? QJsonDocument::Indented : QJsonDocument::Compact );
return s_jsonFormat.get();
}
class GroupConverter {
protected:
QStack<QJsonObject> m_objects;
@ -123,7 +136,7 @@ JsonConfigFile::save() {
QFile out{m_fileName};
if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
auto doc = GroupConverter::toJson(m_rootGroup);
out.write(doc.toJson(QJsonDocument::Compact));
out.write(doc.toJson(jsonFormat()));
out.close();
}
}