tdesktop/Telegram/SourceFiles/export/view/export_view_content.cpp

157 lines
4.1 KiB
C++
Raw Normal View History

/*
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/view/export_view_content.h"
#include "export/export_settings.h"
#include "lang/lang_keys.h"
2018-06-19 18:31:30 +00:00
#include "layout.h"
namespace Export {
namespace View {
const QString Content::kDoneId = "done";
Content ContentFromState(
not_null<Settings*> settings,
const ProcessingState &state) {
using Step = ProcessingState::Step;
auto result = Content();
const auto push = [&](
const QString &id,
const QString &label,
const QString &info,
float64 progress) {
result.rows.push_back({ id, label, info, progress });
};
2018-06-19 18:31:30 +00:00
const auto pushMain = [&](const QString &label) {
const auto info = (state.entityCount > 0)
? (QString::number(state.entityIndex + 1)
2018-06-19 18:31:30 +00:00
+ " / "
+ QString::number(state.entityCount))
: QString();
if (!state.substepsTotal) {
push("main", label, info, 0.);
return;
}
const auto substepsTotal = state.substepsTotal;
const auto step = static_cast<int>(state.step);
const auto done = state.substepsPassed;
const auto add = state.substepsNow;
const auto doneProgress = done / float64(substepsTotal);
const auto addPart = [&](int index, int count) {
return (count > 0)
? ((float64(add) * index)
/ (float64(substepsTotal) * count))
: 0.;
};
const auto addProgress = (state.entityCount == 1
&& !state.entityIndex)
? addPart(state.itemIndex, state.itemCount)
: addPart(state.entityIndex, state.entityCount);
2018-06-19 18:31:30 +00:00
push("main", label, info, doneProgress + addProgress);
};
const auto pushBytes = [&](const QString &id, const QString &label) {
if (!state.bytesCount) {
return;
}
const auto progress = state.bytesLoaded / float64(state.bytesCount);
const auto info = formatDownloadText(
state.bytesLoaded,
state.bytesCount);
push(id, label, info, progress);
};
switch (state.step) {
case Step::Initializing:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_state_initializing(tr::now));
2018-06-19 18:31:30 +00:00
break;
case Step::DialogsList:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_state_chats_list(tr::now));
2018-06-19 18:31:30 +00:00
break;
case Step::PersonalInfo:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_option_info(tr::now));
2018-06-19 18:31:30 +00:00
break;
case Step::Userpics:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_state_userpics(tr::now));
2018-06-19 18:31:30 +00:00
pushBytes(
"userpic" + QString::number(state.entityIndex),
state.bytesName);
2018-06-19 18:31:30 +00:00
break;
case Step::Contacts:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_option_contacts(tr::now));
2018-06-19 18:31:30 +00:00
break;
case Step::Sessions:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_option_sessions(tr::now));
2018-06-19 18:31:30 +00:00
break;
2018-06-24 00:33:47 +00:00
case Step::OtherData:
2019-06-19 15:09:03 +00:00
pushMain(tr::lng_export_option_other(tr::now));
2018-06-24 00:33:47 +00:00
break;
case Step::Dialogs:
if (state.entityCount > 1) {
pushMain(tr::lng_export_state_chats(tr::now));
}
2018-06-24 01:34:47 +00:00
push(
"chat" + QString::number(state.entityIndex),
(state.entityName.isEmpty()
2019-06-19 15:09:03 +00:00
? tr::lng_deleted(tr::now)
: (state.entityType == ProcessingState::EntityType::Chat)
? state.entityName
2019-06-19 15:09:03 +00:00
: tr::lng_saved_messages(tr::now)),
2018-06-24 01:34:47 +00:00
(state.itemCount > 0
? (QString::number(state.itemIndex)
2018-06-19 18:31:30 +00:00
+ " / "
2018-06-24 01:34:47 +00:00
+ QString::number(state.itemCount))
: QString()),
(state.itemCount > 0
? (state.itemIndex / float64(state.itemCount))
: 0.));
2018-06-19 18:31:30 +00:00
pushBytes(
("file"
+ QString::number(state.entityIndex)
+ '_'
+ QString::number(state.itemIndex)),
state.bytesName);
break;
default: Unexpected("Step in ContentFromState.");
}
const auto requiredRows = settings->onlySinglePeer() ? 2 : 3;
while (result.rows.size() < requiredRows) {
2019-06-19 12:41:00 +00:00
result.rows.emplace_back();
}
return result;
}
Content ContentFromState(const FinishedState &state) {
auto result = Content();
result.rows.push_back({
Content::kDoneId,
2019-06-19 12:41:00 +00:00
tr::lng_export_finished(tr::now),
QString(),
1. });
result.rows.push_back({
Content::kDoneId,
2019-06-19 12:41:00 +00:00
tr::lng_export_total_amount(
tr::now,
lt_amount,
QString::number(state.filesCount)),
QString(),
1. });
result.rows.push_back({
Content::kDoneId,
2019-06-19 12:41:00 +00:00
tr::lng_export_total_size(
tr::now,
lt_size,
formatSizeText(state.bytesCount)),
QString(),
1. });
return result;
}
} // namespace View
} // namespace Export