Changed a number of theme properties to be read by reference instead of via copy.

This commit is contained in:
Leon Styhre 2022-11-03 16:03:21 +01:00
parent cfd2f7e4e5
commit 246fd307b6
9 changed files with 53 additions and 53 deletions

View file

@ -291,7 +291,7 @@ void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("slots")) {
// Replace possible whitespace separators with commas.
std::string slotsTag = Utils::String::toLower(elem->get<std::string>("slots"));
std::string slotsTag {Utils::String::toLower(elem->get<std::string>("slots"))};
for (auto& character : slotsTag) {
if (std::isspace(character))
character = ',';
@ -312,7 +312,7 @@ void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
// The "badge_" string is required as ThemeData adds this as a prefix to avoid
// name collisions when using XML attributes.
if (properties & PATH && elem->has("badge_" + slot)) {
const std::string path {elem->get<std::string>("badge_" + slot)};
const std::string& path {elem->get<std::string>("badge_" + slot)};
if (Utils::FileSystem::exists(path) && !Utils::FileSystem::isDirectory(path)) {
mBadgeIcons[slot] = path;
}
@ -385,7 +385,7 @@ void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
for (auto& gameController : sGameControllers) {
if (properties & PATH && elem->has("controller_" + gameController.shortName)) {
const std::string path {
const std::string& path {
elem->get<std::string>("controller_" + gameController.shortName)};
if (Utils::FileSystem::exists(path) && !Utils::FileSystem::isDirectory(path)) {
gameController.fileName = path;

View file

@ -130,51 +130,51 @@ void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (properties & ALIGNMENT && elem->has("horizontalAlignment")) {
std::string str {elem->get<std::string>("horizontalAlignment")};
if (str == "left")
const std::string& horizontalAlignment {elem->get<std::string>("horizontalAlignment")};
if (horizontalAlignment == "left")
setHorizontalAlignment(ALIGN_LEFT);
else if (str == "center")
else if (horizontalAlignment == "center")
setHorizontalAlignment(ALIGN_CENTER);
else if (str == "right")
else if (horizontalAlignment == "right")
setHorizontalAlignment(ALIGN_RIGHT);
else
LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property "
"<horizontalAlignment> defined as \""
<< str << "\"";
<< horizontalAlignment << "\"";
}
if (properties & ALIGNMENT && elem->has("verticalAlignment")) {
std::string str {elem->get<std::string>("verticalAlignment")};
if (str == "top")
const std::string& verticalAlignment {elem->get<std::string>("verticalAlignment")};
if (verticalAlignment == "top")
setVerticalAlignment(ALIGN_TOP);
else if (str == "center")
else if (verticalAlignment == "center")
setVerticalAlignment(ALIGN_CENTER);
else if (str == "bottom")
else if (verticalAlignment == "bottom")
setVerticalAlignment(ALIGN_BOTTOM);
else
LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property "
"<verticalAlignment> defined as \""
<< str << "\"";
<< verticalAlignment << "\"";
}
// Legacy themes only.
if (properties & ALIGNMENT && elem->has("alignment")) {
std::string str {elem->get<std::string>("alignment")};
if (str == "left")
const std::string& alignment {elem->get<std::string>("alignment")};
if (alignment == "left")
setHorizontalAlignment(ALIGN_LEFT);
else if (str == "center")
else if (alignment == "center")
setHorizontalAlignment(ALIGN_CENTER);
else if (str == "right")
else if (alignment == "right")
setHorizontalAlignment(ALIGN_RIGHT);
else
LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property "
"<alignment> defined as \""
<< str << "\"";
<< alignment << "\"";
}
if (properties & METADATA && elem->has("metadata")) {
mThemeMetadata = "";
const std::string metadata {elem->get<std::string>("metadata")};
const std::string& metadata {elem->get<std::string>("metadata")};
if (metadata == "releasedate" || metadata == "lastplayed") {
mThemeMetadata = metadata;
}
@ -192,7 +192,7 @@ void DateTimeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
setDisplayRelative(elem->get<bool>("displayRelative"));
if (properties & LETTER_CASE && elem->has("letterCase")) {
std::string letterCase {elem->get<std::string>("letterCase")};
const std::string& letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") {
setUppercase(true);
}

View file

@ -286,7 +286,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mKeepAspectRatio = elem->get<bool>("keepAspectRatio");
if (elem->has("direction")) {
std::string direction = elem->get<std::string>("direction");
const std::string& direction {elem->get<std::string>("direction")};
if (direction == "normal") {
mStartDirection = "normal";
mAlternate = false;
@ -313,7 +313,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("interpolation")) {
const std::string interpolation {elem->get<std::string>("interpolation")};
const std::string& interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") {
mTexture->setLinearMagnify(true);
}
@ -332,7 +332,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
GuiComponent::applyTheme(theme, view, element, properties);
if (elem->has("path")) {
std::string path {elem->get<std::string>("path")};
const std::string& path {elem->get<std::string>("path")};
if (path != "") {
setAnimation(path);
}

View file

@ -123,7 +123,7 @@ public:
mSelectorName = element.substr(13, std::string::npos);
if (elem->has("selection")) {
const std::string selection {elem->get<std::string>("selection")};
const std::string& selection {elem->get<std::string>("selection")};
if (selection == "random") {
mGameSelection = GameSelection::RANDOM;
}
@ -140,8 +140,8 @@ public:
else {
mGameSelection = GameSelection::RANDOM;
LOG(LogWarning) << "GameSelectorComponent: Invalid theme configuration, property "
"<selection> defined as \""
<< selection << "\"";
"\"selection\" for element \""
<< element.substr(13) << "\" defined as \"" << selection << "\"";
}
}

View file

@ -433,7 +433,7 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("interpolation")) {
const std::string interpolation {elem->get<std::string>("interpolation")};
const std::string& interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") {
mLinearInterpolation = true;
}
@ -454,7 +454,7 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
bool tile {elem->has("tile") && elem->get<bool>("tile")};
if (properties & PATH && elem->has("path")) {
const std::string path {elem->get<std::string>("path")};
const std::string& path {elem->get<std::string>("path")};
if (tile && elem->has("tileSize")) {
glm::vec2 tileSize {elem->get<glm::vec2>("tileSize")};
@ -479,7 +479,7 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
bool updateAlignment {false};
if (elem->has("tileHorizontalAlignment")) {
const std::string alignment {elem->get<std::string>("tileHorizontalAlignment")};
const std::string& alignment {elem->get<std::string>("tileHorizontalAlignment")};
updateAlignment = true;
if (alignment == "left") {
mTileHorizontalAlignment = ALIGN_LEFT;
@ -496,7 +496,7 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("tileVerticalAlignment")) {
const std::string alignment {elem->get<std::string>("tileVerticalAlignment")};
const std::string& alignment {elem->get<std::string>("tileVerticalAlignment")};
updateAlignment = true;
if (alignment == "top") {
mTileVerticalAlignment = ALIGN_TOP;

View file

@ -256,7 +256,7 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mKeepAspectRatio = elem->get<bool>("keepAspectRatio");
if (elem->has("direction")) {
std::string direction = elem->get<std::string>("direction");
const std::string& direction {elem->get<std::string>("direction")};
if (direction == "normal") {
mStartDirection = "normal";
mAlternate = false;

View file

@ -180,7 +180,7 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
// Read the image file in order to retrieve the image dimensions needed to calculate
// the aspect ratio constant.
if (properties & PATH && elem->has("filledPath")) {
std::string path {std::string(elem->get<std::string>("filledPath"))};
const std::string& path {std::string(elem->get<std::string>("filledPath"))};
if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) {
auto tempImage =
TextureResource::get(path, false, false, false, false, false, 0, 0, 0.0f, 0.0f);
@ -212,7 +212,7 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
bool linearInterpolation {false};
if (elem->has("interpolation")) {
const std::string interpolation {elem->get<std::string>("interpolation")};
const std::string& interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") {
linearInterpolation = true;
}

View file

@ -378,49 +378,49 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (properties & ALIGNMENT && elem->has("horizontalAlignment")) {
std::string str {elem->get<std::string>("horizontalAlignment")};
if (str == "left")
const std::string& horizontalAlignment {elem->get<std::string>("horizontalAlignment")};
if (horizontalAlignment == "left")
setHorizontalAlignment(ALIGN_LEFT);
else if (str == "center")
else if (horizontalAlignment == "center")
setHorizontalAlignment(ALIGN_CENTER);
else if (str == "right")
else if (horizontalAlignment == "right")
setHorizontalAlignment(ALIGN_RIGHT);
else
LOG(LogWarning) << componentName
<< ": Invalid theme configuration, property "
"<horizontalAlignment> defined as \""
<< str << "\"";
<< horizontalAlignment << "\"";
}
if (properties & ALIGNMENT && elem->has("verticalAlignment")) {
std::string str {elem->get<std::string>("verticalAlignment")};
if (str == "top")
const std::string& verticalAlignment {elem->get<std::string>("verticalAlignment")};
if (verticalAlignment == "top")
setVerticalAlignment(ALIGN_TOP);
else if (str == "center")
else if (verticalAlignment == "center")
setVerticalAlignment(ALIGN_CENTER);
else if (str == "bottom")
else if (verticalAlignment == "bottom")
setVerticalAlignment(ALIGN_BOTTOM);
else
LOG(LogWarning) << componentName
<< ": Invalid theme configuration, property "
"<verticalAlignment> defined as \""
<< str << "\"";
<< verticalAlignment << "\"";
}
// Legacy themes only.
if (properties & ALIGNMENT && elem->has("alignment")) {
std::string str {elem->get<std::string>("alignment")};
if (str == "left")
const std::string& alignment {elem->get<std::string>("alignment")};
if (alignment == "left")
setHorizontalAlignment(ALIGN_LEFT);
else if (str == "center")
else if (alignment == "center")
setHorizontalAlignment(ALIGN_CENTER);
else if (str == "right")
else if (alignment == "right")
setHorizontalAlignment(ALIGN_RIGHT);
else
LOG(LogWarning) << componentName
<< ": Invalid theme configuration, property "
"<alignment> defined as \""
<< str << "\"";
<< alignment << "\"";
}
if (properties & TEXT && elem->has("text"))
@ -428,7 +428,7 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & METADATA && elem->has("systemdata")) {
mThemeSystemdata = "";
const std::string systemdata {elem->get<std::string>("systemdata")};
const std::string& systemdata {elem->get<std::string>("systemdata")};
for (auto& type : supportedSystemdataTypes) {
if (type == systemdata) {
mThemeSystemdata = type;
@ -444,7 +444,7 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & METADATA && elem->has("metadata")) {
mThemeMetadata = "";
const std::string metadata {elem->get<std::string>("metadata")};
const std::string& metadata {elem->get<std::string>("metadata")};
for (auto& type : supportedMetadataTypes) {
if (type == metadata) {
@ -460,7 +460,7 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (properties & LETTER_CASE && elem->has("letterCase")) {
std::string letterCase {elem->get<std::string>("letterCase")};
const std::string& letterCase {elem->get<std::string>("letterCase")};
if (letterCase == "uppercase") {
setUppercase(true);
}

View file

@ -155,7 +155,7 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mPlayAudio = elem->get<bool>("audio");
if (elem->has("interpolation")) {
const std::string interpolation {elem->get<std::string>("interpolation")};
const std::string& interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") {
mStaticImage.setLinearInterpolation(true);
}
@ -189,7 +189,7 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
if (elem->has("path")) {
const std::string staticPath {elem->get<std::string>("path")};
const std::string& staticPath {elem->get<std::string>("path")};
if (ResourceManager::getInstance().fileExists(staticPath)) {
mConfig.staticVideoPath = staticPath;
}