#Maintainer: Tomoki Tsuchiya <hydrangea_and_snail~at~hotmail~dot~com>

pkgname=ibus
pkgver=1.3.9
pkgrel=3tt
docs=('authors' 'copying' 'changelog' 'install' 'news' 'readme')
url=http://code.google.com/p/ibus/
source=("http://$pkgname.googlecode.com/files/$pkgname-$pkgver.tar.gz")
sourcetemplate=http://people.salixos.org/tsuren/packages/$pkgname/
options=('noautodotnew')

doinst() {
# Run gtk-query-immodules so that "ibus" will appear under Input Method
# when you right- click your mouse in a text box.
if [ -x usr/bin/update-gtk-immodules ]; then
	/usr/bin/update-gtk-immodules --verbose >/dev/null
fi
}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (Intelligent Input Bus)"
"IBus means Intelligent Input Bus. It is an open source input"
"framework for Linux/Unix OS. "
)

build() {
  cd $startdir/src/$pkgname-$pkgver || return 1
  ./configure --prefix=/usr --libdir=/usr/lib${LIBDIRSUFFIX} --localstatedir=/var --sysconfdir=/etc --disable-schemas-install --build=$arch-slackware-linux || return 1
  make || return 1
  make install DESTDIR=$startdir/pkg || return 1
  
  # gconf stuff
  export GCONF_CONFIG_SOURCE="xml::$startdir/pkg/etc/gconf/gconf.xml.defaults"
  if [ -d $startdir/pkg/etc/gconf/schemas ]; then
    install -v -d -m755 $startdir/pkg/etc/gconf/gconf.xml.defaults
    SCHEMAS=$startdir/pkg/etc/gconf/schemas
    for schema in $SCHEMAS/*.schemas; do
        gconftool-2 --makefile-install-rule $schema
    done
    # Reset / Verify correct permissions
    ( cd $startdir/pkg/etc/gconf ; find . -type d -exec chmod 755 {} \; )
    ( cd $startdir/pkg/etc/gconf ; find . -type f -exec chmod 644 {} \; )
  fi
  # Add profile scripts that set up the environment:
  mkdir -p $startdir/pkg/etc/profile.d
  cat <<'EOF' > $startdir/pkg/etc/profile.d/ibus.csh
#!/bin/csh

# ibus - Intelligent Input Bus for Linux / Unix OS. This is used to support the
# entering of text in non-US-English languages.

[ -x /usr/bin/ibus-daemon ]
if ($status == 0) then
  # Enable legacy X applications to use ibus:
  setenv XMODIFIERS="@im=ibus"
  # Enable Qt/KDE applications to use ibus.
  setenv QT_IM_MODULE="ibus"
  # Enable GTK applications to use ibus:
  setenv GTK_IM_MODULE="ibus"
  # Make ibus start automatically if the "magic key" Ctrl-Space is pressed:
  #setenv XIM_PROGRAM="/usr/bin/ibus-daemon -xdrt"
  ibus-daemon -xdr
endif
EOF
  cat <<'EOF' > $startdir/pkg/etc/profile.d/ibus.sh
#!/bin/sh

# ibus - Intelligent Input Bus for Linux / Unix OS. This is used to support the
# entering of text in non-US-English languages.

if [ -x /usr/bin/ibus-daemon ]; then
  # Enable legacy X applications to use ibus:
  export XMODIFIERS="@im=ibus"
  # Enable Qt/KDE applications to use ibus.
  export QT_IM_MODULE="ibus"
  # Enable GTK applications to use ibus:
  export GTK_IM_MODULE="ibus"
  # Make ibus start automatically if the "magic key" Ctrl-Space is pressed:
  #export XIM_PROGRAM="/usr/bin/ibus-daemon -xdrt"
  ibus-daemon -xdr
fi
EOF
  chmod 755 $startdir/pkg/etc/profile.d/*
  # Remove etc/xdg/autostart/ibus.desktop, or ibus will always be started in X...
  rm $startdir/pkg/etc/xdg/autostart/ibus.desktop ; rm -rf $startdir/pkg/etc/xdg
  rm -rf $startdir/pkg/usr/share/gtk-doc
}