From fa933b9a16f54604294e53f1fabb00e0c759e0f9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 10 Apr 2018 08:54:47 -0400 Subject: [PATCH] [plasmalnf] Search for theme screenshots - Search in branding dir, and ., for relative paths, - Absolute paths used as-is. - Document search as such. --- src/modules/plasmalnf/ThemeWidget.cpp | 31 ++++++++++++++++++++++++++- src/modules/plasmalnf/plasmalnf.conf | 4 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index 6a09dceb9..eb4e5c356 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -22,10 +22,39 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "Branding.h" +#include +#include #include #include #include +#include + +/** + * Massage the given @p path to the most-likely + * path that actually contains a screenshot. For + * empty image paths, returns the QRC path for an + * empty screenshot. Returns blank if the path + * doesn't exist anywhere in the search paths. + */ +static QString _munge_imagepath( const QString& path ) +{ + if ( path.isEmpty() ) + return ":/view-preview.png"; + + if ( path.startsWith( '/' ) ) + return path; + + if ( QFileInfo::exists( path ) ) + return path; + + QFileInfo fi( QDir( Calamares::Branding::instance()->componentDirectory() ), path ); + if ( fi.exists() ) + return fi.absoluteFilePath(); + + return QString(); +} ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) : QWidget( parent ) @@ -42,7 +71,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) qMax(12 * CalamaresUtils::defaultFontHeight(), 120), qMax(8 * CalamaresUtils::defaultFontHeight(), 80) }; - QPixmap image( info.imagePath.isEmpty() ? ":/view-preview.png" : info.imagePath ); + QPixmap image( _munge_imagepath( info.imagePath ) ); if ( image.isNull() ) { // Not found or not specified, so convert the name into some (horrible, likely) diff --git a/src/modules/plasmalnf/plasmalnf.conf b/src/modules/plasmalnf/plasmalnf.conf index 85df64f0a..a954c685a 100644 --- a/src/modules/plasmalnf/plasmalnf.conf +++ b/src/modules/plasmalnf/plasmalnf.conf @@ -32,6 +32,10 @@ lnftool: "/usr/bin/lookandfeeltool" # Themes with no image set at all get a "missing screenshot" image; if the # image file is not found, they get a color swatch based on the image name. # +# The image may be an absolute path. If it is a relative path, though, +# it is searched in the current directory and in the branding directory +# (i.e. relative to the directory where your branding.desc lives). +# # Valid forms of entries in the *themes* key: # - A single string (unquoted), which is the theme id # - A pair of *theme* and *image* keys, e.g.