#!/bin/sh

export TEXTDOMAIN=logout_gui

JWM=`ps -A|grep jwm`
if [ "$JWM" ];then
  WM_IS_JWM='
    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
	  <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>
      <button image-position="2">
        <label>'$(gettext 'Rebuild Menu')'</label>
        '"`/usr/lib/gtkdialog/xml_button-icon menu.svg huge`"'
        <action>exit:refreshjwm</action>
      </button>
    </hbox>'
  MSG_JWM="$(gettext "Active window manager"): <b>JWM</b>"
fi

X_SERVER=`type X|awk '{print $3}'`
X=`readlink $X_SERVER`
MSG_X="$(gettext "Active graphical server"): <b>$X</b>"

export logout='
<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>

    '"$WM_IS_JWM"'
  </frame>
  </vbox>

 </vbox>
</window>'

. /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
