KDE/kdebase/workspace/libs/plasma

Aaron J. Seigo aseigo at kde.org
Sat Jun 28 20:57:13 CEST 2008


SVN commit 825592 by aseigo:

Plasma::Theme::wallpaperPath(const QSize&)

a nice improvement that fixes a small handful of packaging bugs and nuisances.
it allows us to do away with harcoding the wallpaper in multiple places (previously 3 places) in application code. as an extra bonus is also allows:

* the theme to define the default wallpaper
* the theme to ship with a default wallpaper (perhaps later on we can load wallpapers shipped with a theme in the config dialog?)
* the default wallpaper to defined in the plasmarc file (so downstream doesn't have to hack the code to change it)

CCMAIL:panel-devel at kde.org
CCMAIL:kde-artists at kde.org


 M  +81 -6     theme.cpp  
 M  +10 -1     theme.h  


--- trunk/KDE/kdebase/workspace/libs/plasma/theme.cpp #825591:825592
@@ -40,6 +40,11 @@
 namespace Plasma
 {
 
+#define DEFAULT_WALLPAPER_THEME "Blue_Curl";
+#define DEFAULT_WALLPAPER_FORMAT ".jpg";
+static const int DEFAULT_WALLPAPER_WIDTH = 1920;
+static const int DEFAULT_WALLPAPER_HEIGHT = 1200;
+
 class Theme::Private
 {
 public:
@@ -102,16 +107,16 @@
     QString search;
 
     if (locolor) {
-        search = "desktoptheme/" + theme + "/locolor/" + image + ".svg";
+        search = "desktoptheme/" + theme + "/locolor/" + image;
         search =  KStandardDirs::locate("data", search);
     } else if (!compositingActive) {
-        search = "desktoptheme/" + theme + "/opaque/" + image + ".svg";
+        search = "desktoptheme/" + theme + "/opaque/" + image;
         search =  KStandardDirs::locate("data", search);
     }
 
     //not found or compositing enabled
     if (search.isEmpty()) {
-        search = "desktoptheme/" + theme + '/' + image + ".svg";
+        search = "desktoptheme/" + theme + '/' + image;
         search =  KStandardDirs::locate("data", search);
     }
 
@@ -246,10 +251,10 @@
 
 QString Theme::imagePath(const QString& name)  const
 {
-    QString path = d->findInTheme(name, d->themeName);
+    QString path = d->findInTheme(name + ".svg", d->themeName);
 
     if (path.isEmpty() && d->themeName != Private::defaultTheme) {
-        path = d->findInTheme(name, Private::defaultTheme);
+        path = d->findInTheme(name + ".svg", Private::defaultTheme);
     }
 
     if (path.isEmpty()) {
@@ -259,9 +264,79 @@
     return path;
 }
 
+QString Theme::wallpaperPath(const QSize &size) const
+{
+    QString fullPath;
+    QString image = DEFAULT_WALLPAPER_THEME;
+    QString format = DEFAULT_WALLPAPER_FORMAT;
+    int width = DEFAULT_WALLPAPER_WIDTH;
+    int height = DEFAULT_WALLPAPER_HEIGHT;
+
+    if (size.isValid()) {
+        width = size.width();
+        height = size.height();
+    }
+
+    bool checkInTheme = false;
+    if (d->colors) {
+        // we have a theme color config, so let's also check to see if
+        // there is a wallpaper defined in there.
+        KConfigGroup cg(d->colors, "Wallpaper");
+        if (cg.hasKey("wallpaper")) {
+            checkInTheme = true;
+            image = cg.readEntry("defaultTheme", image);
+            format = cg.readEntry("defaultFileSuffix", format);
+            width = cg.readEntry("defaultWidth", width);
+            height = cg.readEntry("defaultHeight", height);
+        }
+    }
+
+    if (!checkInTheme) {
+        // since we didn't find an entry in the theme, let's look in the main
+        // theme config
+        KConfigGroup &cg = d->config();
+        image = cg.readEntry("defaultTheme", image);
+    }
+
+    image.append("/contents/images/%1x%2").append(format);
+    //TODO: this should do better than just fallback to the default size.
+    //      a "best fit" matching would be far better, so we don't end
+    //      up returning a 1900x1200 wallpaper for a 640x480 request ;)
+    QString defaultImage = image.arg(DEFAULT_WALLPAPER_WIDTH).arg(DEFAULT_WALLPAPER_HEIGHT);
+    image = image.arg(width).arg(height);
+
+    if (checkInTheme) {
+        // check in the theme, since it was defined in the colors config
+        fullPath = d->findInTheme("wallpaper/" + image, d->themeName);
+
+        if (fullPath.isEmpty()) {
+            fullPath = d->findInTheme("wallpaper/" + defaultImage, d->themeName);
+        }
+    }
+
+    if (fullPath.isEmpty()) {
+        // we failed to find it in the theme, so look in the standard directories
+        kDebug() << "looking for" << image;
+        fullPath = KStandardDirs::locate("wallpaper", image);
+    }
+
+    if (fullPath.isEmpty()) {
+        // we still failed to find it in the theme, so look for the default in
+        // the standard directories
+        kDebug() << "looking for" << defaultImage;
+        fullPath = KStandardDirs::locate("wallpaper", defaultImage);
+
+        if (fullPath.isEmpty()) {
+            kDebug() << "exhausted every effort to find a wallpaper.";
+        }
+    }
+
+    return fullPath;
+}
+
 bool Theme::currentThemeHasImage(const QString& name)  const
 {
-    return (!d->findInTheme(name, d->themeName).isEmpty());
+    return (!d->findInTheme(name + ".svg", d->themeName).isEmpty());
 }
 
 KSharedConfigPtr Theme::colorScheme() const
--- trunk/KDE/kdebase/workspace/libs/plasma/theme.h #825591:825592
@@ -98,9 +98,18 @@
          *           ".svg" part or a leading slash)
          * @return the full path to the requested file for the current theme
          */
-        Q_INVOKABLE QString imagePath( const QString& name ) const;
+        Q_INVOKABLE QString imagePath(const QString& name) const;
 
         /**
+         * Retreives the default wallpaper associated with this theme.
+         * 
+         * @arg size the target height and width of the wallpaper; if an invalid size
+         *           is passed in, then a default size will be provided instead.
+         * @return the full path to the wallpaper image
+         */
+         Q_INVOKABLE QString wallpaperPath(const QSize &size = QSize()) const;
+
+        /**
          * Checks if this theme has an image named in a certain way
          *
          * @arg name the name of the file in the theme directory (without the


More information about the Panel-devel mailing list