* add ability to list info for all available themes

* add ability to create a Theme object for a specific theme without first accessing the defaults

svn path=/trunk/KDE/kdelibs/; revision=969464
This commit is contained in:
Aaron J. Seigo 2009-05-18 12:28:19 +00:00
parent c7399bcbc2
commit 8b7bb8b125
2 changed files with 59 additions and 20 deletions

View File

@ -70,6 +70,25 @@ public:
{
generalFont = QApplication::font();
cacheTheme = cacheConfig().readEntry("CacheTheme", true);
#ifdef Q_WS_X11
Display *dpy = QX11Info::display();
int screen = DefaultScreen(dpy);
locolor = DefaultDepth(dpy, screen) < 16;
if (!locolor) {
char net_wm_cm_name[100];
sprintf(net_wm_cm_name, "_NET_WM_CM_S%d", screen);
compositeWatch = new KSelectionWatcher(net_wm_cm_name, -1, q);
QObject::connect(compositeWatch, SIGNAL(newOwner(Window)), q, SLOT(compositingChanged()));
QObject::connect(compositeWatch, SIGNAL(lostOwner()), q, SLOT(compositingChanged()));
}
#endif
//FIXME: if/when kconfig gets change notification, this will be unecessary
KDirWatch::self()->addFile(KStandardDirs::locateLocal("config", ThemePrivate::themeRcFile));
QObject::connect(KDirWatch::self(), SIGNAL(created(QString)), q, SLOT(settingsFileChanged(QString)));
QObject::connect(KDirWatch::self(), SIGNAL(dirty(QString)), q, SLOT(settingsFileChanged(QString)));
}
~ThemePrivate()
@ -247,25 +266,17 @@ Theme::Theme(QObject *parent)
d(new ThemePrivate(this))
{
settingsChanged();
}
#ifdef Q_WS_X11
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()));
}
#endif
//FIXME: if/when kconfig gets change notification, this will be unecessary
KDirWatch::self()->addFile(KStandardDirs::locateLocal("config", ThemePrivate::themeRcFile));
connect(KDirWatch::self(), SIGNAL(created(QString)), this, SLOT(settingsFileChanged(QString)));
connect(KDirWatch::self(), SIGNAL(dirty(QString)), this, SLOT(settingsFileChanged(QString)));
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;
}
Theme::~Theme()
@ -289,11 +300,20 @@ PackageStructure::Ptr Theme::packageStructure()
return ThemePrivate::packageStructure;
}
KPluginInfo::List Theme::listThemeInfo()
{
QStringList themes = KGlobal::dirs()->findAllResources("data", "desktoptheme/*/metadata.desktop",
KStandardDirs::NoDuplicates);
return KPluginInfo::fromFiles(themes);
}
void ThemePrivate::settingsFileChanged(const QString &file)
{
kDebug() << file;
config().config()->reparseConfiguration();
q->settingsChanged();
if (file.endsWith(themeRcFile)) {
config().config()->reparseConfiguration();
q->settingsChanged();
}
}
void Theme::settingsChanged()

19
theme.h
View File

@ -24,6 +24,7 @@
#include <QtGui/QFont>
#include <QtGui/QFontMetrics>
#include <kplugininfo.h>
#include <ksharedconfig.h>
#include <plasma/plasma_export.h>
@ -79,8 +80,20 @@ class PLASMA_EXPORT Theme : public QObject
/**
* Default constructor. Usually you want to use the singleton instead.
* @see defaultTheme
* @arg parent the parent object
*/
explicit Theme(QObject *parent = 0);
/**
* Construct a theme. Usually you want to use the singleton instead.
* @see defaultTheme
* @arg themeName the name of the theme to create
* @arg parent the parent object
* @since 4.3
*/
explicit Theme(const QString &themeName, QObject *parent = 0);
~Theme();
/**
@ -88,6 +101,12 @@ class PLASMA_EXPORT Theme : public QObject
*/
static PackageStructure::Ptr packageStructure();
/**
* @return a list of all known themes
* @since 4.3
*/
static KPluginInfo::List listThemeInfo();
/**
* Sets the current theme being used.
*/