* allow setting of the theme name (easier runtime configurability)

* if the requested theme does not exist, don't accept it
* if the requested svg can't be found in the current theme, try to find it in the default theme

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=732507
This commit is contained in:
Aaron J. Seigo 2007-11-04 03:04:55 +00:00
parent a5b02c9e66
commit c8e196295f
2 changed files with 35 additions and 14 deletions

View File

@ -31,10 +31,21 @@ class Theme::Private
{
public:
Private()
: themeName( "default" )
: themeName("default")
{
}
KConfigGroup config()
{
QString groupName = "Theme";
if (!app.isEmpty() && app != "plasma") {
groupName.append("-").append(app);
}
KSharedConfig::Ptr config = KSharedConfig::openConfig("plasmarc");
return KConfigGroup(config, groupName);
}
QString themeName;
QString app;
};
@ -61,6 +72,7 @@ Theme::Theme(QObject* parent)
Theme::~Theme()
{
d->config().writeEntry("name", d->themeName);
delete d;
}
@ -74,15 +86,13 @@ void Theme::setApplication(const QString &appname)
void Theme::settingsChanged()
{
QString groupName = "Theme";
if (!d->app.isEmpty() && d->app != "plasma") {
groupName.append("-").append(d->app);
}
setThemeName(d->config().readEntry("name", d->themeName));
}
KSharedConfig::Ptr config = KSharedConfig::openConfig("plasmarc");
KConfigGroup group(config, groupName);
QString themeName = group.readEntry("name", d->themeName);
if (themeName != d->themeName) {
void Theme::setThemeName(const QString &themeName)
{
if (themeName != d->themeName &&
!KStandardDirs::locate("data", "desktoptheme/" + d->themeName).isEmpty()) {
d->themeName = themeName;
emit changed();
}
@ -98,10 +108,16 @@ QString Theme::image( const QString& name ) const
QString search = "desktoptheme/" + d->themeName + '/' + name + ".svg";
QString path = KStandardDirs::locate( "data", search );
if ( path.isEmpty() ) {
kDebug() << "Theme says: bad image path " << name
<< "; looked in: " << search
<< endl;
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;
}
}
return path;

View File

@ -69,7 +69,12 @@ class PLASMA_EXPORT Theme : public QObject
void setApplication(const QString &appname);
/**
* @return the name of the theme. "default" is none set.
* Sets the current theme being used.
*/
void setThemeName(const QString &themeName);
/**
* @return the name of the theme.
*/
QString themeName() const;