Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: scripts/xdg-settings.in

Issue 7433003: Allow xdg-settings to set the default OS handler for url protocols. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/xdg-utils/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« scripts/man/xdg-settings.1 ('K') | « scripts/xdg-settings ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 browser="`kreadconfig --file $configfile --group $configsection --key $confi gkey`"
150 if [ x"$browser" != x ]; then
Mike Mammarella 2011/07/20 00:58:11 Might be good to rename browser to something more
benwells 2011/07/20 04:33:42 Done.
151 echo "$browser"
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 kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
Mike Mammarella 2011/07/20 00:58:11 Same with kdeglobals_dir and kdeglobals.
benwells 2011/07/20 04:33:42 Done.
157 kdeglobals="$kdeglobals_dir/$configfile"
158 [ ! -f "$kdeglobals" ] && return
159 # This will only take the first value if there is more than one.
160 grep "^$configkey"'\[$[^]=]*\]=' "$kdeglobals" | 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
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
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 m ime type
Mike Mammarella 2011/07/20 00:58:11 I might try to format this comment to fit in 80 ch
benwells 2011/07/20 04:33:42 Done.
466 # of x-scheme-handler/scheme. Older versions will not support this but do have s upport
467 # for setting a default mail handler. There is also a system in KDE where .proto col files
468 # can be used, however this is not supported by this script.
469 # When reading a scheme handler we will use the default mail handler for the mai lto scheme,
470 # otherwise we will use the mime type x-scheme-handler/scheme.
471
472 get_url_scheme_handler_kde()
473 {
474 if [ "$1" = "mailto" ]; then
475 handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | fi rst_word`"
476 echo "handler is $handler"
477 if [ x"$handler" != x ]; then
478 binary_to_desktop_file "$handler"
479 else
480 get_browser_mime "x-scheme-handler/$1"
481 fi
482 else
483 get_browser_mime "x-scheme-handler/$1"
484 fi
485 }
486
487 check_url_scheme_handler_kde()
488 {
489 check="`desktop_file_to_binary "$2"`"
490 if [ -z "$check" ]; then
491 echo no
492 exit_success
493 fi
494 if [ x"$1" = "mailto" ]; then
495 binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`"
496 if [ x"$binary" != x"$check" ]; then
497 echo no
498 exit_success
499 fi
500 fi
501 handler="`get_browser_mime x-scheme-handler/$1`"
502 binary="`desktop_file_to_binary "$handler"`"
503 if [ x"$binary" != x"$check" ]; then
504 echo no
505 exit_success
506 fi
507 echo yes
508 exit_success
509 }
510
511 set_url_scheme_handler_kde()
512 {
513 set_browser_mime "$2" "x-scheme-handler/$1" || return
514 if [ "$1" = "mailto" ]; then
515 binary="`desktop_file_to_binary "$2"`"
516 kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailCli ent "$binary"
517 fi
518 }
519
520 # }}} KDE
521 # {{{ GNOME
522
523 get_url_scheme_handler_gnome()
524 {
525 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo rd`"
526 if [ x"$binary" != x"" ]; then
527 # gconftool gives the binary (maybe with %s etc. afterward),
528 # but we want the desktop file name, not the binary. So, we
529 # have to find the desktop file to which it corresponds.
530 desktop="`binary_to_desktop_file "$binary"`"
531 basename "$desktop"
532 fi
533 }
534
535 check_url_scheme_handler_gnome()
536 {
537 check="`desktop_file_to_binary "$2"`"
538 if [ -z "$check" ]; then
539 echo no
540 exit_success
541 fi
542 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo rd`"
543 if [ x"$binary" != x"$check" ]; then
544 echo no
545 exit_success
546 fi
547 echo yes
548 exit_success
549 }
550
551 set_url_scheme_handler_gnome()
552 {
553 binary="`desktop_file_to_binary "$2"`"
554 [ "$binary" ] || exit_failure_file_missing
555
556 gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$bin ary %s"
557 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal false
558 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true
559 }
560
561 # }}} GNOME
562 # {{{ GNOME 3.x
563
564 get_url_scheme_handler_gnome3()
565 {
566 get_browser_mime "x-scheme-handler/$1"
567 }
568
569 check_url_scheme_handler_gnome3()
570 {
571 desktop="$2"
572 check="`desktop_file_to_binary "$2"`"
573 if [ -z "$check" ]; then
574 echo no
575 exit_success
576 fi
577 browser="`get_browser_mime "x-scheme-handler/$1"`"
578 if [ x"$browser" != x"$desktop" ]; then
579 echo no
580 exit_success
581 fi
582 echo yes
583 exit_success
584 }
585
586 set_url_scheme_handler_gnome3()
587 {
588 binary="`desktop_file_to_binary "$2"`"
589 [ "$binary" ] || exit_failure_file_missing
590 set_browser_mime "$2" || return
591
592 # Set the default browser.
593 set_browser_mime "$2" "x-scheme-handler/$1" || return
594 }
595
596 # }}} GNOME 3.x
597 # {{{ xfce
598
599 get_url_scheme_handler_xfce()
600 {
601 exit_unimplemented_default_handler "$1"
602 }
603
604 check_url_scheme_handler_xfce()
605 {
606 exit_unimplemented_default_handler "$1"
607 }
608
609 set_url_scheme_handler_xfce()
610 {
611 exit_unimplemented_default_handler "$1"
612 }
613
614 # }}} xfce
615 # }}} default protocol handler
616
445 dispatch_specific() 617 dispatch_specific()
446 { 618 {
447 # The PROP comments in this function are used to generate the output of 619 # 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 620 # the --list option. The formatting is important. Make sure to line up the
449 # property descriptions with spaces so that it will look nice. 621 # property descriptions with spaces so that it will look nice.
450 if [ x"$op" = x"get" ]; then 622 if [ x"$op" = x"get" ]; then
451 case "$parm" in 623 case "$parm" in
452 default-web-browser) # PROP: Default web browser 624 default-web-browser) # PROP: Default web browser
453 get_browser_$DE 625 get_browser_$DE
454 ;; 626 ;;
455 627
628 default-url-scheme-handler) # PROP: Default handler for url scheme
Mike Mammarella 2011/07/20 00:58:11 Optional: URL
benwells 2011/07/20 04:33:42 Done.
629 get_url_scheme_handler_$DE "$1"
630 ;;
631
456 *) 632 *)
457 exit_failure_syntax 633 exit_failure_syntax
458 ;; 634 ;;
459 esac 635 esac
460 elif [ x"$op" = x"check" ]; then 636 elif [ x"$op" = x"check" ]; then
461 case "$parm" in 637 case "$parm" in
462 default-web-browser) 638 default-web-browser)
463 check_desktop_filename "$1" 639 check_desktop_filename "$1"
464 check_browser_$DE "$1" 640 check_browser_$DE "$1"
465 ;; 641 ;;
466 642
643 default-*-handler)
Mike Mammarella 2011/07/20 00:58:11 Do you mean default-url-scheme-handler here?
benwells 2011/07/20 04:33:42 Done.
644 check_desktop_filename "$2"
645 check_url_scheme_handler_$DE "$1" "$2"
646 ;;
647
467 *) 648 *)
468 exit_failure_syntax 649 exit_failure_syntax
469 ;; 650 ;;
470 esac 651 esac
471 else # set 652 else # set
472 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
473 case "$parm" in 653 case "$parm" in
474 default-web-browser) 654 default-web-browser)
655 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
475 check_desktop_filename "$1" 656 check_desktop_filename "$1"
476 set_browser_$DE "$1" 657 set_browser_$DE "$1"
477 ;; 658 ;;
478 659
660 default-*-handler)
Mike Mammarella 2011/07/20 00:58:11 Same.
benwells 2011/07/20 04:33:42 Done.
661 [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument"
662 check_desktop_filename "$2"
663 set_url_scheme_handler_$DE "$1" "$2"
664 ;;
665
479 *) 666 *)
480 exit_failure_syntax 667 exit_failure_syntax
481 ;; 668 ;;
482 esac 669 esac
483 fi 670 fi
484 671
485 if [ $? -eq 0 ]; then 672 if [ $? -eq 0 ]; then
486 exit_success 673 exit_success
487 else 674 else
488 exit_failure_operation_failed 675 exit_failure_operation_failed
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 ;; 742 ;;
556 743
557 generic) 744 generic)
558 dispatch_generic "$@" 745 dispatch_generic "$@"
559 ;; 746 ;;
560 747
561 *) 748 *)
562 exit_failure_operation_impossible "unknown desktop environment" 749 exit_failure_operation_impossible "unknown desktop environment"
563 ;; 750 ;;
564 esac 751 esac
OLDNEW
« scripts/man/xdg-settings.1 ('K') | « scripts/xdg-settings ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698