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

Side by Side Diff: scripts/xdg-settings

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
« no previous file with comments | « scripts/man/xdg-settings.1 ('k') | scripts/xdg-settings.in » ('j') | 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 21 matching lines...) Expand all
32 32
33 manualpage() 33 manualpage()
34 { 34 {
35 cat << _MANUALPAGE 35 cat << _MANUALPAGE
36 Name 36 Name
37 37
38 xdg-settings - get various settings from the desktop environment 38 xdg-settings - get various settings from the desktop environment
39 39
40 Synopsis 40 Synopsis
41 41
42 xdg-settings { get | check | set } {property} [value] 42 xdg-settings { get | check | set } {property} [subproperty] [value]
43 43
44 xdg-settings { --help | --list | --manual | --version } 44 xdg-settings { --help | --list | --manual | --version }
45 45
46 Description 46 Description
47 47
48 xdg-settings gets various settings from the desktop environment. For instance, 48 xdg-settings gets various settings from the desktop environment. For instance,
49 desktop environments often provide proxy configuration and default web browser 49 desktop environments often provide proxy configuration and default web browser
50 settings. Using xdg-settings these parameters can be extracted for use by 50 settings. Using xdg-settings these parameters can be extracted for use by
51 applications that do not use the desktop environment's libraries (which would 51 applications that do not use the desktop environment's libraries (which would
52 use the settings natively). 52 use the settings natively).
53 53
54 xdg-settings is for use inside a desktop session only. It is not recommended to 54 xdg-settings is for use inside a desktop session only. It is not recommended to
55 use xdg-settings as root. 55 use xdg-settings as root.
56 56
57 Options 57 Options
58 58
59 --help 59 --help
60 Show command synopsis. 60 Show command synopsis.
61 --list 61 --list
62 List all properties xdg-settings knows about. 62 List all properties xdg-settings knows about.
63 --manual 63 --manual
64 Show this manualpage. 64 Show this manualpage.
65 --version 65 --version
66 Show the xdg-utils version information. 66 Show the xdg-utils version information.
67 67
68 Properties
69
70 When using xdg-settings to get, check or set a destkop setting, properties and
71 possibly sub-properties are used to specify the setting to be changed.
72
73 Some properties (such as default-web-browser) fully describe the setting to be
74 changed. Other properties (such as default-url-scheme-handler) require more
75 information (in this case the actual scheme to set the default handler for)
76 which must be provided in a sub-property.
77
68 Exit Codes 78 Exit Codes
69 79
70 An exit code of 0 indicates success while a non-zero exit code indicates 80 An exit code of 0 indicates success while a non-zero exit code indicates
71 failure. The following failure codes can be returned: 81 failure. The following failure codes can be returned:
72 82
73 1 83 1
74 Error in command line syntax. 84 Error in command line syntax.
75 2 85 2
76 One of the files passed on the command line did not exist. 86 One of the files passed on the command line did not exist.
77 3 87 3
(...skipping 13 matching lines...) Expand all
91 of the underlying settings actually reflect that value) 101 of the underlying settings actually reflect that value)
92 102
93 xdg-settings check default-web-browser firefox.desktop 103 xdg-settings check default-web-browser firefox.desktop
94 104
95 105
96 Set the default web browser to google-chrome.desktop 106 Set the default web browser to google-chrome.desktop
97 107
98 xdg-settings set default-web-browser google-chrome.desktop 108 xdg-settings set default-web-browser google-chrome.desktop
99 109
100 110
111 Set the default mailto URL scheme handler to be evolution.desktop
112
113 xdg-settings set default-url-scheme-handler mailto evolution.desktop
114
115
101 _MANUALPAGE 116 _MANUALPAGE
102 } 117 }
103 118
104 usage() 119 usage()
105 { 120 {
106 cat << _USAGE 121 cat << _USAGE
107 xdg-settings - get various settings from the desktop environment 122 xdg-settings - get various settings from the desktop environment
108 123
109 Synopsis 124 Synopsis
110 125
111 xdg-settings { get | check | set } {property} [value] 126 xdg-settings { get | check | set } {property} [subproperty] [value]
112 127
113 xdg-settings { --help | --list | --manual | --version } 128 xdg-settings { --help | --list | --manual | --version }
114 129
115 _USAGE 130 _USAGE
116 } 131 }
117 132
118 #@xdg-utils-common@ 133 #@xdg-utils-common@
119 134
120 #---------------------------------------------------------------------------- 135 #----------------------------------------------------------------------------
121 # Common utility functions included in all XDG wrapper scripts 136 # Common utility functions included in all XDG wrapper scripts
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications" 547 mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications"
533 xdg-mime default "$1" "$MIME" || return 548 xdg-mime default "$1" "$MIME" || return
534 if [ x"`get_browser_mime`" != x"$1" ]; then 549 if [ x"`get_browser_mime`" != x"$1" ]; then
535 # Put back the original value 550 # Put back the original value
536 xdg-mime default "$orig" "$MIME" 551 xdg-mime default "$orig" "$MIME"
537 exit_failure_operation_failed 552 exit_failure_operation_failed
538 fi 553 fi
539 } 554 }
540 555
541 # }}} MIME utilities 556 # }}} MIME utilities
557 # {{{ KDE utilities
558
559 # Reads the KDE configuration setting, compensating for a bug in some versions o f kreadconfig.
560 read_kde_config()
561 {
562 configfile="$1"
563 configsection="$2"
564 configkey="$3"
565 application="`kreadconfig --file $configfile --group $configsection --key $c onfigkey`"
566 if [ x"$application" != x ]; then
567 echo "$application"
568 else
569 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
570 # check by hand if it didn't find anything (oddly kwriteconfig works
571 # fine though).
572 configfile_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
573 configfile_path="$configfile_dir/$configfile"
574 [ ! -f "$configfile_path" ] && return
575 # This will only take the first value if there is more than one.
576 grep "^$configkey"'\[$[^]=]*\]=' "$configfile_path" | head -n 1 | cut -d = -f 2-
577 fi
578 }
579
580 # }}} KDE utilities
542 # {{{ KDE 581 # {{{ KDE
543 582
544 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov es it; 583 # Resolves the KDE browser setting to a binary: if prefixed with !, simply remov es it;
545 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi le. 584 # otherwise, uses desktop_file_to_binary to get the binary out of the desktop fi le.
546 resolve_kde_browser() 585 resolve_kde_browser()
547 { 586 {
548 [ -z "$browser" ] && return 587 [ -z "$browser" ] && return
549 case "$browser" in 588 case "$browser" in
550 !*) 589 !*)
551 echo "${browser#!}" 590 echo "${browser#!}"
(...skipping 13 matching lines...) Expand all
565 !*) 604 !*)
566 desktop="`binary_to_desktop_file "${browser#!}"`" 605 desktop="`binary_to_desktop_file "${browser#!}"`"
567 basename "$desktop" 606 basename "$desktop"
568 ;; 607 ;;
569 *) 608 *)
570 echo "$browser" 609 echo "$browser"
571 ;; 610 ;;
572 esac 611 esac
573 } 612 }
574 613
575 # Reads the KDE browser setting, compensating for a bug in some versions of krea dconfig.
576 read_kde_browser() 614 read_kde_browser()
577 { 615 {
578 browser="`kreadconfig --file kdeglobals --group General --key BrowserApplica tion`" 616 read_kde_config kdeglobals General BrowserApplication
579 if [ x"$browser" != x ]; then
580 echo "$browser"
581 else
582 # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
583 # check by hand if it didn't find anything (oddly kwriteconfig works
584 # fine though).
585 kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
586 kdeglobals="$kdeglobals_dir/kdeglobals"
587 [ ! -f "$kdeglobals" ] && return
588 # This will only take the first value if there is more than one.
589 grep '^BrowserApplication\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut - d= -f 2-
590 fi
591 } 617 }
592 618
593 get_browser_kde() 619 get_browser_kde()
594 { 620 {
595 browser="`read_kde_browser`" 621 browser="`read_kde_browser`"
596 if [ x"$browser" = x ]; then 622 if [ x"$browser" = x ]; then
597 # No explicit default browser; KDE will use the MIME type text/html. 623 # No explicit default browser; KDE will use the MIME type text/html.
598 get_browser_mime 624 get_browser_mime
599 else 625 else
600 resolve_kde_browser_desktop 626 resolve_kde_browser_desktop
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 mv "$temp" "$helpers_rc" 862 mv "$temp" "$helpers_rc"
837 else 863 else
838 rm -f "$temp" 864 rm -f "$temp"
839 return 1 865 return 1
840 fi 866 fi
841 } 867 }
842 868
843 # }}} xfce 869 # }}} xfce
844 # }}} default browser 870 # }}} default browser
845 871
872 # {{{ default url scheme handler
873
874 exit_unimplemented_default_handler()
875 {
876 exit_failure_operation_impossible "default-url-scheme-handler not implemente d for $DE"
877 }
878
879 # {{{ KDE
880
881 # Recent versions of KDE support default scheme handler applications using the
882 # mime type of x-scheme-handler/scheme. Older versions will not support this
883 # but do have support for setting a default mail handler. There is also a
884 # system in KDE where .protocol files can be used, however this is not
885 # supported by this script. When reading a scheme handler we will use the
886 # default mail handler for the mailto scheme, otherwise we will use the mime
887 # type x-scheme-handler/scheme.
888
889 get_url_scheme_handler_kde()
890 {
891 if [ "$1" = "mailto" ]; then
892 handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | fi rst_word`"
893 echo "handler is $handler"
894 if [ x"$handler" != x ]; then
895 binary_to_desktop_file "$handler"
896 else
897 get_browser_mime "x-scheme-handler/$1"
898 fi
899 else
900 get_browser_mime "x-scheme-handler/$1"
901 fi
902 }
903
904 check_url_scheme_handler_kde()
905 {
906 check="`desktop_file_to_binary "$2"`"
907 if [ -z "$check" ]; then
908 echo no
909 exit_success
910 fi
911 if [ x"$1" = "mailto" ]; then
912 binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`"
913 if [ x"$binary" != x"$check" ]; then
914 echo no
915 exit_success
916 fi
917 fi
918 handler="`get_browser_mime x-scheme-handler/$1`"
919 binary="`desktop_file_to_binary "$handler"`"
920 if [ x"$binary" != x"$check" ]; then
921 echo no
922 exit_success
923 fi
924 echo yes
925 exit_success
926 }
927
928 set_url_scheme_handler_kde()
929 {
930 set_browser_mime "$2" "x-scheme-handler/$1" || return
931 if [ "$1" = "mailto" ]; then
932 binary="`desktop_file_to_binary "$2"`"
933 kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailCli ent "$binary"
934 fi
935 }
936
937 # }}} KDE
938 # {{{ GNOME
939
940 get_url_scheme_handler_gnome()
941 {
942 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo rd`"
943 if [ x"$binary" != x"" ]; then
944 # gconftool gives the binary (maybe with %s etc. afterward),
945 # but we want the desktop file name, not the binary. So, we
946 # have to find the desktop file to which it corresponds.
947 desktop="`binary_to_desktop_file "$binary"`"
948 basename "$desktop"
949 fi
950 }
951
952 check_url_scheme_handler_gnome()
953 {
954 check="`desktop_file_to_binary "$2"`"
955 if [ -z "$check" ]; then
956 echo no
957 exit_success
958 fi
959 binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_wo rd`"
960 if [ x"$binary" != x"$check" ]; then
961 echo no
962 exit_success
963 fi
964 echo yes
965 exit_success
966 }
967
968 set_url_scheme_handler_gnome()
969 {
970 binary="`desktop_file_to_binary "$2"`"
971 [ "$binary" ] || exit_failure_file_missing
972
973 gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$bin ary %s"
974 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal false
975 gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true
976 }
977
978 # }}} GNOME
979 # {{{ GNOME 3.x
980
981 get_url_scheme_handler_gnome3()
982 {
983 get_browser_mime "x-scheme-handler/$1"
984 }
985
986 check_url_scheme_handler_gnome3()
987 {
988 desktop="$2"
989 check="`desktop_file_to_binary "$2"`"
990 if [ -z "$check" ]; then
991 echo no
992 exit_success
993 fi
994 browser="`get_browser_mime "x-scheme-handler/$1"`"
995 if [ x"$browser" != x"$desktop" ]; then
996 echo no
997 exit_success
998 fi
999 echo yes
1000 exit_success
1001 }
1002
1003 set_url_scheme_handler_gnome3()
1004 {
1005 binary="`desktop_file_to_binary "$2"`"
1006 [ "$binary" ] || exit_failure_file_missing
1007 set_browser_mime "$2" || return
1008
1009 # Set the default browser.
1010 set_browser_mime "$2" "x-scheme-handler/$1" || return
1011 }
1012
1013 # }}} GNOME 3.x
1014 # {{{ xfce
1015
1016 get_url_scheme_handler_xfce()
1017 {
1018 exit_unimplemented_default_handler "$1"
1019 }
1020
1021 check_url_scheme_handler_xfce()
1022 {
1023 exit_unimplemented_default_handler "$1"
1024 }
1025
1026 set_url_scheme_handler_xfce()
1027 {
1028 exit_unimplemented_default_handler "$1"
1029 }
1030
1031 # }}} xfce
1032 # }}} default protocol handler
1033
846 dispatch_specific() 1034 dispatch_specific()
847 { 1035 {
848 # The PROP comments in this function are used to generate the output of 1036 # The PROP comments in this function are used to generate the output of
849 # the --list option. The formatting is important. Make sure to line up the 1037 # the --list option. The formatting is important. Make sure to line up the
850 # property descriptions with spaces so that it will look nice. 1038 # property descriptions with spaces so that it will look nice.
851 if [ x"$op" = x"get" ]; then 1039 if [ x"$op" = x"get" ]; then
852 case "$parm" in 1040 case "$parm" in
853 default-web-browser) # PROP: Default web browser 1041 default-web-browser) # PROP: Default web browser
854 get_browser_$DE 1042 get_browser_$DE
855 ;; 1043 ;;
856 1044
1045 default-url-scheme-handler) # PROP: Default handler for URL scheme
1046 get_url_scheme_handler_$DE "$1"
1047 ;;
1048
857 *) 1049 *)
858 exit_failure_syntax 1050 exit_failure_syntax
859 ;; 1051 ;;
860 esac 1052 esac
861 elif [ x"$op" = x"check" ]; then 1053 elif [ x"$op" = x"check" ]; then
862 case "$parm" in 1054 case "$parm" in
863 default-web-browser) 1055 default-web-browser)
864 check_desktop_filename "$1" 1056 check_desktop_filename "$1"
865 check_browser_$DE "$1" 1057 check_browser_$DE "$1"
866 ;; 1058 ;;
867 1059
1060 default-url-scheme-handler)
1061 check_desktop_filename "$2"
1062 check_url_scheme_handler_$DE "$1" "$2"
1063 ;;
1064
868 *) 1065 *)
869 exit_failure_syntax 1066 exit_failure_syntax
870 ;; 1067 ;;
871 esac 1068 esac
872 else # set 1069 else # set
873 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
874 case "$parm" in 1070 case "$parm" in
875 default-web-browser) 1071 default-web-browser)
1072 [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
876 check_desktop_filename "$1" 1073 check_desktop_filename "$1"
877 set_browser_$DE "$1" 1074 set_browser_$DE "$1"
878 ;; 1075 ;;
879 1076
1077 default-url-scheme-handler)
1078 [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument"
1079 check_desktop_filename "$2"
1080 set_url_scheme_handler_$DE "$1" "$2"
1081 ;;
1082
880 *) 1083 *)
881 exit_failure_syntax 1084 exit_failure_syntax
882 ;; 1085 ;;
883 esac 1086 esac
884 fi 1087 fi
885 1088
886 if [ $? -eq 0 ]; then 1089 if [ $? -eq 0 ]; then
887 exit_success 1090 exit_success
888 else 1091 else
889 exit_failure_operation_failed 1092 exit_failure_operation_failed
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 ;; 1159 ;;
957 1160
958 generic) 1161 generic)
959 dispatch_generic "$@" 1162 dispatch_generic "$@"
960 ;; 1163 ;;
961 1164
962 *) 1165 *)
963 exit_failure_operation_impossible "unknown desktop environment" 1166 exit_failure_operation_impossible "unknown desktop environment"
964 ;; 1167 ;;
965 esac 1168 esac
OLDNEW
« no previous file with comments | « scripts/man/xdg-settings.1 ('k') | scripts/xdg-settings.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698