%PDF- %PDF-
Direktori : /usr/share/im-config/ |
Current File : //usr/share/im-config/im-config.common |
# Input Method configuration, im-config.common # (C) Osamu Aoki <osamu@debian.org>, GPL-2+ # vim: set sts=4 expandtab: # ############################################################# # IM Configuration functions used by im-config # *** NOT TO BE CALLED BY ANY RUNTIME HOOK SCRIPTS *** ############################################################# # active_im # echo active IM configuration name set in the system/user configuration active_im () { if [ ! -r $IM_CONFIG_XINPUTRC ]; then echo -n "missing" elif check_md5sum $IM_CONFIG_XINPUTRC ; then # when configuration is autogenerated by im-config IM_CONFIG_ACTIVE_IM=$(sed -n -e 's/^run_im \([^ ]*\) *$/\1/p' < $IM_CONFIG_XINPUTRC) if [ -z "$IM_CONFIG_ACTIVE_IM" ]; then echo -n "bogus" elif [ -r $IM_CONFIG_DATA/[012345678]?_$IM_CONFIG_ACTIVE_IM.conf ]; then echo $IM_CONFIG_ACTIVE_IM else echo -n "bogus" fi else # when configuration is changed manually by the user echo -n "custom" fi } # dsc_short <config> # echo IM configuration short description for IM configuration name dsc_short () { if [ -r $IM_CONFIG_DATA/??_$1.conf ] ; then # use subshell here { # subshell . $IM_CONFIG_DATA/??_$1.conf if [ "x$IM_CONFIG_AUTOMATIC" = "x$1" -a "x$IM_CONFIG_PREFERRED" = "x$1" ]; then echo -n "$IM_CONFIG_SHORT @!" elif [ "x$IM_CONFIG_PREFERRED" = "x$1" ]; then echo -n "$IM_CONFIG_SHORT !" elif [ "x$IM_CONFIG_AUTOMATIC" = "x$1" ]; then echo -n "$IM_CONFIG_SHORT @" else echo -n "$IM_CONFIG_SHORT" fi } else IM_CONFIG_CODE="dsc_short" IM_CONFIG_NAME=$1 eval_gettext "E: Configuration for \$IM_CONFIG_NAME not found at \$IM_CONFIG_CODE." >&2 echo >&2 fi } # dsc_long <config> # echo IM configuration long description for IM configuration name dsc_long () { if [ -r $IM_CONFIG_DATA/??_$1.conf ] ; then # use subshell here { # subshell . $IM_CONFIG_DATA/??_$1.conf echo -n "$IM_CONFIG_LONG" } else IM_CONFIG_CODE="dsc_long" IM_CONFIG_NAME=$1 eval_gettext "E: Configuration for \$IM_CONFIG_NAME not found at \$IM_CONFIG_CODE." >&2 echo >&2 fi } ############################################################# # Package status function used by menu ############################################################# # avail_menu <config> # configuration availability for menu listing # define package_menu for 00-89 avail_menu () { if [ -r $IM_CONFIG_DATA/??_$1.conf ]; then . $IM_CONFIG_DATA/??_$1.conf package_menu else IM_CONFIG_CODE="avail_menu" IM_CONFIG_NAME=$1 eval_gettext "E: Configuration for \$IM_CONFIG_NAME not found at \$IM_CONFIG_CODE." >&2 echo >&2 # return FALSE return 1 fi } ############################################################# # User modification verification functions used by im-config ############################################################# # check_md5sum <filename> check_md5sum () { if [ -r "$1" ] && \ [ "# im-config signature: $(head -n -1 $1 | md5sum)" = "$(tail -n 1 $1)" ]; then true elif [ -r "$1" ] && \ [ "# im-config signiture: $(head -n -1 $1 | md5sum)" = "$(tail -n 1 $1)" ]; then true # compatibility else false fi } # write_config <config name> <file name> write_config () { IM_CONFIG_NAME=$1 IM_CONFIG_XINPUTRC=$2 if [ "x$IM_CONFIG_NAME" = "xREMOVE" ]; then rm -f $IM_CONFIG_XINPUTRC elif [ -r $IM_CONFIG_XINPUTRC ] && ! check_md5sum $IM_CONFIG_XINPUTRC ; then eval_gettext "E: Configuration in \$IM_CONFIG_XINPUTRC is manually managed. Doing nothing." >&2 echo >&2 exit 1 elif [ ! -r $IM_CONFIG_DATA/??_$IM_CONFIG_NAME.conf ]; then eval_gettext "E: \$IM_CONFIG_NAME is bogus configuration for \$IM_CONFIG_XINPUTRC. Doing nothing." >&2 echo >&2 exit 1 else echo "# im-config(8) generated on $(date -R)" > $IM_CONFIG_XINPUTRC echo "run_im $IM_CONFIG_NAME" >> $IM_CONFIG_XINPUTRC echo "# im-config signature: $(md5sum < $IM_CONFIG_XINPUTRC)" >> $IM_CONFIG_XINPUTRC fi } ############################################################# # GUI/console UI functions used by im-config ############################################################# # msgbox (wrap and scroll) msgbox () { if [ $IM_CONFIG_DIALOG = "console" ]; then # console whiptail --title "$IM_CONFIG_ID" --msgbox "$1" 15 76 else if [ "$KDE_FULL_SESSION" = true ] && [ -x /usr/bin/kdialog ]; then # KDE GUI tmp_file=$(mktemp --tmpdir im-config-kdialog.XXXXXXXX) echo -n "$1" > $tmp_file kdialog --title "$IM_CONFIG_ID" --textbox $tmp_file 600 400 rm -f $tmp_file else # GTK GUI echo -n "$1" | zenity --width=600 --height=400 --title "$IM_CONFIG_ID" --text-info fi fi } # yesno (text size is fixed and must be small) yesno () { if [ $IM_CONFIG_DIALOG = "console" ]; then # console whiptail --title "$IM_CONFIG_ID" --yesno "$1" 20 76 else if [ "$KDE_FULL_SESSION" = true ] && [ -x /usr/bin/kdialog ]; then # KDE GUI kdialog --title "$IM_CONFIG_ID" --yesno "$1" else # GTK GUI zenity --title "$IM_CONFIG_ID" --width=600 --height=400 --question --text "$1" fi fi } # menulist_init (size fixed) # $1 text # $2 colum1(GUI) # $3 colum2(GUI) # $4 colum3(GUI) menulist_init () { if [ $IM_CONFIG_DIALOG = "console" ]; then # console printf "%s" "whiptail --title \"$IM_CONFIG_ID\" --radiolist \"$1\" 23 76 18" elif [ "$KDE_FULL_SESSION" = true ] && [ -x /usr/bin/kdialog ]; then printf "%s" "kdialog --title=\"$IM_CONFIG_ID\" --radiolist \"$1\"" else # GTK GUI printf "%s" "zenity --title=\"$IM_CONFIG_ID\" --width=600 --height=400 --text=\"$1\" --list --radiolist --column \"$2\" --column \"$3\" --column \"$4\"" fi } # menulist_add (size fixed) # $1 $y # $2 \"$(dsc_short $y)\" # $3 on menulist_add () { if [ $IM_CONFIG_DIALOG = "console" ]; then # console printf "%s" "$1 \"$2\" $3" elif [ "$KDE_FULL_SESSION" = true ] && [ -x /usr/bin/kdialog ]; then printf "%s" "$1 \"$2\" $3" else # GTK GUI if [ "x$3" = "xon" ]; then printf "%s" "TRUE $1 \"$2\"" else printf "%s" "FALSE $1 \"$2\"" fi fi } # menulist_eval # $1 command-line menulist_eval () { if [ $IM_CONFIG_DIALOG = "console" ]; then # console eval "$1" else # KDE or GTK GUI eval "$1" 3>&2 2>/dev/null 1>&3 fi }