| Index: scripts/xdg-settings
|
| ===================================================================
|
| --- scripts/xdg-settings (revision 84895)
|
| +++ scripts/xdg-settings (working copy)
|
| @@ -35,82 +35,104 @@
|
| cat << _MANUALPAGE
|
| Name
|
|
|
| -xdg-settings - get various settings from the desktop environment
|
| + xdg-settings - get various settings from the desktop
|
| + environment
|
|
|
| Synopsis
|
|
|
| -xdg-settings { get | check | set } {property} [value]
|
| + xdg-settings { get | check | set } {property} [subproperty]
|
| + [value]
|
|
|
| -xdg-settings { --help | --list | --manual | --version }
|
| + xdg-settings { --help | --list | --manual | --version }
|
|
|
| Description
|
|
|
| -xdg-settings gets various settings from the desktop environment. For instance,
|
| -desktop environments often provide proxy configuration and default web browser
|
| -settings. Using xdg-settings these parameters can be extracted for use by
|
| -applications that do not use the desktop environment's libraries (which would
|
| -use the settings natively).
|
| + xdg-settings gets various settings from the desktop
|
| + environment. For instance, desktop environments often provide
|
| + proxy configuration and default web browser settings. Using
|
| + xdg-settings these parameters can be extracted for use by
|
| + applications that do not use the desktop environment's
|
| + libraries (which would use the settings natively).
|
|
|
| -xdg-settings is for use inside a desktop session only. It is not recommended to
|
| -use xdg-settings as root.
|
| + xdg-settings is for use inside a desktop session only. It is
|
| + not recommended to use xdg-settings as root.
|
|
|
| Options
|
|
|
| ---help
|
| - Show command synopsis.
|
| ---list
|
| - List all properties xdg-settings knows about.
|
| ---manual
|
| - Show this manualpage.
|
| ---version
|
| - Show the xdg-utils version information.
|
| + --help
|
| + Show command synopsis.
|
|
|
| + --list
|
| + List all properties xdg-settings knows about.
|
| +
|
| + --manual
|
| + Show this manualpage.
|
| +
|
| + --version
|
| + Show the xdg-utils version information.
|
| +
|
| +Properties
|
| +
|
| + When using xdg-settings to get, check or set a destkop setting,
|
| + properties and possibly sub-properties are used to specify the
|
| + setting to be changed.
|
| +
|
| + Some properties (such as default-web-browser) fully describe
|
| + the setting to be changed. Other properties (such as
|
| + default-url-scheme-handler) require more information (in this
|
| + case the actual scheme to set the default handler for) which
|
| + must be provided in a sub-property.
|
| +
|
| Exit Codes
|
|
|
| -An exit code of 0 indicates success while a non-zero exit code indicates
|
| -failure. The following failure codes can be returned:
|
| + An exit code of 0 indicates success while a non-zero exit code
|
| + indicates failure. The following failure codes can be returned:
|
|
|
| -1
|
| - Error in command line syntax.
|
| -2
|
| - One of the files passed on the command line did not exist.
|
| -3
|
| - A required tool could not be found.
|
| -4
|
| - The action failed.
|
| + 1
|
| + Error in command line syntax.
|
|
|
| -Examples
|
| + 2
|
| + One of the files passed on the command line did not
|
| + exist.
|
|
|
| -Get the desktop file name of the current default web browser
|
| + 3
|
| + A required tool could not be found.
|
|
|
| - xdg-settings get default-web-browser
|
| + 4
|
| + The action failed.
|
|
|
| +Examples
|
|
|
| -Check whether the default web browser is firefox.desktop, which can be false
|
| -even if "get default-web-browser" says that is the current value (if only some
|
| -of the underlying settings actually reflect that value)
|
| + Get the desktop file name of the current default web browser
|
| + xdg-settings get default-web-browser
|
|
|
| + Check whether the default web browser is firefox.desktop, which
|
| + can be false even if "get default-web-browser" says that is the
|
| + current value (if only some of the underlying settings actually
|
| + reflect that value)
|
| xdg-settings check default-web-browser firefox.desktop
|
|
|
| -
|
| -Set the default web browser to google-chrome.desktop
|
| -
|
| + Set the default web browser to google-chrome.desktop
|
| xdg-settings set default-web-browser google-chrome.desktop
|
|
|
| -
|
| + Set the default mailto URL scheme handler to be
|
| + evolution.desktop
|
| + xdg-settings set default-url-scheme-handler evolution.desktop
|
| _MANUALPAGE
|
| }
|
|
|
| usage()
|
| {
|
| cat << _USAGE
|
| -xdg-settings - get various settings from the desktop environment
|
| + xdg-settings - get various settings from the desktop
|
| + environment
|
|
|
| Synopsis
|
|
|
| -xdg-settings { get | check | set } {property} [value]
|
| + xdg-settings { get | check | set } {property} [subproperty]
|
| + [value]
|
|
|
| -xdg-settings { --help | --list | --manual | --version }
|
| + xdg-settings { --help | --list | --manual | --version }
|
|
|
| _USAGE
|
| }
|
| @@ -539,6 +561,30 @@
|
| }
|
|
|
| # }}} MIME utilities
|
| +# {{{ KDE utilities
|
| +
|
| +# Reads the KDE configuration setting, compensating for a bug in some versions of kreadconfig.
|
| +read_kde_config()
|
| +{
|
| + configfile="$1"
|
| + configsection="$2"
|
| + configkey="$3"
|
| + browser="`kreadconfig --file $configfile --group $configsection --key $configkey`"
|
| + if [ x"$browser" != x ]; then
|
| + echo "$browser"
|
| + else
|
| + # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
|
| + # check by hand if it didn't find anything (oddly kwriteconfig works
|
| + # fine though).
|
| + kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
|
| + kdeglobals="$kdeglobals_dir/$configfile"
|
| + [ ! -f "$kdeglobals" ] && return
|
| + # This will only take the first value if there is more than one.
|
| + grep "^$configkey"'\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut -d= -f 2-
|
| + fi
|
| +}
|
| +
|
| +# }}} KDE utilities
|
| # {{{ KDE
|
|
|
| # Resolves the KDE browser setting to a binary: if prefixed with !, simply removes it;
|
| @@ -572,22 +618,9 @@
|
| esac
|
| }
|
|
|
| -# Reads the KDE browser setting, compensating for a bug in some versions of kreadconfig.
|
| read_kde_browser()
|
| {
|
| - browser="`kreadconfig --file kdeglobals --group General --key BrowserApplication`"
|
| - if [ x"$browser" != x ]; then
|
| - echo "$browser"
|
| - else
|
| - # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
|
| - # check by hand if it didn't find anything (oddly kwriteconfig works
|
| - # fine though).
|
| - kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
|
| - kdeglobals="$kdeglobals_dir/kdeglobals"
|
| - [ ! -f "$kdeglobals" ] && return
|
| - # This will only take the first value if there is more than one.
|
| - grep '^BrowserApplication\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut -d= -f 2-
|
| - fi
|
| + read_kde_config kdeglobals General BrowserApplication
|
| }
|
|
|
| get_browser_kde()
|
| @@ -843,6 +876,167 @@
|
| # }}} xfce
|
| # }}} default browser
|
|
|
| +# {{{ default url scheme handler
|
| +
|
| +exit_unimplemented_default_handler()
|
| +{
|
| + exit_failure_operation_impossible "default-url-scheme-handler not implemented for $DE"
|
| +}
|
| +
|
| +# {{{ KDE
|
| +
|
| +# Recent versions of KDE support default scheme handler applications using the mime type
|
| +# of x-scheme-handler/scheme. Older versions will not support this but do have support
|
| +# for setting a default mail handler. There is also a system in KDE where .protocol files
|
| +# can be used, however this is not supported by this script.
|
| +# When reading a scheme handler we will use the default mail handler for the mailto scheme,
|
| +# otherwise we will use the mime type x-scheme-handler/scheme.
|
| +
|
| +get_url_scheme_handler_kde()
|
| +{
|
| + if [ "$1" = "mailto" ]; then
|
| + handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | first_word`"
|
| + echo "handler is $handler"
|
| + if [ x"$handler" != x ]; then
|
| + binary_to_desktop_file "$handler"
|
| + else
|
| + get_browser_mime "x-scheme-handler/$1"
|
| + fi
|
| + else
|
| + get_browser_mime "x-scheme-handler/$1"
|
| + fi
|
| +}
|
| +
|
| +check_url_scheme_handler_kde()
|
| +{
|
| + check="`desktop_file_to_binary "$2"`"
|
| + if [ -z "$check" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + if [ x"$1" = "mailto" ]; then
|
| + binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`"
|
| + if [ x"$binary" != x"$check" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + fi
|
| + handler="`get_browser_mime x-scheme-handler/$1`"
|
| + binary="`desktop_file_to_binary "$handler"`"
|
| + if [ x"$binary" != x"$check" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + echo yes
|
| + exit_success
|
| +}
|
| +
|
| +set_url_scheme_handler_kde()
|
| +{
|
| + set_browser_mime "$2" "x-scheme-handler/$1" || return
|
| + if [ "$1" = "mailto" ]; then
|
| + binary="`desktop_file_to_binary "$2"`"
|
| + kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailClient "$binary"
|
| + fi
|
| +}
|
| +
|
| +# }}} KDE
|
| +# {{{ GNOME
|
| +
|
| +get_url_scheme_handler_gnome()
|
| +{
|
| + binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
|
| + if [ x"$binary" != x"" ]; then
|
| + # gconftool gives the binary (maybe with %s etc. afterward),
|
| + # but we want the desktop file name, not the binary. So, we
|
| + # have to find the desktop file to which it corresponds.
|
| + desktop="`binary_to_desktop_file "$binary"`"
|
| + basename "$desktop"
|
| + fi
|
| +}
|
| +
|
| +check_url_scheme_handler_gnome()
|
| +{
|
| + check="`desktop_file_to_binary "$2"`"
|
| + if [ -z "$check" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
|
| + if [ x"$binary" != x"$check" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + echo yes
|
| + exit_success
|
| +}
|
| +
|
| +set_url_scheme_handler_gnome()
|
| +{
|
| + binary="`desktop_file_to_binary "$2"`"
|
| + [ "$binary" ] || exit_failure_file_missing
|
| +
|
| + gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$binary %s"
|
| + gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal false
|
| + gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true
|
| +}
|
| +
|
| +# }}} GNOME
|
| +# {{{ GNOME 3.x
|
| +
|
| +get_url_scheme_handler_gnome3()
|
| +{
|
| + get_browser_mime "x-scheme-handler/$1"
|
| +}
|
| +
|
| +check_url_scheme_handler_gnome3()
|
| +{
|
| + desktop="$2"
|
| + check="`desktop_file_to_binary "$2"`"
|
| + if [ -z "$check" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + browser="`get_browser_mime "x-scheme-handler/$1"`"
|
| + if [ x"$browser" != x"$desktop" ]; then
|
| + echo no
|
| + exit_success
|
| + fi
|
| + echo yes
|
| + exit_success
|
| +}
|
| +
|
| +set_url_scheme_handler_gnome3()
|
| +{
|
| + binary="`desktop_file_to_binary "$2"`"
|
| + [ "$binary" ] || exit_failure_file_missing
|
| + set_browser_mime "$2" || return
|
| +
|
| + # Set the default browser.
|
| + set_browser_mime "$2" "x-scheme-handler/$1" || return
|
| +}
|
| +
|
| +# }}} GNOME 3.x
|
| +# {{{ xfce
|
| +
|
| +get_url_scheme_handler_xfce()
|
| +{
|
| + exit_unimplemented_default_handler "$1"
|
| +}
|
| +
|
| +check_url_scheme_handler_xfce()
|
| +{
|
| + exit_unimplemented_default_handler "$1"
|
| +}
|
| +
|
| +set_url_scheme_handler_xfce()
|
| +{
|
| + exit_unimplemented_default_handler "$1"
|
| +}
|
| +
|
| +# }}} xfce
|
| +# }}} default protocol handler
|
| +
|
| dispatch_specific()
|
| {
|
| # The PROP comments in this function are used to generate the output of
|
| @@ -854,6 +1048,10 @@
|
| get_browser_$DE
|
| ;;
|
|
|
| + default-url-scheme-handler) # PROP: Default handler for url scheme
|
| + get_url_scheme_handler_$DE "$1"
|
| + ;;
|
| +
|
| *)
|
| exit_failure_syntax
|
| ;;
|
| @@ -865,18 +1063,29 @@
|
| check_browser_$DE "$1"
|
| ;;
|
|
|
| + default-*-handler)
|
| + check_desktop_filename "$2"
|
| + check_url_scheme_handler_$DE "$1" "$2"
|
| + ;;
|
| +
|
| *)
|
| exit_failure_syntax
|
| ;;
|
| esac
|
| else # set
|
| - [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
|
| case "$parm" in
|
| default-web-browser)
|
| + [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
|
| check_desktop_filename "$1"
|
| set_browser_$DE "$1"
|
| ;;
|
|
|
| + default-*-handler)
|
| + [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument"
|
| + check_desktop_filename "$2"
|
| + set_url_scheme_handler_$DE "$1" "$2"
|
| + ;;
|
| +
|
| *)
|
| exit_failure_syntax
|
| ;;
|
|
|