2016-10-28 12:44:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-28 12:44:28 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-08 16:20:08 +00:00
|
|
|
#include "data/data_wall_paper.h"
|
2019-09-03 18:04:38 +00:00
|
|
|
#include "data/data_cloud_themes.h"
|
2019-01-25 14:37:28 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2020-07-22 12:10:17 +00:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Window
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Theme {
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-09-03 18:04:38 +00:00
|
|
|
inline constexpr auto kThemeSchemeSizeLimit = 1024 * 1024;
|
2019-09-08 13:40:15 +00:00
|
|
|
inline constexpr auto kThemeBackgroundSizeLimit = 4 * 1024 * 1024;
|
2019-08-26 16:36:23 +00:00
|
|
|
|
2019-09-08 16:29:43 +00:00
|
|
|
struct ParsedTheme;
|
2021-08-26 15:02:21 +00:00
|
|
|
struct Colorizer;
|
2019-09-08 16:29:43 +00:00
|
|
|
|
2019-09-05 07:42:06 +00:00
|
|
|
[[nodiscard]] bool IsEmbeddedTheme(const QString &path);
|
|
|
|
|
2019-09-03 18:04:38 +00:00
|
|
|
struct Object {
|
|
|
|
QString pathRelative;
|
|
|
|
QString pathAbsolute;
|
|
|
|
QByteArray content;
|
|
|
|
Data::CloudTheme cloud;
|
|
|
|
};
|
2016-10-28 12:44:28 +00:00
|
|
|
struct Cached {
|
|
|
|
QByteArray colors;
|
|
|
|
QByteArray background;
|
|
|
|
bool tiled = false;
|
|
|
|
int32 paletteChecksum = 0;
|
|
|
|
int32 contentChecksum = 0;
|
|
|
|
};
|
2018-07-19 14:58:40 +00:00
|
|
|
struct Saved {
|
2019-09-03 18:04:38 +00:00
|
|
|
Object object;
|
2018-07-19 14:58:40 +00:00
|
|
|
Cached cache;
|
|
|
|
};
|
2019-09-05 06:51:46 +00:00
|
|
|
bool Initialize(Saved &&saved);
|
|
|
|
void Uninitialize();
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
struct Instance {
|
|
|
|
style::palette palette;
|
|
|
|
QImage background;
|
|
|
|
Cached cached;
|
|
|
|
bool tiled = false;
|
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
|
|
|
|
struct Preview {
|
2019-09-03 18:04:38 +00:00
|
|
|
Object object;
|
2016-12-23 13:21:01 +00:00
|
|
|
Instance instance;
|
2018-01-02 19:10:49 +00:00
|
|
|
QImage preview;
|
2016-12-23 13:21:01 +00:00
|
|
|
};
|
|
|
|
|
2019-09-05 05:18:21 +00:00
|
|
|
bool Apply(
|
|
|
|
const QString &filepath,
|
|
|
|
const Data::CloudTheme &cloud = Data::CloudTheme());
|
2017-02-21 13:45:56 +00:00
|
|
|
bool Apply(std::unique_ptr<Preview> preview);
|
2019-08-27 13:59:15 +00:00
|
|
|
void ApplyDefaultWithPath(const QString &themePath);
|
2019-09-05 06:51:46 +00:00
|
|
|
bool ApplyEditedPalette(const QByteArray &content);
|
2016-12-23 13:21:01 +00:00
|
|
|
void KeepApplied();
|
2019-09-08 16:29:43 +00:00
|
|
|
void KeepFromEditor(
|
|
|
|
const QByteArray &originalContent,
|
|
|
|
const ParsedTheme &originalParsed,
|
|
|
|
const Data::CloudTheme &cloud,
|
|
|
|
const QByteArray &themeContent,
|
2019-09-09 21:36:16 +00:00
|
|
|
const ParsedTheme &themeParsed,
|
|
|
|
const QImage &background);
|
2018-07-19 14:58:40 +00:00
|
|
|
QString NightThemePath();
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool IsNightMode();
|
2018-07-19 14:58:40 +00:00
|
|
|
void SetNightModeValue(bool nightMode);
|
2021-08-26 13:25:48 +00:00
|
|
|
[[nodiscard]] rpl::producer<bool> IsNightModeValue();
|
2018-07-19 14:58:40 +00:00
|
|
|
void ToggleNightMode();
|
2019-08-27 13:59:15 +00:00
|
|
|
void ToggleNightMode(const QString &themePath);
|
2020-07-22 12:10:17 +00:00
|
|
|
void ToggleNightModeWithConfirmation(
|
|
|
|
not_null<Controller*> window,
|
|
|
|
Fn<void()> toggle);
|
2019-09-08 17:05:26 +00:00
|
|
|
void ResetToSomeDefault();
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool IsNonDefaultBackground();
|
2016-12-23 13:21:01 +00:00
|
|
|
void Revert();
|
|
|
|
|
2019-09-02 16:10:18 +00:00
|
|
|
[[nodiscard]] QString EditingPalettePath();
|
|
|
|
|
2021-08-26 15:02:21 +00:00
|
|
|
// NB! This method looks to Core::App().settings() to get colorizer by 'file'.
|
2019-08-20 16:03:14 +00:00
|
|
|
bool LoadFromFile(
|
2021-08-26 15:02:21 +00:00
|
|
|
const QString &path,
|
2019-09-03 15:24:51 +00:00
|
|
|
not_null<Instance*> out,
|
2019-09-09 06:59:57 +00:00
|
|
|
Cached *outCache,
|
2021-08-26 15:02:21 +00:00
|
|
|
QByteArray *outContent);
|
|
|
|
bool LoadFromFile(
|
|
|
|
const QString &path,
|
|
|
|
not_null<Instance*> out,
|
|
|
|
Cached *outCache,
|
|
|
|
QByteArray *outContent,
|
|
|
|
const Colorizer &colorizer);
|
2019-09-09 06:59:57 +00:00
|
|
|
bool LoadFromContent(
|
|
|
|
const QByteArray &content,
|
|
|
|
not_null<Instance*> out,
|
|
|
|
Cached *outCache);
|
2021-07-23 12:16:22 +00:00
|
|
|
[[nodiscard]] QColor CountAverageColor(const QImage &image);
|
|
|
|
[[nodiscard]] QColor AdjustedColor(QColor original, QColor background);
|
|
|
|
[[nodiscard]] QImage PreprocessBackgroundImage(QImage image);
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
struct BackgroundUpdate {
|
|
|
|
enum class Type {
|
|
|
|
New,
|
|
|
|
Changed,
|
|
|
|
Start,
|
2016-11-02 14:44:33 +00:00
|
|
|
TestingTheme,
|
|
|
|
RevertingTheme,
|
|
|
|
ApplyingTheme,
|
2019-09-05 06:51:46 +00:00
|
|
|
ApplyingEdit,
|
2016-10-28 12:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BackgroundUpdate(Type type, bool tiled) : type(type), tiled(tiled) {
|
|
|
|
}
|
2019-09-02 16:10:18 +00:00
|
|
|
[[nodiscard]] bool paletteChanged() const {
|
2019-09-05 06:51:46 +00:00
|
|
|
return (type == Type::TestingTheme)
|
|
|
|
|| (type == Type::RevertingTheme)
|
2020-10-13 15:11:53 +00:00
|
|
|
|| (type == Type::ApplyingEdit)
|
|
|
|
|| (type == Type::New);
|
2016-12-23 13:21:01 +00:00
|
|
|
}
|
2016-10-28 12:44:28 +00:00
|
|
|
Type type;
|
|
|
|
bool tiled;
|
|
|
|
};
|
|
|
|
|
2019-09-06 15:30:44 +00:00
|
|
|
enum class ClearEditing {
|
|
|
|
Temporary,
|
|
|
|
RevertChanges,
|
|
|
|
KeepChanges,
|
|
|
|
};
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
class ChatBackground final {
|
2016-10-28 12:44:28 +00:00
|
|
|
public:
|
2018-07-21 13:54:00 +00:00
|
|
|
ChatBackground();
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
[[nodiscard]] rpl::producer<BackgroundUpdate> updates() const {
|
|
|
|
return _updates.events();
|
|
|
|
}
|
|
|
|
|
2020-06-19 17:13:43 +00:00
|
|
|
void start();
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
// This method is allowed to (and should) be called before start().
|
|
|
|
void setThemeData(QImage &&themeImage, bool themeTile);
|
|
|
|
|
|
|
|
// This method is setting the default (themed) image if none was set yet.
|
2019-01-29 10:57:29 +00:00
|
|
|
void set(const Data::WallPaper &paper, QImage image = QImage());
|
2016-10-28 12:44:28 +00:00
|
|
|
void setTile(bool tile);
|
2018-07-19 14:58:40 +00:00
|
|
|
void setTileDayValue(bool tile);
|
|
|
|
void setTileNightValue(bool tile);
|
2019-09-03 18:04:38 +00:00
|
|
|
void setThemeObject(const Object &object);
|
|
|
|
[[nodiscard]] const Object &themeObject() const;
|
2019-09-05 20:21:44 +00:00
|
|
|
[[nodiscard]] std::optional<Data::CloudTheme> editingTheme() const;
|
2019-09-06 15:30:44 +00:00
|
|
|
void setEditingTheme(const Data::CloudTheme &editing);
|
|
|
|
void clearEditingTheme(ClearEditing clear = ClearEditing::Temporary);
|
2016-11-02 14:44:33 +00:00
|
|
|
void reset();
|
|
|
|
|
2018-07-21 13:54:00 +00:00
|
|
|
void setTestingTheme(Instance &&theme);
|
|
|
|
void saveAdjustableColors();
|
2016-12-20 13:03:51 +00:00
|
|
|
void setTestingDefaultTheme();
|
2016-11-02 14:44:33 +00:00
|
|
|
void revert();
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
void appliedEditedPalette();
|
|
|
|
void downloadingStarted(bool tile);
|
|
|
|
|
2021-08-12 14:51:44 +00:00
|
|
|
[[nodiscard]] const Data::WallPaper &paper() const {
|
2019-02-07 16:36:30 +00:00
|
|
|
return _paper;
|
|
|
|
}
|
2019-01-28 13:59:49 +00:00
|
|
|
[[nodiscard]] WallPaperId id() const {
|
|
|
|
return _paper.id();
|
|
|
|
}
|
2021-08-13 18:18:06 +00:00
|
|
|
[[nodiscard]] const QImage &prepared() const {
|
|
|
|
return _prepared;
|
2017-01-01 16:45:20 +00:00
|
|
|
}
|
2021-08-13 18:18:06 +00:00
|
|
|
[[nodiscard]] const QImage &preparedForTiled() const {
|
|
|
|
return _preparedForTiled;
|
2017-01-01 16:45:20 +00:00
|
|
|
}
|
2019-01-29 07:29:38 +00:00
|
|
|
[[nodiscard]] std::optional<QColor> colorForFill() const;
|
2021-08-12 14:51:44 +00:00
|
|
|
[[nodiscard]] QImage gradientForFill() const;
|
2021-08-16 13:07:43 +00:00
|
|
|
void recacheGradientForFill(QImage gradient);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] QImage createCurrentImage() const;
|
|
|
|
[[nodiscard]] bool tile() const;
|
|
|
|
[[nodiscard]] bool tileDay() const;
|
|
|
|
[[nodiscard]] bool tileNight() const;
|
2021-08-12 14:51:44 +00:00
|
|
|
[[nodiscard]] std::optional<QColor> imageMonoColor() const;
|
2020-07-22 12:10:17 +00:00
|
|
|
[[nodiscard]] bool nightModeChangeAllowed() const;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
|
|
|
private:
|
2018-07-21 13:54:00 +00:00
|
|
|
struct AdjustableColor {
|
|
|
|
AdjustableColor(style::color data);
|
|
|
|
|
|
|
|
style::color item;
|
|
|
|
QColor original;
|
|
|
|
};
|
|
|
|
|
2020-06-23 15:24:45 +00:00
|
|
|
[[nodiscard]] bool started() const;
|
2020-06-19 17:13:43 +00:00
|
|
|
void initialRead();
|
2016-11-02 14:44:33 +00:00
|
|
|
void saveForRevert();
|
2021-08-12 14:51:44 +00:00
|
|
|
void setPrepared(QImage original, QImage prepared, QImage gradient);
|
2021-08-13 18:18:06 +00:00
|
|
|
void prepareImageForTiled();
|
2016-11-02 14:44:33 +00:00
|
|
|
void writeNewBackgroundSettings();
|
2019-01-17 08:18:23 +00:00
|
|
|
void setPaper(const Data::WallPaper &paper);
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool adjustPaletteRequired();
|
2019-01-29 10:57:29 +00:00
|
|
|
void adjustPaletteUsingBackground(const QImage &image);
|
2019-01-17 08:18:23 +00:00
|
|
|
void adjustPaletteUsingColor(QColor color);
|
2018-07-21 13:54:00 +00:00
|
|
|
void restoreAdjustableColors();
|
|
|
|
|
2018-07-19 14:58:40 +00:00
|
|
|
void setNightModeValue(bool nightMode);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool nightMode() const;
|
2019-08-27 13:59:15 +00:00
|
|
|
void toggleNightMode(std::optional<QString> themePath);
|
2019-09-05 06:51:46 +00:00
|
|
|
void reapplyWithNightMode(
|
|
|
|
std::optional<QString> themePath,
|
|
|
|
bool newNightMode);
|
2019-09-03 18:04:38 +00:00
|
|
|
void keepApplied(const Object &object, bool write);
|
2019-01-17 08:18:23 +00:00
|
|
|
[[nodiscard]] bool isNonDefaultThemeOrBackground();
|
|
|
|
[[nodiscard]] bool isNonDefaultBackground();
|
2019-02-08 16:20:08 +00:00
|
|
|
void checkUploadWallPaper();
|
2021-07-23 12:16:22 +00:00
|
|
|
[[nodiscard]] QImage postprocessBackgroundImage(QImage image);
|
2018-07-19 14:58:40 +00:00
|
|
|
|
|
|
|
friend bool IsNightMode();
|
|
|
|
friend void SetNightModeValue(bool nightMode);
|
|
|
|
friend void ToggleNightMode();
|
2019-08-27 13:59:15 +00:00
|
|
|
friend void ToggleNightMode(const QString &themePath);
|
2019-09-08 17:05:26 +00:00
|
|
|
friend void ResetToSomeDefault();
|
2018-07-19 14:58:40 +00:00
|
|
|
friend void KeepApplied();
|
2019-09-08 16:29:43 +00:00
|
|
|
friend void KeepFromEditor(
|
|
|
|
const QByteArray &originalContent,
|
|
|
|
const ParsedTheme &originalParsed,
|
|
|
|
const Data::CloudTheme &cloud,
|
|
|
|
const QByteArray &themeContent,
|
2019-09-09 21:36:16 +00:00
|
|
|
const ParsedTheme &themeParsed,
|
|
|
|
const QImage &background);
|
2018-09-26 11:28:16 +00:00
|
|
|
friend bool IsNonDefaultBackground();
|
2018-07-19 14:58:40 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session *_session = nullptr;
|
2021-07-15 11:12:38 +00:00
|
|
|
rpl::event_stream<BackgroundUpdate> _updates;
|
2019-01-28 13:59:49 +00:00
|
|
|
Data::WallPaper _paper = Data::details::UninitializedWallPaper();
|
2019-01-17 08:18:23 +00:00
|
|
|
std::optional<QColor> _paperColor;
|
2021-08-12 14:51:44 +00:00
|
|
|
QImage _gradient;
|
2019-01-29 10:57:29 +00:00
|
|
|
QImage _original;
|
2021-08-13 18:18:06 +00:00
|
|
|
QImage _prepared;
|
|
|
|
QImage _preparedForTiled;
|
2018-07-19 14:58:40 +00:00
|
|
|
bool _nightMode = false;
|
|
|
|
bool _tileDayValue = false;
|
|
|
|
bool _tileNightValue = true;
|
2020-06-23 15:24:45 +00:00
|
|
|
std::optional<bool> _localStoredTileDayValue;
|
|
|
|
std::optional<bool> _localStoredTileNightValue;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2021-08-12 14:51:44 +00:00
|
|
|
std::optional<QColor> _imageMonoColor;
|
2019-05-31 17:53:00 +00:00
|
|
|
|
2019-09-03 18:04:38 +00:00
|
|
|
Object _themeObject;
|
2016-10-28 12:44:28 +00:00
|
|
|
QImage _themeImage;
|
|
|
|
bool _themeTile = false;
|
2019-09-05 20:21:44 +00:00
|
|
|
std::optional<Data::CloudTheme> _editingTheme;
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
Data::WallPaper _paperForRevert
|
|
|
|
= Data::details::UninitializedWallPaper();
|
2019-01-29 10:57:29 +00:00
|
|
|
QImage _originalForRevert;
|
2016-11-02 14:44:33 +00:00
|
|
|
bool _tileForRevert = false;
|
|
|
|
|
2018-07-21 13:54:00 +00:00
|
|
|
std::vector<AdjustableColor> _adjustableColors;
|
2019-02-08 16:20:08 +00:00
|
|
|
FullMsgId _wallPaperUploadId;
|
|
|
|
mtpRequestId _wallPaperRequestId = 0;
|
|
|
|
rpl::lifetime _wallPaperUploadLifetime;
|
2018-07-21 13:54:00 +00:00
|
|
|
|
2019-06-06 09:37:12 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
};
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
[[nodiscard]] ChatBackground *Background();
|
2016-10-28 12:44:28 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
bool ReadPaletteValues(const QByteArray &content, Fn<bool(QLatin1String name, QLatin1String value)> callback);
|
2017-02-03 20:07:26 +00:00
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
} // namespace Theme
|
|
|
|
} // namespace Window
|