diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index a12370670..b6d3f82f7 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -3071,12 +3071,27 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) { _wallpapers.clear(); _wallpapers.reserve(data.size() + 1); + const auto defaultBackground = Images::Create( + qsl(":/gui/art/bg.jpg"), + "JPG"); + if (defaultBackground) { + _wallpapers.push_back({ + Window::Theme::kDefaultBackground, + 0ULL, // access_hash + MTPDwallPaper::Flags(0), + QString(), // slug + defaultBackground + }); + } const auto oldBackground = Images::Create( qsl(":/gui/art/bg_initial.jpg"), "JPG"); if (oldBackground) { _wallpapers.push_back({ Window::Theme::kInitialBackground, + 0ULL, // access_hash + MTPDwallPaper::Flags(0), + QString(), // slug oldBackground }); } @@ -3086,6 +3101,9 @@ void Session::setWallpapers(const QVector<MTPWallPaper> &data, int32 hash) { if (document->checkWallPaperProperties()) { _wallpapers.push_back({ paper.vid.v, + paper.vaccess_hash.v, + paper.vflags.v, + qs(paper.vslug), document->thumb, document, }); diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 9082ff311..7a4e5bd21 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -51,11 +51,7 @@ class Feed; enum class FeedUpdateFlag; struct FeedUpdate; -struct WallPaper { - WallPaperId id = WallPaperId(); - ImagePtr thumb; - DocumentData *document = nullptr; -}; +struct WallPaper; class Session final { public: diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 8115f271a..2fb9b57b6 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1508,14 +1508,14 @@ void MainWidget::setGeneratedBackground(QImage &&image) { using namespace Window::Theme; if (image.isNull()) { - Background()->setImage(kDefaultBackground); + Background()->setImage({ kDefaultBackground }); } else if (false || _background->data.id == kInitialBackground || _background->data.id == kDefaultBackground) { - Background()->setImage(_background->data.id); + Background()->setImage(_background->data); } else { Background()->setImage( - _background->data.id, + _background->data, std::move(image)); } const auto tile = (_background->data.id == kInitialBackground); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index d9b88de2e..3813496e3 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -358,7 +358,7 @@ void DefaultTheme::checkedChangedHook(anim::type animated) { } void ChooseFromFile(not_null<QWidget*> parent) { - const auto imgExtensions = cImgExtensions(); + const auto &imgExtensions = cImgExtensions(); auto filters = QStringList( qsl("Theme files (*.tdesktop-theme *.tdesktop-palette *") + imgExtensions.join(qsl(" *")) @@ -401,7 +401,7 @@ void ChooseFromFile(not_null<QWidget*> parent) { } Window::Theme::Background()->setImage( - Window::Theme::kCustomBackground, + { Window::Theme::kCustomBackground }, std::move(image)); Window::Theme::Background()->setTile(false); }; diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index ea03abdc4..d67022981 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -3956,7 +3956,7 @@ void readSavedGifs() { } } -void writeBackground(WallPaperId id, const QImage &img) { +void writeBackground(const Data::WallPaper &paper, const QImage &img) { if (!_working() || !_backgroundCanWrite) { return; } @@ -3982,12 +3982,17 @@ void writeBackground(WallPaperId id, const QImage &img) { _writeMap(WriteMapWhen::Fast); } quint32 size = sizeof(qint32) - + sizeof(quint64) + + 2 * sizeof(quint64) + + sizeof(quint32) + + Serialize::stringSize(paper.slug) + Serialize::bytearraySize(bmp); EncryptedDescriptor data(size); data.stream - << qint32(Window::Theme::internal::kLegacyBackgroundId) - << quint64(id) + << qint32(Window::Theme::details::kLegacyBackgroundId) + << quint64(paper.id) + << quint64(paper.accessHash) + << quint32(paper.flags.value()) + << paper.slug << bmp; FileWriteDescriptor file(backgroundKey); @@ -4010,13 +4015,24 @@ bool readBackground() { } QByteArray bmpData; - qint32 legacyId; - quint64 id; + qint32 legacyId = 0; + quint64 id = 0; + quint64 accessHash = 0; + quint32 flags = 0; + QString slug; bg.stream >> legacyId; - if (legacyId == Window::Theme::internal::kLegacyBackgroundId) { - bg.stream >> id; + if (legacyId == Window::Theme::details::kLegacyBackgroundId) { + bg.stream + >> id + >> accessHash + >> flags + >> slug; } else { - id = Window::Theme::internal::FromLegacyBackgroundId(legacyId); + id = Window::Theme::details::FromLegacyBackgroundId(legacyId); + accessHash = 0; + if (id != Window::Theme::kCustomBackground) { + flags = static_cast<quint32>(MTPDwallPaper::Flag::f_default); + } } bg.stream >> bmpData; auto oldEmptyImage = (bg.stream.status() != QDataStream::Ok); @@ -4025,16 +4041,16 @@ bool readBackground() { || id == Window::Theme::kDefaultBackground) { _backgroundCanWrite = false; if (oldEmptyImage || bg.version < 8005) { - Window::Theme::Background()->setImage(Window::Theme::kDefaultBackground); + Window::Theme::Background()->setImage({ Window::Theme::kDefaultBackground }); Window::Theme::Background()->setTile(false); } else { - Window::Theme::Background()->setImage(id); + Window::Theme::Background()->setImage({ id }); } _backgroundCanWrite = true; return true; } else if (id == Window::Theme::kThemeBackground && bmpData.isEmpty()) { _backgroundCanWrite = false; - Window::Theme::Background()->setImage(id); + Window::Theme::Background()->setImage({ id }); _backgroundCanWrite = true; return true; } @@ -4047,7 +4063,12 @@ bool readBackground() { #endif // OS_MAC_OLD if (reader.read(&image)) { _backgroundCanWrite = false; - Window::Theme::Background()->setImage(id, std::move(image)); + Window::Theme::Background()->setImage({ + id, + accessHash, + MTPDwallPaper::Flags::from_raw(flags), + slug + }, std::move(image)); _backgroundCanWrite = true; return true; } diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index 6f8f74686..183c95d63 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localimageloader.h" #include "auth_session.h" +namespace Data { +struct WallPaper; +} // namespace Data + namespace Lang { struct Language; } // namespace Lang @@ -136,7 +140,7 @@ void writeSavedGifs(); void readSavedGifs(); int32 countSavedGifsHash(); -void writeBackground(WallPaperId id, const QImage &img); +void writeBackground(const Data::WallPaper &paper, const QImage &img); bool readBackground(); void writeTheme(const Window::Theme::Saved &saved); diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 50fbe1489..aec218e3d 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -27,26 +27,20 @@ constexpr auto kThemeSchemeSizeLimit = 1024 * 1024; constexpr auto kMinimumTiledSize = 512; constexpr auto kNightThemeFile = str_const(":/gui/night.tdesktop-theme"); -struct Data { - struct Applying { - QString pathRelative; - QString pathAbsolute; - QByteArray content; - QByteArray paletteForRevert; - Cached cached; - Fn<void()> overrideKeep; - }; - - ChatBackground background; - Applying applying; +struct Applying { + QString pathRelative; + QString pathAbsolute; + QByteArray content; + QByteArray paletteForRevert; + Cached cached; + Fn<void()> overrideKeep; }; -NeverFreedPointer<Data> instance; + +NeverFreedPointer<ChatBackground> GlobalBackground; +Applying GlobalApplying; inline bool AreTestingTheme() { - if (instance) { - return !instance->applying.paletteForRevert.isEmpty(); - } - return false; + return !GlobalApplying.paletteForRevert.isEmpty(); }; QByteArray readThemeContent(const QString &path) { @@ -348,15 +342,15 @@ void adjustColor(style::color color, float64 hue, float64 saturation) { void WriteAppliedTheme() { auto saved = Saved(); - saved.pathRelative = instance->applying.pathRelative; - saved.pathAbsolute = instance->applying.pathAbsolute; - saved.content = std::move(instance->applying.content); - saved.cache = std::move(instance->applying.cached); + saved.pathRelative = GlobalApplying.pathRelative; + saved.pathAbsolute = GlobalApplying.pathAbsolute; + saved.content = std::move(GlobalApplying.content); + saved.cache = std::move(GlobalApplying.cached); Local::writeTheme(saved); } void ClearApplying() { - instance->applying = Data::Applying(); + GlobalApplying = Applying(); } } // namespace @@ -382,51 +376,59 @@ void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) { } void ChatBackground::start() { - if (_id == internal::kUninitializedBackground) { + if (_paper.id == details::kUninitializedBackground) { if (!Local::readBackground()) { - setImage(kThemeBackground); + setImage({ kThemeBackground }); } } } -void ChatBackground::setImage(WallPaperId id, QImage &&image) { - auto needResetAdjustable = (id == kDefaultBackground) - && (_id != kDefaultBackground) +void ChatBackground::setImage( + const Data::WallPaper &paper, + QImage &&image) { + const auto needResetAdjustable = (paper.id == kDefaultBackground) + && (id() != kDefaultBackground) && !nightMode() && _themeAbsolutePath.isEmpty(); - if (id == kThemeBackground && _themeImage.isNull()) { - id = kDefaultBackground; - } else if (needResetAdjustable) { - // If we had a default color theme with non-default background, - // and we switch to default background we must somehow switch from - // adjusted service colors to default (non-adjusted) service colors. - // The only way to do that right now is through full palette reset. - restoreAdjustableColors(); + if (paper.id == kThemeBackground && _themeImage.isNull()) { + _paper = { kDefaultBackground }; + } else { + _paper = paper; + if (needResetAdjustable) { + // If we had a default color theme with non-default background, + // and we switch to default background we must somehow switch from + // adjusted service colors to default (non-adjusted) service colors. + // The only way to do that right now is through full palette reset. + restoreAdjustableColors(); + } } - _id = id; - if (_id == kThemeBackground) { + if (_paper.id == kThemeBackground) { (nightMode() ? _tileNightValue : _tileDayValue) = _themeTile; setPreparedImage(QImage(_themeImage)); - } else if (_id == internal::kTestingThemeBackground - || _id == internal::kTestingDefaultBackground - || _id == internal::kTestingEditorBackground) { - if (_id == internal::kTestingDefaultBackground || image.isNull()) { + } else if (id() == details::kTestingThemeBackground + || id() == details::kTestingDefaultBackground + || id() == details::kTestingEditorBackground) { + if (id() == details::kTestingDefaultBackground || image.isNull()) { image.load(qsl(":/gui/art/bg.jpg")); - _id = internal::kTestingDefaultBackground; + _paper = { details::kTestingDefaultBackground }; } setPreparedImage(std::move(image)); } else { - if (_id == kInitialBackground) { + if (id() == kInitialBackground) { image.load(qsl(":/gui/art/bg_initial.jpg")); const auto scale = cScale() * cIntRetinaFactor(); if (scale != 100) { image = image.scaledToWidth(ConvertScale(image.width(), scale), Qt::SmoothTransformation); } - } else if (_id == kDefaultBackground || image.isNull()) { - _id = kDefaultBackground; + } else if (id() == kDefaultBackground || image.isNull()) { + _paper = { kDefaultBackground }; image.load(qsl(":/gui/art/bg.jpg")); } - Local::writeBackground(_id, (_id == kDefaultBackground || _id == kInitialBackground) ? QImage() : image); + Local::writeBackground( + _paper, + ((id() == kDefaultBackground || id() == kInitialBackground) + ? QImage() + : image)); setPreparedImage(prepareBackgroundImage(std::move(image))); } Assert(!_pixmap.isNull() && !_pixmapForTiled.isNull()); @@ -441,18 +443,18 @@ void ChatBackground::setPreparedImage(QImage &&image) { image = std::move(image).convertToFormat(QImage::Format_ARGB32_Premultiplied); image.setDevicePixelRatio(cRetinaFactor()); - auto adjustColors = [&] { + const auto adjustColors = [&] { const auto usingThemeBackground = [&] { - return (_id == kThemeBackground) - || (_id == internal::kTestingThemeBackground); + return (id() == kThemeBackground) + || (id() == details::kTestingThemeBackground); }; const auto usingDefaultBackground = [&] { - return (_id == kDefaultBackground) - || (_id == internal::kTestingDefaultBackground); + return (id() == kDefaultBackground) + || (id() == details::kTestingDefaultBackground); }; const auto testingPalette = [&] { const auto path = AreTestingTheme() - ? instance->applying.pathAbsolute + ? GlobalApplying.pathAbsolute : _themeAbsolutePath; return IsPaletteTestingPath(path); }; @@ -529,7 +531,7 @@ void ChatBackground::adjustPaletteUsingBackground(const QImage &img) { } WallPaperId ChatBackground::id() const { - return _id; + return _paper.id; } bool ChatBackground::tile() const { @@ -537,8 +539,8 @@ bool ChatBackground::tile() const { } bool ChatBackground::tileDay() const { - if (_id == internal::kTestingThemeBackground || - _id == internal::kTestingDefaultBackground) { + if (id() == details::kTestingThemeBackground || + id() == details::kTestingDefaultBackground) { if (!nightMode()) { return _tileForRevert; } @@ -547,8 +549,8 @@ bool ChatBackground::tileDay() const { } bool ChatBackground::tileNight() const { - if (_id == internal::kTestingThemeBackground || - _id == internal::kTestingDefaultBackground) { + if (id() == details::kTestingThemeBackground || + id() == details::kTestingDefaultBackground) { if (nightMode()) { return _tileForRevert; } @@ -573,8 +575,8 @@ void ChatBackground::setTile(bool tile) { setTileDayValue(tile); } if (this->tile() != old) { - if (_id != internal::kTestingThemeBackground - && _id != internal::kTestingDefaultBackground) { + if (id() != details::kTestingThemeBackground + && id() != details::kTestingDefaultBackground) { Local::writeUserSettings(); } notify(BackgroundUpdate(BackgroundUpdate::Type::Changed, tile)); @@ -600,19 +602,19 @@ QString ChatBackground::themeAbsolutePath() const { } void ChatBackground::reset() { - if (_id == internal::kTestingThemeBackground - || _id == internal::kTestingDefaultBackground) { + if (id() == details::kTestingThemeBackground + || id() == details::kTestingDefaultBackground) { if (_themeImage.isNull()) { - _idForRevert = kDefaultBackground; + _paperForRevert = { kDefaultBackground }; _imageForRevert = QImage(); _tileForRevert = false; } else { - _idForRevert = kThemeBackground; + _paperForRevert = { kThemeBackground }; _imageForRevert = _themeImage; _tileForRevert = _themeTile; } } else { - setImage(kThemeBackground); + setImage({ kThemeBackground }); restoreAdjustableColors(); notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); @@ -621,9 +623,9 @@ void ChatBackground::reset() { void ChatBackground::saveForRevert() { ensureStarted(); - if (_id != internal::kTestingThemeBackground - && _id != internal::kTestingDefaultBackground) { - _idForRevert = _id; + if (id() != details::kTestingThemeBackground + && id() != details::kTestingDefaultBackground) { + _paperForRevert = _paper; _imageForRevert = std::move(_pixmap).toImage(); _tileForRevert = tile(); } @@ -647,23 +649,23 @@ void ChatBackground::setTestingTheme(Instance &&theme) { saveAdjustableColors(); auto switchToThemeBackground = !theme.background.isNull() - || (_id == kThemeBackground) - || (_id == kDefaultBackground + || (id() == kThemeBackground) + || (id() == kDefaultBackground && !nightMode() && _themeAbsolutePath.isEmpty()); - if (AreTestingTheme() && IsPaletteTestingPath(instance->applying.pathAbsolute)) { + if (AreTestingTheme() && IsPaletteTestingPath(GlobalApplying.pathAbsolute)) { // Grab current background image if it is not already custom - if (_id != kCustomBackground) { + if (id() != kCustomBackground) { saveForRevert(); - setImage(internal::kTestingEditorBackground, std::move(_pixmap).toImage()); + setImage({ details::kTestingEditorBackground }, std::move(_pixmap).toImage()); } } else if (switchToThemeBackground) { saveForRevert(); - setImage(internal::kTestingThemeBackground, std::move(theme.background)); + setImage({ details::kTestingThemeBackground }, std::move(theme.background)); setTile(theme.tiled); } else { // Apply current background image so that service bg colors are recounted. - setImage(_id, std::move(_pixmap).toImage()); + setImage(_paper, std::move(_pixmap).toImage()); } notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); } @@ -673,29 +675,29 @@ void ChatBackground::setTestingDefaultTheme() { saveAdjustableColors(); saveForRevert(); - setImage(internal::kTestingDefaultBackground); + setImage({ details::kTestingDefaultBackground }); setTile(false); notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); } void ChatBackground::keepApplied(const QString &path, bool write) { setThemeAbsolutePath(path); - if (_id == internal::kTestingEditorBackground) { - _id = kCustomBackground; + if (id() == details::kTestingEditorBackground) { + _paper = { kCustomBackground }; _themeImage = QImage(); _themeTile = false; if (write) { writeNewBackgroundSettings(); } - } else if (_id == internal::kTestingThemeBackground) { - _id = kThemeBackground; + } else if (id() == details::kTestingThemeBackground) { + _paper = { kThemeBackground }; _themeImage = _pixmap.toImage(); _themeTile = tile(); if (write) { writeNewBackgroundSettings(); } - } else if (_id == internal::kTestingDefaultBackground) { - _id = kDefaultBackground; + } else if (id() == details::kTestingDefaultBackground) { + _paper = { kDefaultBackground }; _themeImage = QImage(); _themeTile = false; if (write) { @@ -709,16 +711,16 @@ bool ChatBackground::isNonDefaultThemeOrBackground() { start(); return nightMode() ? (_themeAbsolutePath != NightThemePath() - || _id != kThemeBackground) + || id() != kThemeBackground) : (!_themeAbsolutePath.isEmpty() - || _id != kDefaultBackground); + || id() != kDefaultBackground); } bool ChatBackground::isNonDefaultBackground() { start(); return _themeAbsolutePath.isEmpty() - ? (_id != kDefaultBackground) - : (_id != kThemeBackground); + ? (id() != kDefaultBackground) + : (id() != kThemeBackground); } void ChatBackground::writeNewBackgroundSettings() { @@ -726,21 +728,21 @@ void ChatBackground::writeNewBackgroundSettings() { Local::writeUserSettings(); } Local::writeBackground( - _id, - ((_id == kThemeBackground || _id == kDefaultBackground) + _paper, + ((id() == kThemeBackground || id() == kDefaultBackground) ? QImage() : _pixmap.toImage())); } void ChatBackground::revert() { - if (_id == internal::kTestingThemeBackground - || _id == internal::kTestingDefaultBackground - || _id == internal::kTestingEditorBackground) { + if (id() == details::kTestingThemeBackground + || id() == details::kTestingDefaultBackground + || id() == details::kTestingEditorBackground) { setTile(_tileForRevert); - setImage(_idForRevert, std::move(_imageForRevert)); + setImage(_paperForRevert, std::move(_imageForRevert)); } else { // Apply current background image so that service bg colors are recounted. - setImage(_id, std::move(_pixmap).toImage()); + setImage(_paper, std::move(_pixmap).toImage()); } notify(BackgroundUpdate(BackgroundUpdate::Type::RevertingTheme, tile()), true); } @@ -791,7 +793,7 @@ void ChatBackground::toggleNightMode(std::optional<QString> themePath) { // Theme editor could have already reverted the testing of this toggle. if (AreTestingTheme()) { - instance->applying.overrideKeep = [=] { + GlobalApplying.overrideKeep = [=] { _nightMode = newNightMode; // Restore the value, it was set inside theme testing. @@ -808,15 +810,15 @@ void ChatBackground::toggleNightMode(std::optional<QString> themePath) { } Local::writeSettings(); if (!settingDefault && !Local::readBackground()) { - setImage(kThemeBackground); + setImage({ kThemeBackground }); } }; } } ChatBackground *Background() { - instance.createIfNull(); - return &instance->background; + GlobalBackground.createIfNull(); + return GlobalBackground.data(); } bool Load(Saved &&saved) { @@ -827,7 +829,7 @@ bool Load(Saved &&saved) { return false; } - instance.createIfNull(); + GlobalBackground.createIfNull(); if (loadThemeFromCache(saved.content, saved.cache)) { Background()->setThemeAbsolutePath(saved.pathAbsolute); return true; @@ -842,7 +844,8 @@ bool Load(Saved &&saved) { } void Unload() { - instance.clear(); + GlobalBackground.clear(); + GlobalApplying = Applying(); } bool Apply(const QString &filepath) { @@ -853,13 +856,12 @@ bool Apply(const QString &filepath) { } bool Apply(std::unique_ptr<Preview> preview) { - instance.createIfNull(); - instance->applying.pathRelative = std::move(preview->pathRelative); - instance->applying.pathAbsolute = std::move(preview->pathAbsolute); - instance->applying.content = std::move(preview->content); - instance->applying.cached = std::move(preview->instance.cached); - if (instance->applying.paletteForRevert.isEmpty()) { - instance->applying.paletteForRevert = style::main_palette::save(); + GlobalApplying.pathRelative = std::move(preview->pathRelative); + GlobalApplying.pathAbsolute = std::move(preview->pathAbsolute); + GlobalApplying.content = std::move(preview->content); + GlobalApplying.cached = std::move(preview->instance.cached); + if (GlobalApplying.paletteForRevert.isEmpty()) { + GlobalApplying.paletteForRevert = style::main_palette::save(); } Background()->setTestingTheme(std::move(preview->instance)); return true; @@ -871,13 +873,12 @@ void ApplyDefaultWithPath(const QString &themePath) { Apply(std::move(preview)); } } else { - instance.createIfNull(); - instance->applying.pathRelative = QString(); - instance->applying.pathAbsolute = QString(); - instance->applying.content = QByteArray(); - instance->applying.cached = Cached(); - if (instance->applying.paletteForRevert.isEmpty()) { - instance->applying.paletteForRevert = style::main_palette::save(); + GlobalApplying.pathRelative = QString(); + GlobalApplying.pathAbsolute = QString(); + GlobalApplying.content = QByteArray(); + GlobalApplying.cached = Cached(); + if (GlobalApplying.paletteForRevert.isEmpty()) { + GlobalApplying.paletteForRevert = style::main_palette::save(); } Background()->setTestingDefaultTheme(); } @@ -892,17 +893,16 @@ bool ApplyEditedPalette(const QString &path, const QByteArray &content) { out.cached.paletteChecksum = style::palette::Checksum(); out.cached.contentChecksum = hashCrc32(content.constData(), content.size()); - instance.createIfNull(); - instance->applying.pathRelative = path.isEmpty() + GlobalApplying.pathRelative = path.isEmpty() ? QString() : QDir().relativeFilePath(path); - instance->applying.pathAbsolute = path.isEmpty() + GlobalApplying.pathAbsolute = path.isEmpty() ? QString() : QFileInfo(path).absoluteFilePath(); - instance->applying.content = content; - instance->applying.cached = out.cached; - if (instance->applying.paletteForRevert.isEmpty()) { - instance->applying.paletteForRevert = style::main_palette::save(); + GlobalApplying.content = content; + GlobalApplying.cached = out.cached; + if (GlobalApplying.paletteForRevert.isEmpty()) { + GlobalApplying.paletteForRevert = style::main_palette::save(); } Background()->setTestingTheme(std::move(out)); KeepApplied(); @@ -912,15 +912,15 @@ bool ApplyEditedPalette(const QString &path, const QByteArray &content) { void KeepApplied() { if (!AreTestingTheme()) { return; - } else if (instance->applying.overrideKeep) { + } else if (GlobalApplying.overrideKeep) { // This callback will be destroyed while running. // And it won't be able to safely access captures after that. // So we save it on stack for the time while it is running. - const auto saved = base::take(instance->applying.overrideKeep); - saved(); + const auto onstack = base::take(GlobalApplying.overrideKeep); + onstack(); return; } - const auto path = instance->applying.pathAbsolute; + const auto path = GlobalApplying.pathAbsolute; WriteAppliedTheme(); ClearApplying(); Background()->keepApplied(path, true); @@ -930,7 +930,7 @@ void Revert() { if (!AreTestingTheme()) { return; } - style::main_palette::load(instance->applying.paletteForRevert); + style::main_palette::load(GlobalApplying.paletteForRevert); Background()->saveAdjustableColors(); ClearApplying(); @@ -946,11 +946,11 @@ bool IsNonDefaultBackground() { } bool IsNightMode() { - return instance ? Background()->nightMode() : false; + return GlobalBackground ? Background()->nightMode() : false; } void SetNightModeValue(bool nightMode) { - if (instance || nightMode) { + if (GlobalBackground || nightMode) { Background()->setNightModeValue(nightMode); } } diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index 87dcd1e76..d07b9c1cd 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -7,9 +7,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +namespace Data { + +struct WallPaper { + WallPaperId id = WallPaperId(); + uint64 accessHash = 0; + MTPDwallPaper::Flags flags; + QString slug; + ImagePtr thumb; + DocumentData *document = nullptr; +}; + +} // namespace Data + namespace Window { namespace Theme { -namespace internal { +namespace details { constexpr auto FromLegacyBackgroundId(int32 legacyId) -> WallPaperId { return uint64(0xFFFFFFFF00000000ULL) | uint64(uint32(legacyId)); @@ -21,12 +34,12 @@ constexpr auto kTestingDefaultBackground = FromLegacyBackgroundId(-665); constexpr auto kTestingEditorBackground = FromLegacyBackgroundId(-664); constexpr auto kLegacyBackgroundId = int32(-111); -} // namespace internal +} // namespace details -constexpr auto kThemeBackground = internal::FromLegacyBackgroundId(-2); -constexpr auto kCustomBackground = internal::FromLegacyBackgroundId(-1); -constexpr auto kInitialBackground = internal::FromLegacyBackgroundId(0); -constexpr auto kDefaultBackground = internal::FromLegacyBackgroundId(105); +constexpr auto kThemeBackground = details::FromLegacyBackgroundId(-2); +constexpr auto kCustomBackground = details::FromLegacyBackgroundId(-1); +constexpr auto kInitialBackground = details::FromLegacyBackgroundId(0); +constexpr auto kDefaultBackground = details::FromLegacyBackgroundId(105); struct Cached { QByteArray colors; @@ -103,7 +116,7 @@ public: // This method is setting the default (themed) image if none was set yet. void start(); - void setImage(WallPaperId id, QImage &&image = QImage()); + void setImage(const Data::WallPaper &paper, QImage &&image = QImage()); void setTile(bool tile); void setTileDayValue(bool tile); void setTileNightValue(bool tile); @@ -157,7 +170,7 @@ private: friend void KeepApplied(); friend bool IsNonDefaultBackground(); - WallPaperId _id = internal::kUninitializedBackground; + Data::WallPaper _paper = { details::kUninitializedBackground }; QPixmap _pixmap; QPixmap _pixmapForTiled; bool _nightMode = false; @@ -168,7 +181,7 @@ private: QImage _themeImage; bool _themeTile = false; - WallPaperId _idForRevert = internal::kUninitializedBackground; + Data::WallPaper _paperForRevert = { details::kUninitializedBackground }; QImage _imageForRevert; bool _tileForRevert = false;