Plasma::Theme::wallpaperPath(const QSize&)
a nice improvement that fixes a small handful of packaging bugs and nuisances. it allows us to do away with harcoding the wallpaper in multiple places (previously 3 places) in application code. as an extra bonus is also allows: * the theme to define the default wallpaper * the theme to ship with a default wallpaper (perhaps later on we can load wallpapers shipped with a theme in the config dialog?) * the default wallpaper to defined in the plasmarc file (so downstream doesn't have to hack the code to change it) CCMAIL:panel-devel@kde.org CCMAIL:kde-artists@kde.org svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=825592
This commit is contained in:
parent
77214a87b3
commit
f4b17accac
87
theme.cpp
87
theme.cpp
@ -40,6 +40,11 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#define DEFAULT_WALLPAPER_THEME "Blue_Curl";
|
||||||
|
#define DEFAULT_WALLPAPER_FORMAT ".jpg";
|
||||||
|
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
||||||
|
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
||||||
|
|
||||||
class Theme::Private
|
class Theme::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -102,16 +107,16 @@ QString Theme::Private::findInTheme(const QString &image, const QString &theme)
|
|||||||
QString search;
|
QString search;
|
||||||
|
|
||||||
if (locolor) {
|
if (locolor) {
|
||||||
search = "desktoptheme/" + theme + "/locolor/" + image + ".svg";
|
search = "desktoptheme/" + theme + "/locolor/" + image;
|
||||||
search = KStandardDirs::locate("data", search);
|
search = KStandardDirs::locate("data", search);
|
||||||
} else if (!compositingActive) {
|
} else if (!compositingActive) {
|
||||||
search = "desktoptheme/" + theme + "/opaque/" + image + ".svg";
|
search = "desktoptheme/" + theme + "/opaque/" + image;
|
||||||
search = KStandardDirs::locate("data", search);
|
search = KStandardDirs::locate("data", search);
|
||||||
}
|
}
|
||||||
|
|
||||||
//not found or compositing enabled
|
//not found or compositing enabled
|
||||||
if (search.isEmpty()) {
|
if (search.isEmpty()) {
|
||||||
search = "desktoptheme/" + theme + '/' + image + ".svg";
|
search = "desktoptheme/" + theme + '/' + image;
|
||||||
search = KStandardDirs::locate("data", search);
|
search = KStandardDirs::locate("data", search);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,10 +251,10 @@ QString Theme::themeName() const
|
|||||||
|
|
||||||
QString Theme::imagePath(const QString& name) const
|
QString Theme::imagePath(const QString& name) const
|
||||||
{
|
{
|
||||||
QString path = d->findInTheme(name, d->themeName);
|
QString path = d->findInTheme(name + ".svg", d->themeName);
|
||||||
|
|
||||||
if (path.isEmpty() && d->themeName != Private::defaultTheme) {
|
if (path.isEmpty() && d->themeName != Private::defaultTheme) {
|
||||||
path = d->findInTheme(name, Private::defaultTheme);
|
path = d->findInTheme(name + ".svg", Private::defaultTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
@ -259,9 +264,79 @@ QString Theme::imagePath(const QString& name) const
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Theme::wallpaperPath(const QSize &size) const
|
||||||
|
{
|
||||||
|
QString fullPath;
|
||||||
|
QString image = DEFAULT_WALLPAPER_THEME;
|
||||||
|
QString format = DEFAULT_WALLPAPER_FORMAT;
|
||||||
|
int width = DEFAULT_WALLPAPER_WIDTH;
|
||||||
|
int height = DEFAULT_WALLPAPER_HEIGHT;
|
||||||
|
|
||||||
|
if (size.isValid()) {
|
||||||
|
width = size.width();
|
||||||
|
height = size.height();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkInTheme = false;
|
||||||
|
if (d->colors) {
|
||||||
|
// we have a theme color config, so let's also check to see if
|
||||||
|
// there is a wallpaper defined in there.
|
||||||
|
KConfigGroup cg(d->colors, "Wallpaper");
|
||||||
|
if (cg.hasKey("wallpaper")) {
|
||||||
|
checkInTheme = true;
|
||||||
|
image = cg.readEntry("defaultTheme", image);
|
||||||
|
format = cg.readEntry("defaultFileSuffix", format);
|
||||||
|
width = cg.readEntry("defaultWidth", width);
|
||||||
|
height = cg.readEntry("defaultHeight", height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkInTheme) {
|
||||||
|
// since we didn't find an entry in the theme, let's look in the main
|
||||||
|
// theme config
|
||||||
|
KConfigGroup &cg = d->config();
|
||||||
|
image = cg.readEntry("defaultTheme", image);
|
||||||
|
}
|
||||||
|
|
||||||
|
image.append("/contents/images/%1x%2").append(format);
|
||||||
|
//TODO: this should do better than just fallback to the default size.
|
||||||
|
// a "best fit" matching would be far better, so we don't end
|
||||||
|
// up returning a 1900x1200 wallpaper for a 640x480 request ;)
|
||||||
|
QString defaultImage = image.arg(DEFAULT_WALLPAPER_WIDTH).arg(DEFAULT_WALLPAPER_HEIGHT);
|
||||||
|
image = image.arg(width).arg(height);
|
||||||
|
|
||||||
|
if (checkInTheme) {
|
||||||
|
// check in the theme, since it was defined in the colors config
|
||||||
|
fullPath = d->findInTheme("wallpaper/" + image, d->themeName);
|
||||||
|
|
||||||
|
if (fullPath.isEmpty()) {
|
||||||
|
fullPath = d->findInTheme("wallpaper/" + defaultImage, d->themeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullPath.isEmpty()) {
|
||||||
|
// we failed to find it in the theme, so look in the standard directories
|
||||||
|
kDebug() << "looking for" << image;
|
||||||
|
fullPath = KStandardDirs::locate("wallpaper", image);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullPath.isEmpty()) {
|
||||||
|
// we still failed to find it in the theme, so look for the default in
|
||||||
|
// the standard directories
|
||||||
|
kDebug() << "looking for" << defaultImage;
|
||||||
|
fullPath = KStandardDirs::locate("wallpaper", defaultImage);
|
||||||
|
|
||||||
|
if (fullPath.isEmpty()) {
|
||||||
|
kDebug() << "exhausted every effort to find a wallpaper.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
bool Theme::currentThemeHasImage(const QString& name) const
|
bool Theme::currentThemeHasImage(const QString& name) const
|
||||||
{
|
{
|
||||||
return (!d->findInTheme(name, d->themeName).isEmpty());
|
return (!d->findInTheme(name + ".svg", d->themeName).isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
KSharedConfigPtr Theme::colorScheme() const
|
KSharedConfigPtr Theme::colorScheme() const
|
||||||
|
9
theme.h
9
theme.h
@ -100,6 +100,15 @@ class PLASMA_EXPORT Theme : public QObject
|
|||||||
*/
|
*/
|
||||||
Q_INVOKABLE QString imagePath(const QString& name) const;
|
Q_INVOKABLE QString imagePath(const QString& name) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retreives the default wallpaper associated with this theme.
|
||||||
|
*
|
||||||
|
* @arg size the target height and width of the wallpaper; if an invalid size
|
||||||
|
* is passed in, then a default size will be provided instead.
|
||||||
|
* @return the full path to the wallpaper image
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QString wallpaperPath(const QSize &size = QSize()) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this theme has an image named in a certain way
|
* Checks if this theme has an image named in a certain way
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user