Skip to content

Commit

Permalink
Add export format selection (text / json).
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 21, 2018
1 parent 1a24ba8 commit 4e0d11f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct Result;
class Stats;

enum class Format {
Json,
Text,
Json,
Yaml,
Html,
};
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/export/output/export_output_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
}
Expand Down
20 changes: 20 additions & 0 deletions Telegram/SourceFiles/export/view/export_view_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/export/view/export_view_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4e0d11f

Please sign in to comment.