Skip to content

Commit

Permalink
Export panel minimizes to a top bar, like a Call.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 20, 2018
1 parent eaf3ea9 commit 329db0d
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 127 deletions.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_passport_bad_name" = "Please use latin characters only.";

"lng_export_title" = "Personal data export";
"lng_export_progress_title" = "Exporting personal data";
"lng_export_option_info" = "Personal information";
"lng_export_option_contacts" = "Contacts list";
"lng_export_option_sessions" = "Sessions list";
Expand Down
28 changes: 28 additions & 0 deletions Telegram/SourceFiles/data/data_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ For license and copyright information please follow this link:
#include "observer_peer.h"
#include "auth_session.h"
#include "apiwrap.h"
#include "export/export_controller.h"
#include "export/view/export_view_panel_controller.h"
#include "window/notifications_manager.h"
#include "history/history.h"
#include "history/history_item_components.h"
Expand Down Expand Up @@ -68,6 +70,32 @@ Session::Session(not_null<AuthSession*> session)
setupChannelLeavingViewer();
}

void Session::startExport() {
_export = std::make_unique<Export::ControllerWrap>();
_exportPanel = std::make_unique<Export::View::PanelController>(
_export.get());

_exportViewChanges.fire(_exportPanel.get());

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

rpl::producer<Export::View::PanelController*> Session::currentExportView(
) const {
return _exportViewChanges.events_starting_with(_exportPanel.get());
}

void Session::clearExport() {
if (_exportPanel) {
_exportPanel = nullptr;
_exportViewChanges.fire(nullptr);
}
_export = nullptr;
}

void Session::setupContactViewsViewer() {
Notify::PeerUpdateViewer(
Notify::PeerUpdate::Flag::UserIsContact
Expand Down
16 changes: 16 additions & 0 deletions Telegram/SourceFiles/data/data_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class Reader;
} // namespace Clip
} // namespace Media

namespace Export {
class ControllerWrap;
namespace View {
class PanelController;
} // namespace View
} // namespace Export

namespace Data {

class Feed;
Expand All @@ -44,6 +51,9 @@ class Session final {
return *_session;
}

void startExport();
rpl::producer<Export::View::PanelController*> currentExportView() const;

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

private:
void clearExport();

void setupContactViewsViewer();
void setupChannelLeavingViewer();
void photoApplyFields(
Expand Down Expand Up @@ -489,6 +501,10 @@ class Session final {

not_null<AuthSession*> _session;

std::unique_ptr<Export::ControllerWrap> _export;
std::unique_ptr<Export::View::PanelController> _exportPanel;
rpl::event_stream<Export::View::PanelController*> _exportViewChanges;

base::Variable<bool> _contactsLoaded = { false };
base::Variable<bool> _allChatsLoaded = { false };
base::Observable<void> _moreChatsLoaded;
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/export/export_api_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ void ApiWrap::requestMessages(
void ApiWrap::requestDialogsSlice() {
Expects(_dialogsProcess != nullptr);

LOG(("REQUEST %1 %2").arg(_dialogsProcess->offsetDate).arg(_dialogsProcess->offsetId));
mainRequest(MTPmessages_GetDialogs(
MTP_flags(0),
MTP_int(_dialogsProcess->offsetDate),
Expand All @@ -722,6 +723,10 @@ void ApiWrap::requestDialogsSlice() {
_dialogsProcess->offsetDate = last.topMessageDate;
_dialogsProcess->offsetPeer = last.input;

for (const auto &item : info.list) {
LOG(("RESULT: %1 %2").arg(item.topMessageDate).arg(item.topMessageId));
}

appendDialogsSlice(std::move(info));

const auto count = _dialogsProcess->info.list.size();
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/export/view/export.style
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ exportProgressInfoLabel: FlatLabel(boxLabel) {
exportProgressWidth: 3px;
exportProgressFg: mediaPlayerActiveFg;
exportProgressBg: mediaPlayerInactiveFg;

exportTopBarLabel: FlatLabel(defaultFlatLabel) {
maxHeight: 20px;
palette: TextPalette(defaultTextPalette) {
linkFg: windowSubTextFg;
}
}
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/export/view/export_view_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Content ContentFromState(const ProcessingState &state) {
pushMain(lang(lng_export_state_userpics));
pushBytes(
"userpic" + QString::number(state.entityIndex),
"Photo_" + QString::number(state.entityIndex + 1) + ".jpg");
state.bytesName);
break;
case Step::Contacts:
pushMain(lang(lng_export_option_contacts));
Expand Down
12 changes: 7 additions & 5 deletions Telegram/SourceFiles/export/view/export_view_content.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ struct Content {
Content ContentFromState(const ProcessingState &state);

inline auto ContentFromState(rpl::producer<State> state) {
return rpl::single(Content()) | rpl::then(std::move(
return std::move(
state
) | rpl::filter([](const State &state) {
return state.template is<ProcessingState>();
return state.is<ProcessingState>() || state.is<FinishedState>();
}) | rpl::map([](const State &state) {
return ContentFromState(
state.template get_unchecked<ProcessingState>());
}));
if (const auto process = base::get_if<ProcessingState>(&state)) {
return ContentFromState(*process);
}
return Content();
});
}

} // namespace View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ PanelController::PanelController(not_null<ControllerWrap*> process)
}, _lifetime);
}

void PanelController::activatePanel() {
_panel->showAndActivate();
}

void PanelController::createPanel() {
_panel = base::make_unique_q<Ui::SeparatePanel>();
_panel->setTitle(Lang::Viewer(lng_export_title));
Expand Down Expand Up @@ -84,22 +88,30 @@ void PanelController::showError(const QString &text) {
}, container->lifetime());

_panel->showInner(std::move(container));
_panel->setHideOnDeactivate(false);
}

void PanelController::showProgress() {
_panel->setTitle(Lang::Viewer(lng_export_progress_title));

auto progress = base::make_unique_q<ProgressWidget>(
_panel.get(),
ContentFromState(_process->state()));
rpl::single(
ContentFromState(ProcessingState())
) | rpl::then(progressState()));

progress->cancelClicks(
) | rpl::start_with_next([=] {
_panel->hideGetDuration();
}, progress->lifetime());

_panel->showInner(std::move(progress));
_panel->setHideOnDeactivate(true);
}

void PanelController::showDone(const QString &path) {
_panel->setTitle(Lang::Viewer(lng_export_title));

auto done = base::make_unique_q<DoneWidget>(_panel.get());

done->showClicks(
Expand All @@ -114,6 +126,7 @@ void PanelController::showDone(const QString &path) {
}, done->lifetime());

_panel->showInner(std::move(done));
_panel->setHideOnDeactivate(false);
}

rpl::producer<> PanelController::closed() const {
Expand Down
11 changes: 11 additions & 0 deletions Telegram/SourceFiles/export/view/export_view_panel_controller.h
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:
#pragma once

#include "export/export_controller.h"
#include "export/view/export_view_content.h"
#include "base/unique_qptr.h"

namespace Ui {
Expand All @@ -23,8 +24,18 @@ class PanelController {
public:
PanelController(not_null<ControllerWrap*> process);

void activatePanel();

rpl::producer<> closed() const;

rpl::lifetime &lifetime() {
return _lifetime;
}

auto progressState() const {
return ContentFromState(_process->state());
}

~PanelController();

private:
Expand Down
91 changes: 91 additions & 0 deletions Telegram/SourceFiles/export/view/export_view_top_bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
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/view/export_view_top_bar.h"

#include "export/view/export_view_content.h"
#include "ui/widgets/continuous_sliders.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/shadow.h"
#include "lang/lang_keys.h"
#include "styles/style_export.h"
#include "styles/style_media_player.h"

namespace Export {
namespace View {

TopBar::TopBar(QWidget *parent, Content &&content)
: RpWidget(parent)
, _info(this, st::exportTopBarLabel)
, _shadow(this)
, _progress(this, st::mediaPlayerPlayback)
, _button(this) {
resize(width(), st::mediaPlayerHeight + st::lineWidth);
_progress->setAttribute(Qt::WA_TransparentForMouseEvents);
updateData(std::move(content));
}

rpl::producer<> TopBar::clicks() const {
return _button->clicks();
}

void TopBar::updateData(Content &&content) {
if (content.rows.empty()) {
return;
}
const auto &row = content.rows[0];
const auto clean = &TextUtilities::Clean;
_info->setRichText(textcmdStartSemibold()
+ clean(lang(lng_export_progress_title))
+ textcmdStopSemibold()
+ QString::fromUtf8(" \xe2\x80\x93 ")
+ clean(row.label)
+ ' '
+ textcmdLink(1, clean(row.info)));
_progress->setValue(row.progress);
}

void TopBar::resizeEvent(QResizeEvent *e) {
_info->moveToLeft(
st::mediaPlayerPlayLeft + st::mediaPlayerPadding,
st::mediaPlayerNameTop - st::mediaPlayerName.style.font->ascent);
_button->setGeometry(0, 0, width(), height() - st::lineWidth);
_progress->setGeometry(
0,
height() - st::mediaPlayerPlayback.fullWidth,
width(),
st::mediaPlayerPlayback.fullWidth);
}

void TopBar::paintEvent(QPaintEvent *e) {
Painter p(this);
auto fill = e->rect().intersected(
QRect(0, 0, width(), st::mediaPlayerHeight));
if (!fill.isEmpty()) {
p.fillRect(fill, st::mediaPlayerBg);
}
}

void TopBar::setShadowGeometryToLeft(int x, int y, int w, int h) {
_shadow->setGeometryToLeft(x, y, w, h);
}

void TopBar::showShadow() {
_shadow->show();
_progress->show();
}

void TopBar::hideShadow() {
_shadow->hide();
_progress->hide();
}

TopBar::~TopBar() = default;

} // namespace View
} // namespace Export
51 changes: 51 additions & 0 deletions Telegram/SourceFiles/export/view/export_view_top_bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
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
*/
#pragma once

#include "ui/rp_widget.h"

namespace Ui {
class FlatLabel;
class FilledSlider;
class AbstractButton;
class PlainShadow;
} // namespace Ui

namespace Export {
namespace View {

struct Content;

class TopBar : public Ui::RpWidget {
public:
TopBar(QWidget *parent, Content &&content);

rpl::producer<> clicks() const;

void updateData(Content &&content);

void setShadowGeometryToLeft(int x, int y, int w, int h);
void showShadow();
void hideShadow();

~TopBar();

protected:
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;

private:
object_ptr<Ui::FlatLabel> _info;
object_ptr<Ui::PlainShadow> _shadow = { nullptr };
object_ptr<Ui::FilledSlider> _progress;
object_ptr<Ui::AbstractButton> _button;

};

} // namespace View
} // namespace Export
Loading

0 comments on commit 329db0d

Please sign in to comment.