-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathexport_manager.cpp
More file actions
116 lines (99 loc) · 2.58 KB
/
Copy pathexport_manager.cpp
File metadata and controls
116 lines (99 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
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/export_manager.h"
#include "export/export_controller.h"
#include "export/view/export_view_panel_controller.h"
#include "data/data_peer.h"
#include "main/main_session.h"
#include "main/main_account.h"
#include "ui/layers/box_content.h"
#include "base/unixtime.h"
namespace Export {
Manager::Manager() = default;
Manager::~Manager() = default;
void Manager::start(not_null<PeerData*> peer) {
start(&peer->session(), peer->input());
}
void Manager::startTopic(
not_null<PeerData*> peer,
MsgId topicRootId,
const QString &topicTitle) {
if (_panel) {
_panel->activatePanel();
return;
}
_controller = std::make_unique<Controller>(
&peer->session().mtp(),
peer->input(),
int32(topicRootId.bare),
uint64(peer->id.value),
topicTitle);
setupPanel(&peer->session());
}
void Manager::start(
not_null<Main::Session*> session,
const MTPInputPeer &singlePeer) {
if (_panel) {
_panel->activatePanel();
return;
}
_controller = std::make_unique<Controller>(
&session->mtp(),
singlePeer);
setupPanel(session);
}
void Manager::setupPanel(not_null<Main::Session*> session) {
_panel = std::make_unique<View::PanelController>(
session,
_controller.get());
session->account().sessionChanges(
) | rpl::filter([=](Main::Session *value) {
return (value != session);
}) | rpl::on_next([=] {
stop();
}, _panel->lifetime());
_viewChanges.fire(_panel.get());
_panel->stopRequests(
) | rpl::on_next([=] {
LOG(("Export Info: Stop requested."));
stop();
}, _controller->lifetime());
}
rpl::producer<View::PanelController*> Manager::currentView(
) const {
return _viewChanges.events_starting_with(_panel.get());
}
bool Manager::inProgress() const {
return _controller != nullptr;
}
bool Manager::inProgress(not_null<Main::Session*> session) const {
return _panel && (&_panel->session() == session);
}
void Manager::stopWithConfirmation(Fn<void()> callback) {
if (!_panel) {
callback();
return;
}
auto closeAndCall = [=, callback = std::move(callback)]() mutable {
auto saved = std::move(callback);
LOG(("Export Info: Stop With Confirmation."));
stop();
if (saved) {
saved();
}
};
_panel->stopWithConfirmation(std::move(closeAndCall));
}
void Manager::stop() {
if (_panel) {
LOG(("Export Info: Destroying."));
_panel = nullptr;
_viewChanges.fire(nullptr);
}
_controller = nullptr;
}
} // namespace Export