From ca45fb617e1334ffa1d393a192c7906192088f7c Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 Sep 2019 00:36:16 +0300 Subject: [PATCH] Fix applying background after theme edit. --- .../SourceFiles/window/themes/window_theme.cpp | 8 +++++++- .../SourceFiles/window/themes/window_theme.h | 6 ++++-- .../window/themes/window_theme_editor.cpp | 9 +++------ .../window/themes/window_theme_editor_box.cpp | 16 +++++++++++++++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 1f159783a..259d254b7 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -1202,7 +1202,8 @@ void KeepFromEditor( const ParsedTheme &originalParsed, const Data::CloudTheme &cloud, const QByteArray &themeContent, - const ParsedTheme &themeParsed) { + const ParsedTheme &themeParsed, + const QImage &background) { ClearApplying(); const auto content = themeContent.isEmpty() ? originalContent @@ -1223,6 +1224,11 @@ void KeepFromEditor( cloud.documentId); Local::writeTheme(saved); Background()->keepApplied(saved.object, true); + Background()->setThemeData( + base::duplicate(background), + themeParsed.tiled); + Background()->set(Data::ThemeWallPaper()); + Background()->writeNewBackgroundSettings(); } void Revert() { diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index fc08add93..be9833fb9 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -69,7 +69,8 @@ void KeepFromEditor( const ParsedTheme &originalParsed, const Data::CloudTheme &cloud, const QByteArray &themeContent, - const ParsedTheme &themeParsed); + const ParsedTheme &themeParsed, + const QImage &background); QString NightThemePath(); [[nodiscard]] bool IsNightMode(); void SetNightModeValue(bool nightMode); @@ -210,7 +211,8 @@ private: const ParsedTheme &originalParsed, const Data::CloudTheme &cloud, const QByteArray &themeContent, - const ParsedTheme &themeParsed); + const ParsedTheme &themeParsed, + const QImage &background); friend bool IsNonDefaultBackground(); Main::Session *_session = nullptr; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index 9498194de..3d67cbd48 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -330,7 +330,9 @@ QByteArray ReplaceValueInPaletteContent( if (end - lastValidValueEnd > 0) result.append(lastValidValueEnd, end - lastValidValueEnd); return result; } - return QByteArray(); + auto newline = (content.indexOf("\r\n") >= 0 ? "\r\n" : "\n"); + auto addedline = (content.endsWith('\n') ? "" : newline); + return content + addedline + name + ": " + value + ";" + newline; } [[nodiscard]] QByteArray WriteCloudToText(const Data::CloudTheme &cloud) { @@ -608,11 +610,6 @@ void Editor::Inner::applyEditing(const QString &name, const QString ©Of, QCo error(); return; } - if (newContent.isEmpty()) { - auto newline = (_paletteContent.indexOf("\r\n") >= 0 ? "\r\n" : "\n"); - auto addedline = (_paletteContent.endsWith('\n') ? "" : newline); - newContent = _paletteContent + addedline + plainName + ": " + plainValue + ";" + newline; - } applyNewPalette(newContent); } diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index eea50c5cb..1e2fc4d7f 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -65,6 +65,7 @@ public: const ParsedTheme &parsed); [[nodiscard]] ParsedTheme result() const; + [[nodiscard]] QImage image() const; int resizeGetHeight(int newWidth) override; @@ -213,6 +214,10 @@ ParsedTheme BackgroundSelector::result() const { return result; } +QImage BackgroundSelector::image() const { + return _background; +} + bool PaletteChanged( const QByteArray &editorPalette, const QByteArray &originalPalette, @@ -273,6 +278,12 @@ void ImportFromFile( data, name, ColorHexString(color->c)); + if (data == "error") { + LOG(("Theme Error: could not adjust '%1: %2' in content" + ).arg(QString::fromLatin1(name) + ).arg(QString::fromLatin1(ColorHexString(color->c)))); + return QByteArray(); + } } return data; } @@ -459,6 +470,7 @@ SendMediaReady PrepareThemeMedia( Fn SavePreparedTheme( not_null window, const ParsedTheme &parsed, + const QImage &background, const QByteArray &originalContent, const ParsedTheme &originalParsed, const Data::CloudTheme &fields, @@ -510,7 +522,8 @@ Fn SavePreparedTheme( originalParsed, cloud, state->themeContent, - parsed); + parsed, + background); }; const auto createTheme = [=](const MTPDocument &data) { @@ -918,6 +931,7 @@ void SaveThemeBox( *cancel = SavePreparedTheme( window, back->result(), + back->image(), collected.originalContent, collected.originalParsed, fields,