diff --git a/browser/components/shell/src/nsGNOMEShellService.cpp b/browser/components/shell/src/nsGNOMEShellService.cpp index 2fde1ebe5876..dcaff2e3f064 100644 --- a/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/browser/components/shell/src/nsGNOMEShellService.cpp @@ -46,6 +46,7 @@ #include "nsStringAPI.h" #include "nsIGConfService.h" #include "nsIGIOService.h" +#include "nsIGSettingsService.h" #include "nsIStringBundle.h" #include "nsIOutputStream.h" #include "nsIProcess.h" @@ -101,19 +102,27 @@ static const char kDesktopOptionsKey[] = DG_BACKGROUND "/picture_options"; static const char kDesktopDrawBGKey[] = DG_BACKGROUND "/draw_background"; static const char kDesktopColorKey[] = DG_BACKGROUND "/primary_color"; +static const char kDesktopBGSchema[] = "org.gnome.desktop.background"; +static const char kDesktopImageGSKey[] = "picture-uri"; +static const char kDesktopOptionGSKey[] = "picture-options"; +static const char kDesktopDrawBGGSKey[] = "draw-background"; +static const char kDesktopColorGSKey[] = "primary-color"; + nsresult nsGNOMEShellService::Init() { nsresult rv; - // GConf or GIO _must_ be available, or we do not allow + // GConf, GSettings or GIO _must_ be available, or we do not allow // CreateInstance to succeed. nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); + nsCOMPtr gsettings = + do_GetService(NS_GSETTINGSSERVICE_CONTRACTID); - if (!gconf && !giovfs) + if (!gconf && !giovfs && !gsettings) return NS_ERROR_NOT_AVAILABLE; // Check G_BROKEN_FILENAMES. If it's set, then filenames in glib use @@ -412,6 +421,15 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement, rv = request->GetImage(getter_AddRefs(container)); if (!container) return rv; + // Set desktop wallpaper filling style + nsCAutoString options; + if (aPosition == BACKGROUND_TILE) + options.Assign("wallpaper"); + else if (aPosition == BACKGROUND_STRETCH) + options.Assign("stretched"); + else + options.Assign("centered"); + // Write the background file to the home directory. nsCAutoString filePath(PR_GetEnv("HOME")); @@ -437,19 +455,38 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement, // write the image to a file in the home dir rv = WriteImage(filePath, container); + NS_ENSURE_SUCCESS(rv, rv); + + // Try GSettings first. If we don't have GSettings or the right schema, fall back + // to using GConf instead. Note that if GSettings works ok, the changes get + // mirrored to GConf by the gsettings->gconf bridge in gnome-settings-daemon + nsCOMPtr gsettings = + do_GetService(NS_GSETTINGSSERVICE_CONTRACTID); + if (gsettings) { + nsCOMPtr background_settings; + gsettings->GetCollectionForSchema( + NS_LITERAL_CSTRING(kDesktopBGSchema), getter_AddRefs(background_settings)); + if (background_settings) { + gchar *file_uri = g_filename_to_uri(filePath.get(), NULL, NULL); + if (!file_uri) + return NS_ERROR_FAILURE; + + background_settings->SetString(NS_LITERAL_CSTRING(kDesktopOptionGSKey), + options); + + background_settings->SetString(NS_LITERAL_CSTRING(kDesktopImageGSKey), + nsDependentCString(file_uri)); + g_free(file_uri); + background_settings->SetBoolean(NS_LITERAL_CSTRING(kDesktopDrawBGGSKey), + PR_TRUE); + return rv; + } + } // if the file was written successfully, set it as the system wallpaper nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); if (gconf) { - nsCAutoString options; - if (aPosition == BACKGROUND_TILE) - options.Assign("wallpaper"); - else if (aPosition == BACKGROUND_STRETCH) - options.Assign("stretched"); - else - options.Assign("centered"); - gconf->SetString(NS_LITERAL_CSTRING(kDesktopOptionsKey), options); // Set the image to an empty string first to force a refresh @@ -471,11 +508,24 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement, NS_IMETHODIMP nsGNOMEShellService::GetDesktopBackgroundColor(PRUint32 *aColor) { - nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); - + nsCOMPtr gsettings = + do_GetService(NS_GSETTINGSSERVICE_CONTRACTID); + nsCOMPtr background_settings; nsCAutoString background; - if (gconf) { - gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background); + + if (gsettings) { + gsettings->GetCollectionForSchema( + NS_LITERAL_CSTRING(kDesktopBGSchema), getter_AddRefs(background_settings)); + if (background_settings) { + background_settings->GetString(NS_LITERAL_CSTRING(kDesktopColorGSKey), + background); + } + } + + if (!background_settings) { + nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); + if (gconf) + gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background); } if (background.IsEmpty()) { @@ -513,12 +563,25 @@ NS_IMETHODIMP nsGNOMEShellService::SetDesktopBackgroundColor(PRUint32 aColor) { NS_ASSERTION(aColor <= 0xffffff, "aColor has extra bits"); + nsCAutoString colorString; + ColorToCString(aColor, colorString); + + nsCOMPtr gsettings = + do_GetService(NS_GSETTINGSSERVICE_CONTRACTID); + if (gsettings) { + nsCOMPtr background_settings; + gsettings->GetCollectionForSchema( + NS_LITERAL_CSTRING(kDesktopBGSchema), getter_AddRefs(background_settings)); + if (background_settings) { + background_settings->SetString(NS_LITERAL_CSTRING(kDesktopColorGSKey), + colorString); + return NS_OK; + } + } + nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); if (gconf) { - nsCAutoString colorString; - ColorToCString(aColor, colorString); - gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString); }