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"
|
|
|
|
|
2006-12-17 00:04:44 +01:00
|
|
|
#include <KSharedConfig>
|
|
|
|
#include <KStandardDirs>
|
2007-10-06 00:21:25 +02:00
|
|
|
#include <kdebug.h>
|
2007-01-29 18:14:20 +01:00
|
|
|
#include <kconfiggroup.h>
|
2006-12-17 00:04:44 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class Theme::Private
|
|
|
|
{
|
2007-07-17 22:51:12 +02:00
|
|
|
public:
|
|
|
|
Private()
|
2007-11-04 04:04:55 +01:00
|
|
|
: themeName("default")
|
2007-07-17 22:51:12 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-04 04:04:55 +01:00
|
|
|
KConfigGroup config()
|
|
|
|
{
|
|
|
|
QString groupName = "Theme";
|
|
|
|
if (!app.isEmpty() && app != "plasma") {
|
|
|
|
groupName.append("-").append(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
KSharedConfig::Ptr config = KSharedConfig::openConfig("plasmarc");
|
|
|
|
return KConfigGroup(config, groupName);
|
|
|
|
}
|
|
|
|
|
2007-07-17 22:51:12 +02:00
|
|
|
QString themeName;
|
|
|
|
QString app;
|
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 04:04:55 +01:00
|
|
|
setThemeName(d->config().readEntry("name", d->themeName));
|
|
|
|
}
|
2007-07-17 22:51:12 +02:00
|
|
|
|
2007-11-04 04:04:55 +01:00
|
|
|
void Theme::setThemeName(const QString &themeName)
|
|
|
|
{
|
|
|
|
if (themeName != d->themeName &&
|
|
|
|
!KStandardDirs::locate("data", "desktoptheme/" + d->themeName).isEmpty()) {
|
2007-07-17 22:51:12 +02:00
|
|
|
d->themeName = themeName;
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <theme.moc>
|