2018-09-05 19:05:49 +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 "settings/settings_chat.h"
|
|
|
|
|
|
|
|
#include "settings/settings_common.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "boxes/connection_box.h"
|
2018-12-06 15:47:28 +00:00
|
|
|
#include "boxes/auto_download_box.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "boxes/stickers_box.h"
|
2019-09-09 09:02:06 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "boxes/background_box.h"
|
2019-02-08 13:43:31 +00:00
|
|
|
#include "boxes/background_preview_box.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "boxes/download_path_box.h"
|
2018-09-17 10:52:34 +00:00
|
|
|
#include "boxes/local_storage_box.h"
|
2019-08-20 16:03:14 +00:00
|
|
|
#include "boxes/edit_color_box.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2018-09-29 12:18:26 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2019-11-02 17:06:47 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2018-10-07 20:16:23 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-02-08 13:43:31 +00:00
|
|
|
#include "ui/image/image_source.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
#include "window/themes/window_themes_embedded.h"
|
2019-09-03 08:25:19 +00:00
|
|
|
#include "window/themes/window_theme_editor_box.h"
|
2019-09-03 15:24:51 +00:00
|
|
|
#include "window/themes/window_themes_cloud_list.h"
|
2019-07-24 14:00:30 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2019-09-03 15:24:51 +00:00
|
|
|
#include "window/window_controller.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
|
|
|
#include "core/file_utilities.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
#include "core/application.h"
|
2018-09-17 10:52:34 +00:00
|
|
|
#include "data/data_session.h"
|
2019-09-03 15:24:51 +00:00
|
|
|
#include "data/data_cloud_themes.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2018-12-26 14:00:08 +00:00
|
|
|
#include "chat_helpers/emoji_sets_manager.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2019-09-26 10:55:35 +00:00
|
|
|
#include "base/call_delayed.h"
|
2018-09-29 12:18:26 +00:00
|
|
|
#include "support/support_common.h"
|
2018-10-05 08:14:00 +00:00
|
|
|
#include "support/support_templates.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-09-07 12:19:56 +00:00
|
|
|
#include "mainwidget.h"
|
2019-09-03 08:25:19 +00:00
|
|
|
#include "mainwindow.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "styles/style_settings.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
2019-08-23 16:00:24 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const auto kSchemesList = Window::Theme::EmbeddedThemes();
|
2019-09-02 09:04:49 +00:00
|
|
|
constexpr auto kCustomColorButtonParts = 7;
|
2019-08-23 16:00:24 +00:00
|
|
|
|
|
|
|
class ColorsPalette final {
|
|
|
|
public:
|
|
|
|
using Type = Window::Theme::EmbeddedType;
|
|
|
|
using Scheme = Window::Theme::EmbeddedScheme;
|
|
|
|
|
|
|
|
explicit ColorsPalette(not_null<Ui::VerticalLayout*> container);
|
|
|
|
|
|
|
|
void show(Type type);
|
|
|
|
|
|
|
|
rpl::producer<QColor> selected() const;
|
|
|
|
|
|
|
|
private:
|
2019-09-02 09:04:49 +00:00
|
|
|
class Button {
|
|
|
|
public:
|
|
|
|
Button(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
std::vector<QColor> &&colors,
|
|
|
|
bool selected);
|
|
|
|
|
|
|
|
void moveToLeft(int x, int y);
|
|
|
|
void update(std::vector<QColor> &&colors, bool selected);
|
|
|
|
rpl::producer<> clicks() const;
|
|
|
|
bool selected() const;
|
|
|
|
QColor color() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paint();
|
|
|
|
|
|
|
|
Ui::AbstractButton _widget;
|
|
|
|
std::vector<QColor> _colors;
|
|
|
|
Ui::Animations::Simple _selectedAnimation;
|
|
|
|
bool _selected = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void show(
|
|
|
|
not_null<const Scheme*> scheme,
|
|
|
|
std::vector<QColor> &&colors,
|
|
|
|
int selected);
|
|
|
|
void selectCustom(not_null<const Scheme*> scheme);
|
2019-08-23 16:00:24 +00:00
|
|
|
void updateInnerGeometry();
|
|
|
|
|
|
|
|
not_null<Ui::SlideWrap<>*> _outer;
|
2019-09-02 09:04:49 +00:00
|
|
|
std::vector<std::unique_ptr<Button>> _buttons;
|
2019-08-23 16:00:24 +00:00
|
|
|
|
|
|
|
rpl::event_stream<QColor> _selected;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-09-02 09:04:49 +00:00
|
|
|
void PaintColorButton(Painter &p, QColor color, float64 selected) {
|
|
|
|
const auto size = st::settingsAccentColorSize;
|
|
|
|
const auto rect = QRect(0, 0, size, size);
|
|
|
|
|
|
|
|
p.setBrush(color);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
|
|
|
|
if (selected > 0.) {
|
|
|
|
const auto startSkip = -st::settingsAccentColorLine / 2.;
|
|
|
|
const auto endSkip = float64(st::settingsAccentColorSkip);
|
|
|
|
const auto skip = startSkip + (endSkip - startSkip) * selected;
|
|
|
|
auto pen = st::boxBg->p;
|
|
|
|
pen.setWidth(st::settingsAccentColorLine);
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
p.setPen(pen);
|
|
|
|
p.setOpacity(selected);
|
|
|
|
p.drawEllipse(QRectF(rect).marginsRemoved({ skip, skip, skip, skip }));
|
|
|
|
}
|
2019-08-23 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 09:04:49 +00:00
|
|
|
void PaintCustomButton(Painter &p, const std::vector<QColor> &colors) {
|
|
|
|
Expects(colors.size() >= kCustomColorButtonParts);
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
|
2019-08-23 16:00:24 +00:00
|
|
|
const auto size = st::settingsAccentColorSize;
|
2019-09-02 09:04:49 +00:00
|
|
|
const auto smallSize = size / 8.;
|
|
|
|
const auto drawAround = [&](QPointF center, int index) {
|
|
|
|
const auto where = QPointF{
|
|
|
|
size * (1. + center.x()) / 2,
|
|
|
|
size * (1. + center.y()) / 2
|
2019-08-23 16:00:24 +00:00
|
|
|
};
|
2019-09-02 09:04:49 +00:00
|
|
|
p.setBrush(colors[index]);
|
|
|
|
p.drawEllipse(
|
|
|
|
where.x() - smallSize,
|
|
|
|
where.y() - smallSize,
|
|
|
|
2 * smallSize,
|
|
|
|
2 * smallSize);
|
|
|
|
};
|
|
|
|
drawAround(QPointF(), 0);
|
|
|
|
for (auto i = 0; i != 6; ++i) {
|
|
|
|
const auto angle = i * M_PI / 3.;
|
|
|
|
const auto point = QPointF{ cos(angle), sin(angle) };
|
|
|
|
const auto adjusted = point * (1. - (2 * smallSize / size));
|
|
|
|
drawAround(adjusted, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorsPalette::Button::Button(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
std::vector<QColor> &&colors,
|
|
|
|
bool selected)
|
|
|
|
: _widget(parent.get())
|
|
|
|
, _colors(std::move(colors))
|
|
|
|
, _selected(selected) {
|
|
|
|
_widget.show();
|
|
|
|
_widget.resize(st::settingsAccentColorSize, st::settingsAccentColorSize);
|
|
|
|
_widget.paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
paint();
|
|
|
|
}, _widget.lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorsPalette::Button::moveToLeft(int x, int y) {
|
|
|
|
_widget.moveToLeft(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorsPalette::Button::update(
|
|
|
|
std::vector<QColor> &&colors,
|
|
|
|
bool selected) {
|
|
|
|
if (_colors != colors) {
|
|
|
|
_colors = std::move(colors);
|
|
|
|
_widget.update();
|
|
|
|
}
|
|
|
|
if (_selected != selected) {
|
|
|
|
_selected = selected;
|
|
|
|
_selectedAnimation.start(
|
|
|
|
[=] { _widget.update(); },
|
|
|
|
_selected ? 0. : 1.,
|
|
|
|
_selected ? 1. : 0.,
|
|
|
|
st::defaultRadio.duration * 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ColorsPalette::Button::clicks() const {
|
|
|
|
return _widget.clicks() | rpl::map([] { return rpl::empty_value(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ColorsPalette::Button::selected() const {
|
|
|
|
return _selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor ColorsPalette::Button::color() const {
|
|
|
|
Expects(_colors.size() == 1);
|
|
|
|
|
|
|
|
return _colors.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorsPalette::Button::paint() {
|
|
|
|
Painter p(&_widget);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
if (_colors.size() == 1) {
|
|
|
|
PaintColorButton(
|
|
|
|
p,
|
|
|
|
_colors.front(),
|
|
|
|
_selectedAnimation.value(_selected ? 1. : 0.));
|
|
|
|
} else if (_colors.size() >= kCustomColorButtonParts) {
|
|
|
|
PaintCustomButton(p, _colors);
|
|
|
|
}
|
2019-08-23 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorsPalette::ColorsPalette(not_null<Ui::VerticalLayout*> container)
|
|
|
|
: _outer(container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Ui::RpWidget>(container)))) {
|
|
|
|
_outer->hide(anim::type::instant);
|
|
|
|
|
|
|
|
const auto inner = _outer->entity();
|
|
|
|
inner->widthValue(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateInnerGeometry();
|
|
|
|
}, inner->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorsPalette::show(Type type) {
|
|
|
|
const auto scheme = ranges::find(kSchemesList, type, &Scheme::type);
|
|
|
|
if (scheme == end(kSchemesList)) {
|
|
|
|
_outer->hide(anim::type::instant);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto list = Window::Theme::DefaultAccentColors(type);
|
|
|
|
if (list.empty()) {
|
|
|
|
_outer->hide(anim::type::instant);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
list.insert(list.begin(), scheme->accentColor);
|
|
|
|
const auto color = Core::App().settings().themesAccentColors().get(type);
|
|
|
|
const auto current = color.value_or(scheme->accentColor);
|
|
|
|
const auto i = ranges::find(list, current);
|
|
|
|
if (i == end(list)) {
|
|
|
|
list.back() = current;
|
|
|
|
}
|
2019-09-02 09:04:49 +00:00
|
|
|
const auto selected = std::clamp(
|
|
|
|
int(i - begin(list)),
|
|
|
|
0,
|
|
|
|
int(list.size()) - 1);
|
|
|
|
|
2019-08-23 16:00:24 +00:00
|
|
|
_outer->show(anim::type::instant);
|
2019-09-02 09:04:49 +00:00
|
|
|
|
|
|
|
show(&*scheme, std::move(list), selected);
|
|
|
|
|
2019-08-23 16:00:24 +00:00
|
|
|
const auto inner = _outer->entity();
|
|
|
|
inner->resize(_outer->width(), inner->height());
|
|
|
|
updateInnerGeometry();
|
|
|
|
}
|
|
|
|
|
2019-09-02 09:04:49 +00:00
|
|
|
void ColorsPalette::show(
|
|
|
|
not_null<const Scheme*> scheme,
|
|
|
|
std::vector<QColor> &&colors,
|
|
|
|
int selected) {
|
|
|
|
Expects(selected >= 0 && selected < colors.size());
|
|
|
|
|
|
|
|
while (_buttons.size() > colors.size()) {
|
|
|
|
_buttons.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto index = 0;
|
|
|
|
const auto inner = _outer->entity();
|
|
|
|
const auto pushButton = [&](std::vector<QColor> &&colors) {
|
|
|
|
auto result = rpl::producer<>();
|
|
|
|
const auto chosen = (index == selected);
|
|
|
|
if (_buttons.size() > index) {
|
|
|
|
_buttons[index]->update(std::move(colors), chosen);
|
|
|
|
} else {
|
|
|
|
_buttons.push_back(std::make_unique<Button>(
|
|
|
|
inner,
|
|
|
|
std::move(colors),
|
|
|
|
chosen));
|
|
|
|
result = _buttons.back()->clicks();
|
|
|
|
}
|
|
|
|
++index;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
for (const auto &color : colors) {
|
|
|
|
auto clicks = pushButton({ color });
|
|
|
|
if (clicks) {
|
|
|
|
std::move(
|
|
|
|
clicks
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return _buttons[index - 1]->color();
|
|
|
|
}) | rpl::start_with_next([=](QColor color) {
|
|
|
|
_selected.fire_copy(color);
|
|
|
|
}, inner->lifetime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto clicks = pushButton(std::move(colors));
|
|
|
|
if (clicks) {
|
|
|
|
std::move(
|
|
|
|
clicks
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
selectCustom(scheme);
|
|
|
|
}, inner->lifetime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorsPalette::selectCustom(not_null<const Scheme*> scheme) {
|
|
|
|
const auto selected = ranges::find(_buttons, true, &Button::selected);
|
|
|
|
Assert(selected != end(_buttons));
|
|
|
|
|
|
|
|
const auto colorizer = Window::Theme::ColorizerFrom(
|
|
|
|
*scheme,
|
|
|
|
scheme->accentColor);
|
|
|
|
auto box = Box<EditColorBox>(
|
|
|
|
tr::lng_settings_theme_accent_title(tr::now),
|
|
|
|
EditColorBox::Mode::HSL,
|
|
|
|
(*selected)->color());
|
|
|
|
box->setLightnessLimits(
|
|
|
|
colorizer.lightnessMin,
|
|
|
|
colorizer.lightnessMax);
|
|
|
|
box->setSaveCallback(crl::guard(_outer, [=](QColor result) {
|
|
|
|
_selected.fire_copy(result);
|
|
|
|
}));
|
|
|
|
Ui::show(std::move(box));
|
|
|
|
}
|
|
|
|
|
2019-08-23 16:00:24 +00:00
|
|
|
rpl::producer<QColor> ColorsPalette::selected() const {
|
|
|
|
return _selected.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColorsPalette::updateInnerGeometry() {
|
2019-09-02 09:04:49 +00:00
|
|
|
if (_buttons.size() < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-23 16:00:24 +00:00
|
|
|
const auto inner = _outer->entity();
|
|
|
|
const auto size = st::settingsAccentColorSize;
|
|
|
|
const auto padding = st::settingsButton.padding;
|
|
|
|
const auto width = inner->width() - padding.left() - padding.right();
|
2019-09-02 09:04:49 +00:00
|
|
|
const auto skip = (width - size * _buttons.size())
|
|
|
|
/ float64(_buttons.size() - 1);
|
|
|
|
const auto y = st::settingsSectionSkip * 2;
|
|
|
|
auto x = float64(padding.left());
|
|
|
|
for (const auto &button : _buttons) {
|
|
|
|
button->moveToLeft(int(std::round(x)), y);
|
|
|
|
x += size + skip;
|
2019-08-23 16:00:24 +00:00
|
|
|
}
|
2019-09-02 09:04:49 +00:00
|
|
|
inner->resize(inner->width(), y + size);
|
2019-08-23 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2018-09-07 12:19:56 +00:00
|
|
|
|
|
|
|
class BackgroundRow : public Ui::RpWidget {
|
|
|
|
public:
|
2019-07-24 14:00:30 +00:00
|
|
|
BackgroundRow(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateImage();
|
|
|
|
|
|
|
|
float64 radialProgress() const;
|
|
|
|
bool radialLoading() const;
|
|
|
|
QRect radialRect() const;
|
|
|
|
void radialStart();
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time radialTimeShift() const;
|
2019-04-01 17:44:54 +00:00
|
|
|
void radialAnimationCallback(crl::time now);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
|
|
|
QPixmap _background;
|
|
|
|
object_ptr<Ui::LinkButton> _chooseFromGallery;
|
|
|
|
object_ptr<Ui::LinkButton> _chooseFromFile;
|
|
|
|
|
|
|
|
Ui::RadialAnimation _radial;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void ChooseFromFile(
|
|
|
|
not_null<::Main::Session*> session,
|
|
|
|
not_null<QWidget*> parent);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
BackgroundRow::BackgroundRow(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: RpWidget(parent)
|
2018-09-07 12:19:56 +00:00
|
|
|
, _chooseFromGallery(
|
|
|
|
this,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_settings_bg_from_gallery(tr::now),
|
2018-09-07 12:19:56 +00:00
|
|
|
st::settingsLink)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _chooseFromFile(this, tr::lng_settings_bg_from_file(tr::now), st::settingsLink)
|
2019-04-01 17:44:54 +00:00
|
|
|
, _radial([=](crl::time now) { radialAnimationCallback(now); }) {
|
2018-09-07 12:19:56 +00:00
|
|
|
updateImage();
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
_chooseFromGallery->addClickHandler([=] {
|
|
|
|
Ui::show(Box<BackgroundBox>(&controller->session()));
|
2018-09-07 12:19:56 +00:00
|
|
|
});
|
|
|
|
_chooseFromFile->addClickHandler([=] {
|
2019-07-24 14:00:30 +00:00
|
|
|
ChooseFromFile(&controller->session(), this);
|
2018-09-07 12:19:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
using Update = const Window::Theme::BackgroundUpdate;
|
|
|
|
base::ObservableViewer(
|
|
|
|
*Window::Theme::Background()
|
|
|
|
) | rpl::filter([](const Update &update) {
|
|
|
|
return (update.type == Update::Type::New
|
|
|
|
|| update.type == Update::Type::Start
|
|
|
|
|| update.type == Update::Type::Changed);
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
updateImage();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRow::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
const auto radial = _radial.animating();
|
|
|
|
const auto radialOpacity = radial ? _radial.opacity() : 0.;
|
2018-09-07 12:19:56 +00:00
|
|
|
if (radial) {
|
|
|
|
const auto backThumb = App::main()->newBackgroundThumb();
|
2019-01-25 14:37:28 +00:00
|
|
|
if (!backThumb) {
|
2018-09-07 12:19:56 +00:00
|
|
|
p.drawPixmap(0, 0, _background);
|
|
|
|
} else {
|
|
|
|
const auto &pix = backThumb->pixBlurred(
|
|
|
|
Data::FileOrigin(),
|
|
|
|
st::settingsBackgroundThumb);
|
|
|
|
const auto factor = cIntRetinaFactor();
|
|
|
|
p.drawPixmap(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
pix,
|
|
|
|
0,
|
|
|
|
(pix.height() - st::settingsBackgroundThumb * factor) / 2,
|
|
|
|
st::settingsBackgroundThumb * factor,
|
|
|
|
st::settingsBackgroundThumb * factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto outer = radialRect();
|
|
|
|
const auto inner = QRect(
|
|
|
|
QPoint(
|
|
|
|
outer.x() + (outer.width() - st::radialSize.width()) / 2,
|
|
|
|
outer.y() + (outer.height() - st::radialSize.height()) / 2),
|
|
|
|
st::radialSize);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setOpacity(radialOpacity);
|
|
|
|
p.setBrush(st::radialBg);
|
|
|
|
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setOpacity(1);
|
|
|
|
const auto arc = inner.marginsRemoved(QMargins(
|
|
|
|
st::radialLine,
|
|
|
|
st::radialLine,
|
|
|
|
st::radialLine,
|
|
|
|
st::radialLine));
|
|
|
|
_radial.draw(p, arc, st::radialLine, st::radialFg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(0, 0, _background);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int BackgroundRow::resizeGetHeight(int newWidth) {
|
|
|
|
auto linkTop = st::settingsFromGalleryTop;
|
|
|
|
auto linkLeft = st::settingsBackgroundThumb + st::settingsThumbSkip;
|
|
|
|
auto linkWidth = newWidth - linkLeft;
|
|
|
|
_chooseFromGallery->resizeToWidth(
|
|
|
|
qMin(linkWidth, _chooseFromGallery->naturalWidth()));
|
|
|
|
_chooseFromFile->resizeToWidth(
|
|
|
|
qMin(linkWidth, _chooseFromFile->naturalWidth()));
|
|
|
|
_chooseFromGallery->moveToLeft(linkLeft, linkTop, newWidth);
|
|
|
|
linkTop += _chooseFromGallery->height() + st::settingsFromFileTop;
|
|
|
|
_chooseFromFile->moveToLeft(linkLeft, linkTop, newWidth);
|
|
|
|
return st::settingsBackgroundThumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 BackgroundRow::radialProgress() const {
|
|
|
|
return App::main()->chatBackgroundProgress();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundRow::radialLoading() const {
|
|
|
|
const auto main = App::main();
|
|
|
|
if (main->chatBackgroundLoading()) {
|
|
|
|
main->checkChatBackground();
|
|
|
|
if (main->chatBackgroundLoading()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
const_cast<BackgroundRow*>(this)->updateImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect BackgroundRow::radialRect() const {
|
|
|
|
return QRect(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
st::settingsBackgroundThumb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRow::radialStart() {
|
|
|
|
if (radialLoading() && !_radial.animating()) {
|
|
|
|
_radial.start(radialProgress());
|
|
|
|
if (const auto shift = radialTimeShift()) {
|
|
|
|
_radial.update(
|
|
|
|
radialProgress(),
|
|
|
|
!radialLoading(),
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::now() + shift);
|
2018-09-07 12:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time BackgroundRow::radialTimeShift() const {
|
2018-09-07 12:19:56 +00:00
|
|
|
return st::radialDuration;
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
void BackgroundRow::radialAnimationCallback(crl::time now) {
|
2018-09-20 16:39:59 +00:00
|
|
|
const auto updated = _radial.update(
|
2018-09-07 12:19:56 +00:00
|
|
|
radialProgress(),
|
|
|
|
!radialLoading(),
|
2019-04-01 17:44:54 +00:00
|
|
|
now + radialTimeShift());
|
|
|
|
if (!anim::Disabled() || updated) {
|
2018-09-07 12:19:56 +00:00
|
|
|
rtlupdate(radialRect());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundRow::updateImage() {
|
|
|
|
int32 size = st::settingsBackgroundThumb * cIntRetinaFactor();
|
|
|
|
QImage back(size, size, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
back.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
{
|
|
|
|
Painter p(&back);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
2019-01-29 07:29:38 +00:00
|
|
|
if (const auto color = Window::Theme::Background()->colorForFill()) {
|
2019-01-17 08:18:23 +00:00
|
|
|
p.fillRect(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
*color);
|
|
|
|
} else {
|
|
|
|
const auto &pix = Window::Theme::Background()->pixmap();
|
|
|
|
const auto sx = (pix.width() > pix.height())
|
|
|
|
? ((pix.width() - pix.height()) / 2)
|
|
|
|
: 0;
|
|
|
|
const auto sy = (pix.height() > pix.width())
|
|
|
|
? ((pix.height() - pix.width()) / 2)
|
|
|
|
: 0;
|
|
|
|
const auto s = (pix.width() > pix.height())
|
|
|
|
? pix.height()
|
|
|
|
: pix.width();
|
|
|
|
p.drawPixmap(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
st::settingsBackgroundThumb,
|
|
|
|
pix,
|
|
|
|
sx,
|
|
|
|
sy,
|
|
|
|
s,
|
|
|
|
s);
|
|
|
|
}
|
2018-09-07 12:19:56 +00:00
|
|
|
}
|
|
|
|
Images::prepareRound(back, ImageRoundRadius::Small);
|
|
|
|
_background = App::pixmapFromImageInPlace(std::move(back));
|
|
|
|
_background.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
|
|
|
|
rtlupdate(radialRect());
|
|
|
|
|
|
|
|
if (radialLoading()) {
|
|
|
|
radialStart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void ChooseFromFile(
|
|
|
|
not_null<::Main::Session*> session,
|
|
|
|
not_null<QWidget*> parent) {
|
2019-01-16 17:26:26 +00:00
|
|
|
const auto &imgExtensions = cImgExtensions();
|
2018-09-07 12:19:56 +00:00
|
|
|
auto filters = QStringList(
|
|
|
|
qsl("Theme files (*.tdesktop-theme *.tdesktop-palette *")
|
|
|
|
+ imgExtensions.join(qsl(" *"))
|
|
|
|
+ qsl(")"));
|
|
|
|
filters.push_back(FileDialog::AllFilesFilter());
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto callback = crl::guard(session, [=](
|
|
|
|
const FileDialog::OpenResult &result) {
|
2018-09-07 12:19:56 +00:00
|
|
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.paths.isEmpty()) {
|
|
|
|
const auto filePath = result.paths.front();
|
|
|
|
const auto hasExtension = [&](QLatin1String extension) {
|
|
|
|
return filePath.endsWith(extension, Qt::CaseInsensitive);
|
|
|
|
};
|
|
|
|
if (hasExtension(qstr(".tdesktop-theme"))
|
|
|
|
|| hasExtension(qstr(".tdesktop-palette"))) {
|
|
|
|
Window::Theme::Apply(filePath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto image = result.remoteContent.isEmpty()
|
|
|
|
? App::readImage(result.paths.front())
|
|
|
|
: App::readImage(result.remoteContent);
|
|
|
|
if (image.isNull() || image.width() <= 0 || image.height() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-08 13:43:31 +00:00
|
|
|
auto local = Data::CustomWallPaper();
|
|
|
|
local.setLocalImageAsThumbnail(std::make_shared<Image>(
|
|
|
|
std::make_unique<Images::ImageSource>(
|
|
|
|
std::move(image),
|
|
|
|
"JPG")));
|
2019-07-24 14:00:30 +00:00
|
|
|
Ui::show(Box<BackgroundPreviewBox>(session, local));
|
|
|
|
});
|
2018-09-07 12:19:56 +00:00
|
|
|
FileDialog::GetOpenPath(
|
|
|
|
parent.get(),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_choose_image(tr::now),
|
2018-09-07 12:19:56 +00:00
|
|
|
filters.join(qsl(";;")),
|
|
|
|
crl::guard(parent, callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DownloadPathText() {
|
|
|
|
if (Global::DownloadPath().isEmpty()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_download_path_default(tr::now);
|
2018-09-07 12:19:56 +00:00
|
|
|
} else if (Global::DownloadPath() == qsl("tmp")) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_download_path_temp(tr::now);
|
2018-09-07 12:19:56 +00:00
|
|
|
}
|
|
|
|
return QDir::toNativeSeparators(Global::DownloadPath());
|
|
|
|
}
|
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
void SetupStickersEmoji(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-28 11:20:36 +00:00
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
2018-09-13 20:09:26 +00:00
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_stickers_emoji());
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
const auto session = &controller->session();
|
|
|
|
|
2018-09-07 12:19:56 +00:00
|
|
|
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
|
|
|
const auto inner = wrap.data();
|
|
|
|
container->add(object_ptr<Ui::OverrideMargins>(
|
|
|
|
container,
|
|
|
|
std::move(wrap),
|
|
|
|
QMargins(0, 0, 0, st::settingsCheckbox.margin.bottom())));
|
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto checkbox = [&](const QString &label, bool checked) {
|
2018-09-07 12:19:56 +00:00
|
|
|
return object_ptr<Ui::Checkbox>(
|
|
|
|
container,
|
2019-06-19 15:09:03 +00:00
|
|
|
label,
|
2018-09-07 12:19:56 +00:00
|
|
|
checked,
|
|
|
|
st::settingsCheckbox);
|
|
|
|
};
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto add = [&](const QString &label, bool checked, auto &&handle) {
|
2018-12-05 09:55:56 +00:00
|
|
|
inner->add(
|
|
|
|
checkbox(label, checked),
|
|
|
|
st::settingsCheckboxPadding
|
|
|
|
)->checkedChanges(
|
2018-09-07 12:19:56 +00:00
|
|
|
) | rpl::start_with_next(
|
|
|
|
std::move(handle),
|
|
|
|
inner->lifetime());
|
|
|
|
};
|
2019-08-02 10:40:35 +00:00
|
|
|
|
|
|
|
add(
|
|
|
|
tr::lng_settings_large_emoji(tr::now),
|
|
|
|
session->settings().largeEmoji(),
|
|
|
|
[=](bool checked) {
|
|
|
|
session->settings().setLargeEmoji(checked);
|
|
|
|
session->saveSettingsDelayed();
|
|
|
|
});
|
|
|
|
|
2018-09-07 12:19:56 +00:00
|
|
|
add(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_settings_replace_emojis(tr::now),
|
2019-08-02 10:40:35 +00:00
|
|
|
session->settings().replaceEmoji(),
|
|
|
|
[=](bool checked) {
|
|
|
|
session->settings().setReplaceEmoji(checked);
|
|
|
|
session->saveSettingsDelayed();
|
2018-09-07 12:19:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
add(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_settings_suggest_emoji(tr::now),
|
2019-08-02 10:40:35 +00:00
|
|
|
session->settings().suggestEmoji(),
|
|
|
|
[=](bool checked) {
|
|
|
|
session->settings().setSuggestEmoji(checked);
|
|
|
|
session->saveSettingsDelayed();
|
2018-09-07 12:19:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
add(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_settings_suggest_by_emoji(tr::now),
|
2019-08-02 10:40:35 +00:00
|
|
|
session->settings().suggestStickersByEmoji(),
|
|
|
|
[=](bool checked) {
|
|
|
|
session->settings().setSuggestStickersByEmoji(checked);
|
|
|
|
session->saveSettingsDelayed();
|
|
|
|
});
|
|
|
|
|
|
|
|
add(
|
|
|
|
tr::lng_settings_loop_stickers(tr::now),
|
|
|
|
session->settings().loopAnimatedStickers(),
|
|
|
|
[=](bool checked) {
|
|
|
|
session->settings().setLoopAnimatedStickers(checked);
|
|
|
|
session->saveSettingsDelayed();
|
2018-09-07 12:19:56 +00:00
|
|
|
});
|
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_stickers_you_have(),
|
2018-09-28 11:20:36 +00:00
|
|
|
st::settingsChatButton,
|
|
|
|
&st::settingsIconStickers,
|
|
|
|
st::settingsChatIconLeft
|
2019-08-06 16:40:08 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
Ui::show(Box<StickersBox>(session, StickersBox::Section::Installed));
|
2018-09-13 20:09:26 +00:00
|
|
|
});
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2018-12-26 14:00:08 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_emoji_manage_sets(),
|
2018-12-26 14:00:08 +00:00
|
|
|
st::settingsChatButton,
|
2019-01-02 12:11:13 +00:00
|
|
|
&st::settingsIconEmoji,
|
2018-12-26 14:00:08 +00:00
|
|
|
st::settingsChatIconLeft
|
|
|
|
)->addClickHandler([] {
|
|
|
|
Ui::show(Box<Ui::Emoji::ManageSetsBox>());
|
|
|
|
});
|
|
|
|
|
2018-09-10 12:18:39 +00:00
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
2018-09-07 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupMessages(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-07 12:19:56 +00:00
|
|
|
AddDivider(container);
|
2018-09-19 10:29:51 +00:00
|
|
|
AddSkip(container);
|
2018-09-13 20:09:26 +00:00
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_messages());
|
2018-09-13 20:09:26 +00:00
|
|
|
|
|
|
|
AddSkip(container, st::settingsSendTypeSkip);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2018-09-29 12:18:26 +00:00
|
|
|
using SendByType = Ui::InputSubmitSettings;
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
const auto skip = st::settingsSendTypeSkip;
|
2018-09-07 12:19:56 +00:00
|
|
|
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
|
|
|
const auto inner = wrap.data();
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::OverrideMargins>(
|
|
|
|
container,
|
|
|
|
std::move(wrap),
|
|
|
|
QMargins(0, skip, 0, skip)));
|
|
|
|
|
2018-09-29 12:18:26 +00:00
|
|
|
const auto group = std::make_shared<Ui::RadioenumGroup<SendByType>>(
|
2019-07-24 14:00:30 +00:00
|
|
|
controller->session().settings().sendSubmitWay());
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto add = [&](SendByType value, const QString &text) {
|
2018-09-07 12:19:56 +00:00
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::Radioenum<SendByType>>(
|
|
|
|
inner,
|
|
|
|
group,
|
|
|
|
value,
|
2019-06-19 15:09:03 +00:00
|
|
|
text,
|
2018-09-07 12:19:56 +00:00
|
|
|
st::settingsSendType),
|
|
|
|
st::settingsSendTypePadding);
|
|
|
|
};
|
|
|
|
const auto small = st::settingsSendTypePadding;
|
|
|
|
const auto top = skip;
|
2019-06-19 15:09:03 +00:00
|
|
|
add(SendByType::Enter, tr::lng_settings_send_enter(tr::now));
|
2018-09-07 12:19:56 +00:00
|
|
|
add(
|
|
|
|
SendByType::CtrlEnter,
|
2019-06-03 14:41:23 +00:00
|
|
|
(Platform::IsMac()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_settings_send_cmdenter(tr::now)
|
|
|
|
: tr::lng_settings_send_ctrlenter(tr::now)));
|
2018-09-29 12:18:26 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
group->setChangedCallback([=](SendByType value) {
|
|
|
|
controller->session().settings().setSendSubmitWay(value);
|
2018-09-07 12:19:56 +00:00
|
|
|
if (App::main()) {
|
|
|
|
App::main()->ctrlEnterSubmitUpdated();
|
|
|
|
}
|
|
|
|
Local::writeUserSettings();
|
|
|
|
});
|
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
AddSkip(inner, st::settingsCheckboxesSkip);
|
2018-09-17 10:52:34 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupExport(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-17 10:52:34 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_export_data(),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2019-07-24 14:00:30 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
const auto session = &controller->session();
|
2018-09-17 10:52:34 +00:00
|
|
|
Ui::hideSettingsAndLayer();
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(
|
2018-09-17 10:52:34 +00:00
|
|
|
st::boxDuration,
|
2019-07-24 14:00:30 +00:00
|
|
|
session,
|
|
|
|
[=] { session->data().startExport(); });
|
2018-09-17 10:52:34 +00:00
|
|
|
});
|
|
|
|
}
|
2018-09-13 20:09:26 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupLocalStorage(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-17 10:52:34 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_manage_local_storage(),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2019-07-24 14:00:30 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
LocalStorageBox::Show(&controller->session());
|
2018-09-17 10:52:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupDataStorage(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-18 16:32:07 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
2018-09-17 10:52:34 +00:00
|
|
|
AddDivider(container);
|
2018-09-19 10:29:51 +00:00
|
|
|
AddSkip(container);
|
2018-09-17 10:52:34 +00:00
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_data_storage());
|
2018-09-17 10:52:34 +00:00
|
|
|
|
2018-09-18 16:32:07 +00:00
|
|
|
const auto ask = AddButton(
|
2018-09-17 10:52:34 +00:00
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_download_path_ask(),
|
2018-09-18 16:32:07 +00:00
|
|
|
st::settingsButton
|
|
|
|
)->toggleOn(rpl::single(Global::AskDownloadPath()));
|
2018-09-13 20:09:26 +00:00
|
|
|
|
|
|
|
#ifndef OS_WIN_STORE
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto showpath = Ui::CreateChild<rpl::event_stream<bool>>(ask);
|
2018-09-13 20:09:26 +00:00
|
|
|
const auto path = container->add(
|
2018-09-17 10:52:34 +00:00
|
|
|
object_ptr<Ui::SlideWrap<Button>>(
|
2018-09-13 20:09:26 +00:00
|
|
|
container,
|
2018-09-17 10:52:34 +00:00
|
|
|
object_ptr<Button>(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_download_path(),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton)));
|
|
|
|
auto pathtext = rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(base::ObservableViewer(
|
|
|
|
Global::RefDownloadPathChanged()
|
|
|
|
)) | rpl::map([] {
|
|
|
|
return DownloadPathText();
|
|
|
|
});
|
|
|
|
CreateRightLabel(
|
|
|
|
path->entity(),
|
|
|
|
std::move(pathtext),
|
|
|
|
st::settingsButton,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_download_path());
|
2018-09-17 10:52:34 +00:00
|
|
|
path->entity()->addClickHandler([] {
|
|
|
|
Ui::show(Box<DownloadPathBox>());
|
|
|
|
});
|
2018-09-18 16:32:07 +00:00
|
|
|
path->toggleOn(ask->toggledValue() | rpl::map(!_1));
|
2018-09-13 20:09:26 +00:00
|
|
|
#endif // OS_WIN_STORE
|
|
|
|
|
2018-09-18 16:32:07 +00:00
|
|
|
ask->toggledValue(
|
|
|
|
) | rpl::filter([](bool checked) {
|
|
|
|
return (checked != Global::AskDownloadPath());
|
|
|
|
}) | rpl::start_with_next([=](bool checked) {
|
2018-09-17 10:52:34 +00:00
|
|
|
Global::SetAskDownloadPath(checked);
|
2018-09-13 20:09:26 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
|
|
|
|
#ifndef OS_WIN_STORE
|
2018-09-17 10:52:34 +00:00
|
|
|
showpath->fire_copy(!checked);
|
2018-09-13 20:09:26 +00:00
|
|
|
#endif // OS_WIN_STORE
|
|
|
|
|
2018-09-18 16:32:07 +00:00
|
|
|
}, ask->lifetime());
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
SetupLocalStorage(controller, container);
|
|
|
|
SetupExport(controller, container);
|
2018-09-17 10:52:34 +00:00
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
2018-09-07 12:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupAutoDownload(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-12-06 15:47:28 +00:00
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_media_auto_settings());
|
2018-12-06 15:47:28 +00:00
|
|
|
|
|
|
|
using Source = Data::AutoDownload::Source;
|
2019-06-18 12:16:43 +00:00
|
|
|
const auto add = [&](rpl::producer<QString> label, Source source) {
|
2018-12-06 15:47:28 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
std::move(label),
|
2018-12-06 15:47:28 +00:00
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([=] {
|
2019-07-24 14:00:30 +00:00
|
|
|
Ui::show(Box<AutoDownloadBox>(&controller->session(), source));
|
2018-12-06 15:47:28 +00:00
|
|
|
});
|
|
|
|
};
|
2019-06-18 12:16:43 +00:00
|
|
|
add(tr::lng_media_auto_in_private(), Source::User);
|
|
|
|
add(tr::lng_media_auto_in_groups(), Source::Group);
|
|
|
|
add(tr::lng_media_auto_in_channels(), Source::Channel);
|
2018-12-06 15:47:28 +00:00
|
|
|
|
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupChatBackground(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-07 12:19:56 +00:00
|
|
|
AddDivider(container);
|
2018-09-19 10:29:51 +00:00
|
|
|
AddSkip(container);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_section_background());
|
2018-09-07 12:19:56 +00:00
|
|
|
|
|
|
|
container->add(
|
2019-07-24 14:00:30 +00:00
|
|
|
object_ptr<BackgroundRow>(container, controller),
|
2018-09-07 12:19:56 +00:00
|
|
|
st::settingsBackgroundPadding);
|
|
|
|
|
|
|
|
const auto skipTop = st::settingsCheckbox.margin.top();
|
|
|
|
const auto skipBottom = st::settingsCheckbox.margin.bottom();
|
|
|
|
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
|
|
|
const auto inner = wrap.data();
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::OverrideMargins>(
|
|
|
|
container,
|
|
|
|
std::move(wrap),
|
|
|
|
QMargins(0, skipTop, 0, skipBottom)));
|
|
|
|
|
2018-09-10 12:18:39 +00:00
|
|
|
AddSkip(container, st::settingsTileSkip);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
|
|
|
const auto tile = inner->add(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_settings_bg_tile(tr::now),
|
2018-09-07 12:19:56 +00:00
|
|
|
Window::Theme::Background()->tile(),
|
|
|
|
st::settingsCheckbox),
|
|
|
|
st::settingsSendTypePadding);
|
|
|
|
const auto adaptive = inner->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_settings_adaptive_wide(tr::now),
|
2018-09-07 12:19:56 +00:00
|
|
|
Global::AdaptiveForWide(),
|
|
|
|
st::settingsCheckbox),
|
|
|
|
st::settingsSendTypePadding));
|
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
tile->checkedChanges(
|
2018-09-07 12:19:56 +00:00
|
|
|
) | rpl::start_with_next([](bool checked) {
|
|
|
|
Window::Theme::Background()->setTile(checked);
|
|
|
|
}, tile->lifetime());
|
|
|
|
|
|
|
|
using Update = const Window::Theme::BackgroundUpdate;
|
|
|
|
base::ObservableViewer(
|
|
|
|
*Window::Theme::Background()
|
|
|
|
) | rpl::filter([](const Update &update) {
|
|
|
|
return (update.type == Update::Type::Changed);
|
|
|
|
}) | rpl::map([] {
|
|
|
|
return Window::Theme::Background()->tile();
|
|
|
|
}) | rpl::start_with_next([=](bool tiled) {
|
|
|
|
tile->setChecked(tiled);
|
|
|
|
}, tile->lifetime());
|
|
|
|
|
|
|
|
adaptive->toggleOn(rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(base::ObservableViewer(
|
|
|
|
Adaptive::Changed()
|
|
|
|
)) | rpl::map([] {
|
|
|
|
return (Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide);
|
|
|
|
}));
|
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
adaptive->entity()->checkedChanges(
|
2018-09-07 12:19:56 +00:00
|
|
|
) | rpl::start_with_next([](bool checked) {
|
|
|
|
Global::SetAdaptiveForWide(checked);
|
|
|
|
Adaptive::Changed().notify();
|
|
|
|
Local::writeUserSettings();
|
|
|
|
}, adaptive->lifetime());
|
|
|
|
}
|
|
|
|
|
2018-09-26 11:28:16 +00:00
|
|
|
void SetupDefaultThemes(not_null<Ui::VerticalLayout*> container) {
|
2019-09-03 15:24:51 +00:00
|
|
|
using Type = Window::Theme::EmbeddedType;
|
|
|
|
using Scheme = Window::Theme::EmbeddedScheme;
|
|
|
|
using Check = Window::Theme::CloudListCheck;
|
2019-09-09 09:02:06 +00:00
|
|
|
using namespace Window::Theme;
|
2019-08-23 16:00:24 +00:00
|
|
|
|
2018-09-26 11:28:16 +00:00
|
|
|
const auto block = container->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
container));
|
2019-08-23 16:00:24 +00:00
|
|
|
const auto palette = Ui::CreateChild<ColorsPalette>(
|
|
|
|
container.get(),
|
|
|
|
container.get());
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
const auto chosen = [] {
|
2019-09-09 09:02:06 +00:00
|
|
|
const auto &object = Background()->themeObject();
|
2019-09-05 06:51:46 +00:00
|
|
|
if (object.cloud.id) {
|
|
|
|
return Type(-1);
|
|
|
|
}
|
2019-08-23 16:00:24 +00:00
|
|
|
for (const auto &scheme : kSchemesList) {
|
2019-09-03 18:04:38 +00:00
|
|
|
if (object.pathAbsolute == scheme.path) {
|
2018-09-26 11:28:16 +00:00
|
|
|
return scheme.type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Type(-1);
|
|
|
|
};
|
|
|
|
const auto group = std::make_shared<Ui::RadioenumGroup<Type>>(chosen());
|
2019-08-20 16:03:14 +00:00
|
|
|
|
2019-08-27 13:59:15 +00:00
|
|
|
const auto apply = [=](const Scheme &scheme) {
|
2019-08-20 16:03:14 +00:00
|
|
|
const auto isNight = [](const Scheme &scheme) {
|
|
|
|
const auto type = scheme.type;
|
|
|
|
return (type != Type::DayBlue) && (type != Type::Default);
|
|
|
|
};
|
2019-09-03 18:04:38 +00:00
|
|
|
const auto currentlyIsCustom = (chosen() == Type(-1))
|
2019-09-09 09:02:06 +00:00
|
|
|
&& !Background()->themeObject().cloud.id;
|
|
|
|
if (IsNightMode() == isNight(scheme)) {
|
|
|
|
ApplyDefaultWithPath(scheme.path);
|
2019-08-20 16:03:14 +00:00
|
|
|
} else {
|
2019-09-09 09:02:06 +00:00
|
|
|
ToggleNightMode(scheme.path);
|
2019-08-20 16:03:14 +00:00
|
|
|
}
|
|
|
|
if (!currentlyIsCustom) {
|
2019-09-09 09:02:06 +00:00
|
|
|
KeepApplied();
|
2019-08-20 16:03:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
const auto schemeClicked = [=](
|
|
|
|
const Scheme &scheme,
|
|
|
|
Qt::KeyboardModifiers modifiers) {
|
2019-08-27 13:59:15 +00:00
|
|
|
apply(scheme);
|
2019-08-20 16:03:14 +00:00
|
|
|
};
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
auto checks = base::flat_map<Type,not_null<Check*>>();
|
2018-09-26 11:28:16 +00:00
|
|
|
auto buttons = ranges::view::all(
|
2019-08-23 16:00:24 +00:00
|
|
|
kSchemesList
|
2018-09-26 11:28:16 +00:00
|
|
|
) | ranges::view::transform([&](const Scheme &scheme) {
|
2019-09-03 15:24:51 +00:00
|
|
|
auto check = std::make_unique<Check>(
|
|
|
|
ColorsFromScheme(scheme),
|
|
|
|
false);
|
2018-09-26 11:28:16 +00:00
|
|
|
const auto weak = check.get();
|
|
|
|
const auto result = Ui::CreateChild<Ui::Radioenum<Type>>(
|
|
|
|
block,
|
|
|
|
group,
|
|
|
|
scheme.type,
|
2019-08-08 09:22:28 +00:00
|
|
|
scheme.name(tr::now),
|
2018-09-26 11:28:16 +00:00
|
|
|
st::settingsTheme,
|
|
|
|
std::move(check));
|
2019-08-20 16:03:14 +00:00
|
|
|
result->addClickHandler([=] {
|
|
|
|
schemeClicked(scheme, result->clickModifiers());
|
|
|
|
});
|
2018-09-26 11:28:16 +00:00
|
|
|
weak->setUpdateCallback([=] { result->update(); });
|
2019-08-23 13:52:59 +00:00
|
|
|
checks.emplace(scheme.type, weak);
|
2018-09-26 11:28:16 +00:00
|
|
|
return result;
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
const auto refreshColorizer = [=](Type type) {
|
2019-08-23 16:00:24 +00:00
|
|
|
if (type == chosen()) {
|
|
|
|
palette->show(type);
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
const auto &colors = Core::App().settings().themesAccentColors();
|
|
|
|
const auto i = checks.find(type);
|
2019-08-23 16:00:24 +00:00
|
|
|
const auto scheme = ranges::find(kSchemesList, type, &Scheme::type);
|
|
|
|
if (scheme == end(kSchemesList)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (i != end(checks)) {
|
2019-08-23 13:52:59 +00:00
|
|
|
if (const auto color = colors.get(type)) {
|
2019-09-09 09:02:06 +00:00
|
|
|
const auto colorizer = ColorizerFrom(*scheme, *color);
|
2019-09-03 15:24:51 +00:00
|
|
|
i->second->setColors(ColorsFromScheme(*scheme, colorizer));
|
2019-08-23 13:52:59 +00:00
|
|
|
} else {
|
2019-09-03 15:24:51 +00:00
|
|
|
i->second->setColors(ColorsFromScheme(*scheme));
|
2019-08-23 13:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-09-05 10:51:36 +00:00
|
|
|
group->setChangedCallback([=](Type type) {
|
|
|
|
group->setValue(chosen());
|
|
|
|
});
|
2019-08-23 16:00:24 +00:00
|
|
|
for (const auto &scheme : kSchemesList) {
|
2019-08-23 13:52:59 +00:00
|
|
|
refreshColorizer(scheme.type);
|
|
|
|
}
|
|
|
|
|
2018-09-26 11:28:16 +00:00
|
|
|
base::ObservableViewer(
|
2019-09-09 09:02:06 +00:00
|
|
|
*Background()
|
|
|
|
) | rpl::filter([](const BackgroundUpdate &update) {
|
|
|
|
return (update.type == BackgroundUpdate::Type::ApplyingTheme);
|
2018-09-26 11:28:16 +00:00
|
|
|
}) | rpl::map([=] {
|
|
|
|
return chosen();
|
|
|
|
}) | rpl::start_with_next([=](Type type) {
|
2019-08-23 13:52:59 +00:00
|
|
|
refreshColorizer(type);
|
2018-09-26 11:28:16 +00:00
|
|
|
group->setValue(type);
|
|
|
|
}, container->lifetime());
|
|
|
|
|
|
|
|
for (const auto button : buttons) {
|
|
|
|
button->setCheckAlignment(style::al_top);
|
|
|
|
button->resizeToWidth(button->width());
|
|
|
|
}
|
|
|
|
block->resize(block->width(), buttons[0]->height());
|
|
|
|
block->widthValue(
|
|
|
|
) | rpl::start_with_next([buttons = std::move(buttons)](int width) {
|
|
|
|
Expects(!buttons.empty());
|
|
|
|
|
|
|
|
const auto padding = st::settingsButton.padding;
|
|
|
|
width -= padding.left() + padding.right();
|
|
|
|
const auto desired = st::settingsThemePreviewSize.width();
|
|
|
|
const auto count = int(buttons.size());
|
2019-09-04 11:20:07 +00:00
|
|
|
const auto skips = count - 1;
|
2018-09-26 11:28:16 +00:00
|
|
|
const auto minSkip = st::settingsThemeMinSkip;
|
|
|
|
const auto single = [&] {
|
2019-09-04 11:20:07 +00:00
|
|
|
if (width >= skips * minSkip + count * desired) {
|
2018-09-26 11:28:16 +00:00
|
|
|
return desired;
|
|
|
|
}
|
2019-09-04 11:20:07 +00:00
|
|
|
return (width - skips * minSkip) / count;
|
2018-09-26 11:28:16 +00:00
|
|
|
}();
|
|
|
|
if (single <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto fullSkips = width - count * single;
|
2019-09-04 11:20:07 +00:00
|
|
|
const auto skip = fullSkips / float64(skips);
|
2018-09-26 11:28:16 +00:00
|
|
|
auto left = padding.left() + 0.;
|
|
|
|
auto index = 0;
|
|
|
|
for (const auto button : buttons) {
|
|
|
|
button->resizeToWidth(single);
|
|
|
|
button->moveToLeft(int(std::round(left)), 0);
|
2019-09-04 11:20:07 +00:00
|
|
|
left += button->width() + skip;
|
2018-09-26 11:28:16 +00:00
|
|
|
}
|
|
|
|
}, block->lifetime());
|
|
|
|
|
2019-08-23 16:00:24 +00:00
|
|
|
palette->selected(
|
|
|
|
) | rpl::start_with_next([=](QColor color) {
|
2019-09-09 09:02:06 +00:00
|
|
|
if (Background()->editingTheme()) {
|
|
|
|
// We don't remember old accent color to revert it properly
|
|
|
|
// in Window::Theme::Revert which is called by Editor.
|
|
|
|
//
|
|
|
|
// So we check here, before we change the saved accent color.
|
|
|
|
Ui::show(Box<InformBox>(
|
|
|
|
tr::lng_theme_editor_cant_change_theme(tr::now)));
|
|
|
|
return;
|
|
|
|
}
|
2019-08-23 16:00:24 +00:00
|
|
|
const auto type = chosen();
|
|
|
|
const auto scheme = ranges::find(kSchemesList, type, &Scheme::type);
|
|
|
|
if (scheme == end(kSchemesList)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-27 13:59:15 +00:00
|
|
|
auto &colors = Core::App().settings().themesAccentColors();
|
|
|
|
if (colors.get(type) != color) {
|
|
|
|
colors.set(type, color);
|
|
|
|
Local::writeSettings();
|
|
|
|
}
|
|
|
|
apply(*scheme);
|
2019-08-23 16:00:24 +00:00
|
|
|
}, container->lifetime());
|
2019-08-23 13:52:59 +00:00
|
|
|
|
2018-09-26 11:28:16 +00:00
|
|
|
AddSkip(container);
|
|
|
|
}
|
|
|
|
|
2019-09-02 16:10:18 +00:00
|
|
|
void SetupThemeOptions(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2019-09-05 05:18:21 +00:00
|
|
|
using namespace Window::Theme;
|
|
|
|
|
2018-09-28 11:20:36 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySkip);
|
2018-09-07 12:19:56 +00:00
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_themes());
|
2018-09-13 20:09:26 +00:00
|
|
|
|
2018-09-28 11:20:36 +00:00
|
|
|
AddSkip(container, st::settingsThemesTopSkip);
|
2018-09-26 11:28:16 +00:00
|
|
|
SetupDefaultThemes(container);
|
2019-09-04 11:20:07 +00:00
|
|
|
AddSkip(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupCloudThemes(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2019-09-08 12:47:22 +00:00
|
|
|
using namespace Window::Theme;
|
2019-09-04 15:59:43 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
const auto wrap = container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
container,
|
2019-09-08 12:47:22 +00:00
|
|
|
object_ptr<Ui::VerticalLayout>(container))
|
|
|
|
)->setDuration(0);
|
2019-09-04 11:20:07 +00:00
|
|
|
const auto inner = wrap->entity();
|
|
|
|
|
|
|
|
AddDivider(inner);
|
|
|
|
AddSkip(inner, st::settingsPrivacySkip);
|
|
|
|
|
2019-09-04 15:59:43 +00:00
|
|
|
const auto title = AddSubsectionTitle(
|
|
|
|
inner,
|
|
|
|
tr::lng_settings_bg_cloud_themes());
|
|
|
|
const auto showAll = Ui::CreateChild<Ui::LinkButton>(
|
|
|
|
inner,
|
|
|
|
tr::lng_settings_bg_show_all(tr::now));
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
title->topValue(),
|
|
|
|
inner->widthValue(),
|
|
|
|
showAll->widthValue()
|
|
|
|
) | rpl::start_with_next([=](int top, int outerWidth, int width) {
|
|
|
|
showAll->moveToRight(
|
|
|
|
st::settingsSubsectionTitlePadding.left(),
|
|
|
|
top,
|
|
|
|
outerWidth);
|
|
|
|
}, showAll->lifetime());
|
2019-09-04 11:20:07 +00:00
|
|
|
|
|
|
|
AddSkip(inner, st::settingsThemesTopSkip);
|
|
|
|
|
2019-09-08 12:47:22 +00:00
|
|
|
const auto list = inner->lifetime().make_state<CloudList>(
|
2019-09-04 15:59:43 +00:00
|
|
|
inner,
|
|
|
|
controller);
|
|
|
|
inner->add(
|
|
|
|
list->takeWidget(),
|
|
|
|
style::margins(
|
|
|
|
st::settingsButton.padding.left(),
|
|
|
|
0,
|
|
|
|
st::settingsButton.padding.right(),
|
|
|
|
0));
|
|
|
|
|
|
|
|
list->allShown(
|
|
|
|
) | rpl::start_with_next([=](bool shown) {
|
|
|
|
showAll->setVisible(!shown);
|
|
|
|
}, showAll->lifetime());
|
|
|
|
|
|
|
|
showAll->addClickHandler([=] {
|
|
|
|
list->showAll();
|
2019-09-03 15:24:51 +00:00
|
|
|
});
|
2019-09-04 11:20:07 +00:00
|
|
|
|
2019-09-08 12:47:22 +00:00
|
|
|
const auto editWrap = inner->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::VerticalLayout>(inner))
|
|
|
|
)->setDuration(0);
|
|
|
|
const auto edit = editWrap->entity();
|
|
|
|
|
|
|
|
AddSkip(edit, st::settingsThemesBottomSkip);
|
|
|
|
AddButton(
|
|
|
|
edit,
|
|
|
|
tr::lng_settings_bg_theme_edit(),
|
|
|
|
st::settingsChatButton,
|
|
|
|
&st::settingsIconThemes,
|
|
|
|
st::settingsChatIconLeft
|
|
|
|
)->addClickHandler([=] {
|
|
|
|
StartEditor(
|
|
|
|
&controller->window(),
|
|
|
|
Background()->themeObject().cloud);
|
|
|
|
});
|
|
|
|
|
|
|
|
editWrap->toggleOn(rpl::single(BackgroundUpdate(
|
|
|
|
BackgroundUpdate::Type::ApplyingTheme,
|
|
|
|
Background()->tile()
|
|
|
|
)) | rpl::then(base::ObservableViewer(
|
|
|
|
*Background()
|
|
|
|
)) | rpl::filter([](const BackgroundUpdate &update) {
|
|
|
|
return (update.type == BackgroundUpdate::Type::ApplyingTheme);
|
|
|
|
}) | rpl::map([=] {
|
|
|
|
const auto userId = controller->session().userId();
|
|
|
|
return (Background()->themeObject().cloud.createdBy == userId);
|
|
|
|
}));
|
|
|
|
|
|
|
|
AddSkip(inner, 2 * st::settingsSectionSkip);
|
2019-09-04 11:20:07 +00:00
|
|
|
|
2019-09-04 15:59:43 +00:00
|
|
|
wrap->setDuration(0)->toggleOn(list->empty() | rpl::map(!_1));
|
2018-09-11 18:07:04 +00:00
|
|
|
}
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupSupportSwitchSettings(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-29 12:18:26 +00:00
|
|
|
using SwitchType = Support::SwitchSettings;
|
|
|
|
const auto group = std::make_shared<Ui::RadioenumGroup<SwitchType>>(
|
2019-07-24 14:00:30 +00:00
|
|
|
controller->session().settings().supportSwitch());
|
2018-09-29 12:18:26 +00:00
|
|
|
const auto add = [&](SwitchType value, const QString &label) {
|
2018-11-09 13:54:34 +00:00
|
|
|
container->add(
|
2018-09-29 12:18:26 +00:00
|
|
|
object_ptr<Ui::Radioenum<SwitchType>>(
|
2018-11-09 13:54:34 +00:00
|
|
|
container,
|
2018-09-29 12:18:26 +00:00
|
|
|
group,
|
|
|
|
value,
|
|
|
|
label,
|
|
|
|
st::settingsSendType),
|
|
|
|
st::settingsSendTypePadding);
|
|
|
|
};
|
|
|
|
add(SwitchType::None, "Just send the reply");
|
|
|
|
add(SwitchType::Next, "Send and switch to next");
|
|
|
|
add(SwitchType::Previous, "Send and switch to previous");
|
2019-07-24 14:00:30 +00:00
|
|
|
group->setChangedCallback([=](SwitchType value) {
|
|
|
|
controller->session().settings().setSupportSwitch(value);
|
2018-09-29 12:18:26 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
});
|
2018-11-09 13:54:34 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupSupportChatsLimitSlice(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-11-09 13:54:34 +00:00
|
|
|
constexpr auto kDayDuration = 24 * 60 * 60;
|
|
|
|
struct Option {
|
|
|
|
int days = 0;
|
|
|
|
QString label;
|
|
|
|
};
|
|
|
|
const auto options = std::vector<Option>{
|
|
|
|
{ 1, "1 day" },
|
|
|
|
{ 7, "1 week" },
|
|
|
|
{ 30, "1 month" },
|
|
|
|
{ 365, "1 year" },
|
|
|
|
{ 0, "All of them" },
|
|
|
|
};
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto current = controller->session().settings().supportChatsTimeSlice();
|
2018-11-09 13:54:34 +00:00
|
|
|
const auto days = current / kDayDuration;
|
|
|
|
const auto best = ranges::min_element(
|
|
|
|
options,
|
|
|
|
std::less<>(),
|
|
|
|
[&](const Option &option) { return std::abs(option.days - days); });
|
|
|
|
|
|
|
|
const auto group = std::make_shared<Ui::RadiobuttonGroup>(best->days);
|
|
|
|
for (const auto &option : options) {
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::Radiobutton>(
|
|
|
|
container,
|
|
|
|
group,
|
|
|
|
option.days,
|
|
|
|
option.label,
|
|
|
|
st::settingsSendType),
|
|
|
|
st::settingsSendTypePadding);
|
|
|
|
}
|
|
|
|
group->setChangedCallback([=](int days) {
|
2019-07-24 14:00:30 +00:00
|
|
|
controller->session().settings().setSupportChatsTimeSlice(
|
|
|
|
days * kDayDuration);
|
2018-11-09 13:54:34 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupSupport(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-11-09 13:54:34 +00:00
|
|
|
AddSkip(container);
|
|
|
|
|
|
|
|
AddSubsectionTitle(container, rpl::single(qsl("Support settings")));
|
|
|
|
|
|
|
|
AddSkip(container, st::settingsSendTypeSkip);
|
|
|
|
|
|
|
|
const auto skip = st::settingsSendTypeSkip;
|
|
|
|
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
|
|
|
const auto inner = wrap.data();
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::OverrideMargins>(
|
|
|
|
container,
|
|
|
|
std::move(wrap),
|
|
|
|
QMargins(0, skip, 0, skip)));
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
SetupSupportSwitchSettings(controller, inner);
|
2018-09-29 12:18:26 +00:00
|
|
|
|
|
|
|
AddSkip(inner, st::settingsCheckboxesSkip);
|
2018-10-11 11:17:51 +00:00
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
inner,
|
|
|
|
"Enable templates autocomplete",
|
2019-07-24 14:00:30 +00:00
|
|
|
controller->session().settings().supportTemplatesAutocomplete(),
|
2018-12-05 09:55:56 +00:00
|
|
|
st::settingsCheckbox),
|
|
|
|
st::settingsSendTypePadding
|
|
|
|
)->checkedChanges(
|
2018-10-11 11:17:51 +00:00
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2019-07-24 14:00:30 +00:00
|
|
|
controller->session().settings().setSupportTemplatesAutocomplete(
|
|
|
|
checked);
|
2018-10-11 11:17:51 +00:00
|
|
|
Local::writeUserSettings();
|
|
|
|
}, inner->lifetime());
|
|
|
|
|
|
|
|
AddSkip(inner, st::settingsCheckboxesSkip);
|
2018-11-09 13:54:34 +00:00
|
|
|
|
|
|
|
AddSubsectionTitle(inner, rpl::single(qsl("Load chats for a period")));
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
SetupSupportChatsLimitSlice(controller, inner);
|
2018-11-09 13:54:34 +00:00
|
|
|
|
|
|
|
AddSkip(inner, st::settingsCheckboxesSkip);
|
|
|
|
|
2018-10-11 11:17:51 +00:00
|
|
|
AddSkip(inner);
|
2018-09-29 12:18:26 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
Chat::Chat(QWidget *parent, not_null<Window::SessionController*> controller)
|
|
|
|
: Section(parent) {
|
|
|
|
setupContent(controller);
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void Chat::setupContent(not_null<Window::SessionController*> controller) {
|
2018-09-05 19:05:49 +00:00
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2019-09-02 16:10:18 +00:00
|
|
|
SetupThemeOptions(controller, content);
|
2019-09-04 11:20:07 +00:00
|
|
|
SetupCloudThemes(controller, content);
|
2019-07-24 14:00:30 +00:00
|
|
|
SetupChatBackground(controller, content);
|
2019-08-02 10:40:35 +00:00
|
|
|
SetupStickersEmoji(controller, content);
|
2019-07-24 14:00:30 +00:00
|
|
|
SetupMessages(controller, content);
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|