* get rid of setApplication, use the component data instead

* don't keep opening the shared config; do it just once
* avoid copying the KConfigGroup object all the time

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800331
This commit is contained in:
Aaron J. Seigo 2008-04-23 22:24:07 +00:00
parent 0f53feb8af
commit 7f09f15378

View File

@ -29,6 +29,7 @@
#include <KColorScheme> #include <KColorScheme>
#include <KConfigGroup> #include <KConfigGroup>
#include <KDebug> #include <KDebug>
#include <KGlobal>
#include <KSelectionWatcher> #include <KSelectionWatcher>
#include <KSharedConfig> #include <KSharedConfig>
#include <KStandardDirs> #include <KStandardDirs>
@ -50,15 +51,21 @@ public:
generalFont = QApplication::font(); generalFont = QApplication::font();
} }
KConfigGroup config() KConfigGroup& config()
{ {
if (!cfg.isValid()) {
QString groupName = "Theme"; QString groupName = "Theme";
QString app = KGlobal::mainComponent().componentName();
if (!app.isEmpty() && app != "plasma") { if (!app.isEmpty() && app != "plasma") {
kDebug() << "using theme for app" << app;
groupName.append("-").append(app); groupName.append("-").append(app);
} }
KSharedConfigPtr config = KSharedConfig::openConfig("plasmarc"); cfg = KConfigGroup(KSharedConfig::openConfig("plasmarc"), groupName);
return KConfigGroup(config, groupName); }
return cfg;
} }
QString findInTheme(const QString &image, const QString &theme) const; QString findInTheme(const QString &image, const QString &theme) const;
@ -66,8 +73,8 @@ public:
static PackageStructure::Ptr packageStructure; static PackageStructure::Ptr packageStructure;
QString themeName; QString themeName;
QString app;
KSharedConfigPtr colors; KSharedConfigPtr colors;
KConfigGroup cfg;
QFont generalFont; QFont generalFont;
bool locolor; bool locolor;
bool compositingActive; bool compositingActive;
@ -133,14 +140,6 @@ PackageStructure::Ptr Theme::packageStructure()
return Private::packageStructure; return Private::packageStructure;
} }
void Theme::setApplication(const QString &appname)
{
if (d->app != appname) {
d->app = appname;
settingsChanged();
}
}
void Theme::settingsChanged() void Theme::settingsChanged()
{ {
setThemeName(d->config().readEntry("name", Private::defaultTheme)); setThemeName(d->config().readEntry("name", Private::defaultTheme));
@ -203,7 +202,7 @@ void Theme::setThemeName(const QString &themeName)
if (d->isDefault) { if (d->isDefault) {
// we're the default theme, let's save our state // we're the default theme, let's save our state
KConfigGroup cg = d->config(); KConfigGroup &cg = d->config();
if (Private::defaultTheme == d->themeName) { if (Private::defaultTheme == d->themeName) {
cg.deleteEntry("name"); cg.deleteEntry("name");
} else { } else {