firefox-cross-desktop.patch
changeset 419 f6b055dd94bc
parent 223 4555a5d0d661
equal deleted inserted replaced
418:ecd5bb5744dc 419:f6b055dd94bc
     1 From: Wolfgang Rosenauer
     1 # HG changeset patch
     2 NonGnome/KDE integration
     2 # Parent fd2da289a3c15b8c96c248df2710d879793f22c9
     3 
     3 # User Wolfgang Rosenauer <wr@rosenauer.org>
     4 References:
     4 Bug 526717 - remove non-working "Set as desktop background" from the UI for unsupported desktops
     5 https://bugzilla.novell.com/show_bug.cgi?id=170055
       
     6 
     5 
     7 diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js
     6 diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js
     8 --- a/browser/base/content/nsContextMenu.js
     7 --- a/browser/base/content/nsContextMenu.js
     9 +++ b/browser/base/content/nsContextMenu.js
     8 +++ b/browser/base/content/nsContextMenu.js
    10 @@ -237,17 +237,19 @@ nsContextMenu.prototype = {
     9 @@ -262,17 +262,17 @@ nsContextMenu.prototype = {
    11      this.showItem("context-sep-viewsource", shouldShow);
       
    12  
    10  
    13      // Set as Desktop background depends on whether an image was clicked on,
    11      // Set as Desktop background depends on whether an image was clicked on,
    14      // and only works if we have a shell service.
    12      // and only works if we have a shell service.
    15      var haveSetDesktopBackground = false;
    13      var haveSetDesktopBackground = false;
    16  #ifdef HAVE_SHELL_SERVICE
    14  #ifdef HAVE_SHELL_SERVICE
    17      // Only enable Set as Desktop Background if we can get the shell service.
    15      // Only enable Set as Desktop Background if we can get the shell service.
    18      var shell = getShellService();
    16      var shell = getShellService();
    19 -    if (shell)
    17      if (shell)
    20 +    var env = Components.classes["@mozilla.org/process/environment;1"]
    18 -      haveSetDesktopBackground = true;
    21 +                        .getService(Components.interfaces.nsIEnvironment);
    19 +      haveSetDesktopBackground = shell.canSetDesktopBackground;
    22 +    if (shell && env.get('DESKTOP_SESSION') == "gnome")
       
    23        haveSetDesktopBackground = true;
       
    24  #endif
    20  #endif
    25      this.showItem("context-setDesktopBackground",
    21      this.showItem("context-setDesktopBackground",
    26                    haveSetDesktopBackground && this.onLoadedImage);
    22                    haveSetDesktopBackground && this.onLoadedImage);
    27  
    23  
    28      if (haveSetDesktopBackground && this.onLoadedImage) {
    24      if (haveSetDesktopBackground && this.onLoadedImage) {
    29        document.getElementById("context-setDesktopBackground")
    25        document.getElementById("context-setDesktopBackground")
    30                .disabled = this.disableSetDesktopBackground();
    26                .disabled = this.disableSetDesktopBackground();
       
    27      }
       
    28 diff --git a/browser/components/shell/public/nsIShellService.idl b/browser/components/shell/public/nsIShellService.idl
       
    29 --- a/browser/components/shell/public/nsIShellService.idl
       
    30 +++ b/browser/components/shell/public/nsIShellService.idl
       
    31 @@ -69,16 +69,25 @@ interface nsIShellService : nsISupports
       
    32    /** 
       
    33     * Used to determine whether or not to show a "Set Default Browser"
       
    34     * query dialog. This attribute is true if the application is starting
       
    35     * up and "browser.shell.checkDefaultBrowser" is true, otherwise it
       
    36     * is false.
       
    37     */
       
    38    attribute boolean shouldCheckDefaultBrowser;
       
    39  
       
    40 +  /**
       
    41 +   * Used to determine whether or not to offer "Set as desktop background"
       
    42 +   * context menu item. Even if shell service is available it is not
       
    43 +   * guaranteed that it is able to set the background for every desktop
       
    44 +   * which is especially true for Linux with its many different desktop
       
    45 +   * environments.
       
    46 +   */
       
    47 +  readonly attribute boolean canSetDesktopBackground;
       
    48 +
       
    49    /** 
       
    50     * Flags for positioning/sizing of the Desktop Background image.
       
    51     */
       
    52    const long BACKGROUND_TILE      = 1;
       
    53    const long BACKGROUND_STRETCH   = 2;
       
    54    const long BACKGROUND_CENTER    = 3;
       
    55    const long BACKGROUND_FILL      = 4;
       
    56    const long BACKGROUND_FIT       = 5;
       
    57 diff --git a/browser/components/shell/src/nsGNOMEShellService.cpp b/browser/components/shell/src/nsGNOMEShellService.cpp
       
    58 --- a/browser/components/shell/src/nsGNOMEShellService.cpp
       
    59 +++ b/browser/components/shell/src/nsGNOMEShellService.cpp
       
    60 @@ -377,16 +377,31 @@ nsGNOMEShellService::SetShouldCheckDefau
       
    61      pserve->GetBranch("", getter_AddRefs(prefs));
       
    62  
       
    63    if (prefs)
       
    64      prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck);
       
    65  
       
    66    return NS_OK;
       
    67  }
       
    68  
       
    69 +NS_IMETHODIMP
       
    70 +nsGNOMEShellService::GetCanSetDesktopBackground(bool* aResult)
       
    71 +{
       
    72 +  // setting desktop background is currently only supported
       
    73 +  // for Gnome or desktops using the same GSettings and GConf keys
       
    74 +  const char* gnomeSession = getenv("GNOME_DESKTOP_SESSION_ID");
       
    75 +  if (gnomeSession) {
       
    76 +    *aResult = true;
       
    77 +  } else {
       
    78 +    *aResult = false;
       
    79 +  }
       
    80 +
       
    81 +  return NS_OK;
       
    82 +}
       
    83 +
       
    84  static nsresult
       
    85  WriteImage(const nsCString& aPath, imgIContainer* aImage)
       
    86  {
       
    87  #ifndef MOZ_WIDGET_GTK2
       
    88    return NS_ERROR_NOT_AVAILABLE;
       
    89  #else
       
    90    nsCOMPtr<nsIImageToPixbuf> imgToPixbuf =
       
    91      do_GetService("@mozilla.org/widget/image-to-gdk-pixbuf;1");