From 4e0d11f5171673dce890e7ab1278700f7c834304 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 22 Jun 2018 00:47:54 +0100 Subject: [PATCH] Add export format selection (text / json). --- Telegram/Resources/langs/lang.strings | 3 +++ .../export/output/export_output_abstract.h | 2 +- .../export/output/export_output_json.cpp | 5 +++++ .../export/view/export_view_settings.cpp | 20 +++++++++++++++++++ .../export/view/export_view_settings.h | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5f4b5e15e112d..fc860c7db1529 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1676,6 +1676,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_export_option_gifs" = "Animated GIFs"; "lng_export_option_files" = "Files"; "lng_export_option_size_limit" = "Size limit: {size}"; +"lng_export_header_format" = "Format"; +"lng_export_option_text" = "Human-readable text"; +"lng_export_option_json" = "Machine-readable JSON"; "lng_export_start" = "Export"; "lng_export_state_initializing" = "Initializing..."; "lng_export_state_userpics" = "Personal photos"; diff --git a/Telegram/SourceFiles/export/output/export_output_abstract.h b/Telegram/SourceFiles/export/output/export_output_abstract.h index dcf581d83b795..7d79658dc1b0b 100644 --- a/Telegram/SourceFiles/export/output/export_output_abstract.h +++ b/Telegram/SourceFiles/export/output/export_output_abstract.h @@ -29,8 +29,8 @@ struct Result; class Stats; enum class Format { - Json, Text, + Json, Yaml, Html, }; diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index f3543e1b37808..70ffe02bcdfbb 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -143,6 +143,9 @@ QByteArray SerializeText( if (data.empty()) { return SerializeString(""); } + + context.nesting.push_back(Context::kArray); + const auto text = ranges::view::all( data ) | ranges::view::transform([&](const Data::TextPart &part) { @@ -187,6 +190,8 @@ QByteArray SerializeText( }); }) | ranges::to_vector; + context.nesting.pop_back(); + if (data.size() == 1 && data[0].type == Data::TextPart::Type::Text) { return text[0]; } diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index b8fa90f80c24e..32701a04e80a1 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -7,6 +7,7 @@ For license and copyright information please follow this link: */ #include "export/view/export_view_settings.h" +#include "export/output/export_output_abstract.h" #include "lang/lang_keys.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" @@ -213,6 +214,25 @@ void SettingsWidget::setupContent() { addSubOption(lng_export_option_files, MediaType::File); createSizeSlider(media); + const auto formatGroup = std::make_shared>( + _data.format); + formatGroup->setChangedCallback([=](Format format) { + _data.format = format; + }); + const auto addFormatOption = [&](LangKey key, Format format) { + const auto radio = content->add( + object_ptr>( + content, + formatGroup, + format, + lang(key), + st::defaultBoxCheckbox), + st::exportSettingPadding); + }; + addHeader(content, lng_export_header_format); + addFormatOption(lng_export_option_text, Format::Text); + addFormatOption(lng_export_option_json, Format::Json); + _dataTypesChanges.events_starting_with_copy( _data.types ) | rpl::start_with_next([=](Settings::Types types) { diff --git a/Telegram/SourceFiles/export/view/export_view_settings.h b/Telegram/SourceFiles/export/view/export_view_settings.h index d5ff669d94392..e6c535a621551 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.h +++ b/Telegram/SourceFiles/export/view/export_view_settings.h @@ -29,6 +29,7 @@ class SettingsWidget : public Ui::RpWidget { using Types = Settings::Types; using MediaType = MediaSettings::Type; using MediaTypes = MediaSettings::Types; + using Format = Output::Format; void setupContent(); void chooseFolder();