OLD_PATH=$PATH
PATH=/usr/bin:/usr/X11R6/bin:/opt/kde3/bin:$PATH

if ! type -p fcitx > /dev/null 2>&1 ; then
    echo "fcitx is not available."
    PATH=$OLD_PATH
    return 1
fi

#when skim installed, Autostart must be "false".
#here we move $HOME/.kde/share/config/skimrc to skimrc.orig.fcitx
case "$WINDOWMANAGER" in
    *kde*)
        if type -p skim > /dev/null 2>&1 \
          && ! grep -i -q "^[[:space:]]*Autostart.*=.*false" $HOME/.kde/share/config/skimrc
        then
            if [ -f $HOME/.kde/share/config/skimrc.orig.fcitx ] ; then
               mv -f $HOME/.kde/share/config/skimrc $HOME/.kde/share/config/skimrc.orig.fcitx
               chmod 777 $HOME/.kde/share/config/skimrc.orig.fcitx
            fi
        cat > $HOME/.kde/share/config/skimrc << __END
[General]
Autostart=false
__END
        chmod 777 $HOME/.kde/share/config/skimrc
        else
        # do nothing
    	:
        fi
    ;;
    *)
        # do nothing
    ;;
esac


            export LC_CTYPE=$LANG
            # So you can use either zh_CN.UTF-8 or zh_CN.GB2312
            export XMODIFIERS="@im=fcitx" 
            export GTK_IM_MODULE=xim
            export QT_IM_SWITCHER=imsw-multi
            export QT_IM_MODULE=xim
            fcitx -d

PATH=$OLD_PATH

# success:
return 0