[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/plasma
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2010-12-03 17:09:09
Message-ID: 20101203170909.5EA77AC8A5 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1203345 by aseigo:

* this introduces a Theme object used by Svg to cache the rendering of svg's asking \
to be colorized, but which are not part of the theme. this requires an independent \
                cache and set of color files, therefore a second Theme object.
* not dropping the cache just because we change themes; this made sense when just \
plasma-desktop used this or when the apps using Plasma::Theme all used the same \
theme. this is no longer the case, really, and having applications changing themes \
randomly kicking the cache out from underneath other apps that may still be using it \
is undesirable. this does mean that cache files will accumulate. not sure that's a \
big issue as they don't tend to be large and are in an area marked as "cache" (so \
                ripe for clean-without-care)
* cleanups such as getting rid of superfluous use of Plasma:: namespacing in code \
that is now in libplasma, such as the stylesheeting. (it was from a plasmoid sebas \
wrote originally, iirc, explaining the historical reason for the explicit \
namespacing)


 M  +49 -30    theme.cpp  


--- trunk/KDE/kdelibs/plasma/theme.cpp #1203344:1203345
@@ -69,7 +69,7 @@
         : q(theme),
           colorScheme(QPalette::Active, KColorScheme::Window, KSharedConfigPtr(0)),
           buttonColorScheme(QPalette::Active, KColorScheme::Button, \
                KSharedConfigPtr(0)),
-          viewColorScheme(KColorScheme(QPalette::Active, KColorScheme::View, \
KSharedConfigPtr(0))), +          viewColorScheme(QPalette::Active, \
KColorScheme::View, KSharedConfigPtr(0)),  \
defaultWallpaperTheme(DEFAULT_WALLPAPER_THEME),  \
defaultWallpaperSuffix(DEFAULT_WALLPAPER_SUFFIX),  \
defaultWallpaperWidth(DEFAULT_WALLPAPER_WIDTH), @@ -145,6 +145,7 @@
     const QString processStyleSheet(const QString &css);
 
     static const char *defaultTheme;
+    static const char *systemColorsTheme;
     static const char *themeRcFile;
     static PackageStructure::Ptr packageStructure;
 
@@ -186,6 +187,9 @@
 PackageStructure::Ptr ThemePrivate::packageStructure(0);
 const char *ThemePrivate::defaultTheme = "default";
 const char *ThemePrivate::themeRcFile = "plasmarc";
+// the system colors theme is used to cache unthemed svgs with colorization needs
+// these svgs do not follow the theme's colors, but rather the system colors
+const char *ThemePrivate::systemColorsTheme = "internal-system-colors";
 
 bool ThemePrivate::useCache()
 {
@@ -347,25 +351,25 @@
     QHash<QString, QString> elements;
     // If you add elements here, make sure their names are sufficiently unique to \
not cause  // clashes between element keys
-    elements["%textcolor"] = q->color(Plasma::Theme::TextColor).name();
-    elements["%backgroundcolor"] = q->color(Plasma::Theme::BackgroundColor).name();
-    elements["%visitedlink"] = q->color(Plasma::Theme::VisitedLinkColor).name();
-    elements["%activatedlink"] = q->color(Plasma::Theme::HighlightColor).name();
-    elements["%hoveredlink"] = q->color(Plasma::Theme::HighlightColor).name();
-    elements["%link"] = q->color(Plasma::Theme::LinkColor).name();
-    elements["%buttontextcolor"] = q->color(Plasma::Theme::ButtonTextColor).name();
-    elements["%buttonbackgroundcolor"] = \
                q->color(Plasma::Theme::ButtonBackgroundColor).name();
-    elements["%buttonhovercolor"] = \
                q->color(Plasma::Theme::ButtonHoverColor).name();
-    elements["%buttonfocuscolor"] = \
                q->color(Plasma::Theme::ButtonFocusColor).name();
-    elements["%viewtextcolor"] = q->color(Plasma::Theme::ViewTextColor).name();
-    elements["%viewbackgroundcolor"] = \
                q->color(Plasma::Theme::ViewBackgroundColor).name();
-    elements["%viewhovercolor"] = q->color(Plasma::Theme::ViewHoverColor).name();
-    elements["%viewfocuscolor"] = q->color(Plasma::Theme::ViewFocusColor).name();
-    elements["%smallfontsize"] = \
QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize()); +    \
elements["%textcolor"] = q->color(Theme::TextColor).name(); +    \
elements["%backgroundcolor"] = q->color(Theme::BackgroundColor).name(); +    \
elements["%visitedlink"] = q->color(Theme::VisitedLinkColor).name(); +    \
elements["%activatedlink"] = q->color(Theme::HighlightColor).name(); +    \
elements["%hoveredlink"] = q->color(Theme::HighlightColor).name(); +    \
elements["%link"] = q->color(Theme::LinkColor).name(); +    \
elements["%buttontextcolor"] = q->color(Theme::ButtonTextColor).name(); +    \
elements["%buttonbackgroundcolor"] = q->color(Theme::ButtonBackgroundColor).name(); + \
elements["%buttonhovercolor"] = q->color(Theme::ButtonHoverColor).name(); +    \
elements["%buttonfocuscolor"] = q->color(Theme::ButtonFocusColor).name(); +    \
elements["%viewtextcolor"] = q->color(Theme::ViewTextColor).name(); +    \
elements["%viewbackgroundcolor"] = q->color(Theme::ViewBackgroundColor).name(); +    \
elements["%viewhovercolor"] = q->color(Theme::ViewHoverColor).name(); +    \
elements["%viewfocuscolor"] = q->color(Theme::ViewFocusColor).name();  
-    QFont font = q->font(Plasma::Theme::DefaultFont);
+    QFont font = q->font(Theme::DefaultFont);
     elements["%fontsize"] = QString("%1pt").arg(font.pointSize());
     elements["%fontfamily"] = font.family();
+    elements["%smallfontsize"] = \
QString("%1pt").arg(KGlobalSettings::smallestReadableFont().pointSize());  
     foreach (const QString &k, elements.keys()) {
         stylesheet.replace(k, elements[k]);
@@ -526,7 +530,10 @@
         }
     }
 
-    //TODO: should we care about names with relative paths in them?
+    // we have one special theme: essentially a dummy theme used to cache things \
with +    // the system colors.
+    bool realTheme = theme != systemColorsTheme;
+    if (realTheme) {
     QString themePath = KStandardDirs::locate("data", \
QLatin1Literal("desktoptheme/") % theme % QLatin1Char('/'));  if (themePath.isEmpty() \
                && themeName.isEmpty()) {
         themePath = KStandardDirs::locate("data", "desktoptheme/default/");
@@ -537,6 +544,7 @@
 
         theme = ThemePrivate::defaultTheme;
     }
+    }
 
     // check again as ThemePrivate::defaultTheme might be empty
     if (themeName == theme) {
@@ -548,10 +556,14 @@
     themeName = theme;
 
     // load the color scheme config
-    const QString colorsFile = KStandardDirs::locate("data", \
QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/colors")); +    const \
QString colorsFile = realTheme ? KStandardDirs::locate("data", \
QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/colors")) +                \
: QString(); +
     //kDebug() << "we're going for..." << colorsFile << "*******************";
+    bool expireCache = false;
 
     // load the wallpaper settings, if any
+    if (realTheme) {
     const QString metadataPath(KStandardDirs::locate("data", \
QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/metadata.desktop")));  \
KConfig metadata(metadataPath);  
@@ -590,14 +602,25 @@
         processWallpaperSettings(&metadata);
     }
 
-    QObject::disconnect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
-                        q, SLOT(colorsChanged()));
+        //check for expired cache
+        // FIXME: when using the system colors, if they change while the application \
is not running +        // the cache should be dropped; we need a way to detect \
system color change when the +        // application is not running.
+        QFile f(metadataPath);
+        QFileInfo info(f);
 
+        if (useCache() && info.lastModified().toTime_t() > \
pixmapCache->lastModifiedTime()) { +            expireCache = true;
+        }
+    }
+
     if (colorsFile.isEmpty()) {
         colors = 0;
         QObject::connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
+                         q, SLOT(colorsChanged()), Qt::UniqueConnection);
+    } else {
+        QObject::disconnect(KGlobalSettings::self(), \
SIGNAL(kdisplayPaletteChanged()),  q, SLOT(colorsChanged()));
-    } else {
         colors = KSharedConfig::openConfig(colorsFile);
     }
 
@@ -606,7 +629,7 @@
     viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
     hasWallpapers = KStandardDirs::exists(KStandardDirs::locateLocal("data", \
QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/wallpapers/")));  
-    if (isDefault && writeSettings) {
+    if (realTheme && isDefault && writeSettings) {
         // we're the default theme, let's save our state
         KConfigGroup &cg = config();
         if (ThemePrivate::defaultTheme == themeName) {
@@ -617,11 +640,7 @@
         cg.sync();
     }
 
-    //check for expired cache
-    QFile f(metadataPath);
-    QFileInfo info(f);
-
-    if (useCache() && (!oldThemeName.isEmpty() || info.lastModified().toTime_t() > \
pixmapCache->lastModifiedTime())) { +    if (expireCache) {
         discardCache(oldThemeName);
     } else {
         QString svgElementsFile = KStandardDirs::locateLocal("cache", \
QLatin1Literal("plasma-svgelements-") % themeName); @@ -870,7 +889,7 @@
         const QString id = d->keysToCache.value(key);
         if (d->pixmapsToCache.contains(id)) {
             pix = d->pixmapsToCache.value(id);
-            return true;
+            return !pix.isNull();
         }
 
         QPixmap temp;
@@ -878,7 +897,6 @@
             pix = temp;
             return true;
         }
-        return false;
     }
 
     return false;
@@ -1011,6 +1029,7 @@
 
 void Theme::setCacheLimit(int kbytes)
 {
+    Q_UNUSED(kbytes)
     if (d->useCache()) {
         ;
         // Too late for you bub.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic