export_manager.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "export/export_manager.h"
  8. #include "export/export_controller.h"
  9. #include "export/view/export_view_panel_controller.h"
  10. #include "data/data_peer.h"
  11. #include "main/main_session.h"
  12. #include "main/main_account.h"
  13. #include "ui/layers/box_content.h"
  14. #include "base/unixtime.h"
  15. namespace Export {
  16. Manager::Manager() = default;
  17. Manager::~Manager() = default;
  18. void Manager::start(not_null<PeerData*> peer) {
  19. start(&peer->session(), peer->input);
  20. }
  21. void Manager::start(
  22. not_null<Main::Session*> session,
  23. const MTPInputPeer &singlePeer) {
  24. if (_panel) {
  25. _panel->activatePanel();
  26. return;
  27. }
  28. _controller = std::make_unique<Controller>(
  29. &session->mtp(),
  30. singlePeer);
  31. _panel = std::make_unique<View::PanelController>(
  32. session,
  33. _controller.get());
  34. session->account().sessionChanges(
  35. ) | rpl::filter([=](Main::Session *value) {
  36. return (value != session);
  37. }) | rpl::start_with_next([=] {
  38. stop();
  39. }, _panel->lifetime());
  40. _viewChanges.fire(_panel.get());
  41. _panel->stopRequests(
  42. ) | rpl::start_with_next([=] {
  43. LOG(("Export Info: Stop requested."));
  44. stop();
  45. }, _controller->lifetime());
  46. }
  47. rpl::producer<View::PanelController*> Manager::currentView(
  48. ) const {
  49. return _viewChanges.events_starting_with(_panel.get());
  50. }
  51. bool Manager::inProgress() const {
  52. return _controller != nullptr;
  53. }
  54. bool Manager::inProgress(not_null<Main::Session*> session) const {
  55. return _panel && (&_panel->session() == session);
  56. }
  57. void Manager::stopWithConfirmation(Fn<void()> callback) {
  58. if (!_panel) {
  59. callback();
  60. return;
  61. }
  62. auto closeAndCall = [=, callback = std::move(callback)]() mutable {
  63. auto saved = std::move(callback);
  64. LOG(("Export Info: Stop With Confirmation."));
  65. stop();
  66. if (saved) {
  67. saved();
  68. }
  69. };
  70. _panel->stopWithConfirmation(std::move(closeAndCall));
  71. }
  72. void Manager::stop() {
  73. if (_panel) {
  74. LOG(("Export Info: Destroying."));
  75. _panel = nullptr;
  76. _viewChanges.fire(nullptr);
  77. }
  78. _controller = nullptr;
  79. }
  80. } // namespace Export