From f9d56eb4c1b2be8790e8923148b25836a07530ef Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 8 Feb 2019 19:47:02 +0300 Subject: [PATCH] Send installWallPaper requests. --- .../SourceFiles/boxes/background_preview_box.cpp | 8 ++++++++ Telegram/SourceFiles/data/data_wall_paper.cpp | 15 +++++++++++++++ Telegram/SourceFiles/data/data_wall_paper.h | 3 +++ .../SourceFiles/ui/effects/round_checkbox.cpp | 16 ++++++++++------ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 02008930a..32eadbb06 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -476,7 +476,15 @@ void BackgroundPreviewBox::createBlurCheckbox() { } void BackgroundPreviewBox::apply() { + const auto install = (_paper.id() != Window::Theme::Background()->id()) + && Data::IsCloudWallPaper(_paper); App::main()->setChatBackground(_paper, std::move(_full)); + if (install) { + Auth().api().request(MTPaccount_InstallWallPaper( + _paper.mtpInput(), + _paper.mtpSettings() + )).send(); + } closeBox(); } diff --git a/Telegram/SourceFiles/data/data_wall_paper.cpp b/Telegram/SourceFiles/data/data_wall_paper.cpp index 798ac52ed..c7c420739 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.cpp +++ b/Telegram/SourceFiles/data/data_wall_paper.cpp @@ -206,6 +206,10 @@ FileOrigin WallPaper::fileOrigin() const { return FileOriginWallpaper(_id, _accessHash); } +MTPInputWallPaper WallPaper::mtpInput() const { + return MTP_inputWallPaper(MTP_long(_id), MTP_long(_accessHash)); +} + MTPWallPaperSettings WallPaper::mtpSettings() const { return MTP_wallPaperSettings( MTP_flags(_settings), @@ -472,6 +476,17 @@ bool IsDefaultWallPaper(const WallPaper &paper) { || (paper.id() == kIncorrectDefaultBackground); } +bool IsCloudWallPaper(const WallPaper &paper) { + return (paper.id() != kIncorrectDefaultBackground) + && !IsThemeWallPaper(paper) + && !IsCustomWallPaper(paper) + && !IsLegacy1DefaultWallPaper(paper) + && !details::IsUninitializedWallPaper(paper) + && !details::IsTestingThemeWallPaper(paper) + && !details::IsTestingDefaultWallPaper(paper) + && !details::IsTestingEditorWallPaper(paper); +} + QColor PatternColor(QColor background) { const auto hue = background.hueF(); const auto saturation = background.saturationF(); diff --git a/Telegram/SourceFiles/data/data_wall_paper.h b/Telegram/SourceFiles/data/data_wall_paper.h index dc1445d66..adab3d803 100644 --- a/Telegram/SourceFiles/data/data_wall_paper.h +++ b/Telegram/SourceFiles/data/data_wall_paper.h @@ -36,6 +36,8 @@ public: void loadDocument() const; void loadThumbnail() const; [[nodiscard]] FileOrigin fileOrigin() const; + + [[nodiscard]] MTPInputWallPaper mtpInput() const; [[nodiscard]] MTPWallPaperSettings mtpSettings() const; [[nodiscard]] WallPaper withUrlParams( @@ -89,6 +91,7 @@ private: [[nodiscard]] bool IsLegacy1DefaultWallPaper(const WallPaper &paper); [[nodiscard]] WallPaper DefaultWallPaper(); [[nodiscard]] bool IsDefaultWallPaper(const WallPaper &paper); +[[nodiscard]] bool IsCloudWallPaper(const WallPaper &paper); QColor PatternColor(QColor background); QImage PreparePatternImage( diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index a0edaf1f0..ea7255b32 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -317,12 +317,16 @@ void RoundCheckbox::setChecked(bool newChecked, SetStyle speed) { return; } _checked = newChecked; - _checkedProgress.start( - _updateCallback, - _checked ? 0. : 1., - _checked ? 1. : 0., - _st.duration, - anim::linear); + if (speed == SetStyle::Animated) { + _checkedProgress.start( + _updateCallback, + _checked ? 0. : 1., + _checked ? 1. : 0., + _st.duration, + anim::linear); + } else { + _checkedProgress.finish(); + } } void RoundCheckbox::invalidateCache() {