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-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()
|
|
|
|
: themeName( "default" )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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()
|
|
|
|
{
|
|
|
|
QString groupName = "Theme";
|
|
|
|
if (!d->app.isEmpty() && d->app != "plasma") {
|
|
|
|
groupName.append("-").append(d->app);
|
|
|
|
}
|
|
|
|
|
|
|
|
KSharedConfig::Ptr config = KSharedConfig::openConfig("plasmarc");
|
|
|
|
KConfigGroup group(config, groupName);
|
|
|
|
QString themeName = group.readEntry("name", d->themeName);
|
|
|
|
if (themeName != d->themeName) {
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if ( path.isEmpty() ) {
|
|
|
|
kDebug() << "Theme says: bad image path " << name
|
|
|
|
<< "; looked in: " << search
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2006-12-17 00:04:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <theme.moc>
|