~saiarcot895/ubuntu/wily/xdg-utils/fix-multiple-execs

« back to all changes in this revision

Viewing changes to scripts/xdg-settings

  • Committer: Package Import Robot
  • Author(s): Per Olofsson
  • Date: 2011-12-12 12:04:25 UTC
  • mfrom: (1.2.8)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: package-import@ubuntu.com-20111212120425-0rdnrl8tn45vz171
Tags: 1.1.0~rc1+git20111210-1
* New upstream git snapshot b961235b197647d6649ef3d48d7cc2cecafe3d47.
* Drop patches applied upstream:
  - xdg-mime-follow-symlinks.diff
  - x-www-browser.diff
  - xdg-mime-generic-use-mimetype.diff
  - bashisms.diff
  - xdg-screensaver-check-gnome.diff
* Modify patches to make changes to scripts/xdg-*.in, instead of the
  generated scripts.
* Also check for ~/.mutt/muttrc when deciding whether to use mutt as
  MUA or not. Thanks to martin f krafft. Closes: #648733.
* Build scripts/xdg-* from *.in files.
* Build-depend on xmlto and awk, as they are needed when building the
  scripts.
* Also build the manual pages.
* Bump Standards-Version to 3.9.2. No changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
Synopsis
41
41
 
42
 
xdg-settings { get | check | set } {property} [value]
 
42
xdg-settings { get | check | set } {property} [subproperty] [value]
43
43
 
44
44
xdg-settings { --help | --list | --manual | --version }
45
45
 
65
65
--version
66
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
78
Exit Codes
69
79
 
70
80
An exit code of 0 indicates success while a non-zero exit code indicates
98
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
116
_MANUALPAGE
102
117
}
103
118
 
108
123
 
109
124
Synopsis
110
125
 
111
 
xdg-settings { get | check | set } {property} [value]
 
126
xdg-settings { get | check | set } {property} [subproperty] [value]
112
127
 
113
128
xdg-settings { --help | --list | --manual | --version }
114
129
 
287
302
            ;;
288
303
 
289
304
            --version)
290
 
            echo "xdg-settings 1.0.2"
 
305
            echo "xdg-settings 1.1.0 rc1"
291
306
            exit_success
292
307
            ;;
293
308
        esac
315
330
    elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
316
331
    elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
317
332
    elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
318
 
    elif [ x"$DESKTOP_SESSION" = x"LXDE" ]; then DE=lxde;
 
333
    elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
319
334
    else DE=""
320
335
    fi
321
336
}
327
342
 
328
343
kfmclient_fix_exit_code()
329
344
{
330
 
    version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep '^KDE'`
 
345
    [ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
 
346
    version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
331
347
    major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
332
348
    minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
333
349
    release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
487
503
}
488
504
 
489
505
# }}} MIME utilities
 
506
# {{{ KDE utilities
 
507
 
 
508
# Reads the KDE configuration setting, compensating for a bug in some versions of kreadconfig.
 
509
read_kde_config()
 
510
{
 
511
    configfile="$1"
 
512
    configsection="$2"
 
513
    configkey="$3"
 
514
    application="`kreadconfig --file $configfile --group $configsection --key $configkey`"
 
515
    if [ x"$application" != x ]; then
 
516
        echo "$application"
 
517
    else
 
518
        # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
 
519
        # check by hand if it didn't find anything (oddly kwriteconfig works
 
520
        # fine though).
 
521
        configfile_dir=`kde${KDE_SESSION_VERSION}-config --path config  | cut -d ':' -f 1`
 
522
        configfile_path="$configfile_dir/$configfile"
 
523
        [ ! -f "$configfile_path" ] && return
 
524
        # This will only take the first value if there is more than one.
 
525
        grep "^$configkey"'\[$[^]=]*\]=' "$configfile_path" | head -n 1 | cut -d= -f 2-
 
526
    fi
 
527
}
 
528
 
 
529
# }}} KDE utilities
490
530
# {{{ KDE
491
531
 
492
532
# Resolves the KDE browser setting to a binary: if prefixed with !, simply removes it;
520
560
    esac
521
561
}
522
562
 
523
 
# Reads the KDE browser setting, compensating for a bug in some versions of kreadconfig.
524
563
read_kde_browser()
525
564
{
526
 
    browser="`kreadconfig --file kdeglobals --group General --key BrowserApplication`"
527
 
    if [ x"$browser" != x ]; then
528
 
        echo "$browser"
529
 
    else
530
 
        # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
531
 
        # check by hand if it didn't find anything (oddly kwriteconfig works
532
 
        # fine though).
533
 
        kdeglobals_dir=`kde${KDE_SESSION_VERSION}-config --path config  | cut -d ':' -f 1`
534
 
        kdeglobals="$kdeglobals_dir/kdeglobals"
535
 
        [ ! -f "$kdeglobals" ] && return
536
 
        # This will only take the first value if there is more than one.
537
 
        grep '^BrowserApplication\[$[^]=]*\]=' "$kdeglobals" | head -n 1 | cut -d= -f 2-
538
 
    fi
 
565
    read_kde_config kdeglobals General BrowserApplication
539
566
}
540
567
 
541
568
get_browser_kde()
752
779
# }}} xfce
753
780
# }}} default browser
754
781
 
 
782
# {{{ default url scheme handler
 
783
 
 
784
exit_unimplemented_default_handler()
 
785
{
 
786
    exit_failure_operation_impossible "default-url-scheme-handler not implemented for $DE"
 
787
}
 
788
 
 
789
# {{{ KDE
 
790
 
 
791
# Recent versions of KDE support default scheme handler applications using the
 
792
# mime type of x-scheme-handler/scheme. Older versions will not support this
 
793
# but do have support for setting a default mail handler. There is also a
 
794
# system in KDE where .protocol files can be used, however this is not
 
795
# supported by this script. When reading a scheme handler we will use the
 
796
# default mail handler for the mailto scheme, otherwise we will use the mime
 
797
# type x-scheme-handler/scheme.
 
798
 
 
799
get_url_scheme_handler_kde()
 
800
{
 
801
    if [ "$1" = "mailto" ]; then
 
802
        handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | first_word`"
 
803
        echo "handler is $handler"
 
804
        if [ x"$handler" != x ]; then
 
805
            binary_to_desktop_file "$handler"
 
806
        else
 
807
            get_browser_mime "x-scheme-handler/$1"
 
808
        fi
 
809
    else 
 
810
        get_browser_mime "x-scheme-handler/$1"
 
811
    fi
 
812
}
 
813
 
 
814
check_url_scheme_handler_kde()
 
815
{
 
816
    check="`desktop_file_to_binary "$2"`"
 
817
    if [ -z "$check" ]; then
 
818
        echo no
 
819
        exit_success
 
820
    fi
 
821
    if [ x"$1" = "mailto" ]; then
 
822
        binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`"
 
823
        if [ x"$binary" != x"$check" ]; then
 
824
            echo no
 
825
            exit_success
 
826
        fi
 
827
    fi
 
828
    handler="`get_browser_mime x-scheme-handler/$1`"
 
829
    binary="`desktop_file_to_binary "$handler"`"
 
830
    if [ x"$binary" != x"$check" ]; then
 
831
        echo no
 
832
        exit_success
 
833
    fi
 
834
    echo yes
 
835
    exit_success
 
836
}
 
837
 
 
838
set_url_scheme_handler_kde()
 
839
{
 
840
    set_browser_mime "$2" "x-scheme-handler/$1" || return
 
841
    if [ "$1" = "mailto" ]; then
 
842
        binary="`desktop_file_to_binary "$2"`"
 
843
        kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailClient "$binary"
 
844
    fi
 
845
}
 
846
 
 
847
# }}} KDE
 
848
# {{{ GNOME
 
849
 
 
850
get_url_scheme_handler_gnome()
 
851
{
 
852
    binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
 
853
    if [ x"$binary" != x"" ]; then
 
854
        # gconftool gives the binary (maybe with %s etc. afterward),
 
855
        # but we want the desktop file name, not the binary. So, we
 
856
        # have to find the desktop file to which it corresponds.
 
857
        desktop="`binary_to_desktop_file "$binary"`"
 
858
        basename "$desktop"
 
859
    fi
 
860
}
 
861
 
 
862
check_url_scheme_handler_gnome()
 
863
{
 
864
    check="`desktop_file_to_binary "$2"`"
 
865
    if [ -z "$check" ]; then
 
866
        echo no
 
867
        exit_success
 
868
    fi
 
869
    binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
 
870
    if [ x"$binary" != x"$check" ]; then
 
871
        echo no
 
872
        exit_success
 
873
    fi
 
874
    echo yes
 
875
    exit_success
 
876
}
 
877
 
 
878
set_url_scheme_handler_gnome()
 
879
{
 
880
    binary="`desktop_file_to_binary "$2"`"
 
881
    [ "$binary" ] || exit_failure_file_missing
 
882
 
 
883
    gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$binary %s"
 
884
    gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal false
 
885
    gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true
 
886
}
 
887
 
 
888
# }}} GNOME
 
889
# {{{ GNOME 3.x
 
890
 
 
891
get_url_scheme_handler_gnome3()
 
892
{
 
893
    get_browser_mime "x-scheme-handler/$1"
 
894
}
 
895
 
 
896
check_url_scheme_handler_gnome3()
 
897
{
 
898
    desktop="$2"
 
899
    check="`desktop_file_to_binary "$2"`"
 
900
    if [ -z "$check" ]; then
 
901
        echo no
 
902
        exit_success
 
903
    fi
 
904
    browser="`get_browser_mime "x-scheme-handler/$1"`"
 
905
    if [ x"$browser" != x"$desktop" ]; then
 
906
        echo no
 
907
        exit_success
 
908
    fi
 
909
    echo yes
 
910
    exit_success
 
911
}
 
912
 
 
913
set_url_scheme_handler_gnome3()
 
914
{
 
915
    binary="`desktop_file_to_binary "$2"`"
 
916
    [ "$binary" ] || exit_failure_file_missing
 
917
    set_browser_mime "$2" || return
 
918
 
 
919
    # Set the default browser.
 
920
    set_browser_mime "$2" "x-scheme-handler/$1" || return
 
921
}
 
922
 
 
923
# }}} GNOME 3.x
 
924
# {{{ xfce
 
925
 
 
926
get_url_scheme_handler_xfce()
 
927
{
 
928
    exit_unimplemented_default_handler "$1"
 
929
}
 
930
 
 
931
check_url_scheme_handler_xfce()
 
932
{
 
933
    exit_unimplemented_default_handler "$1"
 
934
}
 
935
 
 
936
set_url_scheme_handler_xfce()
 
937
{
 
938
    exit_unimplemented_default_handler "$1"
 
939
}
 
940
 
 
941
# }}} xfce
 
942
# }}} default protocol handler
 
943
 
755
944
dispatch_specific()
756
945
{
757
946
    # The PROP comments in this function are used to generate the output of
763
952
            get_browser_$DE
764
953
            ;;
765
954
 
 
955
          default-url-scheme-handler) # PROP:    Default handler for URL scheme
 
956
            get_url_scheme_handler_$DE "$1"
 
957
            ;;
 
958
 
766
959
          *)
767
960
            exit_failure_syntax
768
961
            ;;
774
967
            check_browser_$DE "$1"
775
968
            ;;
776
969
 
 
970
          default-url-scheme-handler)
 
971
            check_desktop_filename "$2"
 
972
            check_url_scheme_handler_$DE "$1" "$2"
 
973
            ;;
 
974
 
777
975
          *)
778
976
            exit_failure_syntax
779
977
            ;;
780
978
        esac
781
979
    else # set
782
 
        [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
783
980
        case "$parm" in
784
981
          default-web-browser)
 
982
            [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
785
983
            check_desktop_filename "$1"
786
984
            set_browser_$DE "$1"
787
985
            ;;
788
986
 
 
987
          default-url-scheme-handler)
 
988
            [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument"
 
989
            check_desktop_filename "$2"
 
990
            set_url_scheme_handler_$DE "$1" "$2"
 
991
            ;;
 
992
 
789
993
          *)
790
994
            exit_failure_syntax
791
995
            ;;