home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / orca < prev    next >
Encoding:
Text File  |  2010-11-06  |  6.2 KB  |  189 lines

  1. #!/bin/sh
  2. #
  3. # Orca
  4. #
  5. # Copyright 2006-2008 Sun Microsystems Inc.
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Library General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. # Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Library General Public
  18. # License along with this library; if not, write to the
  19. # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
  20. # Boston MA  02110-1301 USA.
  21.  
  22. # This script performs some clean up and will run Orca.  It will also
  23. # rerun Orca if it detects that Orca died an unnatural death.
  24.  
  25. # __id__        = "$Id: orca.in,v 1.22 2006/12/08 16:21:25 wwalker Exp $"
  26. # __version__   = "$Revision: 1.22 $"
  27. # __date__      = "$Date: 2006/12/08 16:21:25 $"
  28. # __copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc."
  29. # __license__   = "LGPL"
  30.  
  31. # Set the user's $PATH for this script.
  32. #
  33. PATH="${PATH}:/usr/bin:/usr/sbin:/bin"
  34. export PATH
  35.  
  36. # Save the arguments away.
  37. #
  38. ARGS="$*"
  39.  
  40. # Save away XMODMAP settings we might change.
  41. #
  42. saveXmodmap() 
  43. {
  44.     # We'll save and restore the Caps_Lock as a modifier just in case
  45.     # the user is using the Caps_Lock as the Orca modifier key.  We
  46.     # will also do so with the KP_Insert key since we want to make
  47.     # sure it only produces the keysyms we expect (it produces
  48.     # KP_Insert and KP_0 by default).  See the use of xmodmap in
  49.     # orca.py:loadUserSettings for the other part of what's going on.
  50.     # 
  51.     # [[[WDW: we probably should save/restore the autorepeat value of
  52.     # the Orca modifier key and turn the autorepeat off when Orca is
  53.     # running.  That can be done using the 'xset' utility, though
  54.     # turning it on/off is easy, but getting the current state is not
  55.     # straightforward.]]]
  56.     #
  57.     if [ "x$DISPLAY" != "x" ] ; then
  58.         CAPSLOCKSETTING=`xmodmap | grep Caps_Lock | cut -f1`
  59.         KPINSERTSETTING=`xmodmap -pke | grep KP_Insert`
  60.         INSERTSETTING=`xmodmap -pke | grep Insert | grep -v KP_`
  61.     fi
  62. }
  63.  
  64. # Restore XMODMAP settings we may have changed.
  65. #
  66. restoreXmodmap()
  67. {
  68.     if [ "x$CAPSLOCKSETTING" != "x" ] ; then
  69.         xmodmap -e "add $CAPSLOCKSETTING = Caps_Lock" > /dev/null 2>&1
  70.     fi
  71.     if [ "x$KPINSERTSETTING" != "x" ] ; then
  72.         xmodmap -e "$KPINSERTSETTING" > /dev/null 2>&1
  73.     fi
  74.     if [ "x$INSERTSETTING" != "x" ] ; then
  75.         xmodmap -e "$INSERTSETTING" > /dev/null 2>&1
  76.     fi
  77. }
  78.  
  79. # Cleans up any orca-related processes that might be running,
  80. # restricting it to those processes owned by the user. These include
  81. # orca itself, any gnome-speech synthesis drivers, and festival
  82. # processes running in server mode.
  83. #
  84. cleanup()
  85. {
  86.     USERID=`id | cut -f2 -d= | cut -f1 -d\(`
  87.     PIDS=`ps -eo pid,ruid,args | grep $USERID | \
  88.     egrep "orca[.]orca|OAFIID[:]GNOME_Speech|OAFIID[:]GNOME_Magnifier|festival [-][-]server"|\
  89.     grep -v grep | awk '{ print $1 }'`
  90.     IFS='
  91.     '
  92.     PIDS=`echo $PIDS`
  93.     if [ "x$PIDS" != "x" ] ; then
  94.         kill -9 $PIDS > /dev/null 2>&1
  95.     fi
  96.     restoreXmodmap
  97. }
  98.  
  99. trap cleanup HUP QUIT TERM INT ABRT
  100.  
  101. # Runs orca.
  102. #
  103. runOrca()
  104. {
  105.     saveXmodmap
  106.     exec /usr/bin/python -c "import orca.orca; orca.orca.main()" "$ARGS"
  107.     restoreXmodmap
  108. }
  109.  
  110. # Orca will fall into a text-based question and answer session if the
  111. # user has not configured orca and/or accessibility yet.  We will
  112. # force that to happen in the foreground (i.e., RUNONCE=true).  In
  113. # addition, if the user passes any command line arguments to orca, we
  114. # will run it in the foreground as well to avoid a situation where
  115. # orca dumps itself into the text-based setup utility.
  116. #
  117. # We make a special exception for gdm, which is used to handle the
  118. # accessible login.  If we're running as gdm, we assume everything is
  119. # all set and we don't need to muck around.
  120. #
  121. if [ "x$LOGNAME" != "xDebian-gdm" ] ; then
  122.     ACCESSIBILITY_ENABLED=`gconftool-2 \
  123.     --get /desktop/gnome/interface/accessibility`
  124.     if [ "x$ACCESSIBILITY_ENABLED" != "xtrue" ] ; then
  125.         # Because we will be running Orca in text-setup mode, we want to
  126.         # make sure it is run in a terminal window.  If we're already in
  127.         # a terminal, this is great.  If not, we spawn a gnome-terminal
  128.         # and run orca in it.
  129.         #
  130.         tty -s && IN_TTY="true" || IN_TTY="false"
  131.         if [ "x$IN_TTY" = "xfalse" ] ; then
  132.             exec gnome-terminal -x $0 $ARGS
  133.         exit
  134.         fi
  135.     fi
  136. fi
  137.  
  138. if [ `echo $ARGS | grep -c "\-q"` -gt 0 ] ; then
  139.     # If the user has done -q or --quit, that means to tell any
  140.     # existing orca process to quit.  So, we just do a cleanup.
  141.     #
  142.     cleanup
  143. else
  144.     # Allow a --replace to kill other orca processes.
  145.     #
  146.     if [ `echo $ARGS | grep -c "\-\-replace"` -gt 0 ] ; then
  147.     cleanup
  148.     fi
  149.  
  150.     # If the user passed in a flag that results in orca only
  151.     # outputting data to the console, don't kill any other orca
  152.     # process.  We do this by looking for flags that *should* result
  153.     # in a cleanup (i.e., every legal command except -?, --help, -v,
  154.     # --version, -l, and --list-apps).  This way, if the user
  155.     # erroneously types an illegal command line argument, the help
  156.     # text is emitted and the other orca is not killed.
  157.     #
  158.     if [ "x$ARGS" = "x" ] ; then
  159.         WONT_EXIT=1
  160.     else
  161.     WONT_EXIT=`echo $ARGS | egrep -c "\-s|\-t|\-n|\-u|\-e|\-d"`
  162.     fi
  163.  
  164.     # Do not run if another Orca is already running.
  165.     #
  166.     if [ "x$DBUS_SESSION_BUS_ADDRESS" != "x" ] && [ $WONT_EXIT -gt 0 ] ; then
  167.     IFS=:
  168.     DBUSSENDCMD=
  169.     for dir in $PATH:/usr/sfw/bin:/usr/local/bin; do
  170.         test -x "$dir/dbus-send" && {
  171.         DBUSSENDCMD="$dir/dbus-send"
  172.         break
  173.         }
  174.     done
  175.     if [ "x$DBUSSENDCMD" != "x" ] ; then
  176.         $DBUSSENDCMD --reply-timeout=5000 --print-reply \
  177.         --dest=org.gnome.Orca / org.freedesktop.DBus.Peer.Ping \
  178.         > /dev/null 2>&1
  179.         if [ "$?" -eq 0 ] ; then
  180.         echo "Another Orca process is already running for this session."
  181.         echo "Run \"orca --replace\" if you want to replace the current"
  182.         echo "process with a new one."
  183.         exit
  184.         fi
  185.     fi
  186.     fi
  187.     runOrca
  188. fi
  189.