mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-28 22:05:03 +00:00
GUI: allow indented JSON via environment variable
This commit is contained in:
parent
cfa061bb0c
commit
bbc429c1ae
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user