#!/bin/sh
#
# langswitch - front end for hiding and unhiding qm files 
# version 0.1
#
# Copyright (C) 2005 hdluc@yahoo.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
######################################################################
# variables
APPNAME="langswitch"
USER=zaurus
ID=`id -u`
SUDO=/usr/bin/sudo
OPIE_SH=/opt/QtPalmtop/bin/opie-sh
FILEDIR=/home/QtPalmtop/i18n/ja
MSG="Please select QM:" 
APP=`basename $0`

switchqm ()
{
  if [ "$ID" = "0" ]; then
    FILE=`su $USER -c "ls -1 *.qm | cut -d. -f1 | $OPIE_SH -i -t \"$APPNAME\" -L \"$MSG\" -l -g 2>/dev/null"` 
  else
    FILE=`ls -1 *.qm | cut -d. -f1 | $OPIE_SH -i -t "$APPNAME" -L "$MSG" -l -g 2>/dev/null` 
  fi
  #echo you selected $FILE
  if [ "$FILE" = "" ]; then
    exit 0
  fi
  if [ -f ${FILEDIR}/${FILE}.qm ]; then
    mv ${FILEDIR}/${FILE}.qm ${FILEDIR}/.hide
  else
    mv ${FILEDIR}/.hide/${FILE}.qm ${FILEDIR}
  fi
  echo $FILE switched
}

# start here
if [ "$APP" = "langswitch-ja" ]; then
  echo switching to japanese
  cd $FILEDIR/.hide
  switchqm
  exit 0
fi
if [ "$APP" = "langswitch-en" ]; then
  echo switching to english
  cd $FILEDIR/
  switchqm
  exit 0
fi
echo please run correct program
exit 1

