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:
parent
bb1aabc5bf
commit
cd2feaca66
@ -61,7 +61,7 @@ ThemePackage::ThemePackage(QObject *parent)
|
|||||||
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
|
addFileDefinition("dialogs/shutdowndialog", "dialogs/shutdowndialog.svg",
|
||||||
i18n("Theme for the logout dialog"));
|
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"));
|
addDirectoryDefinition("widgets", "widgets/", i18n("Images for widgets"));
|
||||||
addFileDefinition("widgets/background", "widgets/background.svg",
|
addFileDefinition("widgets/background", "widgets/background.svg",
|
||||||
|
89
theme.cpp
89
theme.cpp
@ -40,8 +40,8 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
#define DEFAULT_WALLPAPER_THEME "Blue_Curl";
|
#define DEFAULT_WALLPAPER_THEME "Blue_Curl"
|
||||||
#define DEFAULT_WALLPAPER_FORMAT ".jpg";
|
#define DEFAULT_WALLPAPER_SUFFIX ".jpg"
|
||||||
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
||||||
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
||||||
|
|
||||||
@ -50,10 +50,15 @@ class Theme::Private
|
|||||||
public:
|
public:
|
||||||
Private(Theme *theme)
|
Private(Theme *theme)
|
||||||
: q(theme),
|
: q(theme),
|
||||||
|
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
|
||||||
|
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
|
||||||
|
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
|
||||||
|
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
|
||||||
locolor(false),
|
locolor(false),
|
||||||
compositingActive(KWindowSystem::compositingActive()),
|
compositingActive(KWindowSystem::compositingActive()),
|
||||||
isDefault(false),
|
isDefault(false),
|
||||||
useGlobal(true)
|
useGlobal(true),
|
||||||
|
hasWallpapers(false)
|
||||||
{
|
{
|
||||||
generalFont = QApplication::font();
|
generalFont = QApplication::font();
|
||||||
}
|
}
|
||||||
@ -89,6 +94,11 @@ public:
|
|||||||
KSharedConfigPtr colors;
|
KSharedConfigPtr colors;
|
||||||
KConfigGroup cfg;
|
KConfigGroup cfg;
|
||||||
QFont generalFont;
|
QFont generalFont;
|
||||||
|
QString defaultWallpaperTheme;
|
||||||
|
QString defaultWallpaperSuffix;
|
||||||
|
int defaultWallpaperWidth;
|
||||||
|
int defaultWallpaperHeight;
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
KSelectionWatcher *compositeWatch;
|
KSelectionWatcher *compositeWatch;
|
||||||
#endif
|
#endif
|
||||||
@ -96,6 +106,7 @@ public:
|
|||||||
bool compositingActive : 1;
|
bool compositingActive : 1;
|
||||||
bool isDefault : 1;
|
bool isDefault : 1;
|
||||||
bool useGlobal : 1;
|
bool useGlobal : 1;
|
||||||
|
bool hasWallpapers : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
PackageStructure::Ptr Theme::Private::packageStructure(0);
|
PackageStructure::Ptr Theme::Private::packageStructure(0);
|
||||||
@ -223,6 +234,24 @@ void Theme::setThemeName(const QString &themeName)
|
|||||||
QString colorsFile = KStandardDirs::locate("data", "desktoptheme/" + theme + "/colors");
|
QString colorsFile = KStandardDirs::locate("data", "desktoptheme/" + theme + "/colors");
|
||||||
//kDebug() << "we're going for..." << colorsFile << "*******************";
|
//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()));
|
disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SIGNAL(themeChanged()));
|
||||||
if (colorsFile.isEmpty()) {
|
if (colorsFile.isEmpty()) {
|
||||||
d->colors = 0;
|
d->colors = 0;
|
||||||
@ -231,6 +260,8 @@ void Theme::setThemeName(const QString &themeName)
|
|||||||
d->colors = KSharedConfig::openConfig(colorsFile);
|
d->colors = KSharedConfig::openConfig(colorsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->hasWallpapers = !KStandardDirs::locate("data", "desktoptheme/" + theme + "/wallpapers").isEmpty();
|
||||||
|
|
||||||
if (d->isDefault) {
|
if (d->isDefault) {
|
||||||
// we're the default theme, let's save our state
|
// we're the default theme, let's save our state
|
||||||
KConfigGroup &cg = d->config();
|
KConfigGroup &cg = d->config();
|
||||||
@ -267,46 +298,26 @@ QString Theme::imagePath(const QString& name) const
|
|||||||
QString Theme::wallpaperPath(const QSize &size) const
|
QString Theme::wallpaperPath(const QSize &size) const
|
||||||
{
|
{
|
||||||
QString fullPath;
|
QString fullPath;
|
||||||
QString image = DEFAULT_WALLPAPER_THEME;
|
QString image = d->defaultWallpaperTheme;
|
||||||
QString format = DEFAULT_WALLPAPER_FORMAT;
|
|
||||||
int width = DEFAULT_WALLPAPER_WIDTH;
|
image.append("/contents/images/%1x%2").append(d->defaultWallpaperSuffix);
|
||||||
int height = DEFAULT_WALLPAPER_HEIGHT;
|
QString defaultImage = image.arg(d->defaultWallpaperWidth).arg(d->defaultWallpaperHeight);
|
||||||
|
|
||||||
if (size.isValid()) {
|
if (size.isValid()) {
|
||||||
width = size.width();
|
// try to customize the paper to the size requested
|
||||||
height = size.height();
|
//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;
|
//TODO: the theme's wallpaper overrides regularly installed wallpapers.
|
||||||
if (d->colors) {
|
// should it be possible for user installed (e.g. locateLocal) wallpapers
|
||||||
// we have a theme color config, so let's also check to see if
|
// to override the theme?
|
||||||
// there is a wallpaper defined in there.
|
if (d->hasWallpapers) {
|
||||||
KConfigGroup cg(d->colors, "Wallpaper");
|
// check in the theme first
|
||||||
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);
|
fullPath = d->findInTheme("wallpaper/" + image, d->themeName);
|
||||||
|
|
||||||
if (fullPath.isEmpty()) {
|
if (fullPath.isEmpty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user