~ubuntu-branches/ubuntu/trusty/fcitx/trusty-proposed

« back to all changes in this revision

Viewing changes to data/script/fcitx-configtool

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-02-10 17:03:56 UTC
  • mfrom: (1.3.18) (33.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130210170356-2yuv6xy3ed378kn0
Tags: 1:4.2.7-1
* New upstream release.
* New binary packages:
  - fcitx-libs-gclient: D-Bus client library for Glib
  - fcitx-libs-qt: D-Bus client library for Qt
  - fcitx-module-quickphrase-editor: Quick Phrase editor module

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
# from xdg-open
7
7
 
8
 
detectDE()
9
 
{
10
 
    if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
11
 
    elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
12
 
    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;
13
 
    elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
14
 
    fi
15
 
}
16
 
 
17
 
run_kde()
18
 
{
19
 
    command=`which kcmshell4 2>&1`
20
 
    haskde=0
21
 
    if [ $? -eq 0 ]; then
22
 
        checkinstalled=`$command --list | grep -c kcm_fcitx`
23
 
        if [ "x$checkinstalled" != "x0" ]; then
24
 
            haskde=1
25
 
        fi
26
 
    fi
27
 
 
28
 
    if [ $haskde = "1" ]; then
29
 
        if [ x"$1" != x ]; then
30
 
            exec $command kcm_fcitx --args $1
31
 
        else
32
 
            exec $command kcm_fcitx
33
 
        fi
34
 
    else
35
 
        run_gtk3 $1
36
 
    fi
37
 
}
38
 
 
39
 
run_gtk()
40
 
{
41
 
    command=`which fcitx-config-gtk 2>&1`
42
 
    if [ $? -eq 0 ]; then
43
 
        exec $command
44
 
    else
45
 
        run_xdg
46
 
    fi
47
 
}
48
 
 
49
 
run_gtk3()
50
 
{
51
 
    command=`which fcitx-config-gtk3 2>&1`
52
 
    if [ $? -eq 0 ]; then
53
 
        exec $command $1
54
 
    else
55
 
        run_gtk $1
56
 
    fi
57
 
}
58
 
 
59
 
run_xdg()
60
 
{
61
 
    command=`which xdg-open`
62
 
    if [ $? -eq 0 ]; then
63
 
        if [ x"$1" != x ]; then
64
 
            exec $command "$HOME/.config/fcitx/conf/$1.config"
 
8
detectDE() {
 
9
    # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
 
10
    unset GREP_OPTIONS
 
11
 
 
12
    if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
 
13
      case "${XDG_CURRENT_DESKTOP}" in
 
14
         GNOME)
 
15
           DE=gnome;
 
16
           ;;
 
17
         KDE)
 
18
           DE=kde;
 
19
           ;;
 
20
         LXDE)
 
21
           DE=lxde;
 
22
           ;;
 
23
         XFCE)
 
24
           DE=xfce
 
25
      esac
 
26
    fi
 
27
 
 
28
    if [ x"$DE" = x"" ]; then
 
29
      # classic fallbacks
 
30
      if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
 
31
      elif xprop -root KDE_FULL_SESSION 2> /dev/null | grep ' = \"true\"$' > /dev/null 2>&1; then DE=kde;
 
32
      elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
 
33
      elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
 
34
      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;
 
35
      elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
 
36
      elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
 
37
      fi
 
38
    fi
 
39
 
 
40
    if [ x"$DE" = x"" ]; then
 
41
      # fallback to checking $DESKTOP_SESSION
 
42
      case "$DESKTOP_SESSION" in
 
43
         gnome)
 
44
           DE=gnome;
 
45
           ;;
 
46
         LXDE|Lubuntu)
 
47
           DE=lxde;
 
48
           ;;
 
49
         xfce|xfce4|'Xfce Session')
 
50
           DE=xfce;
 
51
           ;;
 
52
      esac
 
53
    fi
 
54
 
 
55
    if [ x"$DE" = x"" ]; then
 
56
      # fallback to uname output for other platforms
 
57
      case "$(uname 2>/dev/null)" in
 
58
        Darwin)
 
59
          DE=darwin;
 
60
          ;;
 
61
      esac
 
62
    fi
 
63
 
 
64
    if [ x"$DE" = x"gnome" ]; then
 
65
      # gnome-default-applications-properties is only available in GNOME 2.x
 
66
      # but not in GNOME 3.x
 
67
      which gnome-default-applications-properties > /dev/null 2>&1  || DE="gnome3"
 
68
    fi
 
69
}
 
70
 
 
71
run_kde() {
 
72
    if (kcmshell4 --list 2>/dev/null | grep ^kcm_fcitx &>/dev/null); then
 
73
        if [ x"$1" != x ]; then
 
74
            exec kcmshell4 kcm_fcitx --args "$1"
 
75
        else
 
76
            exec kcmshell4 kcm_fcitx
 
77
        fi
 
78
    fi
 
79
}
 
80
 
 
81
run_gtk() {
 
82
    if which fcitx-config-gtk &>/dev/null; then
 
83
        exec fcitx-config-gtk "$1"
 
84
    fi
 
85
}
 
86
 
 
87
run_gtk3() {
 
88
    if which fcitx-config-gtk3 &>/dev/null; then
 
89
        exec fcitx-config-gtk3 "$1"
 
90
    fi
 
91
}
 
92
 
 
93
run_xdg() {
 
94
    if command="$(which xdg-open 2>/dev/null)"; then
 
95
        detect_im_addon $1
 
96
        if [ x"$filename" != x ]; then
 
97
            exec $command "$HOME/.config/fcitx/conf/$filename.config"
 
98
        else
 
99
            exec "$command" "$HOME/.config/fcitx/config"
 
100
        fi
 
101
    fi
 
102
}
 
103
 
 
104
_which_cmdline() {
 
105
    cmd="$(which "$1")" || return 1
 
106
    shift
 
107
    echo "$cmd $*"
 
108
}
 
109
 
 
110
detect_im_addon() {
 
111
    filename=$1
 
112
    addonname=
 
113
    if [ x"$filename" != x ]; then
 
114
        addonname=$(fcitx-remote -m $1 2>/dev/null)
 
115
        if [ "$?" != "0" ]; then
 
116
            filename=
 
117
        elif [ x"$addonname" != x ]; then
 
118
            filename=$addonname
 
119
        fi
 
120
    fi
 
121
 
 
122
    if [ ! -f "$HOME/.config/fcitx/conf/$filename.config" ]; then
 
123
        filename=
 
124
    fi
 
125
}
 
126
 
 
127
run_editor() {
 
128
    if command="$(_which_cmdline ${EDITOR} 2>/dev/null)" ||
 
129
        command="$(_which_cmdline ${VISUAL} 2>/dev/null)"; then
 
130
        detect_im_addon $1
 
131
        if [ x"$filename" != x ]; then
 
132
            exec $command "$HOME/.config/fcitx/conf/$filename.config"
65
133
        else
66
134
            exec $command "$HOME/.config/fcitx/config"
67
135
        fi
68
 
    else
69
 
        exit 0
70
136
    fi
71
137
}
72
138
 
73
 
if [ ! -n "$DISPLAY" ]; then
74
 
    [ -n "$EDITOR" ] && which $EDITOR > /dev/null 2>&1 && exec $EDITOR $HOME/.config/fcitx/config
75
 
    [ -n "$VISUAL" ] && which $VISUAL > /dev/null 2>&1 && exec $VISUAL $HOME/.config/fcitx/config
76
 
    echo 'Please run it under X, or set $EDITOR or $VISUAL'
 
139
if [ ! -n "$DISPLAY" ] && [ ! -n "$WAYLAND_DISPLAY" ]; then
 
140
    run_editor "$1"
 
141
    echo 'Please run it under X, or set $EDITOR or $VISUAL' >&2
77
142
    exit 0
78
143
fi
79
144
 
80
145
detectDE
81
146
 
 
147
# even if we are not on KDE, we should still try kde, some wrongly
 
148
# configured kde desktop cannot be detected (usually missing xprop)
 
149
# and if kde one can work, so why not use it if gtk, gtk3 not work?
 
150
# xdg/editor is never a prefered solution
82
151
case "$DE" in
83
152
    kde)
84
 
        run_kde $1
 
153
        order="kde gtk3 gtk xdg editor"
85
154
        ;;
86
155
    *)
87
 
        run_gtk3 $1
 
156
        order="gtk3 gtk kde xdg editor"
88
157
        ;;
89
158
esac
 
159
 
 
160
for cmd in $order; do
 
161
    run_${cmd} "$1"
 
162
done
 
163
 
 
164
echo 'Cannot find a command to run.' >&2