2018-06-19 11:42:21 +01:00
|
|
|
/*
|
|
|
|
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 "lang/lang_keys.h"
|
2018-06-19 19:31:30 +01:00
|
|
|
#include "layout.h"
|
2018-06-19 11:42:21 +01:00
|
|
|
|
|
|
|
namespace Export {
|
|
|
|
namespace View {
|
|
|
|
|
2018-06-20 16:54:13 +01:00
|
|
|
const QString Content::kDoneId = "done";
|
|
|
|
|
2018-06-19 11:42:21 +01:00
|
|
|
Content ContentFromState(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 19:31:30 +01:00
|
|
|
const auto pushMain = [&](const QString &label) {
|
|
|
|
const auto info = (state.entityCount > 0)
|
|
|
|
? (QString::number(state.entityIndex)
|
|
|
|
+ " / "
|
|
|
|
+ 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 addProgress = (state.entityCount > 0)
|
|
|
|
? ((float64(add) * state.entityIndex)
|
|
|
|
/ (float64(substepsTotal) * state.entityCount))
|
|
|
|
: 0.;
|
|
|
|
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);
|
|
|
|
};
|
2018-06-19 11:42:21 +01:00
|
|
|
switch (state.step) {
|
|
|
|
case Step::Initializing:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_state_initializing));
|
|
|
|
break;
|
2018-06-19 11:42:21 +01:00
|
|
|
case Step::LeftChannelsList:
|
|
|
|
case Step::DialogsList:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_state_chats_list));
|
|
|
|
break;
|
2018-06-19 11:42:21 +01:00
|
|
|
case Step::PersonalInfo:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_option_info));
|
|
|
|
break;
|
2018-06-19 11:42:21 +01:00
|
|
|
case Step::Userpics:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_state_userpics));
|
|
|
|
pushBytes(
|
|
|
|
"userpic" + QString::number(state.entityIndex),
|
2018-06-20 01:02:36 +01:00
|
|
|
state.bytesName);
|
2018-06-19 19:31:30 +01:00
|
|
|
break;
|
2018-06-19 11:42:21 +01:00
|
|
|
case Step::Contacts:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_option_contacts));
|
|
|
|
break;
|
2018-06-19 11:42:21 +01:00
|
|
|
case Step::Sessions:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_option_sessions));
|
|
|
|
break;
|
2018-06-24 01:33:47 +01:00
|
|
|
case Step::OtherData:
|
|
|
|
pushMain(lang(lng_export_option_other));
|
|
|
|
break;
|
2018-06-19 11:42:21 +01:00
|
|
|
case Step::LeftChannels:
|
|
|
|
case Step::Dialogs:
|
2018-06-19 19:31:30 +01:00
|
|
|
pushMain(lang(lng_export_state_chats));
|
2018-06-24 02:34:47 +01:00
|
|
|
push(
|
|
|
|
"chat" + QString::number(state.entityIndex),
|
|
|
|
(state.entityName.isEmpty()
|
|
|
|
? lang(lng_deleted)
|
|
|
|
: state.entityName),
|
|
|
|
(state.itemCount > 0
|
|
|
|
? (QString::number(state.itemIndex)
|
2018-06-19 19:31:30 +01:00
|
|
|
+ " / "
|
2018-06-24 02:34:47 +01:00
|
|
|
+ QString::number(state.itemCount))
|
|
|
|
: QString()),
|
|
|
|
(state.itemCount > 0
|
|
|
|
? (state.itemIndex / float64(state.itemCount))
|
|
|
|
: 0.));
|
2018-06-19 19:31:30 +01:00
|
|
|
pushBytes(
|
|
|
|
("file"
|
|
|
|
+ QString::number(state.entityIndex)
|
|
|
|
+ '_'
|
|
|
|
+ QString::number(state.itemIndex)),
|
|
|
|
state.bytesName);
|
2018-06-19 11:42:21 +01:00
|
|
|
break;
|
|
|
|
default: Unexpected("Step in ContentFromState.");
|
|
|
|
}
|
2018-06-20 16:54:13 +01:00
|
|
|
while (result.rows.size() < 3) {
|
|
|
|
result.rows.push_back(Content::Row());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Content ContentFromState(const FinishedState &state) {
|
|
|
|
auto result = Content();
|
|
|
|
result.rows.push_back({
|
|
|
|
Content::kDoneId,
|
|
|
|
lang(lng_export_finished),
|
|
|
|
QString(),
|
|
|
|
1. });
|
|
|
|
result.rows.push_back({
|
|
|
|
Content::kDoneId,
|
|
|
|
lng_export_total_files(lt_count, QString::number(state.filesCount)),
|
|
|
|
QString(),
|
|
|
|
1. });
|
|
|
|
result.rows.push_back({
|
|
|
|
Content::kDoneId,
|
|
|
|
lng_export_total_size(lt_size, formatSizeText(state.bytesCount)),
|
|
|
|
QString(),
|
|
|
|
1. });
|
2018-06-19 11:42:21 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace View
|
|
|
|
} // namespace Export
|