2018-12-26 14:00:08 +00:00
|
|
|
/*
|
|
|
|
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 "chat_helpers/emoji_sets_manager.h"
|
|
|
|
|
2018-12-26 17:05:06 +00:00
|
|
|
#include "mtproto/dedicated_file_loader.h"
|
2018-12-26 14:00:08 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/wrap/fade_wrap.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2018-12-26 14:00:08 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
|
|
|
#include "ui/emoji_config.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2019-07-24 08:46:23 +00:00
|
|
|
#include "main/main_account.h"
|
2018-12-26 17:05:06 +00:00
|
|
|
#include "mainwidget.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2020-02-05 10:29:27 +00:00
|
|
|
#include "storage/storage_cloud_blob.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2018-12-26 14:00:08 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_chat_helpers.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
namespace Emoji {
|
|
|
|
namespace {
|
|
|
|
|
2020-02-05 13:06:38 +00:00
|
|
|
using namespace Storage::CloudBlob;
|
|
|
|
|
|
|
|
struct Set : public Blob {
|
2020-02-05 10:59:07 +00:00
|
|
|
QString previewPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline auto PreviewPath(int i) {
|
|
|
|
return qsl(":/gui/emoji/set%1_preview.webp").arg(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto kSets = {
|
|
|
|
Set{ {0, 0, 0, "Mac"}, PreviewPath(0) },
|
2020-05-07 13:21:21 +00:00
|
|
|
Set{ {1, 713, 7'313'166, "Android"}, PreviewPath(1) },
|
|
|
|
Set{ {2, 714, 4'690'333, "Twemoji"}, PreviewPath(2) },
|
|
|
|
Set{ {3, 716, 5'968'021, "JoyPixels"}, PreviewPath(3) },
|
2020-02-05 10:59:07 +00:00
|
|
|
};
|
|
|
|
|
2018-12-26 17:05:06 +00:00
|
|
|
using Loading = MTP::DedicatedLoader::Progress;
|
2020-02-05 14:13:12 +00:00
|
|
|
using SetState = BlobState;
|
2018-12-26 14:00:08 +00:00
|
|
|
|
2020-05-07 15:06:44 +00:00
|
|
|
class Loader final : public BlobLoader {
|
2020-02-05 14:13:12 +00:00
|
|
|
public:
|
|
|
|
Loader(
|
2020-06-10 10:49:10 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-02-05 14:13:12 +00:00
|
|
|
int id,
|
|
|
|
MTP::DedicatedLoader::Location location,
|
|
|
|
const QString &folder,
|
|
|
|
int size);
|
2018-12-26 14:00:08 +00:00
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
void destroy() override;
|
|
|
|
void unpack(const QString &path) override;
|
2018-12-26 17:05:06 +00:00
|
|
|
|
2020-05-07 15:06:44 +00:00
|
|
|
private:
|
|
|
|
void fail() override;
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Inner : public Ui::RpWidget {
|
|
|
|
public:
|
2020-06-10 10:49:10 +00:00
|
|
|
Inner(QWidget *parent, not_null<Main::Session*> session);
|
2018-12-26 14:00:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setupContent();
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Row : public Ui::RippleButton {
|
|
|
|
public:
|
2020-06-10 10:49:10 +00:00
|
|
|
Row(QWidget *widget, not_null<Main::Session*> session, const Set &set);
|
2018-12-26 14:00:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2018-12-27 09:37:11 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
private:
|
2018-12-27 09:37:11 +00:00
|
|
|
[[nodiscard]] bool showOver() const;
|
|
|
|
[[nodiscard]] bool showOver(State state) const;
|
2019-01-02 12:11:13 +00:00
|
|
|
void updateStatusColorOverride();
|
2018-12-26 14:00:08 +00:00
|
|
|
void setupContent(const Set &set);
|
|
|
|
void setupLabels(const Set &set);
|
2019-01-02 12:11:13 +00:00
|
|
|
void setupPreview(const Set &set);
|
2018-12-27 09:37:11 +00:00
|
|
|
void setupAnimation();
|
2019-01-02 12:11:13 +00:00
|
|
|
void paintPreview(Painter &p) const;
|
2019-04-04 15:24:13 +00:00
|
|
|
void paintRadio(Painter &p);
|
2018-12-26 14:00:08 +00:00
|
|
|
void setupHandler();
|
2018-12-26 17:05:06 +00:00
|
|
|
void load();
|
2019-04-04 15:24:13 +00:00
|
|
|
void radialAnimationCallback(crl::time now);
|
2020-02-11 10:12:42 +00:00
|
|
|
void updateLoadingToFinished();
|
2018-12-27 09:37:11 +00:00
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2018-12-26 14:00:08 +00:00
|
|
|
int _id = 0;
|
2018-12-27 08:01:03 +00:00
|
|
|
bool _switching = false;
|
2018-12-26 14:00:08 +00:00
|
|
|
rpl::variable<SetState> _state;
|
2018-12-27 09:37:11 +00:00
|
|
|
Ui::FlatLabel *_status = nullptr;
|
2019-01-02 12:11:13 +00:00
|
|
|
std::array<QPixmap, 4> _preview;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _toggled;
|
|
|
|
Ui::Animations::Simple _active;
|
2018-12-26 14:00:08 +00:00
|
|
|
std::unique_ptr<Ui::RadialAnimation> _loading;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-12-27 08:01:03 +00:00
|
|
|
base::unique_qptr<Loader> GlobalLoader;
|
2018-12-26 14:00:08 +00:00
|
|
|
rpl::event_stream<Loader*> GlobalLoaderValues;
|
|
|
|
|
2018-12-27 08:01:03 +00:00
|
|
|
void SetGlobalLoader(base::unique_qptr<Loader> loader) {
|
|
|
|
GlobalLoader = std::move(loader);
|
|
|
|
GlobalLoaderValues.fire(GlobalLoader.get());
|
|
|
|
}
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
int GetDownloadSize(int id) {
|
2020-02-06 15:32:02 +00:00
|
|
|
return ranges::find(kSets, id, &Set::id)->size;
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 10:12:42 +00:00
|
|
|
[[nodiscard]] float64 CountProgress(not_null<const Loading*> loading) {
|
|
|
|
return (loading->size > 0)
|
|
|
|
? (loading->already / float64(loading->size))
|
|
|
|
: 0.;
|
|
|
|
}
|
|
|
|
|
2018-12-26 17:05:06 +00:00
|
|
|
MTP::DedicatedLoader::Location GetDownloadLocation(int id) {
|
2020-02-05 14:13:12 +00:00
|
|
|
const auto username = kCloudLocationUsername.utf16();
|
2020-02-06 15:32:02 +00:00
|
|
|
const auto i = ranges::find(kSets, id, &Set::id);
|
2020-02-05 14:13:12 +00:00
|
|
|
return MTP::DedicatedLoader::Location{ username, i->postId };
|
2018-12-26 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
SetState ComputeState(int id) {
|
|
|
|
if (id == CurrentSetId()) {
|
|
|
|
return Active();
|
|
|
|
} else if (SetIsReady(id)) {
|
|
|
|
return Ready();
|
|
|
|
}
|
|
|
|
return Available{ GetDownloadSize(id) };
|
|
|
|
}
|
|
|
|
|
|
|
|
QString StateDescription(const SetState &state) {
|
2020-02-05 14:28:22 +00:00
|
|
|
return StateDescription(
|
|
|
|
state,
|
|
|
|
tr::lng_emoji_set_active);
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 08:01:03 +00:00
|
|
|
bool GoodSetPartName(const QString &name) {
|
|
|
|
return (name == qstr("config.json"))
|
|
|
|
|| (name.startsWith(qstr("emoji_"))
|
|
|
|
&& name.endsWith(qstr(".webp")));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UnpackSet(const QString &path, const QString &folder) {
|
2020-02-05 13:06:38 +00:00
|
|
|
return UnpackBlob(path, folder, GoodSetPartName);
|
2018-12-27 08:01:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 15:06:44 +00:00
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
Loader::Loader(
|
2020-06-10 10:49:10 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-02-05 14:13:12 +00:00
|
|
|
int id,
|
|
|
|
MTP::DedicatedLoader::Location location,
|
|
|
|
const QString &folder,
|
2020-05-07 15:06:44 +00:00
|
|
|
int size)
|
2020-06-10 10:49:10 +00:00
|
|
|
: BlobLoader(nullptr, session, id, location, folder, size) {
|
2018-12-26 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Loader::unpack(const QString &path) {
|
2020-02-05 14:13:12 +00:00
|
|
|
const auto folder = internal::SetDataPath(id());
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2018-12-27 08:01:03 +00:00
|
|
|
crl::async([=] {
|
|
|
|
if (UnpackSet(path, folder)) {
|
|
|
|
QFile(path).remove();
|
2020-02-05 14:13:12 +00:00
|
|
|
SwitchToSet(id(), crl::guard(weak, [=](bool success) {
|
2018-12-27 08:01:03 +00:00
|
|
|
if (success) {
|
|
|
|
destroy();
|
|
|
|
} else {
|
|
|
|
fail();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
crl::on_main(weak, [=] {
|
|
|
|
fail();
|
|
|
|
});
|
2018-12-26 17:05:06 +00:00
|
|
|
}
|
2018-12-27 08:01:03 +00:00
|
|
|
});
|
2018-12-26 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Loader::destroy() {
|
2018-12-27 08:01:03 +00:00
|
|
|
Expects(GlobalLoader == this);
|
2018-12-26 17:05:06 +00:00
|
|
|
|
2018-12-27 08:01:03 +00:00
|
|
|
SetGlobalLoader(nullptr);
|
2018-12-26 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 15:06:44 +00:00
|
|
|
void Loader::fail() {
|
|
|
|
ClearNeedSwitchToId();
|
|
|
|
BlobLoader::fail();
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
Inner::Inner(QWidget *parent, not_null<Main::Session*> session)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _session(session) {
|
2018-12-26 14:00:08 +00:00
|
|
|
setupContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Inner::setupContent() {
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2020-02-06 15:32:02 +00:00
|
|
|
for (const auto &set : kSets) {
|
2020-06-10 10:49:10 +00:00
|
|
|
content->add(object_ptr<Row>(content, _session, set));
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
content->resizeToWidth(st::boxWidth);
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
Row::Row(QWidget *widget, not_null<Main::Session*> session, const Set &set)
|
2020-11-29 18:26:49 +00:00
|
|
|
: RippleButton(widget, st::defaultRippleAnimation)
|
2020-06-10 10:49:10 +00:00
|
|
|
, _session(session)
|
2018-12-26 14:00:08 +00:00
|
|
|
, _id(set.id)
|
|
|
|
, _state(Available{ set.size }) {
|
|
|
|
setupContent(set);
|
|
|
|
setupHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2018-12-27 09:37:11 +00:00
|
|
|
const auto over = showOver();
|
2018-12-26 14:00:08 +00:00
|
|
|
const auto bg = over ? st::windowBgOver : st::windowBg;
|
|
|
|
p.fillRect(rect(), bg);
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, 0, 0);
|
2019-01-02 12:11:13 +00:00
|
|
|
paintPreview(p);
|
2019-04-04 15:24:13 +00:00
|
|
|
paintRadio(p);
|
2019-01-02 12:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Row::paintPreview(Painter &p) const {
|
|
|
|
const auto x = st::manageEmojiPreviewPadding.left();
|
|
|
|
const auto y = st::manageEmojiPreviewPadding.top();
|
|
|
|
const auto width = st::manageEmojiPreviewWidth;
|
|
|
|
const auto height = st::manageEmojiPreviewWidth;
|
2021-03-13 12:12:08 +00:00
|
|
|
auto &&preview = ranges::views::zip(_preview, ranges::views::ints(0, int(_preview.size())));
|
2019-01-02 12:11:13 +00:00
|
|
|
for (const auto &[pixmap, index] : preview) {
|
|
|
|
const auto row = (index / 2);
|
|
|
|
const auto column = (index % 2);
|
|
|
|
const auto left = x + (column ? width - st::manageEmojiPreview : 0);
|
|
|
|
const auto top = y + (row ? height - st::manageEmojiPreview : 0);
|
|
|
|
p.drawPixmap(left, top, pixmap);
|
2018-12-27 09:37:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
void Row::paintRadio(Painter &p) {
|
2020-02-11 10:12:42 +00:00
|
|
|
if (_loading && !_loading->animating()) {
|
|
|
|
_loading = nullptr;
|
|
|
|
}
|
2019-01-02 12:11:13 +00:00
|
|
|
const auto loading = _loading
|
|
|
|
? _loading->computeState()
|
|
|
|
: Ui::RadialState{ 0., 0, FullArcLength };
|
2020-08-31 08:14:53 +00:00
|
|
|
const auto isToggledSet = v::is<Active>(_state.current());
|
|
|
|
const auto isActiveSet = isToggledSet || v::is<Loading>(_state.current());
|
2019-04-02 09:13:30 +00:00
|
|
|
const auto toggled = _toggled.value(isToggledSet ? 1. : 0.);
|
|
|
|
const auto active = _active.value(isActiveSet ? 1. : 0.);
|
2019-01-02 12:11:13 +00:00
|
|
|
const auto _st = &st::defaultRadio;
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
const auto left = width()
|
|
|
|
- st::manageEmojiMarginRight
|
|
|
|
- _st->diameter
|
|
|
|
- _st->thickness;
|
|
|
|
const auto top = (height() - _st->diameter - _st->thickness) / 2;
|
|
|
|
const auto outerWidth = width();
|
|
|
|
|
|
|
|
auto pen = anim::pen(_st->untoggledFg, _st->toggledFg, active);
|
|
|
|
pen.setWidth(_st->thickness);
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
p.setPen(pen);
|
|
|
|
p.setBrush(_st->bg);
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto rect = style::rtlrect(QRectF(
|
2019-01-02 12:11:13 +00:00
|
|
|
left,
|
|
|
|
top,
|
|
|
|
_st->diameter,
|
|
|
|
_st->diameter
|
|
|
|
).marginsRemoved(QMarginsF(
|
|
|
|
_st->thickness / 2.,
|
|
|
|
_st->thickness / 2.,
|
|
|
|
_st->thickness / 2.,
|
|
|
|
_st->thickness / 2.
|
|
|
|
)), outerWidth);
|
|
|
|
if (loading.shown > 0 && anim::Disabled()) {
|
|
|
|
anim::DrawStaticLoading(
|
|
|
|
p,
|
|
|
|
rect,
|
|
|
|
_st->thickness,
|
|
|
|
pen.color(),
|
|
|
|
_st->bg);
|
|
|
|
} else if (loading.arcLength < FullArcLength) {
|
|
|
|
p.drawArc(rect, loading.arcFrom, loading.arcLength);
|
|
|
|
} else {
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
}
|
2018-12-27 09:37:11 +00:00
|
|
|
|
2019-01-02 12:11:13 +00:00
|
|
|
if (toggled > 0 && (!_loading || !anim::Disabled())) {
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(anim::brush(_st->untoggledFg, _st->toggledFg, toggled));
|
|
|
|
|
|
|
|
const auto skip0 = _st->diameter / 2.;
|
|
|
|
const auto skip1 = _st->skip / 10.;
|
|
|
|
const auto checkSkip = skip0 * (1. - toggled) + skip1 * toggled;
|
2019-09-13 12:22:54 +00:00
|
|
|
p.drawEllipse(style::rtlrect(QRectF(
|
2019-01-02 12:11:13 +00:00
|
|
|
left,
|
|
|
|
top,
|
|
|
|
_st->diameter,
|
|
|
|
_st->diameter
|
|
|
|
).marginsRemoved(QMarginsF(
|
|
|
|
checkSkip,
|
|
|
|
checkSkip,
|
|
|
|
checkSkip,
|
|
|
|
checkSkip
|
|
|
|
)), outerWidth));
|
|
|
|
}
|
2018-12-27 09:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Row::showOver(State state) const {
|
|
|
|
return (!(state & StateFlag::Disabled))
|
|
|
|
&& (state & (StateFlag::Over | StateFlag::Down));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Row::showOver() const {
|
|
|
|
return showOver(state());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
2019-01-02 12:11:13 +00:00
|
|
|
if (showOver() != showOver(was)) {
|
|
|
|
updateStatusColorOverride();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::updateStatusColorOverride() {
|
2020-08-31 08:14:53 +00:00
|
|
|
const auto isToggledSet = v::is<Active>(_state.current());
|
2019-04-02 09:13:30 +00:00
|
|
|
const auto toggled = _toggled.value(isToggledSet ? 1. : 0.);
|
2018-12-27 09:37:11 +00:00
|
|
|
const auto over = showOver();
|
2019-01-02 12:11:13 +00:00
|
|
|
if (toggled == 0. && !over) {
|
|
|
|
_status->setTextColorOverride(std::nullopt);
|
|
|
|
} else {
|
|
|
|
_status->setTextColorOverride(anim::color(
|
|
|
|
over ? st::contactsStatusFgOver : st::contactsStatusFg,
|
|
|
|
st::contactsStatusFgOnline,
|
|
|
|
toggled));
|
2018-12-27 09:37:11 +00:00
|
|
|
}
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Row::setupContent(const Set &set) {
|
|
|
|
_state = GlobalLoaderValues.events_starting_with(
|
2018-12-27 08:01:03 +00:00
|
|
|
GlobalLoader.get()
|
2018-12-26 14:00:08 +00:00
|
|
|
) | rpl::map([=](Loader *loader) {
|
|
|
|
return (loader && loader->id() == _id)
|
|
|
|
? loader->state()
|
|
|
|
: rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
|
|
|
Updated()
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return ComputeState(_id);
|
|
|
|
});
|
|
|
|
}) | rpl::flatten_latest(
|
|
|
|
) | rpl::filter([=](const SetState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return !v::is<Failed>(_state.current())
|
|
|
|
|| !v::is<Available>(state);
|
2018-12-26 14:00:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
setupLabels(set);
|
2019-01-02 12:11:13 +00:00
|
|
|
setupPreview(set);
|
2018-12-27 09:37:11 +00:00
|
|
|
setupAnimation();
|
2018-12-26 14:00:08 +00:00
|
|
|
|
2019-01-02 12:11:13 +00:00
|
|
|
const auto height = st::manageEmojiPreviewPadding.top()
|
|
|
|
+ st::manageEmojiPreviewHeight
|
|
|
|
+ st::manageEmojiPreviewPadding.bottom();
|
|
|
|
resize(width(), height);
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Row::setupHandler() {
|
|
|
|
clicks(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
const auto &state = _state.current();
|
2020-08-31 08:14:53 +00:00
|
|
|
return !_switching && (v::is<Ready>(state)
|
|
|
|
|| v::is<Available>(state));
|
2018-12-26 14:00:08 +00:00
|
|
|
}) | rpl::start_with_next([=] {
|
2020-08-31 08:14:53 +00:00
|
|
|
if (v::is<Available>(_state.current())) {
|
2018-12-26 17:05:06 +00:00
|
|
|
load();
|
|
|
|
return;
|
|
|
|
}
|
2018-12-27 08:01:03 +00:00
|
|
|
_switching = true;
|
|
|
|
SwitchToSet(_id, crl::guard(this, [=](bool success) {
|
|
|
|
_switching = false;
|
|
|
|
if (!success) {
|
2018-12-26 17:05:06 +00:00
|
|
|
load();
|
2018-12-27 08:01:03 +00:00
|
|
|
} else if (GlobalLoader && GlobalLoader->id() == _id) {
|
|
|
|
GlobalLoader->destroy();
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
2018-12-27 08:01:03 +00:00
|
|
|
}));
|
2018-12-26 14:00:08 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_state.value(
|
2018-12-26 17:05:06 +00:00
|
|
|
) | rpl::map([=](const SetState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return v::is<Ready>(state) || v::is<Available>(state);
|
2018-12-26 14:00:08 +00:00
|
|
|
}) | rpl::start_with_next([=](bool active) {
|
|
|
|
setDisabled(!active);
|
|
|
|
setPointerCursor(active);
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2018-12-26 17:05:06 +00:00
|
|
|
void Row::load() {
|
2020-06-10 10:49:10 +00:00
|
|
|
LoadAndSwitchTo(_session, _id);
|
2018-12-26 17:05:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
void Row::setupLabels(const Set &set) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
this,
|
|
|
|
set.name,
|
|
|
|
st::localStorageRowTitle);
|
2018-12-26 17:05:06 +00:00
|
|
|
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2018-12-27 09:37:11 +00:00
|
|
|
_status = Ui::CreateChild<Ui::FlatLabel>(
|
2018-12-26 14:00:08 +00:00
|
|
|
this,
|
|
|
|
_state.value() | rpl::map(StateDescription),
|
|
|
|
st::localStorageRowSize);
|
2018-12-27 09:37:11 +00:00
|
|
|
_status->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2018-12-26 14:00:08 +00:00
|
|
|
|
|
|
|
sizeValue(
|
|
|
|
) | rpl::start_with_next([=](QSize size) {
|
2019-01-02 12:11:13 +00:00
|
|
|
const auto left = st::manageEmojiPreviewPadding.left()
|
|
|
|
+ st::manageEmojiPreviewWidth
|
|
|
|
+ st::manageEmojiPreviewPadding.right();
|
|
|
|
const auto namey = st::manageEmojiPreviewPadding.top()
|
|
|
|
+ st::manageEmojiNameTop;
|
|
|
|
const auto statusy = st::manageEmojiPreviewPadding.top()
|
|
|
|
+ st::manageEmojiStatusTop;
|
2018-12-26 14:00:08 +00:00
|
|
|
name->moveToLeft(left, namey);
|
2018-12-27 09:37:11 +00:00
|
|
|
_status->moveToLeft(left, statusy);
|
2018-12-26 14:00:08 +00:00
|
|
|
}, name->lifetime());
|
|
|
|
}
|
|
|
|
|
2019-01-02 12:11:13 +00:00
|
|
|
void Row::setupPreview(const Set &set) {
|
|
|
|
const auto size = st::manageEmojiPreview * cIntRetinaFactor();
|
|
|
|
const auto original = QImage(set.previewPath);
|
|
|
|
const auto full = original.height();
|
2021-03-13 12:12:08 +00:00
|
|
|
auto &&preview = ranges::views::zip(_preview, ranges::views::ints(0, int(_preview.size())));
|
2019-01-02 12:11:13 +00:00
|
|
|
for (auto &&[pixmap, index] : preview) {
|
|
|
|
pixmap = App::pixmapFromImageInPlace(original.copy(
|
|
|
|
{ full * index, 0, full, full }
|
|
|
|
).scaledToWidth(size, Qt::SmoothTransformation));
|
|
|
|
pixmap.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 10:12:42 +00:00
|
|
|
void Row::updateLoadingToFinished() {
|
|
|
|
_loading->update(
|
2020-08-31 08:14:53 +00:00
|
|
|
v::is<Failed>(_state.current()) ? 0. : 1.,
|
2020-02-11 10:12:42 +00:00
|
|
|
true,
|
|
|
|
crl::now());
|
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
void Row::radialAnimationCallback(crl::time now) {
|
|
|
|
const auto updated = [&] {
|
|
|
|
const auto state = _state.current();
|
2020-08-31 08:14:53 +00:00
|
|
|
if (const auto loading = std::get_if<Loading>(&state)) {
|
2020-02-11 10:12:42 +00:00
|
|
|
return _loading->update(CountProgress(loading), false, now);
|
|
|
|
} else {
|
|
|
|
updateLoadingToFinished();
|
2019-04-04 15:24:13 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}();
|
|
|
|
if (!anim::Disabled() || updated) {
|
2018-12-27 09:37:11 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::setupAnimation() {
|
2019-01-02 12:11:13 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
2018-12-27 09:37:11 +00:00
|
|
|
_state.value(
|
|
|
|
) | rpl::start_with_next([=](const SetState &state) {
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2019-01-02 12:11:13 +00:00
|
|
|
|
|
|
|
_state.value(
|
|
|
|
) | rpl::map(
|
2020-08-31 08:14:53 +00:00
|
|
|
_1 == SetState{ Active() }
|
2019-01-02 12:11:13 +00:00
|
|
|
) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](bool toggled) {
|
|
|
|
_toggled.start(
|
|
|
|
[=] { updateStatusColorOverride(); update(); },
|
|
|
|
toggled ? 0. : 1.,
|
|
|
|
toggled ? 1. : 0.,
|
|
|
|
st::defaultRadio.duration);
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_state.value(
|
|
|
|
) | rpl::map([](const SetState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return v::is<Loading>(state) || v::is<Active>(state);
|
2019-01-02 12:11:13 +00:00
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](bool active) {
|
|
|
|
_active.start(
|
|
|
|
[=] { update(); },
|
|
|
|
active ? 0. : 1.,
|
|
|
|
active ? 1. : 0.,
|
|
|
|
st::defaultRadio.duration);
|
|
|
|
}, lifetime());
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
_state.value(
|
|
|
|
) | rpl::map([](const SetState &state) {
|
2020-08-31 08:14:53 +00:00
|
|
|
return std::get_if<Loading>(&state);
|
2019-04-04 15:24:13 +00:00
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](const Loading *loading) {
|
|
|
|
if (loading && !_loading) {
|
2018-12-27 09:37:11 +00:00
|
|
|
_loading = std::make_unique<Ui::RadialAnimation>(
|
2019-04-04 15:24:13 +00:00
|
|
|
[=](crl::time now) { radialAnimationCallback(now); });
|
2020-02-11 10:12:42 +00:00
|
|
|
_loading->start(CountProgress(loading));
|
2019-04-04 15:24:13 +00:00
|
|
|
} else if (!loading && _loading) {
|
2020-02-11 10:12:42 +00:00
|
|
|
updateLoadingToFinished();
|
2018-12-27 09:37:11 +00:00
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_toggled.stop();
|
|
|
|
_active.stop();
|
|
|
|
updateStatusColorOverride();
|
2018-12-27 09:37:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
ManageSetsBox::ManageSetsBox(QWidget*, not_null<Main::Session*> session)
|
|
|
|
: _session(session) {
|
2018-12-26 14:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ManageSetsBox::prepare() {
|
2020-06-10 10:49:10 +00:00
|
|
|
const auto inner = setInnerWidget(object_ptr<Inner>(this, _session));
|
2018-12-26 14:00:08 +00:00
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_emoji_manage_sets());
|
2018-12-26 14:00:08 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_close(), [=] { closeBox(); });
|
2018-12-26 14:00:08 +00:00
|
|
|
|
|
|
|
setDimensionsToContent(st::boxWidth, inner);
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
void LoadAndSwitchTo(not_null<Main::Session*> session, int id) {
|
2020-05-07 15:06:44 +00:00
|
|
|
if (!ranges::contains(kSets, id, &Set::id)) {
|
|
|
|
ClearNeedSwitchToId();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetGlobalLoader(base::make_unique_q<Loader>(
|
2020-06-10 10:49:10 +00:00
|
|
|
session,
|
2020-05-07 15:06:44 +00:00
|
|
|
id,
|
|
|
|
GetDownloadLocation(id),
|
|
|
|
internal::SetDataPath(id),
|
|
|
|
GetDownloadSize(id)));
|
|
|
|
}
|
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
} // namespace Emoji
|
|
|
|
} // namespace Ui
|