Add export format selection (text / json).

This commit is contained in:
John Preston 2018-06-22 00:47:54 +01:00
parent 1a24ba857c
commit 4e0d11f517
5 changed files with 30 additions and 1 deletions

View file

@ -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";

View file

@ -29,8 +29,8 @@ struct Result;
class Stats;
enum class Format {
Json,
Text,
Json,
Yaml,
Html,
};

View file

@ -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];
}

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#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<Ui::RadioenumGroup<Format>>(
_data.format);
formatGroup->setChangedCallback([=](Format format) {
_data.format = format;
});
const auto addFormatOption = [&](LangKey key, Format format) {
const auto radio = content->add(
object_ptr<Ui::Radioenum<Format>>(
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) {

View file

@ -29,6 +29,7 @@ private:
using Types = Settings::Types;
using MediaType = MediaSettings::Type;
using MediaTypes = MediaSettings::Types;
using Format = Output::Format;
void setupContent();
void chooseFolder();