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

View File

@ -69,7 +69,12 @@ class PLASMA_EXPORT Theme : public QObject
void setApplication(const QString &appname); 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; QString themeName() const;