2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "theme.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QFile>
|
2008-11-09 21:41:27 +01:00
|
|
|
#include <QFileInfo>
|
2010-10-30 00:14:18 +02:00
|
|
|
#include <QMutableListIterator>
|
2009-07-20 22:30:07 +02:00
|
|
|
#include <QPair>
|
2010-09-22 09:46:09 +02:00
|
|
|
#include <QStringBuilder>
|
|
|
|
#include <QTimer>
|
2012-08-03 12:19:50 +02:00
|
|
|
|
2012-08-25 03:00:36 +02:00
|
|
|
#include "config-plasma.h"
|
2012-08-03 12:19:50 +02:00
|
|
|
|
2012-08-03 13:00:02 +02:00
|
|
|
#if HAVE_X11
|
2011-01-15 18:51:55 +01:00
|
|
|
#include "private/effectwatcher_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#endif
|
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kcolorscheme.h>
|
|
|
|
#include <kcomponentdata.h>
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kdebug.h>
|
2009-01-26 07:22:44 +01:00
|
|
|
#include <kdirwatch.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kglobalsettings.h>
|
2008-11-04 03:55:37 +01:00
|
|
|
#include <kmanagerselection.h>
|
2010-05-04 05:59:35 +02:00
|
|
|
#include <kimagecache.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <ksharedconfig.h>
|
|
|
|
#include <kstandarddirs.h>
|
2012-02-19 13:41:26 +01:00
|
|
|
#include <kwindoweffects.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kwindowsystem.h>
|
2012-06-12 12:59:34 +02:00
|
|
|
#include <qstandardpaths.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-03-28 21:37:29 +02:00
|
|
|
|
2009-10-07 20:44:33 +02:00
|
|
|
#include "libplasma-theme-global.h"
|
2010-04-28 19:40:29 +02:00
|
|
|
#include "private/packages_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2011-04-27 18:30:19 +02:00
|
|
|
//NOTE: Default wallpaper can be set from the theme configuration
|
|
|
|
#define DEFAULT_WALLPAPER_THEME "default"
|
2010-01-11 23:43:19 +01:00
|
|
|
#define DEFAULT_WALLPAPER_SUFFIX ".png"
|
2008-11-04 00:08:39 +01:00
|
|
|
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
|
|
|
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
|
|
|
|
2010-10-01 18:04:34 +02:00
|
|
|
enum styles {
|
|
|
|
DEFAULTSTYLE,
|
|
|
|
SVGSTYLE
|
|
|
|
};
|
|
|
|
|
2010-12-13 21:14:52 +01:00
|
|
|
enum CacheType {
|
|
|
|
NoCache = 0,
|
|
|
|
PixmapCache = 1,
|
|
|
|
SvgElementsCache = 2
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(CacheTypes, CacheType)
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(CacheTypes)
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
class ThemePrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThemePrivate(Theme *theme)
|
|
|
|
: q(theme),
|
|
|
|
colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)),
|
|
|
|
buttonColorScheme(QPalette::Active, KColorScheme::Button, KSharedConfigPtr(0)),
|
2010-12-03 18:09:09 +01:00
|
|
|
viewColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(0)),
|
2008-11-04 00:08:39 +01:00
|
|
|
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
|
|
|
|
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
|
|
|
|
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
|
|
|
|
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
|
|
|
|
pixmapCache(0),
|
2011-12-08 12:45:23 +01:00
|
|
|
cachesToDiscard(NoCache),
|
2008-11-04 00:08:39 +01:00
|
|
|
locolor(false),
|
2011-12-08 12:45:23 +01:00
|
|
|
compositingActive(KWindowSystem::self()->compositingActive()),
|
2011-01-15 18:51:55 +01:00
|
|
|
blurActive(false),
|
2008-11-04 00:08:39 +01:00
|
|
|
isDefault(false),
|
|
|
|
useGlobal(true),
|
2009-02-24 23:42:06 +01:00
|
|
|
hasWallpapers(false),
|
|
|
|
useNativeWidgetStyle(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
generalFont = QApplication::font();
|
2009-10-07 20:44:33 +02:00
|
|
|
ThemeConfig config;
|
|
|
|
cacheTheme = config.cacheTheme();
|
2009-05-18 14:28:19 +02:00
|
|
|
|
2011-12-08 12:45:23 +01:00
|
|
|
saveTimer = new QTimer(q);
|
|
|
|
saveTimer->setSingleShot(true);
|
|
|
|
saveTimer->setInterval(600);
|
|
|
|
QObject::connect(saveTimer, SIGNAL(timeout()), q, SLOT(scheduledCacheUpdate()));
|
|
|
|
|
|
|
|
updateNotificationTimer = new QTimer(q);
|
|
|
|
updateNotificationTimer->setSingleShot(true);
|
|
|
|
updateNotificationTimer->setInterval(500);
|
|
|
|
QObject::connect(updateNotificationTimer, SIGNAL(timeout()), q, SLOT(notifyOfChanged()));
|
|
|
|
|
2011-07-28 23:37:17 +02:00
|
|
|
if (QPixmap::defaultDepth() > 8) {
|
|
|
|
QObject::connect(KWindowSystem::self(), SIGNAL(compositingChanged(bool)), q, SLOT(compositingChanged(bool)));
|
2013-01-19 18:06:53 +01:00
|
|
|
#if HAVE_X11
|
2011-01-15 18:51:55 +01:00
|
|
|
//watch for blur effect property changes as well
|
2011-12-08 12:48:34 +01:00
|
|
|
if (!s_blurEffectWatcher) {
|
|
|
|
s_blurEffectWatcher = new EffectWatcher("_KDE_NET_WM_BLUR_BEHIND_REGION");
|
|
|
|
}
|
2011-12-08 12:45:23 +01:00
|
|
|
|
2011-12-08 12:48:34 +01:00
|
|
|
QObject::connect(s_blurEffectWatcher, SIGNAL(effectChanged(bool)), q, SLOT(blurBehindChanged(bool)));
|
2011-07-30 12:52:18 +02:00
|
|
|
#endif
|
2009-05-18 14:28:19 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~ThemePrivate()
|
|
|
|
{
|
|
|
|
delete pixmapCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup &config()
|
|
|
|
{
|
|
|
|
if (!cfg.isValid()) {
|
|
|
|
QString groupName = "Theme";
|
|
|
|
|
|
|
|
if (!useGlobal) {
|
2012-09-16 18:53:38 +02:00
|
|
|
QString app = QCoreApplication::applicationName();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-06-23 23:16:20 +02:00
|
|
|
if (!app.isEmpty()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << "using theme for app" << app;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
groupName.append("-").append(app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-26 07:22:44 +01:00
|
|
|
cfg = KConfigGroup(KSharedConfig::openConfig(themeRcFile), groupName);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
2011-07-22 17:34:46 +02:00
|
|
|
QString findInTheme(const QString &image, const QString &theme, bool cache = true);
|
2011-07-28 23:37:17 +02:00
|
|
|
void compositingChanged(bool active);
|
2010-12-13 21:14:52 +01:00
|
|
|
void discardCache(CacheTypes caches);
|
2009-05-30 05:08:33 +02:00
|
|
|
void scheduledCacheUpdate();
|
2011-12-08 12:45:23 +01:00
|
|
|
void scheduleThemeChangeNotification(CacheTypes caches);
|
|
|
|
void notifyOfChanged();
|
2008-12-19 02:48:42 +01:00
|
|
|
void colorsChanged();
|
2011-01-15 18:51:55 +01:00
|
|
|
void blurBehindChanged(bool blur);
|
2008-12-04 21:13:50 +01:00
|
|
|
bool useCache();
|
2009-01-26 07:22:44 +01:00
|
|
|
void settingsFileChanged(const QString &);
|
2009-02-24 21:49:46 +01:00
|
|
|
void setThemeName(const QString &themeName, bool writeSettings);
|
2010-03-04 23:28:39 +01:00
|
|
|
void onAppExitCleanup();
|
2010-04-28 19:40:29 +02:00
|
|
|
void processWallpaperSettings(KConfigBase *metadata);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-05-11 10:23:41 +02:00
|
|
|
const QString processStyleSheet(const QString &css);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
static const char *defaultTheme;
|
2010-12-03 18:09:09 +01:00
|
|
|
static const char *systemColorsTheme;
|
2009-01-26 07:22:44 +01:00
|
|
|
static const char *themeRcFile;
|
2013-01-19 18:06:53 +01:00
|
|
|
#if HAVE_X11
|
2011-12-08 12:45:23 +01:00
|
|
|
static EffectWatcher *s_blurEffectWatcher;
|
2011-12-09 14:13:22 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Theme *q;
|
|
|
|
QString themeName;
|
2009-06-26 12:02:32 +02:00
|
|
|
QList<QString> fallbackThemes;
|
2008-11-04 00:08:39 +01:00
|
|
|
KSharedConfigPtr colors;
|
|
|
|
KColorScheme colorScheme;
|
|
|
|
KColorScheme buttonColorScheme;
|
2009-07-08 21:25:20 +02:00
|
|
|
KColorScheme viewColorScheme;
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup cfg;
|
|
|
|
QFont generalFont;
|
|
|
|
QString defaultWallpaperTheme;
|
|
|
|
QString defaultWallpaperSuffix;
|
|
|
|
int defaultWallpaperWidth;
|
|
|
|
int defaultWallpaperHeight;
|
2010-05-04 05:59:35 +02:00
|
|
|
KImageCache *pixmapCache;
|
2008-11-04 00:08:39 +01:00
|
|
|
KSharedConfigPtr svgElementsCache;
|
2008-12-11 00:17:12 +01:00
|
|
|
QHash<QString, QSet<QString> > invalidElements;
|
2009-05-30 05:08:33 +02:00
|
|
|
QHash<QString, QPixmap> pixmapsToCache;
|
2009-07-20 22:30:07 +02:00
|
|
|
QHash<QString, QString> keysToCache;
|
|
|
|
QHash<QString, QString> idsToCache;
|
2010-10-01 18:04:34 +02:00
|
|
|
QHash<styles, QString> cachedStyleSheets;
|
2011-07-22 17:34:46 +02:00
|
|
|
QHash<QString, QString> discoveries;
|
2009-05-30 05:08:33 +02:00
|
|
|
QTimer *saveTimer;
|
2011-12-08 12:45:23 +01:00
|
|
|
QTimer *updateNotificationTimer;
|
2011-12-06 22:42:23 +01:00
|
|
|
int toolTipDelay;
|
2011-12-08 12:45:23 +01:00
|
|
|
CacheTypes cachesToDiscard;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
bool locolor : 1;
|
|
|
|
bool compositingActive : 1;
|
2011-01-15 18:51:55 +01:00
|
|
|
bool blurActive : 1;
|
2008-11-04 00:08:39 +01:00
|
|
|
bool isDefault : 1;
|
|
|
|
bool useGlobal : 1;
|
|
|
|
bool hasWallpapers : 1;
|
2008-12-04 21:13:50 +01:00
|
|
|
bool cacheTheme : 1;
|
2009-02-24 23:42:06 +01:00
|
|
|
bool useNativeWidgetStyle :1;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *ThemePrivate::defaultTheme = "default";
|
2009-01-26 07:22:44 +01:00
|
|
|
const char *ThemePrivate::themeRcFile = "plasmarc";
|
2010-12-03 18:09:09 +01:00
|
|
|
// the system colors theme is used to cache unthemed svgs with colorization needs
|
|
|
|
// these svgs do not follow the theme's colors, but rather the system colors
|
|
|
|
const char *ThemePrivate::systemColorsTheme = "internal-system-colors";
|
2013-01-19 18:06:53 +01:00
|
|
|
#if HAVE_X11
|
2011-12-08 12:45:23 +01:00
|
|
|
EffectWatcher *ThemePrivate::s_blurEffectWatcher = 0;
|
2011-12-09 14:13:22 +01:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-04 21:13:50 +01:00
|
|
|
bool ThemePrivate::useCache()
|
|
|
|
{
|
|
|
|
if (cacheTheme && !pixmapCache) {
|
2009-10-07 20:44:33 +02:00
|
|
|
ThemeConfig config;
|
2010-05-04 05:59:35 +02:00
|
|
|
pixmapCache = new KImageCache("plasma_theme_" + themeName, config.themeCacheKb() * 1024);
|
2010-12-13 21:14:52 +01:00
|
|
|
if (themeName != systemColorsTheme) {
|
|
|
|
//check for expired cache
|
|
|
|
// FIXME: when using the system colors, if they change while the application is not running
|
|
|
|
// the cache should be dropped; we need a way to detect system color change when the
|
|
|
|
// application is not running.
|
2012-05-30 20:25:25 +02:00
|
|
|
QFile f(QStandardPaths::locate(QStandardPaths::GenericDataLocation, "desktoptheme/" + themeName + "/metadata.desktop"));
|
2010-12-13 21:14:52 +01:00
|
|
|
QFileInfo info(f);
|
2011-01-30 22:47:29 +01:00
|
|
|
if (info.lastModified().toTime_t() > uint(pixmapCache->lastModifiedTime())) {
|
2010-12-13 21:14:52 +01:00
|
|
|
pixmapCache->clear();
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 21:13:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return cacheTheme;
|
|
|
|
}
|
2008-12-09 21:37:41 +01:00
|
|
|
|
2010-03-04 23:28:39 +01:00
|
|
|
void ThemePrivate::onAppExitCleanup()
|
|
|
|
{
|
|
|
|
pixmapsToCache.clear();
|
|
|
|
delete pixmapCache;
|
|
|
|
pixmapCache = 0;
|
|
|
|
cacheTheme = false;
|
|
|
|
}
|
|
|
|
|
2011-07-22 17:34:46 +02:00
|
|
|
QString ThemePrivate::findInTheme(const QString &image, const QString &theme, bool cache)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2011-07-22 17:34:46 +02:00
|
|
|
if (cache && discoveries.contains(image)) {
|
|
|
|
return discoveries[image];
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString search;
|
|
|
|
|
|
|
|
if (locolor) {
|
2010-10-02 22:06:47 +02:00
|
|
|
search = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/locolor/") % image;
|
2012-05-30 20:25:25 +02:00
|
|
|
search = QStandardPaths::locate(QStandardPaths::GenericDataLocation, search);
|
2009-05-01 18:28:10 +02:00
|
|
|
} else if (!compositingActive) {
|
2010-10-02 22:06:47 +02:00
|
|
|
search = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/opaque/") % image;
|
2012-05-30 20:25:25 +02:00
|
|
|
search = QStandardPaths::locate(QStandardPaths::GenericDataLocation, search);
|
2012-02-19 13:41:26 +01:00
|
|
|
} else if (KWindowEffects::isEffectAvailable(KWindowEffects::BlurBehind)) {
|
2010-10-02 22:06:47 +02:00
|
|
|
search = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/translucent/") % image;
|
2012-05-30 20:25:25 +02:00
|
|
|
search = QStandardPaths::locate(QStandardPaths::GenericDataLocation, search);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//not found or compositing enabled
|
|
|
|
if (search.isEmpty()) {
|
2010-10-02 22:06:47 +02:00
|
|
|
search = QLatin1Literal("desktoptheme/") % theme % QLatin1Char('/') % image;
|
2012-05-30 20:25:25 +02:00
|
|
|
search = QStandardPaths::locate(QStandardPaths::GenericDataLocation, search);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-22 17:34:46 +02:00
|
|
|
if (cache && !search.isEmpty()) {
|
|
|
|
discoveries.insert(image, search);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return search;
|
|
|
|
}
|
|
|
|
|
2011-07-28 23:37:17 +02:00
|
|
|
void ThemePrivate::compositingChanged(bool active)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-08-03 13:00:02 +02:00
|
|
|
#if HAVE_X11
|
2011-07-28 23:37:17 +02:00
|
|
|
if (compositingActive != active) {
|
|
|
|
compositingActive = active;
|
2011-12-08 12:45:23 +01:00
|
|
|
//kDebug() << QTime::currentTime();
|
|
|
|
scheduleThemeChangeNotification(PixmapCache | SvgElementsCache);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-12-13 21:14:52 +01:00
|
|
|
void ThemePrivate::discardCache(CacheTypes caches)
|
2008-11-16 21:53:24 +01:00
|
|
|
{
|
2010-12-13 21:14:52 +01:00
|
|
|
if (caches & PixmapCache) {
|
2011-01-30 22:47:29 +01:00
|
|
|
pixmapsToCache.clear();
|
|
|
|
saveTimer->stop();
|
|
|
|
if (pixmapCache) {
|
|
|
|
pixmapCache->clear();
|
|
|
|
}
|
2010-09-11 01:03:24 +02:00
|
|
|
} else {
|
2010-12-13 21:14:52 +01:00
|
|
|
// This deletes the object but keeps the on-disk cache for later use
|
2010-09-11 01:03:24 +02:00
|
|
|
delete pixmapCache;
|
|
|
|
pixmapCache = 0;
|
|
|
|
}
|
2011-01-30 22:47:29 +01:00
|
|
|
|
2010-10-01 18:04:34 +02:00
|
|
|
cachedStyleSheets.clear();
|
2008-12-04 21:13:50 +01:00
|
|
|
|
2010-12-13 21:14:52 +01:00
|
|
|
if (caches & SvgElementsCache) {
|
2011-07-22 17:55:57 +02:00
|
|
|
discoveries.clear();
|
2011-01-30 22:47:29 +01:00
|
|
|
invalidElements.clear();
|
|
|
|
|
2010-12-13 21:14:52 +01:00
|
|
|
if (svgElementsCache) {
|
|
|
|
QFile f(svgElementsCache->name());
|
|
|
|
svgElementsCache = 0;
|
|
|
|
f.remove();
|
|
|
|
}
|
2010-09-11 01:03:24 +02:00
|
|
|
|
2012-11-23 20:31:42 +01:00
|
|
|
const QString svgElementsFile = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1Char('/') + "plasma-svgelements-" + themeName;
|
2010-12-13 21:14:52 +01:00
|
|
|
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
2008-12-04 21:13:50 +01:00
|
|
|
}
|
2008-11-16 21:53:24 +01:00
|
|
|
}
|
|
|
|
|
2009-05-30 05:08:33 +02:00
|
|
|
void ThemePrivate::scheduledCacheUpdate()
|
|
|
|
{
|
2011-07-30 21:18:38 +02:00
|
|
|
if (useCache()) {
|
|
|
|
QHashIterator<QString, QPixmap> it(pixmapsToCache);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
pixmapCache->insertPixmap(idsToCache[it.key()], it.value());
|
|
|
|
}
|
2009-05-30 05:08:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pixmapsToCache.clear();
|
2009-07-20 22:30:07 +02:00
|
|
|
keysToCache.clear();
|
|
|
|
idsToCache.clear();
|
2009-05-30 05:08:33 +02:00
|
|
|
}
|
|
|
|
|
2008-12-19 02:48:42 +01:00
|
|
|
void ThemePrivate::colorsChanged()
|
|
|
|
{
|
|
|
|
colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, colors);
|
|
|
|
buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors);
|
2009-07-08 21:25:20 +02:00
|
|
|
viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
|
2011-12-08 12:45:23 +01:00
|
|
|
scheduleThemeChangeNotification(PixmapCache);
|
2008-12-19 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
2011-01-15 18:51:55 +01:00
|
|
|
void ThemePrivate::blurBehindChanged(bool blur)
|
|
|
|
{
|
2011-12-08 12:45:23 +01:00
|
|
|
if (blurActive != blur) {
|
|
|
|
blurActive = blur;
|
|
|
|
scheduleThemeChangeNotification(PixmapCache | SvgElementsCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemePrivate::scheduleThemeChangeNotification(CacheTypes caches)
|
|
|
|
{
|
|
|
|
cachesToDiscard |= caches;
|
|
|
|
updateNotificationTimer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemePrivate::notifyOfChanged()
|
|
|
|
{
|
|
|
|
//kDebug() << cachesToDiscard;
|
|
|
|
discardCache(cachesToDiscard);
|
|
|
|
cachesToDiscard = NoCache;
|
2011-01-15 18:51:55 +01:00
|
|
|
emit q->themeChanged();
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:23:41 +02:00
|
|
|
const QString ThemePrivate::processStyleSheet(const QString &css)
|
|
|
|
{
|
|
|
|
QString stylesheet;
|
|
|
|
if (css.isEmpty()) {
|
2010-11-28 12:13:27 +01:00
|
|
|
stylesheet = cachedStyleSheets.value(DEFAULTSTYLE);
|
|
|
|
if (stylesheet.isEmpty()) {
|
2010-10-01 18:04:34 +02:00
|
|
|
stylesheet = QString("\n\
|
|
|
|
body {\n\
|
|
|
|
color: %textcolor;\n\
|
|
|
|
font-size: %fontsize;\n\
|
|
|
|
font-family: %fontfamily;\n\
|
|
|
|
}\n\
|
|
|
|
a:active { color: %activatedlink; }\n\
|
|
|
|
a:link { color: %link; }\n\
|
|
|
|
a:visited { color: %visitedlink; }\n\
|
|
|
|
a:hover { color: %hoveredlink; text-decoration: none; }\n\
|
|
|
|
");
|
|
|
|
stylesheet = processStyleSheet(stylesheet);
|
2010-11-28 12:13:27 +01:00
|
|
|
cachedStyleSheets.insert(DEFAULTSTYLE, stylesheet);
|
2010-10-01 18:04:34 +02:00
|
|
|
}
|
2010-11-28 12:13:27 +01:00
|
|
|
|
2010-10-01 18:04:34 +02:00
|
|
|
return stylesheet;
|
2010-11-28 12:13:27 +01:00
|
|
|
} else if (css == "SVG") {
|
|
|
|
stylesheet = cachedStyleSheets.value(SVGSTYLE);
|
|
|
|
if (stylesheet.isEmpty()) {
|
2010-10-01 18:04:34 +02:00
|
|
|
QString skel = ".ColorScheme-%1{color:%2;}";
|
|
|
|
|
|
|
|
stylesheet += skel.arg("Text","%textcolor");
|
|
|
|
stylesheet += skel.arg("Background","%backgroundcolor");
|
|
|
|
|
|
|
|
stylesheet += skel.arg("ButtonText","%buttontextcolor");
|
|
|
|
stylesheet += skel.arg("ButtonBackground","%buttonbackgroundcolor");
|
|
|
|
stylesheet += skel.arg("ButtonHover","%buttonhovercolor");
|
|
|
|
stylesheet += skel.arg("ButtonFocus","%buttonfocuscolor");
|
|
|
|
|
|
|
|
stylesheet += skel.arg("ViewText","%viewtextcolor");
|
|
|
|
stylesheet += skel.arg("ViewBackground","%viewbackgroundcolor");
|
2010-10-09 20:14:11 +02:00
|
|
|
stylesheet += skel.arg("ViewHover","%viewhovercolor");
|
|
|
|
stylesheet += skel.arg("ViewFocus","%viewfocuscolor");
|
2010-10-01 18:04:34 +02:00
|
|
|
|
|
|
|
stylesheet = processStyleSheet(stylesheet);
|
2010-11-28 12:13:27 +01:00
|
|
|
cachedStyleSheets.insert(SVGSTYLE, stylesheet);
|
2010-10-01 18:04:34 +02:00
|
|
|
}
|
2010-11-28 12:13:27 +01:00
|
|
|
|
2010-10-01 18:04:34 +02:00
|
|
|
return stylesheet;
|
2010-05-11 10:23:41 +02:00
|
|
|
} else {
|
|
|
|
stylesheet = css;
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<QString, QString> elements;
|
|
|
|
// If you add elements here, make sure their names are sufficiently unique to not cause
|
|
|
|
// clashes between element keys
|
2010-12-03 18:09:09 +01:00
|
|
|
elements["%textcolor"] = q->color(Theme::TextColor).name();
|
|
|
|
elements["%backgroundcolor"] = q->color(Theme::BackgroundColor).name();
|
|
|
|
elements["%visitedlink"] = q->color(Theme::VisitedLinkColor).name();
|
|
|
|
elements["%activatedlink"] = q->color(Theme::HighlightColor).name();
|
|
|
|
elements["%hoveredlink"] = q->color(Theme::HighlightColor).name();
|
|
|
|
elements["%link"] = q->color(Theme::LinkColor).name();
|
|
|
|
elements["%buttontextcolor"] = q->color(Theme::ButtonTextColor).name();
|
|
|
|
elements["%buttonbackgroundcolor"] = q->color(Theme::ButtonBackgroundColor).name();
|
|
|
|
elements["%buttonhovercolor"] = q->color(Theme::ButtonHoverColor).name();
|
|
|
|
elements["%buttonfocuscolor"] = q->color(Theme::ButtonFocusColor).name();
|
|
|
|
elements["%viewtextcolor"] = q->color(Theme::ViewTextColor).name();
|
|
|
|
elements["%viewbackgroundcolor"] = q->color(Theme::ViewBackgroundColor).name();
|
|
|
|
elements["%viewhovercolor"] = q->color(Theme::ViewHoverColor).name();
|
|
|
|
elements["%viewfocuscolor"] = q->color(Theme::ViewFocusColor).name();
|
|
|
|
|
|
|
|
QFont font = q->font(Theme::DefaultFont);
|
2010-11-28 12:13:27 +01:00
|
|
|
elements["%fontsize"] = QString("%1pt").arg(font.pointSize());
|
2011-04-24 14:20:53 +02:00
|
|
|
elements["%fontfamily"] = font.family().split('[').first();
|
2010-12-03 18:09:09 +01:00
|
|
|
elements["%smallfontsize"] = QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize());
|
2010-05-11 10:23:41 +02:00
|
|
|
|
2010-12-13 14:36:08 +01:00
|
|
|
QHash<QString, QString>::const_iterator it = elements.constBegin();
|
|
|
|
QHash<QString, QString>::const_iterator itEnd = elements.constEnd();
|
|
|
|
for ( ; it != itEnd; ++it) {
|
|
|
|
stylesheet.replace(it.key(), it.value());
|
2010-05-11 10:23:41 +02:00
|
|
|
}
|
|
|
|
return stylesheet;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
class ThemeSingleton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThemeSingleton()
|
|
|
|
{
|
|
|
|
self.d->isDefault = true;
|
2009-05-25 22:02:29 +02:00
|
|
|
|
2009-12-10 10:16:30 +01:00
|
|
|
//FIXME: if/when kconfig gets change notification, this will be unnecessary
|
2012-05-30 20:25:25 +02:00
|
|
|
KDirWatch::self()->addFile(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + ThemePrivate::themeRcFile);
|
2009-05-25 22:02:29 +02:00
|
|
|
QObject::connect(KDirWatch::self(), SIGNAL(created(QString)), &self, SLOT(settingsFileChanged(QString)));
|
|
|
|
QObject::connect(KDirWatch::self(), SIGNAL(dirty(QString)), &self, SLOT(settingsFileChanged(QString)));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Theme self;
|
|
|
|
};
|
|
|
|
|
2012-07-19 21:16:59 +02:00
|
|
|
Q_GLOBAL_STATIC(ThemeSingleton, privateThemeSelf)
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Theme *Theme::defaultTheme()
|
|
|
|
{
|
2012-07-19 21:16:59 +02:00
|
|
|
return &privateThemeSelf()->self;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Theme::Theme(QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new ThemePrivate(this))
|
|
|
|
{
|
|
|
|
settingsChanged();
|
2010-03-04 23:28:39 +01:00
|
|
|
if (QCoreApplication::instance()) {
|
|
|
|
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
|
|
|
|
this, SLOT(onAppExitCleanup()));
|
|
|
|
}
|
2009-05-18 14:28:19 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-05-18 14:28:19 +02:00
|
|
|
Theme::Theme(const QString &themeName, QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new ThemePrivate(this))
|
|
|
|
{
|
|
|
|
// turn off caching so we don't accidently trigger unnecessary disk activity at this point
|
|
|
|
bool useCache = d->cacheTheme;
|
|
|
|
d->cacheTheme = false;
|
|
|
|
setThemeName(themeName);
|
|
|
|
d->cacheTheme = useCache;
|
2010-03-04 23:28:39 +01:00
|
|
|
if (QCoreApplication::instance()) {
|
|
|
|
connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
|
|
|
|
this, SLOT(onAppExitCleanup()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Theme::~Theme()
|
|
|
|
{
|
2011-01-30 22:47:29 +01:00
|
|
|
if (d->svgElementsCache) {
|
|
|
|
QHashIterator<QString, QSet<QString> > it(d->invalidElements);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
KConfigGroup imageGroup(d->svgElementsCache, it.key());
|
|
|
|
imageGroup.writeEntry("invalidElements", it.value().toList()); //FIXME: add QSet support to KConfig
|
|
|
|
}
|
2008-12-11 00:17:12 +01:00
|
|
|
}
|
|
|
|
|
2011-01-30 22:47:29 +01:00
|
|
|
d->onAppExitCleanup();
|
2008-11-04 00:08:39 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2009-05-18 14:28:19 +02:00
|
|
|
KPluginInfo::List Theme::listThemeInfo()
|
|
|
|
{
|
2012-06-12 12:59:34 +02:00
|
|
|
const QStringList themes = KGlobal::dirs()->findAllResources("data", "desktoptheme/*/metadata.desktop", KStandardDirs::NoDuplicates);
|
2009-05-18 14:28:19 +02:00
|
|
|
return KPluginInfo::fromFiles(themes);
|
|
|
|
}
|
|
|
|
|
2009-01-26 07:22:44 +01:00
|
|
|
void ThemePrivate::settingsFileChanged(const QString &file)
|
|
|
|
{
|
2009-05-18 14:28:19 +02:00
|
|
|
if (file.endsWith(themeRcFile)) {
|
|
|
|
config().config()->reparseConfiguration();
|
|
|
|
q->settingsChanged();
|
|
|
|
}
|
2009-01-26 07:22:44 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Theme::settingsChanged()
|
|
|
|
{
|
2011-12-06 22:42:23 +01:00
|
|
|
KConfigGroup cg = d->config();
|
|
|
|
d->setThemeName(cg.readEntry("name", ThemePrivate::defaultTheme), false);
|
|
|
|
cg = KConfigGroup(cg.config(), "PlasmaToolTips");
|
2012-01-27 15:10:36 +01:00
|
|
|
d->toolTipDelay = cg.readEntry("Delay", 700);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::setThemeName(const QString &themeName)
|
2009-02-24 21:49:46 +01:00
|
|
|
{
|
|
|
|
d->setThemeName(themeName, true);
|
|
|
|
}
|
|
|
|
|
2010-04-28 19:40:29 +02:00
|
|
|
void ThemePrivate::processWallpaperSettings(KConfigBase *metadata)
|
|
|
|
{
|
2010-06-23 15:03:13 +02:00
|
|
|
if (!defaultWallpaperTheme.isEmpty() && defaultWallpaperTheme != DEFAULT_WALLPAPER_THEME) {
|
2010-04-28 19:40:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = config();
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultWallpaperTheme = cg.readEntry("defaultWallpaperTheme", DEFAULT_WALLPAPER_THEME);
|
|
|
|
defaultWallpaperSuffix = cg.readEntry("defaultFileSuffix", DEFAULT_WALLPAPER_SUFFIX);
|
|
|
|
defaultWallpaperWidth = cg.readEntry("defaultWidth", DEFAULT_WALLPAPER_WIDTH);
|
|
|
|
defaultWallpaperHeight = cg.readEntry("defaultHeight", DEFAULT_WALLPAPER_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2009-02-24 21:49:46 +01:00
|
|
|
void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-04-28 19:10:17 +02:00
|
|
|
//kDebug() << tempThemeName;
|
2009-02-24 21:49:46 +01:00
|
|
|
QString theme = tempThemeName;
|
|
|
|
if (theme.isEmpty() || theme == themeName) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// let's try and get the default theme at least
|
2009-02-24 21:49:46 +01:00
|
|
|
if (themeName.isEmpty()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
theme = ThemePrivate::defaultTheme;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
// we have one special theme: essentially a dummy theme used to cache things with
|
|
|
|
// the system colors.
|
|
|
|
bool realTheme = theme != systemColorsTheme;
|
|
|
|
if (realTheme) {
|
2012-05-30 20:25:25 +02:00
|
|
|
QString themePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % theme % QLatin1Char('/'));
|
2010-12-03 18:09:09 +01:00
|
|
|
if (themePath.isEmpty() && themeName.isEmpty()) {
|
2012-05-30 20:25:25 +02:00
|
|
|
themePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "desktoptheme/default", QStandardPaths::LocateDirectory);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
if (themePath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
theme = ThemePrivate::defaultTheme;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-11 01:03:24 +02:00
|
|
|
// check again as ThemePrivate::defaultTheme might be empty
|
2009-02-24 21:49:46 +01:00
|
|
|
if (themeName == theme) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-24 21:49:46 +01:00
|
|
|
themeName = theme;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
// load the color scheme config
|
2012-05-30 20:25:25 +02:00
|
|
|
const QString colorsFile = realTheme ? QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/colors"))
|
2010-12-03 18:09:09 +01:00
|
|
|
: QString();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//kDebug() << "we're going for..." << colorsFile << "*******************";
|
|
|
|
|
|
|
|
// load the wallpaper settings, if any
|
2010-12-03 18:09:09 +01:00
|
|
|
if (realTheme) {
|
2012-05-30 20:25:25 +02:00
|
|
|
const QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/metadata.desktop")));
|
2010-12-03 18:09:09 +01:00
|
|
|
KConfig metadata(metadataPath);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
processWallpaperSettings(&metadata);
|
2010-04-28 19:40:29 +02:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
KConfigGroup cg(&metadata, "Settings");
|
|
|
|
useNativeWidgetStyle = cg.readEntry("UseNativeWidgetStyle", false);
|
|
|
|
QString fallback = cg.readEntry("FallbackTheme", QString());
|
2009-06-26 12:02:32 +02:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
fallbackThemes.clear();
|
|
|
|
while (!fallback.isEmpty() && !fallbackThemes.contains(fallback)) {
|
|
|
|
fallbackThemes.append(fallback);
|
2009-06-26 12:02:32 +02:00
|
|
|
|
2012-05-30 20:25:25 +02:00
|
|
|
QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/metadata.desktop")));
|
2010-12-03 18:09:09 +01:00
|
|
|
KConfig metadata(metadataPath);
|
|
|
|
KConfigGroup cg(&metadata, "Settings");
|
|
|
|
fallback = cg.readEntry("FallbackTheme", QString());
|
|
|
|
}
|
2009-06-26 12:20:51 +02:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
if (!fallbackThemes.contains("oxygen")) {
|
|
|
|
fallbackThemes.append("oxygen");
|
|
|
|
}
|
2009-06-26 12:20:51 +02:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
if (!fallbackThemes.contains(ThemePrivate::defaultTheme)) {
|
|
|
|
fallbackThemes.append(ThemePrivate::defaultTheme);
|
|
|
|
}
|
2009-02-24 23:42:06 +01:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
foreach (const QString &theme, fallbackThemes) {
|
2012-05-30 20:25:25 +02:00
|
|
|
QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/metadata.desktop")));
|
2010-12-03 18:09:09 +01:00
|
|
|
KConfig metadata(metadataPath);
|
|
|
|
processWallpaperSettings(&metadata);
|
|
|
|
}
|
|
|
|
}
|
2008-11-16 21:53:24 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (colorsFile.isEmpty()) {
|
2009-02-24 21:49:46 +01:00
|
|
|
colors = 0;
|
|
|
|
QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
|
2010-12-03 18:09:09 +01:00
|
|
|
q, SLOT(colorsChanged()), Qt::UniqueConnection);
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2010-12-03 18:09:09 +01:00
|
|
|
QObject::disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
|
|
|
|
q, SLOT(colorsChanged()));
|
2009-02-24 21:49:46 +01:00
|
|
|
colors = KSharedConfig::openConfig(colorsFile);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-02-24 21:49:46 +01:00
|
|
|
colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, colors);
|
|
|
|
buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors);
|
2009-07-08 21:25:20 +02:00
|
|
|
viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
|
2012-05-30 20:25:25 +02:00
|
|
|
hasWallpapers = KStandardDirs::exists(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/"));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-12-03 18:09:09 +01:00
|
|
|
if (realTheme && isDefault && writeSettings) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// we're the default theme, let's save our state
|
2009-02-24 21:49:46 +01:00
|
|
|
KConfigGroup &cg = config();
|
|
|
|
if (ThemePrivate::defaultTheme == themeName) {
|
2008-11-04 00:08:39 +01:00
|
|
|
cg.deleteEntry("name");
|
|
|
|
} else {
|
2009-02-24 21:49:46 +01:00
|
|
|
cg.writeEntry("name", themeName);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-02-28 07:40:54 +01:00
|
|
|
cg.sync();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:45:23 +01:00
|
|
|
scheduleThemeChangeNotification(SvgElementsCache);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Theme::themeName() const
|
|
|
|
{
|
|
|
|
return d->themeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Theme::imagePath(const QString &name) const
|
|
|
|
{
|
|
|
|
// look for a compressed svg file in the theme
|
2009-05-19 10:53:56 +02:00
|
|
|
if (name.contains("../") || name.isEmpty()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
// we don't support relative paths
|
2011-12-08 12:45:23 +01:00
|
|
|
//kDebug() << "Theme says: bad image path " << name;
|
2008-11-04 00:08:39 +01:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2010-10-04 23:50:42 +02:00
|
|
|
const QString svgzName = name % QLatin1Literal(".svgz");
|
|
|
|
QString path = d->findInTheme(svgzName, d->themeName);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
// try for an uncompressed svg file
|
2010-10-04 23:50:42 +02:00
|
|
|
const QString svgName = name % QLatin1Literal(".svg");
|
|
|
|
path = d->findInTheme(svgName, d->themeName);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-06-26 12:02:32 +02:00
|
|
|
// search in fallback themes if necessary
|
|
|
|
for (int i = 0; path.isEmpty() && i < d->fallbackThemes.count(); ++i) {
|
|
|
|
if (d->themeName == d->fallbackThemes[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try a compressed svg file in the fallback theme
|
2010-10-07 15:51:31 +02:00
|
|
|
path = d->findInTheme(svgzName, d->fallbackThemes[i]);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
2009-06-26 12:02:32 +02:00
|
|
|
// try an uncompressed svg file in the fallback theme
|
2010-10-04 23:50:42 +02:00
|
|
|
path = d->findInTheme(svgName, d->fallbackThemes[i]);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-28 19:40:29 +02:00
|
|
|
/*
|
2008-11-04 00:08:39 +01:00
|
|
|
if (path.isEmpty()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2010-04-28 19:40:29 +02:00
|
|
|
kDebug() << "Theme says: bad image path " << name;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-04-28 19:40:29 +02:00
|
|
|
*/
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:23:41 +02:00
|
|
|
QString Theme::styleSheet(const QString &css) const
|
|
|
|
{
|
|
|
|
return d->processStyleSheet(css);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString Theme::wallpaperPath(const QSize &size) const
|
|
|
|
{
|
|
|
|
QString fullPath;
|
|
|
|
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()) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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
|
2010-10-02 22:06:47 +02:00
|
|
|
fullPath = d->findInTheme(QLatin1Literal("wallpapers/") % image, d->themeName);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (fullPath.isEmpty()) {
|
2010-10-02 22:06:47 +02:00
|
|
|
fullPath = d->findInTheme(QLatin1Literal("wallpapers/") % defaultImage, d->themeName);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fullPath.isEmpty()) {
|
|
|
|
// we failed to find it in the theme, so look in the standard directories
|
|
|
|
//kDebug() << "looking for" << image;
|
2012-06-12 12:59:34 +02:00
|
|
|
fullPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("wallpapers/") + image);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2012-06-12 12:59:34 +02:00
|
|
|
fullPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("wallpapers/") + defaultImage);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (fullPath.isEmpty()) {
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << "exhausted every effort to find a wallpaper.";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Theme::currentThemeHasImage(const QString &name) const
|
|
|
|
{
|
|
|
|
if (name.contains("../")) {
|
|
|
|
// we don't support relative paths
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-22 17:34:46 +02:00
|
|
|
return !(d->findInTheme(name % QLatin1Literal(".svgz"), d->themeName, false).isEmpty()) ||
|
|
|
|
!(d->findInTheme(name % QLatin1Literal(".svg"), d->themeName, false).isEmpty());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
KSharedConfigPtr Theme::colorScheme() const
|
|
|
|
{
|
|
|
|
return d->colors;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor Theme::color(ColorRole role) const
|
|
|
|
{
|
|
|
|
switch (role) {
|
|
|
|
case TextColor:
|
|
|
|
return d->colorScheme.foreground(KColorScheme::NormalText).color();
|
|
|
|
|
|
|
|
case HighlightColor:
|
2009-06-09 13:52:18 +02:00
|
|
|
return d->colorScheme.decoration(KColorScheme::HoverColor).color();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
case BackgroundColor:
|
2010-09-27 14:08:24 +02:00
|
|
|
return d->colorScheme.background(KColorScheme::NormalBackground).color();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
case ButtonTextColor:
|
|
|
|
return d->buttonColorScheme.foreground(KColorScheme::NormalText).color();
|
|
|
|
|
|
|
|
case ButtonBackgroundColor:
|
2010-09-27 14:08:24 +02:00
|
|
|
return d->buttonColorScheme.background(KColorScheme::NormalBackground).color();
|
2010-10-01 18:04:34 +02:00
|
|
|
|
|
|
|
case ButtonHoverColor:
|
|
|
|
return d->buttonColorScheme.decoration(KColorScheme::HoverColor).color();
|
|
|
|
|
|
|
|
case ButtonFocusColor:
|
|
|
|
return d->buttonColorScheme.decoration(KColorScheme::FocusColor).color();
|
|
|
|
|
|
|
|
case ViewTextColor:
|
|
|
|
return d->viewColorScheme.foreground(KColorScheme::NormalText).color();
|
|
|
|
|
|
|
|
case ViewBackgroundColor:
|
|
|
|
return d->viewColorScheme.background(KColorScheme::NormalBackground).color();
|
2009-07-08 21:25:20 +02:00
|
|
|
|
2010-10-09 20:14:11 +02:00
|
|
|
case ViewHoverColor:
|
|
|
|
return d->viewColorScheme.decoration(KColorScheme::HoverColor).color();
|
|
|
|
|
|
|
|
case ViewFocusColor:
|
|
|
|
return d->viewColorScheme.decoration(KColorScheme::FocusColor).color();
|
|
|
|
|
2009-07-08 21:25:20 +02:00
|
|
|
case LinkColor:
|
|
|
|
return d->viewColorScheme.foreground(KColorScheme::LinkText).color();
|
|
|
|
|
|
|
|
case VisitedLinkColor:
|
|
|
|
return d->viewColorScheme.foreground(KColorScheme::VisitedText).color();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return QColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::setFont(const QFont &font, FontRole role)
|
|
|
|
{
|
|
|
|
Q_UNUSED(role)
|
|
|
|
d->generalFont = font;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFont Theme::font(FontRole role) const
|
|
|
|
{
|
|
|
|
switch (role) {
|
2011-08-17 18:07:12 +02:00
|
|
|
case DesktopFont: {
|
2012-03-24 19:33:54 +01:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), "General");
|
2010-06-26 22:55:52 +02:00
|
|
|
return cg.readEntry("desktopFont", d->generalFont);
|
2011-08-17 18:07:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
case DefaultFont:
|
|
|
|
default:
|
|
|
|
return d->generalFont;
|
|
|
|
break;
|
2011-08-17 18:07:12 +02:00
|
|
|
|
|
|
|
case SmallestFont:
|
|
|
|
return KGlobalSettings::smallestReadableFont();
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-11-05 19:53:56 +01:00
|
|
|
|
|
|
|
return d->generalFont;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QFontMetrics Theme::fontMetrics() const
|
|
|
|
{
|
|
|
|
//TODO: allow this to be overridden with a plasma specific font?
|
|
|
|
return QFontMetrics(d->generalFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Theme::windowTranslucencyEnabled() const
|
|
|
|
{
|
|
|
|
return d->compositingActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::setUseGlobalSettings(bool useGlobal)
|
|
|
|
{
|
|
|
|
if (d->useGlobal == useGlobal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->useGlobal = useGlobal;
|
|
|
|
d->cfg = KConfigGroup();
|
|
|
|
d->themeName.clear();
|
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Theme::useGlobalSettings() const
|
|
|
|
{
|
|
|
|
return d->useGlobal;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:42:06 +01:00
|
|
|
bool Theme::useNativeWidgetStyle() const
|
|
|
|
{
|
|
|
|
return d->useNativeWidgetStyle;
|
|
|
|
}
|
|
|
|
|
2011-05-20 08:23:43 +02:00
|
|
|
bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModified)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2011-05-20 08:23:43 +02:00
|
|
|
if (lastModified != 0 && d->useCache() && lastModified > uint(d->pixmapCache->lastModifiedTime())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-30 05:08:33 +02:00
|
|
|
if (d->useCache()) {
|
2009-08-04 21:13:58 +02:00
|
|
|
const QString id = d->keysToCache.value(key);
|
2009-07-20 22:30:07 +02:00
|
|
|
if (d->pixmapsToCache.contains(id)) {
|
|
|
|
pix = d->pixmapsToCache.value(id);
|
2010-12-03 18:09:09 +01:00
|
|
|
return !pix.isNull();
|
2009-05-30 05:08:33 +02:00
|
|
|
}
|
|
|
|
|
2010-05-04 05:59:35 +02:00
|
|
|
QPixmap temp;
|
2010-12-03 18:09:09 +01:00
|
|
|
if (d->pixmapCache->findPixmap(key, &temp) && !temp.isNull()) {
|
2010-05-04 05:59:35 +02:00
|
|
|
pix = temp;
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-30 05:08:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::insertIntoCache(const QString& key, const QPixmap& pix)
|
|
|
|
{
|
2008-12-04 21:13:50 +01:00
|
|
|
if (d->useCache()) {
|
2010-05-04 05:59:35 +02:00
|
|
|
d->pixmapCache->insertPixmap(key, pix);
|
2009-07-20 22:30:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::insertIntoCache(const QString& key, const QPixmap& pix, const QString& id)
|
|
|
|
{
|
|
|
|
if (d->useCache()) {
|
|
|
|
d->pixmapsToCache.insert(id, pix);
|
|
|
|
|
|
|
|
if (d->idsToCache.contains(id)) {
|
|
|
|
d->keysToCache.remove(d->idsToCache[id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->keysToCache.insert(key, id);
|
|
|
|
d->idsToCache.insert(id, key);
|
2011-12-08 12:45:23 +01:00
|
|
|
d->saveTimer->start();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Theme::findInRectsCache(const QString &image, const QString &element, QRectF &rect) const
|
|
|
|
{
|
2011-01-30 22:47:29 +01:00
|
|
|
if (!d->svgElementsCache) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup imageGroup(d->svgElementsCache, image);
|
2010-10-02 22:06:47 +02:00
|
|
|
rect = imageGroup.readEntry(element % QLatin1Literal("Size"), QRectF());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-11 00:17:12 +01:00
|
|
|
if (rect.isValid()) {
|
|
|
|
return true;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-07-31 20:47:20 +02:00
|
|
|
//Name starting by _ means the element is empty and we're asked for the size of
|
2009-01-22 20:59:25 +01:00
|
|
|
//the whole image, so the whole image is never invalid
|
2009-07-31 20:47:20 +02:00
|
|
|
if (element.indexOf('_') <= 0) {
|
2009-01-22 20:59:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-11 00:17:12 +01:00
|
|
|
bool invalid = false;
|
|
|
|
|
|
|
|
QHash<QString, QSet<QString> >::iterator it = d->invalidElements.find(image);
|
|
|
|
if (it == d->invalidElements.end()) {
|
|
|
|
QSet<QString> elements = imageGroup.readEntry("invalidElements", QStringList()).toSet();
|
|
|
|
d->invalidElements.insert(image, elements);
|
|
|
|
invalid = elements.contains(element);
|
|
|
|
} else {
|
|
|
|
invalid = it.value().contains(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return invalid;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-10-30 00:14:18 +02:00
|
|
|
QStringList Theme::listCachedRectKeys(const QString &image) const
|
|
|
|
{
|
2011-01-30 22:47:29 +01:00
|
|
|
if (!d->svgElementsCache) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2010-10-30 00:14:18 +02:00
|
|
|
KConfigGroup imageGroup(d->svgElementsCache, image);
|
|
|
|
QStringList keys = imageGroup.keyList();
|
|
|
|
|
|
|
|
QMutableListIterator<QString> i(keys);
|
|
|
|
while (i.hasNext()) {
|
2010-10-30 00:30:10 +02:00
|
|
|
QString key = i.next();
|
2010-10-30 00:14:18 +02:00
|
|
|
if (key.endsWith("Size")) {
|
|
|
|
// The actual cache id used from outside doesn't end on "Size".
|
2010-10-30 00:30:10 +02:00
|
|
|
key.resize(key.size() - 4);
|
|
|
|
i.setValue(key);
|
2010-10-30 00:14:18 +02:00
|
|
|
} else {
|
|
|
|
i.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Theme::insertIntoRectsCache(const QString& image, const QString &element, const QRectF &rect)
|
|
|
|
{
|
2011-01-30 22:47:29 +01:00
|
|
|
if (!d->svgElementsCache) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rect.isValid()) {
|
2008-12-11 00:17:12 +01:00
|
|
|
KConfigGroup imageGroup(d->svgElementsCache, image);
|
2010-10-02 22:06:47 +02:00
|
|
|
imageGroup.writeEntry(element % QLatin1Literal("Size"), rect);
|
2008-12-11 00:17:12 +01:00
|
|
|
} else {
|
|
|
|
QHash<QString, QSet<QString> >::iterator it = d->invalidElements.find(image);
|
|
|
|
if (it == d->invalidElements.end()) {
|
|
|
|
d->invalidElements[image].insert(element);
|
|
|
|
} else if (!it.value().contains(element)) {
|
|
|
|
if (it.value().count() > 1000) {
|
|
|
|
it.value().erase(it.value().begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
it.value().insert(element);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::invalidateRectsCache(const QString& image)
|
|
|
|
{
|
2011-01-30 22:47:29 +01:00
|
|
|
if (d->svgElementsCache) {
|
|
|
|
KConfigGroup imageGroup(d->svgElementsCache, image);
|
|
|
|
imageGroup.deleteGroup();
|
|
|
|
}
|
2008-12-11 03:45:45 +01:00
|
|
|
|
2011-01-30 22:47:29 +01:00
|
|
|
d->invalidElements.remove(image);
|
2008-12-11 03:45:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::releaseRectsCache(const QString &image)
|
|
|
|
{
|
|
|
|
QHash<QString, QSet<QString> >::iterator it = d->invalidElements.find(image);
|
|
|
|
if (it != d->invalidElements.end()) {
|
2011-01-30 22:47:29 +01:00
|
|
|
if (!d->svgElementsCache) {
|
|
|
|
KConfigGroup imageGroup(d->svgElementsCache, it.key());
|
|
|
|
imageGroup.writeEntry("invalidElements", it.value().toList());
|
|
|
|
}
|
|
|
|
|
2008-12-11 03:45:45 +01:00
|
|
|
d->invalidElements.erase(it);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::setCacheLimit(int kbytes)
|
|
|
|
{
|
2010-12-03 18:09:09 +01:00
|
|
|
Q_UNUSED(kbytes)
|
2008-12-04 21:13:50 +01:00
|
|
|
if (d->useCache()) {
|
2010-05-04 05:59:35 +02:00
|
|
|
;
|
|
|
|
// Too late for you bub.
|
|
|
|
// d->pixmapCache->setCacheLimit(kbytes);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-18 11:13:54 +01:00
|
|
|
QUrl Theme::homepage() const
|
2010-12-27 01:46:17 +01:00
|
|
|
{
|
2012-05-30 20:25:25 +02:00
|
|
|
const QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % d->themeName % QLatin1Literal("/metadata.desktop")));
|
2010-12-27 01:46:17 +01:00
|
|
|
KConfig metadata(metadataPath);
|
|
|
|
KConfigGroup brandConfig(&metadata, "Branding");
|
2012-02-18 11:13:54 +01:00
|
|
|
return brandConfig.readEntry("homepage", QUrl("http://www.kde.org"));
|
2010-12-27 01:46:17 +01:00
|
|
|
}
|
|
|
|
|
2011-12-06 22:42:23 +01:00
|
|
|
int Theme::toolTipDelay() const
|
|
|
|
{
|
|
|
|
return d->toolTipDelay;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
#include "moc_theme.cpp"
|