2006-12-17 00:04:44 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
2006-12-17 00:04:44 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2006-12-17 00:04:44 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-21 16:28:03 +02:00
|
|
|
#include "theme.h"
|
|
|
|
|
2007-12-19 20:56:39 +01:00
|
|
|
#include <QApplication>
|
2007-11-04 07:57:42 +01:00
|
|
|
#include <QFile>
|
2008-03-05 20:06:03 +01:00
|
|
|
#ifdef Q_WS_X11
|
2008-02-07 11:54:38 +01:00
|
|
|
#include <QX11Info>
|
2008-03-05 20:06:03 +01:00
|
|
|
#endif
|
2007-11-04 07:57:42 +01:00
|
|
|
|
2008-01-10 21:53:13 +01:00
|
|
|
#include <KWindowSystem>
|
2007-11-27 22:56:47 +01:00
|
|
|
#include <KColorScheme>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KDebug>
|
2008-04-24 00:24:07 +02:00
|
|
|
#include <KGlobal>
|
2008-02-07 11:54:38 +01:00
|
|
|
#include <KSelectionWatcher>
|
2006-12-17 00:04:44 +01:00
|
|
|
#include <KSharedConfig>
|
|
|
|
#include <KStandardDirs>
|
2008-02-26 06:08:08 +01:00
|
|
|
#include <KGlobalSettings>
|
2006-12-17 00:04:44 +01:00
|
|
|
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "private/packages_p.h"
|
2008-02-15 11:35:00 +01:00
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-06-28 22:20:22 +02:00
|
|
|
#define DEFAULT_WALLPAPER_THEME "Blue_Curl"
|
|
|
|
#define DEFAULT_WALLPAPER_SUFFIX ".jpg"
|
2008-06-28 20:57:12 +02:00
|
|
|
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
|
|
|
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class ThemePrivate
|
2006-12-17 00:04:44 +01:00
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
public:
|
2008-07-01 20:56:43 +02:00
|
|
|
ThemePrivate(Theme *theme)
|
2008-04-24 00:55:30 +02:00
|
|
|
: q(theme),
|
2008-10-03 19:44:04 +02:00
|
|
|
colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)),
|
2008-10-06 06:10:34 +02:00
|
|
|
buttonColorScheme(QPalette::Active, KColorScheme::Button, KSharedConfigPtr(0)),
|
2008-06-28 22:20:22 +02:00
|
|
|
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
|
|
|
|
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
|
|
|
|
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
|
|
|
|
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
|
2008-04-24 00:55:30 +02:00
|
|
|
locolor(false),
|
|
|
|
compositingActive(KWindowSystem::compositingActive()),
|
2008-05-12 06:53:13 +02:00
|
|
|
isDefault(false),
|
2008-06-28 22:20:22 +02:00
|
|
|
useGlobal(true),
|
|
|
|
hasWallpapers(false)
|
2008-04-24 00:55:30 +02:00
|
|
|
{
|
|
|
|
generalFont = QApplication::font();
|
|
|
|
}
|
2007-07-17 22:51:12 +02:00
|
|
|
|
2008-04-24 00:24:07 +02:00
|
|
|
KConfigGroup& config()
|
|
|
|
{
|
|
|
|
if (!cfg.isValid()) {
|
|
|
|
QString groupName = "Theme";
|
2007-11-04 04:04:55 +01:00
|
|
|
|
2008-05-12 06:53:13 +02:00
|
|
|
if (!useGlobal) {
|
|
|
|
QString app = KGlobal::mainComponent().componentName();
|
|
|
|
|
|
|
|
if (!app.isEmpty() && app != "plasma") {
|
|
|
|
kDebug() << "using theme for app" << app;
|
|
|
|
groupName.append("-").append(app);
|
|
|
|
}
|
2008-04-24 00:24:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg = KConfigGroup(KSharedConfig::openConfig("plasmarc"), groupName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg;
|
|
|
|
}
|
2007-11-04 04:04:55 +01:00
|
|
|
|
2008-02-09 05:54:43 +01:00
|
|
|
QString findInTheme(const QString &image, const QString &theme) const;
|
2008-04-24 00:55:30 +02:00
|
|
|
void compositingChanged();
|
2008-02-09 05:54:43 +01:00
|
|
|
|
2008-04-24 00:55:30 +02:00
|
|
|
static const char *defaultTheme;
|
2008-02-26 05:08:51 +01:00
|
|
|
static PackageStructure::Ptr packageStructure;
|
2008-04-24 00:55:30 +02:00
|
|
|
|
|
|
|
Theme *q;
|
2008-04-23 06:50:44 +02:00
|
|
|
QString themeName;
|
|
|
|
KSharedConfigPtr colors;
|
2008-10-03 19:44:04 +02:00
|
|
|
KColorScheme colorScheme;
|
2008-10-06 06:10:34 +02:00
|
|
|
KColorScheme buttonColorScheme;
|
2008-04-24 00:24:07 +02:00
|
|
|
KConfigGroup cfg;
|
2008-04-23 06:50:44 +02:00
|
|
|
QFont generalFont;
|
2008-06-28 22:20:22 +02:00
|
|
|
QString defaultWallpaperTheme;
|
|
|
|
QString defaultWallpaperSuffix;
|
|
|
|
int defaultWallpaperWidth;
|
|
|
|
int defaultWallpaperHeight;
|
|
|
|
|
2008-02-07 11:54:38 +01:00
|
|
|
#ifdef Q_WS_X11
|
2008-04-23 06:50:44 +02:00
|
|
|
KSelectionWatcher *compositeWatch;
|
2008-02-07 11:54:38 +01:00
|
|
|
#endif
|
2008-05-12 06:53:13 +02:00
|
|
|
bool locolor : 1;
|
|
|
|
bool compositingActive : 1;
|
|
|
|
bool isDefault : 1;
|
|
|
|
bool useGlobal : 1;
|
2008-06-28 22:20:22 +02:00
|
|
|
bool hasWallpapers : 1;
|
2006-12-17 00:04:44 +01:00
|
|
|
};
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
PackageStructure::Ptr ThemePrivate::packageStructure(0);
|
|
|
|
const char *ThemePrivate::defaultTheme = "default";
|
2008-02-09 05:54:43 +01:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
QString ThemePrivate::findInTheme(const QString &image, const QString &theme) const
|
2008-04-24 00:55:30 +02:00
|
|
|
{
|
|
|
|
//TODO: this should be using Package
|
|
|
|
QString search;
|
|
|
|
|
|
|
|
if (locolor) {
|
2008-06-28 20:57:12 +02:00
|
|
|
search = "desktoptheme/" + theme + "/locolor/" + image;
|
2008-04-24 00:55:30 +02:00
|
|
|
search = KStandardDirs::locate("data", search);
|
|
|
|
} else if (!compositingActive) {
|
2008-06-28 20:57:12 +02:00
|
|
|
search = "desktoptheme/" + theme + "/opaque/" + image;
|
2008-04-24 00:55:30 +02:00
|
|
|
search = KStandardDirs::locate("data", search);
|
|
|
|
}
|
|
|
|
|
|
|
|
//not found or compositing enabled
|
|
|
|
if (search.isEmpty()) {
|
2008-06-28 20:57:12 +02:00
|
|
|
search = "desktoptheme/" + theme + '/' + image;
|
2008-04-24 00:55:30 +02:00
|
|
|
search = KStandardDirs::locate("data", search);
|
|
|
|
}
|
|
|
|
|
|
|
|
return search;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ThemePrivate::compositingChanged()
|
2008-04-24 00:55:30 +02:00
|
|
|
{
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
bool nowCompositingActive = compositeWatch->owner() != None;
|
|
|
|
|
|
|
|
if (compositingActive != nowCompositingActive) {
|
|
|
|
compositingActive = nowCompositingActive;
|
|
|
|
emit q->themeChanged();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
class ThemeSingleton
|
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
public:
|
2008-04-23 06:50:44 +02:00
|
|
|
ThemeSingleton()
|
|
|
|
{
|
|
|
|
self.d->isDefault = true;
|
|
|
|
}
|
|
|
|
|
2007-07-17 22:51:12 +02:00
|
|
|
Theme self;
|
2007-03-08 00:27:37 +01:00
|
|
|
};
|
|
|
|
|
2007-07-21 17:58:44 +02:00
|
|
|
K_GLOBAL_STATIC( ThemeSingleton, privateThemeSelf )
|
2007-03-08 00:27:37 +01:00
|
|
|
|
2008-04-22 23:10:14 +02:00
|
|
|
Theme* Theme::defaultTheme()
|
2007-03-08 00:27:37 +01:00
|
|
|
{
|
2007-07-21 17:58:44 +02:00
|
|
|
return &privateThemeSelf->self;
|
2007-03-08 00:27:37 +01:00
|
|
|
}
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
Theme::Theme(QObject* parent)
|
|
|
|
: QObject(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new ThemePrivate(this))
|
2006-12-17 00:04:44 +01:00
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
settingsChanged();
|
2008-02-07 11:54:38 +01:00
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
2008-02-09 05:54:43 +01:00
|
|
|
Display *dpy = QX11Info::display();
|
|
|
|
int screen = DefaultScreen(dpy);
|
|
|
|
d->locolor = DefaultDepth(dpy, screen) < 16;
|
|
|
|
|
|
|
|
if (!d->locolor) {
|
|
|
|
char net_wm_cm_name[100];
|
|
|
|
sprintf(net_wm_cm_name, "_NET_WM_CM_S%d", screen);
|
|
|
|
d->compositeWatch = new KSelectionWatcher(net_wm_cm_name, -1, this);
|
|
|
|
connect(d->compositeWatch, SIGNAL(newOwner(Window)), this, SLOT(compositingChanged()));
|
|
|
|
connect(d->compositeWatch, SIGNAL(lostOwner()), this, SLOT(compositingChanged()));
|
|
|
|
}
|
2008-02-07 11:54:38 +01:00
|
|
|
#endif
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Theme::~Theme()
|
|
|
|
{
|
2007-06-07 22:57:18 +02:00
|
|
|
delete d;
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
2008-02-26 05:08:51 +01:00
|
|
|
PackageStructure::Ptr Theme::packageStructure()
|
2008-02-15 11:35:00 +01:00
|
|
|
{
|
2008-07-01 20:56:43 +02:00
|
|
|
if (!ThemePrivate::packageStructure) {
|
|
|
|
ThemePrivate::packageStructure = new ThemePackage();
|
2008-02-26 05:08:51 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
return ThemePrivate::packageStructure;
|
2008-02-15 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
2007-07-17 22:51:12 +02:00
|
|
|
void Theme::settingsChanged()
|
|
|
|
{
|
2008-07-01 20:56:43 +02:00
|
|
|
setThemeName(d->config().readEntry("name", ThemePrivate::defaultTheme));
|
2007-11-04 04:04:55 +01:00
|
|
|
}
|
2007-07-17 22:51:12 +02:00
|
|
|
|
2007-11-04 04:04:55 +01:00
|
|
|
void Theme::setThemeName(const QString &themeName)
|
|
|
|
{
|
2008-01-25 07:10:44 +01:00
|
|
|
QString theme = themeName;
|
|
|
|
if (theme.isEmpty() || theme == d->themeName) {
|
2007-11-04 07:57:42 +01:00
|
|
|
// let's try and get the default theme at least
|
|
|
|
if (d->themeName.isEmpty()) {
|
2008-07-01 20:56:43 +02:00
|
|
|
theme = ThemePrivate::defaultTheme;
|
2008-01-25 07:10:44 +01:00
|
|
|
} else {
|
|
|
|
return;
|
2007-11-04 07:57:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: should we care about names with relative paths in them?
|
2008-05-09 07:32:15 +02:00
|
|
|
QString themePath = KStandardDirs::locate("data", "desktoptheme/" + theme + '/');
|
2008-01-25 07:10:44 +01:00
|
|
|
if (themePath.isEmpty() && d->themeName.isEmpty()) {
|
|
|
|
themePath = KStandardDirs::locate("data", "desktoptheme/default/");
|
|
|
|
|
|
|
|
if (themePath.isEmpty()) {
|
|
|
|
return;
|
2007-11-04 07:57:42 +01:00
|
|
|
}
|
2008-01-25 07:10:44 +01:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
theme = ThemePrivate::defaultTheme;
|
2007-11-04 07:57:42 +01:00
|
|
|
}
|
|
|
|
|
2008-01-25 07:10:44 +01:00
|
|
|
d->themeName = theme;
|
2007-11-04 07:57:42 +01:00
|
|
|
|
|
|
|
// load the color scheme config
|
2008-01-25 07:10:44 +01:00
|
|
|
QString colorsFile = KStandardDirs::locate("data", "desktoptheme/" + theme + "/colors");
|
|
|
|
//kDebug() << "we're going for..." << colorsFile << "*******************";
|
|
|
|
|
2008-06-28 22:20:22 +02:00
|
|
|
// 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);
|
|
|
|
|
2008-04-24 00:55:30 +02:00
|
|
|
disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SIGNAL(themeChanged()));
|
2008-01-25 07:10:44 +01:00
|
|
|
if (colorsFile.isEmpty()) {
|
2007-11-04 07:57:42 +01:00
|
|
|
d->colors = 0;
|
2008-04-24 00:55:30 +02:00
|
|
|
connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SIGNAL(themeChanged()));
|
2008-01-25 07:10:44 +01:00
|
|
|
} else {
|
|
|
|
d->colors = KSharedConfig::openConfig(colorsFile);
|
2007-07-17 22:51:12 +02:00
|
|
|
}
|
2007-11-04 07:57:42 +01:00
|
|
|
|
2008-10-03 19:44:04 +02:00
|
|
|
d->colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, d->colors);
|
2008-10-06 06:10:34 +02:00
|
|
|
d->buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, d->colors);
|
2008-06-28 22:20:22 +02:00
|
|
|
d->hasWallpapers = !KStandardDirs::locate("data", "desktoptheme/" + theme + "/wallpapers").isEmpty();
|
|
|
|
|
2008-04-23 06:50:44 +02:00
|
|
|
if (d->isDefault) {
|
|
|
|
// we're the default theme, let's save our state
|
2008-04-24 00:24:07 +02:00
|
|
|
KConfigGroup &cg = d->config();
|
2008-07-01 20:56:43 +02:00
|
|
|
if (ThemePrivate::defaultTheme == d->themeName) {
|
2008-04-22 22:27:56 +02:00
|
|
|
cg.deleteEntry("name");
|
|
|
|
} else {
|
|
|
|
cg.writeEntry("name", d->themeName);
|
|
|
|
}
|
2008-02-15 11:47:56 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 10:35:35 +02:00
|
|
|
emit themeChanged();
|
2007-07-17 22:51:12 +02:00
|
|
|
}
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
QString Theme::themeName() const
|
|
|
|
{
|
|
|
|
return d->themeName;
|
|
|
|
}
|
|
|
|
|
2008-04-16 17:53:16 +02:00
|
|
|
QString Theme::imagePath(const QString& name) const
|
2008-02-09 05:54:43 +01:00
|
|
|
{
|
2008-07-20 11:23:59 +02:00
|
|
|
// look for a compressed svg file in the theme
|
2008-08-17 22:52:37 +02:00
|
|
|
if (name.contains("../")) {
|
|
|
|
// we don't support relative paths
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2008-07-20 11:23:59 +02:00
|
|
|
QString path = d->findInTheme(name + ".svgz", d->themeName);
|
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
// try for an uncompressed svg file
|
|
|
|
path = d->findInTheme(name + ".svg", d->themeName);
|
|
|
|
|
|
|
|
if (path.isEmpty() && d->themeName != ThemePrivate::defaultTheme) {
|
|
|
|
// try a compressed svg file in the default theme
|
|
|
|
path = d->findInTheme(name + ".svgz", ThemePrivate::defaultTheme);
|
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
// try an uncompressed svg file in the default theme
|
2008-07-27 17:50:00 +02:00
|
|
|
path = d->findInTheme(name + ".svg", ThemePrivate::defaultTheme);
|
2008-07-20 11:23:59 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-09 05:54:43 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
kDebug() << "Theme says: bad image path " << name;
|
2007-03-08 00:27:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
2008-06-28 20:57:12 +02:00
|
|
|
QString Theme::wallpaperPath(const QSize &size) const
|
|
|
|
{
|
|
|
|
QString fullPath;
|
2008-06-28 22:20:22 +02:00
|
|
|
QString image = d->defaultWallpaperTheme;
|
2008-06-28 20:57:12 +02:00
|
|
|
|
2008-06-28 22:20:22 +02:00
|
|
|
image.append("/contents/images/%1x%2").append(d->defaultWallpaperSuffix);
|
|
|
|
QString defaultImage = image.arg(d->defaultWallpaperWidth).arg(d->defaultWallpaperHeight);
|
2008-06-28 20:57:12 +02:00
|
|
|
|
2008-06-28 22:20:22 +02:00
|
|
|
if (size.isValid()) {
|
|
|
|
// 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;
|
2008-06-28 20:57:12 +02:00
|
|
|
}
|
|
|
|
|
2008-06-28 22:20:22 +02:00
|
|
|
//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
|
2008-06-28 20:57:12 +02:00
|
|
|
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
|
2008-06-28 21:08:14 +02:00
|
|
|
//kDebug() << "looking for" << image;
|
2008-06-28 20:57:12 +02:00
|
|
|
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
|
2008-06-28 21:08:14 +02:00
|
|
|
//kDebug() << "looking for" << defaultImage;
|
2008-06-28 20:57:12 +02:00
|
|
|
fullPath = KStandardDirs::locate("wallpaper", defaultImage);
|
|
|
|
|
|
|
|
if (fullPath.isEmpty()) {
|
|
|
|
kDebug() << "exhausted every effort to find a wallpaper.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
2008-06-04 19:44:37 +02:00
|
|
|
bool Theme::currentThemeHasImage(const QString& name) const
|
|
|
|
{
|
2008-08-17 22:52:37 +02:00
|
|
|
if (name.contains("../")) {
|
|
|
|
// we don't support relative paths
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-21 21:36:47 +02:00
|
|
|
return !(d->findInTheme(name + ".svgz", d->themeName).isEmpty()) ||
|
|
|
|
!(d->findInTheme(name + ".svg", d->themeName).isEmpty());
|
2008-06-04 19:44:37 +02:00
|
|
|
}
|
|
|
|
|
2008-04-16 17:53:16 +02:00
|
|
|
KSharedConfigPtr Theme::colorScheme() const
|
2007-11-04 07:57:42 +01:00
|
|
|
{
|
|
|
|
return d->colors;
|
|
|
|
}
|
|
|
|
|
2008-04-24 00:36:00 +02:00
|
|
|
QColor Theme::color(ColorRole role) const
|
2007-11-27 22:56:47 +01:00
|
|
|
{
|
2008-04-24 00:36:00 +02:00
|
|
|
switch (role) {
|
|
|
|
case TextColor:
|
2008-10-03 19:44:04 +02:00
|
|
|
return d->colorScheme.foreground(KColorScheme::NormalText).color();
|
2008-04-24 00:36:00 +02:00
|
|
|
break;
|
|
|
|
|
2008-06-03 10:51:57 +02:00
|
|
|
case HighlightColor:
|
2008-10-03 19:44:04 +02:00
|
|
|
return d->colorScheme.background(KColorScheme::ActiveBackground).color();
|
2008-06-03 10:51:57 +02:00
|
|
|
break;
|
|
|
|
|
2008-04-24 00:36:00 +02:00
|
|
|
case BackgroundColor:
|
2008-10-03 19:44:04 +02:00
|
|
|
return d->colorScheme.background().color();
|
2008-04-24 00:36:00 +02:00
|
|
|
break;
|
2008-10-06 06:10:34 +02:00
|
|
|
|
|
|
|
case ButtonTextColor:
|
|
|
|
return d->buttonColorScheme.foreground(KColorScheme::NormalText).color();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonBackgroundColor:
|
|
|
|
return d->buttonColorScheme.background(KColorScheme::ActiveBackground).color();
|
|
|
|
break;
|
2008-04-24 00:36:00 +02:00
|
|
|
}
|
2008-04-24 00:55:30 +02:00
|
|
|
|
|
|
|
return QColor();
|
2008-01-08 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
2008-04-24 00:36:00 +02:00
|
|
|
void Theme::setFont(const QFont &font, FontRole role)
|
2007-12-21 00:44:08 +01:00
|
|
|
{
|
2008-04-24 00:36:00 +02:00
|
|
|
Q_UNUSED(role)
|
2007-12-21 00:44:08 +01:00
|
|
|
d->generalFont = font;
|
|
|
|
}
|
|
|
|
|
2008-04-24 00:36:00 +02:00
|
|
|
QFont Theme::font(FontRole role) const
|
2007-12-19 20:56:39 +01:00
|
|
|
{
|
2008-04-24 00:36:00 +02:00
|
|
|
Q_UNUSED(role)
|
2008-10-06 06:10:34 +02:00
|
|
|
switch (role) {
|
|
|
|
case DesktopFont: {
|
|
|
|
KConfigGroup cg(KGlobal::config(), "General");
|
|
|
|
return cg.readEntry("desktopFont", QFont("Sans Serif", 10));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DefaultFont:
|
|
|
|
default:
|
|
|
|
return d->generalFont;
|
|
|
|
break;
|
|
|
|
}
|
2007-12-19 20:56:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QFontMetrics Theme::fontMetrics() const
|
|
|
|
{
|
|
|
|
//TODO: allow this to be overridden with a plasma specific font?
|
2007-12-21 00:44:08 +01:00
|
|
|
return QFontMetrics(d->generalFont);
|
2007-12-19 20:56:39 +01:00
|
|
|
}
|
|
|
|
|
2008-04-24 00:55:30 +02:00
|
|
|
bool Theme::windowTranslucencyEnabled() const
|
2008-03-05 22:03:27 +01:00
|
|
|
{
|
|
|
|
return d->compositingActive;
|
|
|
|
}
|
|
|
|
|
2008-05-12 06:53:13 +02:00
|
|
|
void Theme::setUseGlobalSettings(bool useGlobal)
|
|
|
|
{
|
2008-06-15 22:09:27 +02:00
|
|
|
if (d->useGlobal == useGlobal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-12 06:53:13 +02:00
|
|
|
d->useGlobal = useGlobal;
|
2008-06-15 22:09:27 +02:00
|
|
|
d->cfg = KConfigGroup();
|
|
|
|
d->themeName = QString();
|
|
|
|
settingsChanged();
|
2008-05-12 06:53:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Theme::useGlobalSettings() const
|
|
|
|
{
|
|
|
|
return d->useGlobal;
|
|
|
|
}
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <theme.moc>
|