Skip to content

Commit

Permalink
Confirm export stop on quit and logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 20, 2018
1 parent 13e6b91 commit 154e566
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
9 changes: 8 additions & 1 deletion Telegram/SourceFiles/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ For license and copyright information please follow this link:
#include "styles/style_history.h"
#include "styles/style_boxes.h"
#include "lang/lang_keys.h"
#include "boxes/confirm_box.h"
#include "data/data_abstract_structure.h"
#include "data/data_media_types.h"
#include "data/data_session.h"
Expand Down Expand Up @@ -1589,7 +1590,13 @@ namespace App {
}

void quit() {
if (quitting()) return;
if (quitting()) {
return;
} else if (AuthSession::Exists()
&& Auth().data().exportInProgress()) {
Auth().data().stopExportWithConfirmation([] { App::quit(); });
return;
}
setLaunchState(QuitRequested);

if (auto window = wnd()) {
Expand Down
23 changes: 21 additions & 2 deletions Telegram/SourceFiles/data/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void Session::startExport() {

_exportPanel->closed(
) | rpl::start_with_next([=] {
clearExport();
stopExport();
}, _export->lifetime());
}

Expand All @@ -88,7 +88,26 @@ rpl::producer<Export::View::PanelController*> Session::currentExportView(
return _exportViewChanges.events_starting_with(_exportPanel.get());
}

void Session::clearExport() {
bool Session::exportInProgress() const {
return _export != nullptr;
}

void Session::stopExportWithConfirmation(FnMut<void()> callback) {
if (!_exportPanel) {
callback();
return;
}
auto closeAndCall = [=, callback = std::move(callback)]() mutable {
auto saved = std::move(callback);
stopExport();
if (saved) {
saved();
}
};
_exportPanel->stopWithConfirmation(std::move(closeAndCall));
}

void Session::stopExport() {
if (_exportPanel) {
_exportPanel = nullptr;
_exportViewChanges.fire(nullptr);
Expand Down
5 changes: 3 additions & 2 deletions Telegram/SourceFiles/data/data_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Session final {

void startExport();
rpl::producer<Export::View::PanelController*> currentExportView() const;
bool exportInProgress() const;
void stopExportWithConfirmation(FnMut<void()> callback);
void stopExport();

[[nodiscard]] base::Variable<bool> &contactsLoaded() {
return _contactsLoaded;
Expand Down Expand Up @@ -405,8 +408,6 @@ class Session final {
}

private:
void clearExport();

void setupContactViewsViewer();
void setupChannelLeavingViewer();
void photoApplyFields(
Expand Down
29 changes: 25 additions & 4 deletions Telegram/SourceFiles/export/view/export_view_panel_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,37 @@ void PanelController::showProgress() {
_panel->setHideOnDeactivate(true);
}

void PanelController::stopWithConfirmation() {
void PanelController::stopWithConfirmation(FnMut<void()> callback) {
if (!_state.is<ProcessingState>()) {
stopExport();
callback();
return;
}
auto stop = [=, callback = std::move(callback)]() mutable {
auto saved = std::move(callback);
stopExport();
if (saved) {
saved();
}
};
const auto hidden = _panel->isHidden();
const auto old = _confirmStopBox;
auto box = Box<ConfirmBox>(
lang(lng_export_sure_stop),
lang(lng_export_stop),
st::attentionBoxButton,
[=] { stopExport(); });
std::move(stop));
_confirmStopBox = box.data();
_panel->showBox(
std::move(box),
LayerOption::KeepOther,
anim::type::normal);
LayerOption::CloseOther,
hidden ? anim::type::instant : anim::type::normal);
if (hidden) {
_panel->showAndActivate();
}
if (old) {
old->closeBox();
}
}

void PanelController::stopExport() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For license and copyright information please follow this link:
#include "export/view/export_view_content.h"
#include "base/unique_qptr.h"

class BoxContent;

namespace Ui {
class SeparatePanel;
} // namespace Ui
Expand All @@ -25,7 +27,7 @@ class PanelController {
PanelController(not_null<ControllerWrap*> process);

void activatePanel();
void stopWithConfirmation();
void stopWithConfirmation(FnMut<void()> callback = nullptr);

rpl::producer<> closed() const;

Expand Down Expand Up @@ -54,6 +56,7 @@ class PanelController {
base::unique_qptr<Ui::SeparatePanel> _panel;

State _state;
QPointer<BoxContent> _confirmStopBox;
rpl::event_stream<rpl::producer<>> _panelCloseEvents;
bool _stopRequested = false;
rpl::lifetime _lifetime;
Expand Down
14 changes: 13 additions & 1 deletion Telegram/SourceFiles/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For license and copyright information please follow this link:
#include "mainwindow.h"

#include "data/data_document.h"
#include "data/data_session.h"
#include "dialogs/dialogs_layout.h"
#include "styles/style_dialogs.h"
#include "styles/style_window.h"
Expand Down Expand Up @@ -618,11 +619,22 @@ void MainWindow::onLogout() {
showFromTray();
}

const auto logout = [] {
Messenger::Instance().logOut();
};
const auto callback = [=] {
if (AuthSession::Exists() && Auth().data().exportInProgress()) {
Ui::hideLayer();
Auth().data().stopExportWithConfirmation(logout);
} else {
logout();
}
};
Ui::show(Box<ConfirmBox>(
lang(lng_sure_logout),
lang(lng_settings_logout),
st::attentionBoxButton,
[] { Messenger::Instance().logOut(); }));
callback));
}

void MainWindow::quitFromTray() {
Expand Down

0 comments on commit 154e566

Please sign in to comment.