move ThmemePrivate in own file
it will make easier making it implicitly shared
This commit is contained in:
parent
ed84d47425
commit
4d71b527dc
195
src/plasma/private/theme_p.h
Normal file
195
src/plasma/private/theme_p.h
Normal file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2013 Marco Martin <mart@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.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_THEME_P_H
|
||||
#define PLASMA_THEME_P_H
|
||||
|
||||
#include <QHash>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <KColorScheme>
|
||||
#include <KImageCache>
|
||||
#include <KWindowSystem>
|
||||
#include <QTimer>
|
||||
|
||||
#if HAVE_X11
|
||||
#include "private/effectwatcher_p.h"
|
||||
#endif
|
||||
|
||||
#include "libplasma-theme-global.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
//NOTE: Default wallpaper can be set from the theme configuration
|
||||
#define DEFAULT_WALLPAPER_THEME "default"
|
||||
#define DEFAULT_WALLPAPER_SUFFIX ".png"
|
||||
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
||||
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
||||
|
||||
enum styles {
|
||||
DEFAULTSTYLE,
|
||||
SVGSTYLE
|
||||
};
|
||||
|
||||
enum CacheType {
|
||||
NoCache = 0,
|
||||
PixmapCache = 1,
|
||||
SvgElementsCache = 2
|
||||
};
|
||||
Q_DECLARE_FLAGS(CacheTypes, CacheType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(CacheTypes)
|
||||
|
||||
class ThemePrivate
|
||||
{
|
||||
public:
|
||||
ThemePrivate(Theme *theme)
|
||||
: q(theme),
|
||||
colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)),
|
||||
buttonColorScheme(QPalette::Active, KColorScheme::Button, KSharedConfigPtr(0)),
|
||||
viewColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(0)),
|
||||
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
|
||||
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
|
||||
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
|
||||
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
|
||||
pixmapCache(0),
|
||||
cacheSize(0),
|
||||
cachesToDiscard(NoCache),
|
||||
locolor(false),
|
||||
compositingActive(KWindowSystem::self()->compositingActive()),
|
||||
blurActive(false),
|
||||
isDefault(false),
|
||||
useGlobal(true),
|
||||
hasWallpapers(false)
|
||||
{
|
||||
ThemeConfig config;
|
||||
cacheTheme = config.cacheTheme();
|
||||
|
||||
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()));
|
||||
|
||||
if (QPixmap::defaultDepth() > 8) {
|
||||
#if HAVE_X11
|
||||
//watch for blur effect property changes as well
|
||||
if (!s_blurEffectWatcher) {
|
||||
s_blurEffectWatcher = new EffectWatcher("_KDE_NET_WM_BLUR_BEHIND_REGION");
|
||||
}
|
||||
|
||||
QObject::connect(s_blurEffectWatcher, SIGNAL(effectChanged(bool)), q, SLOT(blurBehindChanged(bool)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
~ThemePrivate()
|
||||
{
|
||||
delete pixmapCache;
|
||||
}
|
||||
|
||||
KConfigGroup &config()
|
||||
{
|
||||
if (!cfg.isValid()) {
|
||||
QString groupName = "Theme";
|
||||
|
||||
if (!useGlobal) {
|
||||
QString app = QCoreApplication::applicationName();
|
||||
|
||||
if (!app.isEmpty()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "using theme for app" << app;
|
||||
#endif
|
||||
groupName.append("-").append(app);
|
||||
}
|
||||
}
|
||||
|
||||
cfg = KConfigGroup(KSharedConfig::openConfig(themeRcFile), groupName);
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
QString findInTheme(const QString &image, const QString &theme, bool cache = true);
|
||||
void compositingChanged(bool active);
|
||||
void discardCache(CacheTypes caches);
|
||||
void scheduledCacheUpdate();
|
||||
void scheduleThemeChangeNotification(CacheTypes caches);
|
||||
void notifyOfChanged();
|
||||
void colorsChanged();
|
||||
void settingsChanged();
|
||||
void blurBehindChanged(bool blur);
|
||||
bool useCache();
|
||||
void settingsFileChanged(const QString &);
|
||||
void setThemeName(const QString &themeName, bool writeSettings);
|
||||
void onAppExitCleanup();
|
||||
void processWallpaperSettings(KConfigBase *metadata);
|
||||
|
||||
const QString processStyleSheet(const QString &css);
|
||||
|
||||
static const char *defaultTheme;
|
||||
static const char *systemColorsTheme;
|
||||
static const char *themeRcFile;
|
||||
#if HAVE_X11
|
||||
static EffectWatcher *s_blurEffectWatcher;
|
||||
#endif
|
||||
|
||||
Theme *q;
|
||||
QString themeName;
|
||||
KPluginInfo pluginInfo;
|
||||
QList<QString> fallbackThemes;
|
||||
KSharedConfigPtr colors;
|
||||
KColorScheme colorScheme;
|
||||
KColorScheme buttonColorScheme;
|
||||
KColorScheme viewColorScheme;
|
||||
KConfigGroup cfg;
|
||||
QString defaultWallpaperTheme;
|
||||
QString defaultWallpaperSuffix;
|
||||
int defaultWallpaperWidth;
|
||||
int defaultWallpaperHeight;
|
||||
KImageCache *pixmapCache;
|
||||
KSharedConfigPtr svgElementsCache;
|
||||
QHash<QString, QSet<QString> > invalidElements;
|
||||
QHash<QString, QPixmap> pixmapsToCache;
|
||||
QHash<QString, QString> keysToCache;
|
||||
QHash<QString, QString> idsToCache;
|
||||
QHash<styles, QString> cachedStyleSheets;
|
||||
QHash<QString, QString> discoveries;
|
||||
QTimer *saveTimer;
|
||||
QTimer *updateNotificationTimer;
|
||||
unsigned cacheSize;
|
||||
CacheTypes cachesToDiscard;
|
||||
|
||||
bool locolor : 1;
|
||||
bool compositingActive : 1;
|
||||
bool blurActive : 1;
|
||||
bool isDefault : 1;
|
||||
bool useGlobal : 1;
|
||||
bool hasWallpapers : 1;
|
||||
bool cacheTheme : 1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "theme.h"
|
||||
#include "private/theme_p.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
@ -29,10 +30,6 @@
|
||||
|
||||
#include "config-plasma.h"
|
||||
|
||||
#if HAVE_X11
|
||||
#include "private/effectwatcher_p.h"
|
||||
#endif
|
||||
|
||||
#include <kcolorscheme.h>
|
||||
#include <kcomponentdata.h>
|
||||
#include <kconfiggroup.h>
|
||||
@ -47,165 +44,11 @@
|
||||
#include <kwindowsystem.h>
|
||||
#include <qstandardpaths.h>
|
||||
|
||||
|
||||
#include "libplasma-theme-global.h"
|
||||
#include "private/packages_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
//NOTE: Default wallpaper can be set from the theme configuration
|
||||
#define DEFAULT_WALLPAPER_THEME "default"
|
||||
#define DEFAULT_WALLPAPER_SUFFIX ".png"
|
||||
static const int DEFAULT_WALLPAPER_WIDTH = 1920;
|
||||
static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
|
||||
|
||||
enum styles {
|
||||
DEFAULTSTYLE,
|
||||
SVGSTYLE
|
||||
};
|
||||
|
||||
enum CacheType {
|
||||
NoCache = 0,
|
||||
PixmapCache = 1,
|
||||
SvgElementsCache = 2
|
||||
};
|
||||
Q_DECLARE_FLAGS(CacheTypes, CacheType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(CacheTypes)
|
||||
|
||||
class ThemePrivate
|
||||
{
|
||||
public:
|
||||
ThemePrivate(Theme *theme)
|
||||
: q(theme),
|
||||
colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)),
|
||||
buttonColorScheme(QPalette::Active, KColorScheme::Button, KSharedConfigPtr(0)),
|
||||
viewColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(0)),
|
||||
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),
|
||||
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),
|
||||
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH),
|
||||
defaultWallpaperHeight(DEFAULT_WALLPAPER_HEIGHT),
|
||||
pixmapCache(0),
|
||||
cacheSize(0),
|
||||
cachesToDiscard(NoCache),
|
||||
locolor(false),
|
||||
compositingActive(KWindowSystem::self()->compositingActive()),
|
||||
blurActive(false),
|
||||
isDefault(false),
|
||||
useGlobal(true),
|
||||
hasWallpapers(false)
|
||||
{
|
||||
ThemeConfig config;
|
||||
cacheTheme = config.cacheTheme();
|
||||
|
||||
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()));
|
||||
|
||||
if (QPixmap::defaultDepth() > 8) {
|
||||
#if HAVE_X11
|
||||
//watch for blur effect property changes as well
|
||||
if (!s_blurEffectWatcher) {
|
||||
s_blurEffectWatcher = new EffectWatcher("_KDE_NET_WM_BLUR_BEHIND_REGION");
|
||||
}
|
||||
|
||||
QObject::connect(s_blurEffectWatcher, SIGNAL(effectChanged(bool)), q, SLOT(blurBehindChanged(bool)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
~ThemePrivate()
|
||||
{
|
||||
delete pixmapCache;
|
||||
}
|
||||
|
||||
KConfigGroup &config()
|
||||
{
|
||||
if (!cfg.isValid()) {
|
||||
QString groupName = "Theme";
|
||||
|
||||
if (!useGlobal) {
|
||||
QString app = QCoreApplication::applicationName();
|
||||
|
||||
if (!app.isEmpty()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "using theme for app" << app;
|
||||
#endif
|
||||
groupName.append("-").append(app);
|
||||
}
|
||||
}
|
||||
|
||||
cfg = KConfigGroup(KSharedConfig::openConfig(themeRcFile), groupName);
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
QString findInTheme(const QString &image, const QString &theme, bool cache = true);
|
||||
void compositingChanged(bool active);
|
||||
void discardCache(CacheTypes caches);
|
||||
void scheduledCacheUpdate();
|
||||
void scheduleThemeChangeNotification(CacheTypes caches);
|
||||
void notifyOfChanged();
|
||||
void colorsChanged();
|
||||
void settingsChanged();
|
||||
void blurBehindChanged(bool blur);
|
||||
bool useCache();
|
||||
void settingsFileChanged(const QString &);
|
||||
void setThemeName(const QString &themeName, bool writeSettings);
|
||||
void onAppExitCleanup();
|
||||
void processWallpaperSettings(KConfigBase *metadata);
|
||||
|
||||
const QString processStyleSheet(const QString &css);
|
||||
|
||||
static const char *defaultTheme;
|
||||
static const char *systemColorsTheme;
|
||||
static const char *themeRcFile;
|
||||
#if HAVE_X11
|
||||
static EffectWatcher *s_blurEffectWatcher;
|
||||
#endif
|
||||
|
||||
Theme *q;
|
||||
QString themeName;
|
||||
KPluginInfo pluginInfo;
|
||||
QList<QString> fallbackThemes;
|
||||
KSharedConfigPtr colors;
|
||||
KColorScheme colorScheme;
|
||||
KColorScheme buttonColorScheme;
|
||||
KColorScheme viewColorScheme;
|
||||
KConfigGroup cfg;
|
||||
QString defaultWallpaperTheme;
|
||||
QString defaultWallpaperSuffix;
|
||||
int defaultWallpaperWidth;
|
||||
int defaultWallpaperHeight;
|
||||
KImageCache *pixmapCache;
|
||||
KSharedConfigPtr svgElementsCache;
|
||||
QHash<QString, QSet<QString> > invalidElements;
|
||||
QHash<QString, QPixmap> pixmapsToCache;
|
||||
QHash<QString, QString> keysToCache;
|
||||
QHash<QString, QString> idsToCache;
|
||||
QHash<styles, QString> cachedStyleSheets;
|
||||
QHash<QString, QString> discoveries;
|
||||
QTimer *saveTimer;
|
||||
QTimer *updateNotificationTimer;
|
||||
unsigned cacheSize;
|
||||
CacheTypes cachesToDiscard;
|
||||
|
||||
bool locolor : 1;
|
||||
bool compositingActive : 1;
|
||||
bool blurActive : 1;
|
||||
bool isDefault : 1;
|
||||
bool useGlobal : 1;
|
||||
bool hasWallpapers : 1;
|
||||
bool cacheTheme : 1;
|
||||
};
|
||||
|
||||
const char *ThemePrivate::defaultTheme = "default";
|
||||
const char *ThemePrivate::themeRcFile = "plasmarc";
|
||||
// the system colors theme is used to cache unthemed svgs with colorization needs
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2013 Marco Martin <mart@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
|
||||
|
Loading…
Reference in New Issue
Block a user