Improve single chat export progress display.

This commit is contained in:
John Preston 2020-06-01 16:28:18 +04:00
parent 1686eb394d
commit 368eeaf754
5 changed files with 29 additions and 10 deletions

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "export/view/export_view_content.h" #include "export/view/export_view_content.h"
#include "export/export_settings.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "layout.h" #include "layout.h"
@ -15,7 +16,9 @@ namespace View {
const QString Content::kDoneId = "done"; const QString Content::kDoneId = "done";
Content ContentFromState(const ProcessingState &state) { Content ContentFromState(
not_null<Settings*> settings,
const ProcessingState &state) {
using Step = ProcessingState::Step; using Step = ProcessingState::Step;
auto result = Content(); auto result = Content();
@ -89,7 +92,9 @@ Content ContentFromState(const ProcessingState &state) {
pushMain(tr::lng_export_option_other(tr::now)); pushMain(tr::lng_export_option_other(tr::now));
break; break;
case Step::Dialogs: case Step::Dialogs:
pushMain(tr::lng_export_state_chats(tr::now)); if (state.entityCount > 1) {
pushMain(tr::lng_export_state_chats(tr::now));
}
push( push(
"chat" + QString::number(state.entityIndex), "chat" + QString::number(state.entityIndex),
(state.entityName.isEmpty() (state.entityName.isEmpty()
@ -114,7 +119,8 @@ Content ContentFromState(const ProcessingState &state) {
break; break;
default: Unexpected("Step in ContentFromState."); default: Unexpected("Step in ContentFromState.");
} }
while (result.rows.size() < 3) { const auto requiredRows = settings->onlySinglePeer() ? 2 : 3;
while (result.rows.size() < requiredRows) {
result.rows.emplace_back(); result.rows.emplace_back();
} }
return result; return result;

View File

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "export/export_controller.h" #include "export/export_controller.h"
namespace Export {
struct Settings;
} // namespace Export
namespace Export { namespace Export {
namespace View { namespace View {
@ -26,17 +30,21 @@ struct Content {
}; };
Content ContentFromState(const ProcessingState &state); [[nodiscard]] Content ContentFromState(
Content ContentFromState(const FinishedState &state); not_null<Settings*> settings,
const ProcessingState &state);
[[nodiscard]] Content ContentFromState(const FinishedState &state);
inline auto ContentFromState(rpl::producer<State> state) { [[nodiscard]] inline auto ContentFromState(
not_null<Settings*> settings,
rpl::producer<State> state) {
return std::move( return std::move(
state state
) | rpl::filter([](const State &state) { ) | rpl::filter([](const State &state) {
return state.is<ProcessingState>() || state.is<FinishedState>(); return state.is<ProcessingState>() || state.is<FinishedState>();
}) | rpl::map([](const State &state) { }) | rpl::map([=](const State &state) {
if (const auto process = base::get_if<ProcessingState>(&state)) { if (const auto process = base::get_if<ProcessingState>(&state)) {
return ContentFromState(*process); return ContentFromState(settings, *process);
} else if (const auto done = base::get_if<FinishedState>(&state)) { } else if (const auto done = base::get_if<FinishedState>(&state)) {
return ContentFromState(*done); return ContentFromState(*done);
} }

View File

@ -280,7 +280,7 @@ void PanelController::showProgress() {
auto progress = base::make_unique_q<ProgressWidget>( auto progress = base::make_unique_q<ProgressWidget>(
_panel.get(), _panel.get(),
rpl::single( rpl::single(
ContentFromState(ProcessingState()) ContentFromState(_settings.get(), ProcessingState())
) | rpl::then(progressState())); ) | rpl::then(progressState()));
progress->cancelClicks( progress->cancelClicks(

View File

@ -46,7 +46,7 @@ public:
} }
auto progressState() const { auto progressState() const {
return ContentFromState(_process->state()); return ContentFromState(_settings.get(), _process->state());
} }
private: private:

View File

@ -288,6 +288,7 @@ void ProgressWidget::updateState(Content &&content) {
showDone(); showDone();
} }
const auto wasCount = _rows.size();
auto index = 0; auto index = 0;
for (auto &row : content.rows) { for (auto &row : content.rows) {
if (index < _rows.size()) { if (index < _rows.size()) {
@ -297,12 +298,16 @@ void ProgressWidget::updateState(Content &&content) {
index, index,
object_ptr<Row>(this, std::move(row)), object_ptr<Row>(this, std::move(row)),
st::exportProgressRowPadding)); st::exportProgressRowPadding));
_rows.back()->show();
} }
++index; ++index;
} }
for (const auto count = _rows.size(); index != count; ++index) { for (const auto count = _rows.size(); index != count; ++index) {
_rows[index]->updateData(Content::Row()); _rows[index]->updateData(Content::Row());
} }
if (_rows.size() != wasCount) {
_body->resizeToWidth(width());
}
} }
void ProgressWidget::showDone() { void ProgressWidget::showDone() {