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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" | 131 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" |
132 xdg-mime default "$1" "$MIME" || return | 132 xdg-mime default "$1" "$MIME" || return |
133 if [ x"`get_browser_mime`" != x"$1" ]; then | 133 if [ x"`get_browser_mime`" != x"$1" ]; then |
134 # Put back the original value | 134 # Put back the original value |
135 xdg-mime default "$orig" "$MIME" | 135 xdg-mime default "$orig" "$MIME" |
136 exit_failure_operation_failed | 136 exit_failure_operation_failed |
137 fi | 137 fi |
138 } | 138 } |
139 | 139 |
140 # }}} MIME utilities | 140 # }}} MIME utilities |
| 141 # {{{ KDE utilities |
| 142 |
| 143 # Reads the KDE configuration setting, compensating for a bug in some versions o
f kreadconfig. |
| 144 read_kde_config() |
| 145 { |
| 146 configfile="$1" |
| 147 configsection="$2" |
| 148 configkey="$3" |
| 149 application="`kreadconfig --file $configfile --group $configsection --key $c
onfigkey`" |
| 150 if [ x"$application" != x ]; then |
| 151 echo "$application" |
| 152 else |
| 153 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so |
| 154 # check by hand if it didn't find anything (oddly kwriteconfig works |
| 155 # fine though). |
| 156 configfile_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d
':' -f 1` |
| 157 configfile_path="$configfile_dir/$configfile" |
| 158 [ ! -f "$configfile_path" ] && return |
| 159 # This will only take the first value if there is more than one. |
| 160 grep "^$configkey"'\[$[^]=]*\]=' "$configfile_path" | head -n 1 | cut -d
= -f 2- |
| 161 fi |
| 162 } |
| 163 |
| 164 # }}} KDE utilities |
141 # {{{ KDE | 165 # {{{ KDE |
142 | 166 |
143 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; | 167 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov
es it; |
144 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. | 168 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi
le. |
145 resolve_kde_browser() | 169 resolve_kde_browser() |
146 { | 170 { |
147 [ -z "$browser" ] && return | 171 [ -z "$browser" ] && return |
148 case "$browser" in | 172 case "$browser" in |
149 !*) | 173 !*) |
150 echo "${browser#!}" | 174 echo "${browser#!}" |
(...skipping 13 matching lines...) Expand all Loading... |
164 !*) | 188 !*) |
165 desktop="`binary_to_desktop_file "${browser#!}"`" | 189 desktop="`binary_to_desktop_file "${browser#!}"`" |
166 basename "$desktop" | 190 basename "$desktop" |
167 ;; | 191 ;; |
168 *) | 192 *) |
169 echo "$browser" | 193 echo "$browser" |
170 ;; | 194 ;; |
171 esac | 195 esac |
172 } | 196 } |
173 | 197 |
174 # Reads the KDE browser setting, compensating for a bug in some versions of krea
dconfig. | |
175 read_kde_browser() | 198 read_kde_browser() |
176 { | 199 { |
177 browser="`kreadconfig --file kdeglobals --group General --key BrowserApplica
tion`" | 200 read_kde_config kdeglobals General BrowserApplication |
178 if [ x"$browser" != x ]; then | |
179 echo "$browser" | |
180 else | |
181 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so | |
182 # check by hand if it didn't find anything (oddly kwriteconfig works | |
183 # fine though). | |
184 kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d
':' -f 1` | |
185 kdeglobals="$kdeglobals_dir/kdeglobals" | |
186 [ ! -f "$kdeglobals" ] && return | |
187 # This will only take the first value if there is more than one. | |
188 grep '^BrowserApplication\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut -
d= -f 2- | |
189 fi | |
190 } | 201 } |
191 | 202 |
192 get_browser_kde() | 203 get_browser_kde() |
193 { | 204 { |
194 browser="`read_kde_browser`" | 205 browser="`read_kde_browser`" |
195 if [ x"$browser" = x ]; then | 206 if [ x"$browser" = x ]; then |
196 # No explicit default browser; KDE will use the MIME type text/html. | 207 # No explicit default browser; KDE will use the MIME type text/html. |
197 get_browser_mime | 208 get_browser_mime |
198 else | 209 else |
199 resolve_kde_browser_desktop | 210 resolve_kde_browser_desktop |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 mv "$temp" "$helpers_rc" | 446 mv "$temp" "$helpers_rc" |
436 else | 447 else |
437 rm -f "$temp" | 448 rm -f "$temp" |
438 return 1 | 449 return 1 |
439 fi | 450 fi |
440 } | 451 } |
441 | 452 |
442 # }}} xfce | 453 # }}} xfce |
443 # }}} default browser | 454 # }}} default browser |
444 | 455 |
| 456 # {{{ default url scheme handler |
| 457 |
| 458 exit_unimplemented_default_handler() |
| 459 { |
| 460 exit_failure_operation_impossible "default-url-scheme-handler not implemente
d for $DE" |
| 461 } |
| 462 |
| 463 # {{{ KDE |
| 464 |
| 465 # Recent versions of KDE support default scheme handler applications using the |
| 466 # mime type of x-scheme-handler/scheme. Older versions will not support this |
| 467 # but do have support for setting a default mail handler. There is also a |
| 468 # system in KDE where .protocol files can be used, however this is not |
| 469 # supported by this script. When reading a scheme handler we will use the |
| 470 # default mail handler for the mailto scheme, otherwise we will use the mime |
| 471 # type x-scheme-handler/scheme. |
| 472 |
| 473 get_url_scheme_handler_kde() |
| 474 { |
| 475 if [ "$1" = "mailto" ]; then |
| 476 handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | fi
rst_word`" |
| 477 echo "handler is $handler" |
| 478 if [ x"$handler" != x ]; then |
| 479 binary_to_desktop_file "$handler" |
| 480 else |
| 481 get_browser_mime "x-scheme-handler/$1" |
| 482 fi |
| 483 else |
| 484 get_browser_mime "x-scheme-handler/$1" |
| 485 fi |
| 486 } |
| 487 |
| 488 check_url_scheme_handler_kde() |
| 489 { |
| 490 check="`desktop_file_to_binary "$2"`" |
| 491 if [ -z "$check" ]; then |
| 492 echo no |
| 493 exit_success |
| 494 fi |
| 495 if [ x"$1" = "mailto" ]; then |
| 496 binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`" |
| 497 if [ x"$binary" != x"$check" ]; then |
| 498 echo no |
| 499 exit_success |
| 500 fi |
| 501 fi |
| 502 handler="`get_browser_mime x-scheme-handler/$1`" |
| 503 binary="`desktop_file_to_binary "$handler"`" |
| 504 if [ x"$binary" != x"$check" ]; then |
| 505 echo no |
| 506 exit_success |
| 507 fi |
| 508 echo yes |
| 509 exit_success |
| 510 } |
| 511 |
| 512 set_url_scheme_handler_kde() |
| 513 { |
| 514 set_browser_mime "$2" "x-scheme-handler/$1" || return |
| 515 if [ "$1" = "mailto" ]; then |
| 516 binary="`desktop_file_to_binary "$2"`" |
| 517 kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailCli
ent "$binary" |
| 518 fi |
| 519 } |
| 520 |
| 521 # }}} KDE |
| 522 # {{{ GNOME |
| 523 |
| 524 get_url_scheme_handler_gnome() |
| 525 { |
| 526 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo
rd`" |
| 527 if [ x"$binary" != x"" ]; then |
| 528 # gconftool gives the binary (maybe with %s etc. afterward), |
| 529 # but we want the desktop file name, not the binary. So, we |
| 530 # have to find the desktop file to which it corresponds. |
| 531 desktop="`binary_to_desktop_file "$binary"`" |
| 532 basename "$desktop" |
| 533 fi |
| 534 } |
| 535 |
| 536 check_url_scheme_handler_gnome() |
| 537 { |
| 538 check="`desktop_file_to_binary "$2"`" |
| 539 if [ -z "$check" ]; then |
| 540 echo no |
| 541 exit_success |
| 542 fi |
| 543 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo
rd`" |
| 544 if [ x"$binary" != x"$check" ]; then |
| 545 echo no |
| 546 exit_success |
| 547 fi |
| 548 echo yes |
| 549 exit_success |
| 550 } |
| 551 |
| 552 set_url_scheme_handler_gnome() |
| 553 { |
| 554 binary="`desktop_file_to_binary "$2"`" |
| 555 [ "$binary" ] || exit_failure_file_missing |
| 556 |
| 557 gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$bin
ary %s" |
| 558 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal
false |
| 559 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true |
| 560 } |
| 561 |
| 562 # }}} GNOME |
| 563 # {{{ GNOME 3.x |
| 564 |
| 565 get_url_scheme_handler_gnome3() |
| 566 { |
| 567 get_browser_mime "x-scheme-handler/$1" |
| 568 } |
| 569 |
| 570 check_url_scheme_handler_gnome3() |
| 571 { |
| 572 desktop="$2" |
| 573 check="`desktop_file_to_binary "$2"`" |
| 574 if [ -z "$check" ]; then |
| 575 echo no |
| 576 exit_success |
| 577 fi |
| 578 browser="`get_browser_mime "x-scheme-handler/$1"`" |
| 579 if [ x"$browser" != x"$desktop" ]; then |
| 580 echo no |
| 581 exit_success |
| 582 fi |
| 583 echo yes |
| 584 exit_success |
| 585 } |
| 586 |
| 587 set_url_scheme_handler_gnome3() |
| 588 { |
| 589 binary="`desktop_file_to_binary "$2"`" |
| 590 [ "$binary" ] || exit_failure_file_missing |
| 591 set_browser_mime "$2" || return |
| 592 |
| 593 # Set the default browser. |
| 594 set_browser_mime "$2" "x-scheme-handler/$1" || return |
| 595 } |
| 596 |
| 597 # }}} GNOME 3.x |
| 598 # {{{ xfce |
| 599 |
| 600 get_url_scheme_handler_xfce() |
| 601 { |
| 602 exit_unimplemented_default_handler "$1" |
| 603 } |
| 604 |
| 605 check_url_scheme_handler_xfce() |
| 606 { |
| 607 exit_unimplemented_default_handler "$1" |
| 608 } |
| 609 |
| 610 set_url_scheme_handler_xfce() |
| 611 { |
| 612 exit_unimplemented_default_handler "$1" |
| 613 } |
| 614 |
| 615 # }}} xfce |
| 616 # }}} default protocol handler |
| 617 |
445 dispatch_specific() | 618 dispatch_specific() |
446 { | 619 { |
447 # The PROP comments in this function are used to generate the output of | 620 # The PROP comments in this function are used to generate the output of |
448 # the --list option. The formatting is important. Make sure to line up the | 621 # the --list option. The formatting is important. Make sure to line up the |
449 # property descriptions with spaces so that it will look nice. | 622 # property descriptions with spaces so that it will look nice. |
450 if [ x"$op" = x"get" ]; then | 623 if [ x"$op" = x"get" ]; then |
451 case "$parm" in | 624 case "$parm" in |
452 default-web-browser) # PROP: Default web browser | 625 default-web-browser) # PROP: Default web browser |
453 get_browser_$DE | 626 get_browser_$DE |
454 ;; | 627 ;; |
455 | 628 |
| 629 default-url-scheme-handler) # PROP: Default handler for URL scheme |
| 630 get_url_scheme_handler_$DE "$1" |
| 631 ;; |
| 632 |
456 *) | 633 *) |
457 exit_failure_syntax | 634 exit_failure_syntax |
458 ;; | 635 ;; |
459 esac | 636 esac |
460 elif [ x"$op" = x"check" ]; then | 637 elif [ x"$op" = x"check" ]; then |
461 case "$parm" in | 638 case "$parm" in |
462 default-web-browser) | 639 default-web-browser) |
463 check_desktop_filename "$1" | 640 check_desktop_filename "$1" |
464 check_browser_$DE "$1" | 641 check_browser_$DE "$1" |
465 ;; | 642 ;; |
466 | 643 |
| 644 default-url-scheme-handler) |
| 645 check_desktop_filename "$2" |
| 646 check_url_scheme_handler_$DE "$1" "$2" |
| 647 ;; |
| 648 |
467 *) | 649 *) |
468 exit_failure_syntax | 650 exit_failure_syntax |
469 ;; | 651 ;; |
470 esac | 652 esac |
471 else # set | 653 else # set |
472 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument" | |
473 case "$parm" in | 654 case "$parm" in |
474 default-web-browser) | 655 default-web-browser) |
| 656 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument" |
475 check_desktop_filename "$1" | 657 check_desktop_filename "$1" |
476 set_browser_$DE "$1" | 658 set_browser_$DE "$1" |
477 ;; | 659 ;; |
478 | 660 |
| 661 default-url-scheme-handler) |
| 662 [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument" |
| 663 check_desktop_filename "$2" |
| 664 set_url_scheme_handler_$DE "$1" "$2" |
| 665 ;; |
| 666 |
479 *) | 667 *) |
480 exit_failure_syntax | 668 exit_failure_syntax |
481 ;; | 669 ;; |
482 esac | 670 esac |
483 fi | 671 fi |
484 | 672 |
485 if [ $? -eq 0 ]; then | 673 if [ $? -eq 0 ]; then |
486 exit_success | 674 exit_success |
487 else | 675 else |
488 exit_failure_operation_failed | 676 exit_failure_operation_failed |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 ;; | 743 ;; |
556 | 744 |
557 generic) | 745 generic) |
558 dispatch_generic "$@" | 746 dispatch_generic "$@" |
559 ;; | 747 ;; |
560 | 748 |
561 *) | 749 *) |
562 exit_failure_operation_impossible "unknown desktop environment" | 750 exit_failure_operation_impossible "unknown desktop environment" |
563 ;; | 751 ;; |
564 esac | 752 esac |
OLD | NEW |