#!/bin/sh

export TEXTDOMAIN=logout_gui

X_SERVER=`type X|awk '{print $3}'`
X=`readlink $X_SERVER`
MSG_X="$(gettext "Active graphical server"): <b>$X</b>"
[ "`grep -F 'jwm' <<< $(ps -eo pid,command)`" ] && MSG_JWM="$(gettext "Active window manager"): <b>JWM</b>"

S='
<window title="'$(gettext 'Puppy Log Out')'" icon-name="gtk-preferences" window-position="1">
<vbox space-expand="true" space-fill="true">
  '"`/usr/lib/gtkdialog/xml_info fixed puppy_config.svg 60 "$MSG_JWM" "$MSG_X"`"'
  <vbox spacing="10" space-expand="true" space-fill="true">
  <frame>
    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2">
        <label>'$(gettext 'Reboot')'</label>
        '"`/usr/lib/gtkdialog/xml_button-icon reboot.svg huge`"'
        <action>exit:reboot</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Shut Down')'</label>
         '"`/usr/lib/gtkdialog/xml_button-icon shutdown.svg huge`"'
        <action>exit:poweroff</action>
      </button>
    </hbox>
  
    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2">
        <label>'$(gettext 'Restart graphical server')'</label>
        '"`/usr/lib/gtkdialog/xml_button-icon graphics_restart.svg huge`"'
        <action>exit:restartx</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Exit to Prompt')'</label>
        '"`/usr/lib/gtkdialog/xml_button-icon terminal.svg huge`"'
        <action>exit:logout</action>
      </button>
    </hbox>
    
    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">'
      if [ "`grep -F 'jwm' <<< $(ps -eo pid,command)`" ]; then S=$S'
        <button image-position="2">
          <label>'$(gettext 'Restart window manager')'</label>
          '"`/usr/lib/gtkdialog/xml_button-icon wm_restart.svg huge`"'
          <action>exit:restartjwm</action>
        </button>'
      else
        S=$S'<text><label>""</label></text>'
      fi
      if [ "`which xlock`" ]; then S=$S'
        <button image-position="2">
          <label>'$(gettext 'Lock screen')'</label>
          '"`/usr/lib/gtkdialog/xml_button-icon screen_lock.svg huge`"'
          <action>/usr/local/apps/Xlock/AppRun</action>
        </button>'
      elif [ "`grep -F 'jwm' <<< $(ps -eo pid,command)`" ]; then S=$S'
        <button image-position="2">
          <label>'$(gettext 'Rebuild Menu')'</label>
          '"`/usr/lib/gtkdialog/xml_button-icon menu.svg huge`"'
          <action>exit:refreshjwm</action>
        </button>'
      else
        S=$S'<text><label>""</label></text>'
      fi
  
    S=$S'</hbox>
  </frame>
  </vbox>
</vbox>
</window>'

export logout="$S"

. /usr/lib/gtkdialog/xml_info gtk > /dev/null #build bg_pixmap for gtk-theme
eval `gtkdialog -p logout`
case $EXIT in
  logout)exec wmexit ;;
  reboot)exec wmreboot ;;
  poweroff)exec wmpoweroff ;;
  restartx)restartwm ;;
  restartjwm)jwm -restart ;;
  refreshjwm)fixmenus; jwm -reload ;;
  *)exit ;;
esac
