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>
|
|
|
|
|
2007-11-27 22:56:47 +01:00
|
|
|
#include <KColorScheme>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KDebug>
|
2006-12-17 00:04:44 +01:00
|
|
|
#include <KSharedConfig>
|
|
|
|
#include <KStandardDirs>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class Theme::Private
|
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
public:
|
|
|
|
Private()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-04 04:04:55 +01:00
|
|
|
KConfigGroup config()
|
|
|
|
{
|
|
|
|
QString groupName = "Theme";
|
|
|
|
if (!app.isEmpty() && app != "plasma") {
|
|
|
|
groupName.append("-").append(app);
|
|
|
|
}
|
|
|
|
|
2007-11-04 07:57:42 +01:00
|
|
|
KSharedConfigPtr config = KSharedConfig::openConfig("plasmarc");
|
2007-11-04 04:04:55 +01:00
|
|
|
return KConfigGroup(config, groupName);
|
|
|
|
}
|
|
|
|
|
2007-07-17 22:51:12 +02:00
|
|
|
QString themeName;
|
|
|
|
QString app;
|
2007-11-04 07:57:42 +01:00
|
|
|
KSharedConfigPtr colors;
|
2006-12-17 00:04:44 +01:00
|
|
|
};
|
|
|
|
|
2007-03-08 00:27:37 +01:00
|
|
|
class ThemeSingleton
|
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
public:
|
|
|
|
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
|
|
|
|
|
|
|
Theme* Theme::self()
|
|
|
|
{
|
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),
|
|
|
|
d(new Private)
|
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
settingsChanged();
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Theme::~Theme()
|
|
|
|
{
|
2007-11-04 04:04:55 +01:00
|
|
|
d->config().writeEntry("name", d->themeName);
|
2007-06-07 22:57:18 +02:00
|
|
|
delete d;
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
2007-07-17 22:51:12 +02:00
|
|
|
void Theme::setApplication(const QString &appname)
|
|
|
|
{
|
|
|
|
if (d->app != appname) {
|
|
|
|
d->app = appname;
|
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Theme::settingsChanged()
|
|
|
|
{
|
2007-11-04 07:57:42 +01:00
|
|
|
setThemeName(d->config().readEntry("name", "default"));
|
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)
|
|
|
|
{
|
2007-11-04 07:57:42 +01:00
|
|
|
if (themeName.isEmpty() || themeName == d->themeName) {
|
|
|
|
// let's try and get the default theme at least
|
|
|
|
if (d->themeName.isEmpty()) {
|
|
|
|
setThemeName("default");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: should we care about names with relative paths in them?
|
|
|
|
QString themePath = KStandardDirs::locate("data", "desktoptheme/" + themeName + "/");
|
|
|
|
if (themePath.isEmpty()) {
|
|
|
|
// let's try and get the default theme at least
|
|
|
|
if (d->themeName.isEmpty() && themeName != "default") {
|
|
|
|
setThemeName("default");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->themeName = themeName;
|
|
|
|
|
|
|
|
// load the color scheme config
|
|
|
|
themePath = themePath.append("colors");
|
|
|
|
if (QFile::exists(themePath)) {
|
|
|
|
d->colors = KSharedConfig::openConfig(themePath);
|
|
|
|
} else {
|
|
|
|
d->colors = 0;
|
2007-07-17 22:51:12 +02:00
|
|
|
}
|
2007-11-04 07:57:42 +01:00
|
|
|
|
|
|
|
emit changed();
|
2007-07-17 22:51:12 +02:00
|
|
|
}
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
QString Theme::themeName() const
|
|
|
|
{
|
|
|
|
return d->themeName;
|
|
|
|
}
|
|
|
|
|
2007-03-05 01:07:21 +01:00
|
|
|
QString Theme::image( const QString& name ) const
|
2006-12-17 00:04:44 +01:00
|
|
|
{
|
2007-11-04 07:57:42 +01:00
|
|
|
//TODO: performance ... should we try and cache the results of KStandardDirs::locate?
|
|
|
|
// should we just use whatever theme path was returned and not care about cascades?
|
|
|
|
// (probably "no" on the last question)
|
2007-05-13 19:47:20 +02:00
|
|
|
QString search = "desktoptheme/" + d->themeName + '/' + name + ".svg";
|
2007-03-08 00:27:37 +01:00
|
|
|
QString path = KStandardDirs::locate( "data", search );
|
|
|
|
|
2007-11-04 04:04:55 +01:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
if (d->themeName != "default") {
|
|
|
|
search = "desktoptheme/default/" + name + ".svg";
|
|
|
|
path = KStandardDirs::locate("data", search);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
kDebug() << "Theme says: bad image path " << name
|
|
|
|
<< "; looked in: " << search << endl;
|
|
|
|
}
|
2007-03-08 00:27:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
2007-11-04 07:57:42 +01:00
|
|
|
KSharedConfigPtr Theme::colors() const
|
|
|
|
{
|
|
|
|
return d->colors;
|
|
|
|
}
|
|
|
|
|
2007-11-27 22:56:47 +01:00
|
|
|
QColor Theme::textColor() const
|
|
|
|
{
|
2007-11-28 04:20:56 +01:00
|
|
|
KColorScheme colors(QPalette::Active, KColorScheme::Window, Theme::self()->colors());
|
2007-11-27 22:56:47 +01:00
|
|
|
return colors.foreground(KColorScheme::NormalText).color();
|
|
|
|
}
|
|
|
|
|
2007-12-19 20:56:39 +01:00
|
|
|
QFont Theme::font() const
|
|
|
|
{
|
|
|
|
//TODO: allow this to be overridden with a plasma specific font?
|
|
|
|
return QApplication::font();
|
|
|
|
}
|
|
|
|
|
|
|
|
QFontMetrics Theme::fontMetrics() const
|
|
|
|
{
|
|
|
|
//TODO: allow this to be overridden with a plasma specific font?
|
|
|
|
return QApplication::fontMetrics();
|
|
|
|
}
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <theme.moc>
|