| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 #--------------------------------------------- | 2 #--------------------------------------------- |
| 3 # xdg-settings | 3 # xdg-settings |
| 4 # | 4 # |
| 5 # Utility script to get various settings from the desktop environment. | 5 # Utility script to get various settings from the desktop environment. |
| 6 # | 6 # |
| 7 # Refer to the usage() function below for usage. | 7 # Refer to the usage() function below for usage. |
| 8 # | 8 # |
| 9 # Copyright 2009, Google Inc. | 9 # Copyright 2009, Google Inc. |
| 10 # | 10 # |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 # In order to remove an application from the automatically-generated list of | 100 # In order to remove an application from the automatically-generated list of |
| 101 # applications for handling a given MIME type, the desktop environment may copy | 101 # applications for handling a given MIME type, the desktop environment may copy |
| 102 # the global .desktop file into the user's .local directory, and remove that | 102 # the global .desktop file into the user's .local directory, and remove that |
| 103 # MIME type from its list. In that case, we must restore the MIME type to the | 103 # MIME type from its list. In that case, we must restore the MIME type to the |
| 104 # application's list of MIME types before we can set it as the default for that | 104 # application's list of MIME types before we can set it as the default for that |
| 105 # MIME type. (We can't just delete the local version, since the user may have | 105 # MIME type. (We can't just delete the local version, since the user may have |
| 106 # made other changes to it as well. So, tweak the existing file.) | 106 # made other changes to it as well. So, tweak the existing file.) |
| 107 # This function is hard-coded for text/html but it could be adapted if needed. | 107 # This function is hard-coded for text/html but it could be adapted if needed. |
| 108 fix_local_desktop_file() | 108 fix_local_desktop_file() |
| 109 { | 109 { |
| 110 if test -z "$2" ; then |
| 111 MIME="text/html" |
| 112 else |
| 113 MIME="$2" |
| 114 fi |
| 110 apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" | 115 apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" |
| 111 # No local desktop file? | 116 # No local desktop file? |
| 112 [ ! -f "$apps/$1" ] && return | 117 [ ! -f "$apps/$1" ] && return |
| 113 MIME="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`" | 118 MIMETYPES="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`" |
| 114 case "$MIME" in | 119 case "$MIMETYPES" in |
| 115 text/html\;*|*\;text/html\;*|*\;text/html\;|*\;text/html) | 120 $MIME\;*|*\;$MIME\;*|*\;$MIME\;|*\;$MIME) |
| 116 # Already has text/html? Great! | 121 # Already has the mime-type? Great! |
| 117 return 0 | 122 return 0 |
| 118 ;; | 123 ;; |
| 119 esac | 124 esac |
| 120 | 125 |
| 121 # Add text/html to the list | 126 # Add the mime-type to the list |
| 122 temp="`mktemp "$apps/$1.XXXXXX"`" || return | 127 temp="`mktemp "$apps/$1.XXXXXX"`" || return |
| 123 grep -v "^MimeType=" "$apps/$1" >> "$temp" | 128 grep -v "^MimeType=" "$apps/$1" >> "$temp" |
| 124 echo "MimeType=text/html;$MIME" >> "$temp" | 129 echo "MimeType=$MIME;$MIMETYPES" >> "$temp" |
| 125 | 130 |
| 126 oldlines="`wc -l < "$apps/$1"`" | 131 oldlines="`wc -l < "$apps/$1"`" |
| 127 newlines="`wc -l < "$temp"`" | 132 newlines="`wc -l < "$temp"`" |
| 128 # The new file should have at least as many lines as the old. | 133 # The new file should have at least as many lines as the old. |
| 129 if [ $oldlines -le $newlines ]; then | 134 if [ $oldlines -le $newlines ]; then |
| 130 mv "$temp" "$apps/$1" | 135 mv "$temp" "$apps/$1" |
| 131 # This can take a little bit to get noticed. | 136 # This can take a little bit to get noticed. |
| 132 sleep 4 | 137 sleep 4 |
| 133 else | 138 else |
| 134 rm -f "$temp" | 139 rm -f "$temp" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 148 # copy here, that copy will be used in xdg-mime and we will avoid waiting. | 153 # copy here, that copy will be used in xdg-mime and we will avoid waiting. |
| 149 if [ "$DE" = kde -a -z "$XDG_MIME_FIXED" ]; then | 154 if [ "$DE" = kde -a -z "$XDG_MIME_FIXED" ]; then |
| 150 ktradertest text/html Application > /dev/null 2>&1 | 155 ktradertest text/html Application > /dev/null 2>&1 |
| 151 # Only do this once, as we only need it once. | 156 # Only do this once, as we only need it once. |
| 152 XDG_MIME_FIXED=yes | 157 XDG_MIME_FIXED=yes |
| 153 fi | 158 fi |
| 154 } | 159 } |
| 155 | 160 |
| 156 get_browser_mime() | 161 get_browser_mime() |
| 157 { | 162 { |
| 163 if test -z "$1" ; then |
| 164 MIME="text/html" |
| 165 else |
| 166 MIME="$1" |
| 167 fi |
| 158 xdg_mime_fixup | 168 xdg_mime_fixup |
| 159 xdg-mime query default text/html | 169 xdg-mime query default "$MIME" |
| 160 } | 170 } |
| 161 | 171 |
| 162 set_browser_mime() | 172 set_browser_mime() |
| 163 { | 173 { |
| 164 xdg_mime_fixup | 174 xdg_mime_fixup |
| 165 orig="`get_browser_mime`" | 175 if test -z "$2" ; then |
| 176 MIME="text/html" |
| 177 else |
| 178 MIME="$2" |
| 179 fi |
| 180 orig="`get_browser_mime $MIME`" |
| 166 # Fixing the local desktop file can actually change the default browser all | 181 # Fixing the local desktop file can actually change the default browser all |
| 167 # by itself, so we fix it only after querying to find the current default. | 182 # by itself, so we fix it only after querying to find the current default. |
| 168 fix_local_desktop_file "$1" || return | 183 fix_local_desktop_file "$1" "$MIME" || return |
| 169 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" | 184 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" |
| 170 xdg-mime default "$1" text/html || return | 185 xdg-mime default "$1" "$MIME" || return |
| 171 if [ x"`get_browser_mime`" != x"$1" ]; then | 186 if [ x"`get_browser_mime`" != x"$1" ]; then |
| 172 # Put back the original value | 187 # Put back the original value |
| 173 xdg-mime default "$orig" text/html | 188 xdg-mime default "$orig" "$MIME" |
| 174 exit_failure_operation_failed | 189 exit_failure_operation_failed |
| 175 fi | 190 fi |
| 176 } | 191 } |
| 177 | 192 |
| 178 # }}} MIME utilities | 193 # }}} MIME utilities |
| 179 # {{{ KDE | 194 # {{{ KDE |
| 180 | 195 |
| 181 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; | 196 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; |
| 182 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. | 197 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. |
| 183 resolve_kde_browser() | 198 resolve_kde_browser() |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/need
s_terminal false | 348 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/need
s_terminal false |
| 334 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/enab
led true | 349 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/enab
led true |
| 335 done | 350 done |
| 336 # Set the handler for about: and unknown URL types. | 351 # Set the handler for about: and unknown URL types. |
| 337 for protocol in about unknown; do | 352 for protocol in about unknown; do |
| 338 gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/co
mmand "$binary %s" | 353 gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/co
mmand "$binary %s" |
| 339 done | 354 done |
| 340 } | 355 } |
| 341 | 356 |
| 342 # }}} GNOME | 357 # }}} GNOME |
| 358 # {{{ GNOME 3.x |
| 359 |
| 360 get_browser_gnome3() |
| 361 { |
| 362 get_browser_mime "x-scheme-handler/http" |
| 363 } |
| 364 |
| 365 check_browser_gnome3() |
| 366 { |
| 367 desktop="$1" |
| 368 check="`desktop_file_to_binary "$1"`" |
| 369 if [ -z "$check" ]; then |
| 370 echo no |
| 371 exit_success |
| 372 fi |
| 373 # Check HTTP and HTTPS, but not about: and unknown:. |
| 374 for protocol in http https; do |
| 375 browser="`get_browser_mime "x-scheme-handler/$protocol"`" |
| 376 if [ x"$browser" != x"$desktop" ]; then |
| 377 echo no |
| 378 exit_success |
| 379 fi |
| 380 done |
| 381 echo yes |
| 382 exit_success |
| 383 } |
| 384 |
| 385 set_browser_gnome3() |
| 386 { |
| 387 binary="`desktop_file_to_binary "$1"`" |
| 388 [ "$binary" ] || exit_failure_file_missing |
| 389 set_browser_mime "$1" || return |
| 390 |
| 391 # Set the default browser. |
| 392 for protocol in http https about unknown; do |
| 393 set_browser_mime "$1" "x-scheme-handler/$protocol" || return |
| 394 done |
| 395 } |
| 396 # }}} GNOME 3.x |
| 343 # {{{ xfce | 397 # {{{ xfce |
| 344 | 398 |
| 345 get_browser_xfce() | 399 get_browser_xfce() |
| 346 { | 400 { |
| 347 search="${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}" | 401 search="${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}" |
| 348 IFS=: | 402 IFS=: |
| 349 for dir in $search; do | 403 for dir in $search; do |
| 350 unset IFS | 404 unset IFS |
| 351 [ "$dir" -a -d "$dir/xfce4" ] || continue | 405 [ "$dir" -a -d "$dir/xfce4" ] || continue |
| 352 file="$dir/xfce4/helpers.rc" | 406 file="$dir/xfce4/helpers.rc" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 parm="$2" | 596 parm="$2" |
| 543 shift 2 | 597 shift 2 |
| 544 | 598 |
| 545 if [ x"$op" != x"get" -a x"$op" != x"check" -a x"$op" != x"set" ]; then | 599 if [ x"$op" != x"get" -a x"$op" != x"check" -a x"$op" != x"set" ]; then |
| 546 exit_failure_syntax "invalid operation" | 600 exit_failure_syntax "invalid operation" |
| 547 fi | 601 fi |
| 548 | 602 |
| 549 detectDE | 603 detectDE |
| 550 | 604 |
| 551 case "$DE" in | 605 case "$DE" in |
| 552 kde|gnome|xfce) | 606 kde|gnome*|xfce) |
| 553 dispatch_specific "$@" | 607 dispatch_specific "$@" |
| 554 ;; | 608 ;; |
| 555 | 609 |
| 556 generic) | 610 generic) |
| 557 dispatch_generic "$@" | 611 dispatch_generic "$@" |
| 558 ;; | 612 ;; |
| 559 | 613 |
| 560 *) | 614 *) |
| 561 exit_failure_operation_impossible "unknown desktop environment" | 615 exit_failure_operation_impossible "unknown desktop environment" |
| 562 ;; | 616 ;; |
| 563 esac | 617 esac |
| OLD | NEW |