Beta version 3.0.4: Add some theme loading logging.

This commit is contained in:
John Preston 2021-09-13 20:09:55 +03:00
parent 889c3293e7
commit 6a53fc7edc
4 changed files with 58 additions and 6 deletions

View file

@ -618,6 +618,7 @@ bool ReadSetting(
stream >> key;
if (!CheckStreamStatus(stream)) return false;
DEBUG_LOG(("Theme: read key legacy: %1").arg(key));
context.themeKeyLegacy = key;
context.legacyRead = true;
} break;
@ -628,6 +629,10 @@ bool ReadSetting(
stream >> keyDay >> keyNight >> nightMode;
if (!CheckStreamStatus(stream)) return false;
DEBUG_LOG(("Theme: read keys (night: %1) day_key: %2, night_key: %3, "
).arg(Logs::b(nightMode == 1)
).arg(keyDay
).arg(keyNight));
context.themeKeyDay = keyDay;
context.themeKeyNight = keyNight;
Window::Theme::SetNightModeValue(nightMode == 1);

View file

@ -125,6 +125,10 @@ bool CheckStreamStatus(QDataStream &stream) {
void applyReadContext(ReadSettingsContext &&context) {
ApplyReadFallbackConfig(context);
DEBUG_LOG(("Theme: applying context, legacy: %1, day: %2, night: %3"
).arg(context.themeKeyLegacy
).arg(context.themeKeyDay
).arg(context.themeKeyNight));
_themeKeyLegacy = context.themeKeyLegacy;
_themeKeyDay = context.themeKeyDay;
_themeKeyNight = context.themeKeyNight;
@ -869,6 +873,7 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
FileReadDescriptor theme;
if (!ReadEncryptedFile(theme, key, _basePath, SettingsKey)) {
DEBUG_LOG(("Theme: Could not read file for key: %1").arg(key));
return {};
}
@ -893,6 +898,9 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
object.pathRelative = tag;
}
if (theme.stream.status() != QDataStream::Ok) {
DEBUG_LOG(("Theme: Bad status for key: %1, tag: %2"
).arg(key
).arg(tag));
return {};
}
@ -932,6 +940,9 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
>> field2;
if (!ignoreCache) {
if (theme.stream.status() != QDataStream::Ok) {
DEBUG_LOG(("Theme: Bad status for cache, key: %1, tag: %2"
).arg(key
).arg(tag));
return {};
}
cache.paletteChecksum = cachePaletteChecksum;
@ -950,8 +961,12 @@ Window::Theme::Saved readThemeUsingKey(FileKey key) {
std::optional<QString> InitialLoadThemeUsingKey(FileKey key) {
auto read = readThemeUsingKey(key);
const auto result = read.object.pathAbsolute;
if (read.object.content.isEmpty()) {
DEBUG_LOG(("Theme: Could not read content for key: %1").arg(key));
}
if (read.object.content.isEmpty()
|| !Window::Theme::Initialize(std::move(read))) {
DEBUG_LOG(("Theme: Could not initialized for key: %1").arg(key));
return std::nullopt;
}
return result;
@ -961,13 +976,23 @@ void writeTheme(const Window::Theme::Saved &saved) {
using namespace Window::Theme;
if (_themeKeyLegacy) {
DEBUG_LOG(("Theme: skipping write, because legacy: %1"
).arg(_themeKeyLegacy));
return;
}
auto &themeKey = IsNightMode()
? _themeKeyNight
: _themeKeyDay;
DEBUG_LOG(("Theme: writing (night: %1), key_day: %2, key_night: %3"
).arg(Logs::b(IsNightMode())
).arg(_themeKeyDay
).arg(_themeKeyNight));
if (saved.object.content.isEmpty()) {
if (themeKey) {
if (IsNightMode()) {
DEBUG_LOG(("Theme: cleared for night mode."));
SetNightModeValue(false);
}
ClearKey(themeKey, _basePath);
themeKey = 0;
writeSettings();
@ -1032,17 +1057,36 @@ void InitialLoadTheme() {
: (Window::Theme::IsNightMode()
? _themeKeyNight
: _themeKeyDay);
DEBUG_LOG(("Theme: initial load (night: %1), "
"key_legacy: %2, key_day: %3, key_night: %4"
).arg(Logs::b(Window::Theme::IsNightMode())
).arg(_themeKeyLegacy
).arg(_themeKeyDay
).arg(_themeKeyNight));
if (!key) {
if (Window::Theme::IsNightMode()) {
DEBUG_LOG(("Theme: zero key for night mode."));
Window::Theme::SetNightModeValue(false);
}
return;
} else if (const auto path = InitialLoadThemeUsingKey(key)) {
DEBUG_LOG(("Theme: loaded with result: %1").arg(*path));
if (_themeKeyLegacy) {
Window::Theme::SetNightModeValue(*path
== Window::Theme::NightThemePath());
(Window::Theme::IsNightMode()
? _themeKeyNight
: _themeKeyDay) = base::take(_themeKeyLegacy);
DEBUG_LOG(("Theme: now (night: %1), "
"key_legacy: %2, key_day: %3, key_night: %4 (path: %5)"
).arg(Logs::b(Window::Theme::IsNightMode())
).arg(_themeKeyLegacy
).arg(_themeKeyDay
).arg(_themeKeyNight
).arg(*path));
}
} else {
DEBUG_LOG(("Theme: could not load, clearing.."));
clearTheme();
}
}

View file

@ -154,7 +154,6 @@ bool readNameAndValue(const char *&from, const char *end, QLatin1String *outName
enum class SetResult {
Ok,
Bad,
NotFound,
};
SetResult setColorSchemeValue(
@ -202,7 +201,7 @@ SetResult setColorSchemeValue(
} else {
LOG(("Theme Error: Unexpected internal error."));
}
return SetResult::Bad;
Unexpected("Value after palette.setColor().");
}
bool loadColorScheme(
@ -215,9 +214,7 @@ bool loadColorScheme(
value = unsupported.value(value, value);
auto result = setColorSchemeValue(name, value, colorizer, out);
if (result == SetResult::Bad) {
return false;
} else if (result == SetResult::NotFound) {
if (result == SetResult::NotFound) {
unsupported.insert(name, value);
}
return true;
@ -302,6 +299,7 @@ bool LoadTheme(
return false;
}
if (!loadColorScheme(schemeContent, paletteColorizer, out)) {
DEBUG_LOG(("Theme: Could not loadColorScheme."));
return false;
}
if (!out) {
@ -311,6 +309,7 @@ bool LoadTheme(
auto backgroundTiled = false;
auto backgroundContent = QByteArray();
if (!loadBackground(file, &backgroundContent, &backgroundTiled)) {
DEBUG_LOG(("Theme: Could not loadBackground."));
return false;
}
@ -347,6 +346,7 @@ bool LoadTheme(
} else {
// Looks like it is not a .zip theme.
if (!loadColorScheme(editedPalette.value_or(content), paletteColorizer, out)) {
DEBUG_LOG(("Theme: Could not loadColorScheme from non-zip."));
return false;
}
if (!out) {
@ -422,6 +422,7 @@ bool InitializeFromSaved(Saved &&saved) {
const auto colorizer = ColorizerForTheme(saved.object.pathAbsolute);
if (!LoadTheme(saved.object.content, colorizer, editing, &saved.cache)) {
DEBUG_LOG(("Theme: Could not load from saved."));
return false;
}
if (editing) {
@ -1235,6 +1236,7 @@ bool Initialize(Saved &&saved) {
Background()->setThemeObject(saved.object);
return true;
}
DEBUG_LOG(("Theme: Could not initialize from saved."));
return false;
}
@ -1464,6 +1466,7 @@ bool ReadPaletteValues(const QByteArray &content, Fn<bool(QLatin1String name, QL
auto name = QLatin1String("");
auto value = QLatin1String("");
if (!readNameAndValue(from, end, &name, &value)) {
DEBUG_LOG(("Theme: Could not readNameAndValue."));
return false;
}
if (name.size() == 0) { // End of content reached.

2
cmake

@ -1 +1 @@
Subproject commit 2827dd851edfca602cbb98cae6b3dbd123c4aa39
Subproject commit c94b46f2fd99341a8217fe74b250bd0d0827b060