export_view_content.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "export/export_controller.h"
  9. namespace Export {
  10. struct Settings;
  11. } // namespace Export
  12. namespace Export {
  13. namespace View {
  14. struct Content {
  15. struct Row {
  16. QString id;
  17. QString label;
  18. QString info;
  19. float64 progress = 0.;
  20. uint64 randomId = 0;
  21. };
  22. std::vector<Row> rows;
  23. static const QString kDoneId;
  24. };
  25. [[nodiscard]] Content ContentFromState(
  26. not_null<Settings*> settings,
  27. const ProcessingState &state);
  28. [[nodiscard]] Content ContentFromState(const FinishedState &state);
  29. [[nodiscard]] inline auto ContentFromState(
  30. not_null<Settings*> settings,
  31. rpl::producer<State> state) {
  32. return std::move(
  33. state
  34. ) | rpl::filter([](const State &state) {
  35. return v::is<ProcessingState>(state) || v::is<FinishedState>(state);
  36. }) | rpl::map([=](const State &state) {
  37. if (const auto process = std::get_if<ProcessingState>(&state)) {
  38. return ContentFromState(settings, *process);
  39. } else if (const auto done = std::get_if<FinishedState>(&state)) {
  40. return ContentFromState(*done);
  41. }
  42. Unexpected("State type in ContentFromState.");
  43. });
  44. }
  45. } // namespace View
  46. } // namespace Export