Index: ./browser/components/shell/content/setDesktopBackground.js =================================================================== RCS file: /cvsroot/mozilla/browser/components/shell/content/setDesktopBackground.js,v retrieving revision 1.3.4.2 diff -u -r1.3.4.2 setDesktopBackground.js --- ./browser/components/shell/content/setDesktopBackground.js 1 Sep 2006 14:27:15 -0000 1.3.4.2 +++ ./browser/components/shell/content/setDesktopBackground.js 3 May 2007 16:36:46 -0000 @@ -42,6 +42,8 @@ const kIMacShellService = Components.interfaces.nsIMacShellService; #endif +var isKDEDesktop = "false"; + var gSetBackground = { _position : kIShellService.BACKGROUND_STRETCH, _monitor : null, @@ -108,6 +110,7 @@ var position = kIShellService.BACKGROUND_STRETCH; #endif this.updatePosition(position); + this.readKdesktoprc(); }, #ifndef XP_MACOSX @@ -168,11 +171,19 @@ this._shell.setDesktopBackground(this._image, this._position); this._shell.desktopBackgroundColor = this._hexStringToLong(this._backgroundColor); document.persist("menuPosition", "value"); + //set kde wallpaper - yes also set the gconf pref + this.setKDEwallpaper(); + this.setKDEbackground(this._backgroundColor); }, #endif updateColor: function (color) { + if (this.isKDEDesktop == "true") { + this._backgroundColor = color; + this._monitor.style.backgroundColor = color; + } + #ifndef XP_MACOSX this._backgroundColor = color; @@ -228,8 +239,9 @@ _tileImage: function () { var bundle = document.getElementById("backgroundBundle"); - - this._monitor.style.backgroundColor = "white"; + //Doing this makes the user think the background is also being changed + //so I'm commenting it out. + //this._monitor.style.backgroundColor = "white"; var text = document.createElementNS(kXUL_NS, "label"); text.setAttribute("id", "noPreviewAvailable"); @@ -249,5 +261,148 @@ img.width = Math.floor(width); img.height = Math.floor(height); this._monitor.appendChild(img); + }, + + setKDEwallpaper: function () + { + //set kde wallpaper - yes also set the gconf pref + var fileConstruct = Components.Constructor("@mozilla.org/file/local;1", "nsILocalFile"); + var filePath = new fileConstruct(); + + var processIface = Components.classes["@mozilla.org/process/util;1"].createInstance(); + processIface = processIface.QueryInterface(Components.interfaces.nsIProcess); + var homePath = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment); + homePath = homePath.get("HOME"); + homePath += "/Web Browser_wallpaper.png"; + try { + var imgPosition = document.getElementById("menuPosition").value; + + switch(imgPosition) { + case "1": + //tiled + imgPosition = 3; + break; + case "2": + // stretch + imgPosition = 6; + break; + case "3": + //centred + imgPosition = 7; + break; + default: + imgPosition = 4; + break; + + } + var progObj = new Object(); + var blockingBool; + var procToStart = "/usr/bin/dcop"; + var procArgs = ["kdesktop", "KBackgroundIface", "setWallpaper", homePath, imgPosition]; + filePath.initWithPath(procToStart); + processIface.init(filePath); + + progObj.value = 19; + processIface.run( blockingBool, procArgs, procArgs.length, progObj); + } catch (e) { + //dump("FAILURE OF RUN :: " + e + "\n"); + } + }, + + setKDEbackground: function (color) + { + //set kde background color - yes also set the gconf pref + var fileConstruct = Components.Constructor("@mozilla.org/file/local;1", "nsILocalFile"); + var filePath = new fileConstruct(); + + var processIface = Components.classes["@mozilla.org/process/util;1"].createInstance(); + processIface = processIface.QueryInterface(Components.interfaces.nsIProcess); + + var progObj = new Object(); + var blockingBool; + var procToStart = "/usr/bin/dcop"; + var procArgs = ["kdesktop", "KBackgroundIface", "setColor", color, true]; + filePath.initWithPath(procToStart); + processIface.init(filePath); + try { + progObj.value = 19; + processIface.run( blockingBool, procArgs, procArgs.length, progObj); + } catch (e) { + //dump("FAILURE OF RUN :: " + e + "\n"); + } + + }, + + readKdesktoprc: function() + { +try { + var localFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); + + var inputFile = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); + + var readInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); + + var homePath = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment); + // construct path to kdesktoprc using env var $HOME + homePath = homePath.get("HOME") + "/.kde/share/config/kdesktoprc"; + + localFile.initWithPath(homePath); + + var tmp; + inputFile.init(localFile, 0x01, 444, tmp); + readInputStream.init(inputFile); + var fileStream = readInputStream.read(-1); + + inputFile.close(); + readInputStream.close(); + + //look thru kdesktoprc for Desktop0 Color1 + var lineCount = fileStream.split(/\s+/); + var j; + for(var i = 0; i < lineCount.length; i++) { + if (lineCount[i] == "[Desktop0]") { + dump("--Kdesktop " + i + ": " + lineCount[i] + "\n"); + for( j = i; j < lineCount.length; j++) { + tmp = lineCount[j].substring(0,6); + if(tmp == "Color1") { + //set the color if found + var tempLine = lineCount[j].split("="); + dump("**Kdesktop " + tmp + " : " + j + ": " + tempLine[1] + "\n"); + this.TestrgbToHex(tempLine[1]); + i = j = lineCount.length; //no need to look further + this.isKDEDesktop = "true"; //we found our color so we are KDE + } + } + } + } + +} catch (e) { + // Propably failed on file not found - must not be a kde desktop + //dump("readKdesktoprc failed because: " + e); +} + + }, + + TestrgbToHex: function(tempLine) + { + //for example change 255,255,255 into #FFFFFF + var temp = tempLine.split(","); + var aR = parseInt(temp[0]); + var aG = parseInt(temp[1]); + var aB = parseInt(temp[2]); + + var rHex = aR.toString(16).toUpperCase(); + var gHex = aG.toString(16).toUpperCase(); + var bHex = aB.toString(16).toUpperCase(); + + if (rHex.length == 1) rHex ='0' + rHex; + if (gHex.length == 1) gHex ='0' + gHex; + if (bHex.length == 1) bHex ='0' + bHex; + + var tempb = '#' + rHex + gHex + bHex; + document.getElementById("desktopColor").color = tempb; + document.getElementById("monitor").style.backgroundColor = tempb; + this._backgroundColor = tempb; } + };