Compare commits
3 Commits
dev
...
bothExport
Author | SHA1 | Date |
---|---|---|
mrbesen | 580f103512 | |
mrbesen | 62a8eeac77 | |
mrbesen | 3bad69fbaa |
|
@ -3525,6 +3525,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_export_option_choose_format" = "Choose export format";
|
||||
"lng_export_option_html" = "Human-readable HTML";
|
||||
"lng_export_option_json" = "Machine-readable JSON";
|
||||
"lng_export_option_both" = "Both";
|
||||
"lng_export_limits" = "From: {from}, to: {till}";
|
||||
"lng_export_beginning" = "the oldest message";
|
||||
"lng_export_end" = "present";
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "export/output/export_output_html.h"
|
||||
#include "export/output/export_output_json.h"
|
||||
#include "export/output/export_output_both.h"
|
||||
#include "export/output/export_output_stats.h"
|
||||
#include "export/output/export_output_result.h"
|
||||
|
||||
|
@ -50,6 +51,7 @@ std::unique_ptr<AbstractWriter> CreateWriter(Format format) {
|
|||
switch (format) {
|
||||
case Format::Html: return std::make_unique<HtmlWriter>();
|
||||
case Format::Json: return std::make_unique<JsonWriter>();
|
||||
case Format::Both: return std::make_unique<BothWriter>();
|
||||
}
|
||||
Unexpected("Format in Export::Output::CreateWriter.");
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class Stats;
|
|||
enum class Format {
|
||||
Html,
|
||||
Json,
|
||||
Both,
|
||||
};
|
||||
|
||||
class AbstractWriter {
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "export/output/export_output_both.h"
|
||||
|
||||
#include "export/output/export_output_result.h"
|
||||
#include "export/output/export_output_html.h"
|
||||
#include "export/output/export_output_json.h"
|
||||
|
||||
namespace Export {
|
||||
namespace Output {
|
||||
|
||||
BothWriter::BothWriter() {
|
||||
_html = std::make_shared<HtmlWriter>();
|
||||
_json = std::make_shared<JsonWriter>();
|
||||
}
|
||||
|
||||
Result BothWriter::start(
|
||||
const Settings &settings,
|
||||
const Environment &environment,
|
||||
Stats *stats) {
|
||||
Expects(_html != nullptr);
|
||||
Expects(_json != nullptr);
|
||||
|
||||
Result res = _html->start(settings, environment, stats);
|
||||
if(res.isError()) {
|
||||
return res;
|
||||
}
|
||||
return _json->start(settings, environment, stats);
|
||||
}
|
||||
|
||||
Result BothWriter::writePersonal(const Data::PersonalInfo &data) {
|
||||
return runForBoth<Data::PersonalInfo, &AbstractWriter::writePersonal>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeUserpicsStart(const Data::UserpicsInfo &data) {
|
||||
return runForBoth<Data::UserpicsInfo, &AbstractWriter::writeUserpicsStart>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeUserpicsSlice(const Data::UserpicsSlice &data) {
|
||||
return runForBoth<Data::UserpicsSlice, &AbstractWriter::writeUserpicsSlice>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeUserpicsEnd() {
|
||||
return runForBoth<&AbstractWriter::writeUserpicsEnd>();
|
||||
}
|
||||
|
||||
Result BothWriter::writeContactsList(const Data::ContactsList &data) {
|
||||
return runForBoth<Data::ContactsList, &AbstractWriter::writeContactsList>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeSessionsList(const Data::SessionsList &data) {
|
||||
return runForBoth<Data::SessionsList, &AbstractWriter::writeSessionsList>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeOtherData(const Data::File &data) {
|
||||
return runForBoth<Data::File, &AbstractWriter::writeOtherData>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeDialogsStart(const Data::DialogsInfo &data) {
|
||||
return runForBoth<Data::DialogsInfo, &AbstractWriter::writeDialogsStart>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeDialogStart(const Data::DialogInfo &data) {
|
||||
return runForBoth<Data::DialogInfo, &AbstractWriter::writeDialogStart>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeDialogSlice(const Data::MessagesSlice &data) {
|
||||
return runForBoth<Data::MessagesSlice, &AbstractWriter::writeDialogSlice>(data);
|
||||
}
|
||||
|
||||
Result BothWriter::writeDialogEnd() {
|
||||
return runForBoth<&AbstractWriter::writeDialogEnd>();
|
||||
}
|
||||
|
||||
Result BothWriter::writeDialogsEnd() {
|
||||
return runForBoth<&AbstractWriter::writeDialogsEnd>();
|
||||
}
|
||||
|
||||
Result BothWriter::finish() {
|
||||
return runForBoth<&AbstractWriter::finish>();
|
||||
}
|
||||
|
||||
QString BothWriter::mainFilePath() {
|
||||
return _html->mainFilePath();
|
||||
}
|
||||
|
||||
template<typename ARG, Result (AbstractWriter::* FUNC)(const ARG&)>
|
||||
Result BothWriter::runForBoth(const ARG& data) {
|
||||
Result res = (_html.get()->*FUNC)(data);
|
||||
if(res.isError()) {
|
||||
return res;
|
||||
}
|
||||
return (_json.get()->*FUNC)(data);
|
||||
}
|
||||
|
||||
template<Result (AbstractWriter::* FUNC)()>
|
||||
Result BothWriter::runForBoth() {
|
||||
Result res = (_html.get()->*FUNC)();
|
||||
if(res.isError()) {
|
||||
return res;
|
||||
}
|
||||
return (_json.get()->*FUNC)();
|
||||
}
|
||||
|
||||
} // namespace Output
|
||||
} // namespace Export
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "export/output/export_output_abstract.h"
|
||||
#include "export/output/export_output_file.h"
|
||||
#include "export/export_settings.h"
|
||||
#include "export/data/export_data_types.h"
|
||||
|
||||
namespace Export {
|
||||
namespace Output {
|
||||
namespace details {
|
||||
|
||||
struct BothContext {
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
class HtmlWriter;
|
||||
class JsonWriter;
|
||||
|
||||
class BothWriter : public AbstractWriter {
|
||||
public:
|
||||
BothWriter();
|
||||
|
||||
Format format() override {
|
||||
return Format::Both;
|
||||
}
|
||||
|
||||
Result start(
|
||||
const Settings &settings,
|
||||
const Environment &environment,
|
||||
Stats *stats) override;
|
||||
|
||||
Result writePersonal(const Data::PersonalInfo &data) override;
|
||||
|
||||
Result writeUserpicsStart(const Data::UserpicsInfo &data) override;
|
||||
Result writeUserpicsSlice(const Data::UserpicsSlice &data) override;
|
||||
Result writeUserpicsEnd() override;
|
||||
|
||||
Result writeContactsList(const Data::ContactsList &data) override;
|
||||
|
||||
Result writeSessionsList(const Data::SessionsList &data) override;
|
||||
|
||||
Result writeOtherData(const Data::File &data) override;
|
||||
|
||||
Result writeDialogsStart(const Data::DialogsInfo &data) override;
|
||||
Result writeDialogStart(const Data::DialogInfo &data) override;
|
||||
Result writeDialogSlice(const Data::MessagesSlice &data) override;
|
||||
Result writeDialogEnd() override;
|
||||
Result writeDialogsEnd() override;
|
||||
|
||||
Result finish() override;
|
||||
|
||||
QString mainFilePath() override;
|
||||
|
||||
private:
|
||||
template<typename ARG, Result (AbstractWriter::* FUNC)(const ARG&)>
|
||||
Result runForBoth(const ARG& data);
|
||||
|
||||
template<Result (AbstractWriter::* FUNC)()>
|
||||
Result runForBoth();
|
||||
|
||||
std::shared_ptr<HtmlWriter> _html;
|
||||
std::shared_ptr<JsonWriter> _json;
|
||||
};
|
||||
|
||||
} // namespace Output
|
||||
} // namespace Export
|
|
@ -75,6 +75,7 @@ void ChooseFormatBox(
|
|||
box->setTitle(tr::lng_export_option_choose_format());
|
||||
addFormatOption(tr::lng_export_option_html(tr::now), Format::Html);
|
||||
addFormatOption(tr::lng_export_option_json(tr::now), Format::Json);
|
||||
addFormatOption(tr::lng_export_option_both(tr::now), Format::Both);
|
||||
box->addButton(tr::lng_settings_save(), [=] { done(group->value()); });
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
@ -280,6 +281,7 @@ void SettingsWidget::setupPathAndFormat(
|
|||
addLocationLabel(container);
|
||||
addFormatOption(tr::lng_export_option_html(tr::now), Format::Html);
|
||||
addFormatOption(tr::lng_export_option_json(tr::now), Format::Json);
|
||||
addFormatOption(tr::lng_export_option_both(tr::now), Format::Both);
|
||||
}
|
||||
|
||||
void SettingsWidget::addLocationLabel(
|
||||
|
@ -347,7 +349,7 @@ void SettingsWidget::addFormatAndLocationLabel(
|
|||
return data.format;
|
||||
}) | rpl::distinct_until_changed(
|
||||
) | rpl::map([](Format format) {
|
||||
const auto text = (format == Format::Html) ? "HTML" : "JSON";
|
||||
const auto text = (format == Format::Html) ? "HTML" : ((format == Format::Json) ? "JSON" : "BOTH");
|
||||
return Ui::Text::Link(text, u"internal:edit_format"_q);
|
||||
});
|
||||
const auto label = container->add(
|
||||
|
|
|
@ -28,6 +28,8 @@ PRIVATE
|
|||
export/output/export_output_html.h
|
||||
export/output/export_output_json.cpp
|
||||
export/output/export_output_json.h
|
||||
export/output/export_output_both.cpp
|
||||
export/output/export_output_both.h
|
||||
export/output/export_output_result.h
|
||||
export/output/export_output_stats.cpp
|
||||
export/output/export_output_stats.h
|
||||
|
|
Loading…
Reference in New Issue