while writing documentation it occurred to me that the colors file is the wrong place for this: it must be possible to define a wallpaper and colors separately

also put the checking for wallpapers in the theme into theme initialization instead of doing it on every wallpaper lookup

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=825612
This commit is contained in:
Aaron J. Seigo 2008-06-28 20:20:22 +00:00
parent bb1aabc5bf
commit cd2feaca66
2 changed files with 51 additions and 40 deletions

View File

@ -61,7 +61,7 @@ ThemePackage::ThemePackage(QObject *parent)
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
i18n("Theme for the logout dialog"));
addDirectoryDefinition("wallpapers", "wallpapers/", "Wallpapers"); //FIXME 4.2: i18n("Wallpapers"));
addDirectoryDefinition("wallpapers", "wallpapers/", "Wallpapers"); //FIXME 4.2: i18n("Wallpaper Packages"));
addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
addFileDefinition("widgets/background", "widgets/background.svg",

View File

@ -40,8 +40,8 @@
namespace Plasma
{
#define DEFAULT_WALLPAPER_THEME "Blue_Curl";
#define DEFAULT_WALLPAPER_FORMAT ".jpg";
#define DEFAULT_WALLPAPER_THEME "Blue_Curl"
#define DEFAULT_WALLPAPER_SUFFIX ".jpg"
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
@ -50,10 +50,15 @@ class Theme::Private
public:
Private(Theme *theme)
: q(theme),
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
locolor(false),
compositingActive(KWindowSystem::compositingActive()),
isDefault(false),
useGlobal(true)
useGlobal(true),
hasWallpapers(false)
{
generalFont = QApplication::font();
}
@ -89,6 +94,11 @@ public:
KSharedConfigPtr colors;
KConfigGroup cfg;
QFont generalFont;
QString defaultWallpaperTheme;
QString defaultWallpaperSuffix;
int defaultWallpaperWidth;
int defaultWallpaperHeight;
#ifdef Q_WS_X11
KSelectionWatcher *compositeWatch;
#endif
@ -96,6 +106,7 @@ public:
bool compositingActive : 1;
bool isDefault : 1;
bool useGlobal : 1;
bool hasWallpapers : 1;
};
PackageStructure::Ptr Theme::Private::packageStructure(0);
@ -223,6 +234,24 @@ void Theme::setThemeName(const QString &themeName)
QString colorsFile = KStandardDirs::locate("data", "desktoptheme/" + theme + "/colors");
//kDebug() << "we're going for..." << colorsFile << "*******************";
// load the wallpaper settings, if any
KConfig metadata(KStandardDirs::locate("data", "desktoptheme/" + theme + "/metadata.desktop"));
KConfigGroup cg;
if (metadata.hasGroup("Wallpaper")) {
// we have a theme color config, so let's also check to see if
// there is a wallpaper defined in there.
cg = KConfigGroup(&metadata, "Wallpaper");
} else {
// since we didn't find an entry in the theme, let's look in the main
// theme config
cg = d->config();
}
d->defaultWallpaperTheme = cg.readEntry("defaultWallpaperTheme", DEFAULT_WALLPAPER_THEME);
d->defaultWallpaperSuffix = cg.readEntry("defaultFileSuffix", DEFAULT_WALLPAPER_SUFFIX);
d->defaultWallpaperWidth = cg.readEntry("defaultWidth", DEFAULT_WALLPAPER_WIDTH);
d->defaultWallpaperHeight = cg.readEntry("defaultHeight", DEFAULT_WALLPAPER_HEIGHT);
disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SIGNAL(themeChanged()));
if (colorsFile.isEmpty()) {
d->colors = 0;
@ -231,6 +260,8 @@ void Theme::setThemeName(const QString &themeName)
d->colors = KSharedConfig::openConfig(colorsFile);
}
d->hasWallpapers = !KStandardDirs::locate("data", "desktoptheme/" + theme + "/wallpapers").isEmpty();
if (d->isDefault) {
// we're the default theme, let's save our state
KConfigGroup &cg = d->config();
@ -267,46 +298,26 @@ QString Theme::imagePath(const QString& name) const
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;
QString image = d->defaultWallpaperTheme;
image.append("/contents/images/%1x%2").append(d->defaultWallpaperSuffix);
QString defaultImage = image.arg(d->defaultWallpaperWidth).arg(d->defaultWallpaperHeight);
if (size.isValid()) {
width = size.width();
height = size.height();
// try to customize the paper to the size requested
//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 1920x1200 wallpaper for a 640x480 request ;)
image = image.arg(size.width()).arg(size.height());
} else {
image = defaultImage;
}
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
//TODO: the theme's wallpaper overrides regularly installed wallpapers.
// should it be possible for user installed (e.g. locateLocal) wallpapers
// to override the theme?
if (d->hasWallpapers) {
// check in the theme first
fullPath = d->findInTheme("wallpaper/" + image, d->themeName);
if (fullPath.isEmpty()) {