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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 #-------------------------------------- | 308 #-------------------------------------- |
309 # Checks for known desktop environments | 309 # Checks for known desktop environments |
310 # set variable DE to the desktop environments name, lowercase | 310 # set variable DE to the desktop environments name, lowercase |
311 | 311 |
312 detectDE() | 312 detectDE() |
313 { | 313 { |
314 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; | 314 if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde; |
315 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; | 315 elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome; |
316 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; | 316 elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/D
Bus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/nul
l 2>&1` ; then DE=gnome; |
317 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; | 317 elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/nul
l 2>&1; then DE=xfce; |
318 elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde; | 318 fi |
319 else DE="" | 319 |
| 320 if [ x"$DE" = x"" ]; then |
| 321 # fallback to checking $DESKTOP_SESSION |
| 322 case "$DESKTOP_SESSION" in |
| 323 LXDE) |
| 324 DE=lxde; |
| 325 ;; |
| 326 xfce|xfce4) |
| 327 DE=xfce; |
| 328 ;; |
| 329 esac |
| 330 fi |
| 331 |
| 332 if [ x"$DE" = x"" ]; then |
| 333 # fallback to uname output for other platforms |
| 334 case "$(uname 2>/dev/null)" in |
| 335 Darwin) |
| 336 DE=darwin; |
| 337 ;; |
| 338 esac |
| 339 fi |
| 340 |
| 341 if [ x"$DE" = x"gnome" ]; then |
| 342 # gnome-default-applications-properties is only available in GNOME 2.x |
| 343 # but not in GNOME 3.x |
| 344 which gnome-default-applications-properties 2> /dev/null || DE="gnome3" |
320 fi | 345 fi |
321 } | 346 } |
322 | 347 |
323 #---------------------------------------------------------------------------- | 348 #---------------------------------------------------------------------------- |
324 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 | 349 # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4 |
325 # It also always returns 1 in KDE 3.4 and earlier | 350 # It also always returns 1 in KDE 3.4 and earlier |
326 # Simply return 0 in such case | 351 # Simply return 0 in such case |
327 | 352 |
328 kfmclient_fix_exit_code() | 353 kfmclient_fix_exit_code() |
329 { | 354 { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 # In order to remove an application from the automatically-generated list of | 437 # In order to remove an application from the automatically-generated list of |
413 # applications for handling a given MIME type, the desktop environment may copy | 438 # applications for handling a given MIME type, the desktop environment may copy |
414 # the global .desktop file into the user's .local directory, and remove that | 439 # the global .desktop file into the user's .local directory, and remove that |
415 # MIME type from its list. In that case, we must restore the MIME type to the | 440 # MIME type from its list. In that case, we must restore the MIME type to the |
416 # application's list of MIME types before we can set it as the default for that | 441 # application's list of MIME types before we can set it as the default for that |
417 # MIME type. (We can't just delete the local version, since the user may have | 442 # MIME type. (We can't just delete the local version, since the user may have |
418 # made other changes to it as well. So, tweak the existing file.) | 443 # made other changes to it as well. So, tweak the existing file.) |
419 # This function is hard-coded for text/html but it could be adapted if needed. | 444 # This function is hard-coded for text/html but it could be adapted if needed. |
420 fix_local_desktop_file() | 445 fix_local_desktop_file() |
421 { | 446 { |
| 447 if test -z "$2" ; then |
| 448 MIME="text/html" |
| 449 else |
| 450 MIME="$2" |
| 451 fi |
422 apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" | 452 apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications" |
423 # No local desktop file? | 453 # No local desktop file? |
424 [ ! -f "$apps/$1" ] && return | 454 [ ! -f "$apps/$1" ] && return |
425 MIME="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`" | 455 MIMETYPES="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`" |
426 case "$MIME" in | 456 case "$MIMETYPES" in |
427 text/html\;*|*\;text/html\;*|*\;text/html\;|*\;text/html) | 457 $MIME\;*|*\;$MIME\;*|*\;$MIME\;|*\;$MIME) |
428 # Already has text/html? Great! | 458 # Already has the mime-type? Great! |
429 return 0 | 459 return 0 |
430 ;; | 460 ;; |
431 esac | 461 esac |
432 | 462 |
433 # Add text/html to the list | 463 # Add the mime-type to the list |
434 temp="`mktemp "$apps/$1.XXXXXX"`" || return | 464 temp="`mktemp "$apps/$1.XXXXXX"`" || return |
435 grep -v "^MimeType=" "$apps/$1" >> "$temp" | 465 grep -v "^MimeType=" "$apps/$1" >> "$temp" |
436 echo "MimeType=text/html;$MIME" >> "$temp" | 466 echo "MimeType=$MIME;$MIMETYPES" >> "$temp" |
437 | 467 |
438 oldlines="`wc -l < "$apps/$1"`" | 468 oldlines="`wc -l < "$apps/$1"`" |
439 newlines="`wc -l < "$temp"`" | 469 newlines="`wc -l < "$temp"`" |
440 # The new file should have at least as many lines as the old. | 470 # The new file should have at least as many lines as the old. |
441 if [ $oldlines -le $newlines ]; then | 471 if [ $oldlines -le $newlines ]; then |
442 mv "$temp" "$apps/$1" | 472 mv "$temp" "$apps/$1" |
443 # This can take a little bit to get noticed. | 473 # This can take a little bit to get noticed. |
444 sleep 4 | 474 sleep 4 |
445 else | 475 else |
446 rm -f "$temp" | 476 rm -f "$temp" |
(...skipping 13 matching lines...) Expand all Loading... |
460 # copy here, that copy will be used in xdg-mime and we will avoid waiting. | 490 # copy here, that copy will be used in xdg-mime and we will avoid waiting. |
461 if [ "$DE" = kde -a -z "$XDG_MIME_FIXED" ]; then | 491 if [ "$DE" = kde -a -z "$XDG_MIME_FIXED" ]; then |
462 ktradertest text/html Application > /dev/null 2>&1 | 492 ktradertest text/html Application > /dev/null 2>&1 |
463 # Only do this once, as we only need it once. | 493 # Only do this once, as we only need it once. |
464 XDG_MIME_FIXED=yes | 494 XDG_MIME_FIXED=yes |
465 fi | 495 fi |
466 } | 496 } |
467 | 497 |
468 get_browser_mime() | 498 get_browser_mime() |
469 { | 499 { |
| 500 if test -z "$1" ; then |
| 501 MIME="text/html" |
| 502 else |
| 503 MIME="$1" |
| 504 fi |
470 xdg_mime_fixup | 505 xdg_mime_fixup |
471 xdg-mime query default text/html | 506 xdg-mime query default "$MIME" |
472 } | 507 } |
473 | 508 |
474 set_browser_mime() | 509 set_browser_mime() |
475 { | 510 { |
476 xdg_mime_fixup | 511 xdg_mime_fixup |
477 orig="`get_browser_mime`" | 512 if test -z "$2" ; then |
| 513 MIME="text/html" |
| 514 else |
| 515 MIME="$2" |
| 516 fi |
| 517 orig="`get_browser_mime $MIME`" |
478 # Fixing the local desktop file can actually change the default browser all | 518 # Fixing the local desktop file can actually change the default browser all |
479 # by itself, so we fix it only after querying to find the current default. | 519 # by itself, so we fix it only after querying to find the current default. |
480 fix_local_desktop_file "$1" || return | 520 fix_local_desktop_file "$1" "$MIME" || return |
481 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" | 521 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" |
482 xdg-mime default "$1" text/html || return | 522 xdg-mime default "$1" "$MIME" || return |
483 if [ x"`get_browser_mime`" != x"$1" ]; then | 523 if [ x"`get_browser_mime`" != x"$1" ]; then |
484 # Put back the original value | 524 # Put back the original value |
485 xdg-mime default "$orig" text/html | 525 xdg-mime default "$orig" "$MIME" |
486 exit_failure_operation_failed | 526 exit_failure_operation_failed |
487 fi | 527 fi |
488 } | 528 } |
489 | 529 |
490 # }}} MIME utilities | 530 # }}} MIME utilities |
491 # {{{ KDE | 531 # {{{ KDE |
492 | 532 |
493 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; | 533 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; |
494 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. | 534 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. |
495 resolve_kde_browser() | 535 resolve_kde_browser() |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/need
s_terminal false | 685 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/need
s_terminal false |
646 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/enab
led true | 686 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/enab
led true |
647 done | 687 done |
648 # Set the handler for about: and unknown URL types. | 688 # Set the handler for about: and unknown URL types. |
649 for protocol in about unknown; do | 689 for protocol in about unknown; do |
650 gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/co
mmand "$binary %s" | 690 gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/co
mmand "$binary %s" |
651 done | 691 done |
652 } | 692 } |
653 | 693 |
654 # }}} GNOME | 694 # }}} GNOME |
| 695 # {{{ GNOME 3.x |
| 696 |
| 697 get_browser_gnome3() |
| 698 { |
| 699 get_browser_mime "x-scheme-handler/http" |
| 700 } |
| 701 |
| 702 check_browser_gnome3() |
| 703 { |
| 704 desktop="$1" |
| 705 check="`desktop_file_to_binary "$1"`" |
| 706 if [ -z "$check" ]; then |
| 707 echo no |
| 708 exit_success |
| 709 fi |
| 710 # Check HTTP and HTTPS, but not about: and unknown:. |
| 711 for protocol in http https; do |
| 712 browser="`get_browser_mime "x-scheme-handler/$protocol"`" |
| 713 if [ x"$browser" != x"$desktop" ]; then |
| 714 echo no |
| 715 exit_success |
| 716 fi |
| 717 done |
| 718 echo yes |
| 719 exit_success |
| 720 } |
| 721 |
| 722 set_browser_gnome3() |
| 723 { |
| 724 binary="`desktop_file_to_binary "$1"`" |
| 725 [ "$binary" ] || exit_failure_file_missing |
| 726 set_browser_mime "$1" || return |
| 727 |
| 728 # Set the default browser. |
| 729 for protocol in http https about unknown; do |
| 730 set_browser_mime "$1" "x-scheme-handler/$protocol" || return |
| 731 done |
| 732 } |
| 733 # }}} GNOME 3.x |
655 # {{{ xfce | 734 # {{{ xfce |
656 | 735 |
657 get_browser_xfce() | 736 get_browser_xfce() |
658 { | 737 { |
659 search="${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}" | 738 search="${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}" |
660 IFS=: | 739 IFS=: |
661 for dir in $search; do | 740 for dir in $search; do |
662 unset IFS | 741 unset IFS |
663 [ "$dir" -a -d "$dir/xfce4" ] || continue | 742 [ "$dir" -a -d "$dir/xfce4" ] || continue |
664 file="$dir/xfce4/helpers.rc" | 743 file="$dir/xfce4/helpers.rc" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 parm="$2" | 933 parm="$2" |
855 shift 2 | 934 shift 2 |
856 | 935 |
857 if [ x"$op" != x"get" -a x"$op" != x"check" -a x"$op" != x"set" ]; then | 936 if [ x"$op" != x"get" -a x"$op" != x"check" -a x"$op" != x"set" ]; then |
858 exit_failure_syntax "invalid operation" | 937 exit_failure_syntax "invalid operation" |
859 fi | 938 fi |
860 | 939 |
861 detectDE | 940 detectDE |
862 | 941 |
863 case "$DE" in | 942 case "$DE" in |
864 kde|gnome|xfce) | 943 kde|gnome*|xfce) |
865 dispatch_specific "$@" | 944 dispatch_specific "$@" |
866 ;; | 945 ;; |
867 | 946 |
868 generic) | 947 generic) |
869 dispatch_generic "$@" | 948 dispatch_generic "$@" |
870 ;; | 949 ;; |
871 | 950 |
872 *) | 951 *) |
873 exit_failure_operation_impossible "unknown desktop environment" | 952 exit_failure_operation_impossible "unknown desktop environment" |
874 ;; | 953 ;; |
875 esac | 954 esac |
OLD | NEW |