2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-05 00:46:08 +00:00

Save wallpaper information.

This commit is contained in:
John Preston
2019-01-16 21:26:26 +04:00
parent b8cb792831
commit 466c6da5e3
8 changed files with 211 additions and 159 deletions

View File

@@ -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;
}