#!/bin/bash

# Barry Kauler www.puppylinux.com
# 2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
# v411 modified network-connect button.
# 100215 fix exit button.
# 101019 added video upgrade wizard.
# 120202 BK: internationalized.
# 130216 BK: change text for mouse.
# 131210 zigbert: gui (gtkdialog) improvements.
# 210415 radky: adjust for JWMdesk
# 210930 radky: adjust GUI header
# 220101 radky: adjust compatibility with upstream Woof-CE

export TEXTDOMAIN=wizardwizard
export OUTPUT_CHARSET=UTF-8

export APPDIR=/usr/local/jwmdesk
export PREFDIR=$APPDIR/preferences
export ICONDIR=$APPDIR/jwm_menu_icons

# define gtkdialog
[ "`which gtkdialog4 2>/dev/null`" ] && GTKDIALOG=gtkdialog4 || GTKDIALOG=gtkdialog
export GTKDIALOG

# set header
. /etc/DISTRO_SPECS
XML_INFO_COLOR='#EDEBD7' # background color
XML_INFO_OPACITY=0.5 # background opacity
. $APPDIR/xml_info_jwmdesk gtk > /dev/null # build bg_pixmap for gtk-theme

BOX_HEIGHT=90 # HEADER
ICON=$APPDIR/icons/puppy_config.svg
ICON_HEIGHT=85
MSG_1="<b><span size='"'x-large'"'>$(gettext "Puppy Setup")</span></b>"
MSG_2="<b>$(gettext "Basic configuration guide")</b>"
MSG_3="<b>$DISTRO_NAME $DISTRO_VERSION</b>"
ALIGN=center # center or left
HEADER="
   <hbox height-request="'"${BOX_HEIGHT}"'">
   $(. $APPDIR/xml_info_jwmdesk "$ICON" "$ICON_HEIGHT" "$MSG_1" "$MSG_2" "$MSG_3" "$ALIGN")
   </hbox>"

# define menu manager
menu_checkbox=''
if [ -f /usr/sbin/menumanager ]; then
   menu_checkbox='
      <checkbox space-expand="false" space-fill="false">
        <label>'$(gettext 'Legacy menu manager')'</label>
        <variable>LMM</variable>
        <input>cat '$PREFDIR'/legacy-mm 2>/dev/null</input>
        <action>if true echo true > '$PREFDIR'/legacy-mm</action>
        <action>if false echo false > '$PREFDIR'/legacy-mm</action>
      </checkbox>
      <text space-expand="true" space-fill="true"><label>" "</label></text>'
fi

func_menu_manager(){
if [ ! -f /usr/sbin/menumanager ]; then
 /usr/local/jwmdesk/menumanager & exit 0
else
 LMM=$(cat $PREFDIR/legacy-mm 2>/dev/null)
 if [ "$LMM" = "true" ]; then
   /usr/sbin/menumanager &
 else
   /usr/local/jwmdesk/menumanager &
 fi
fi
}
export -f func_menu_manager

func_sound_manager(){
if [ "`which pulseaudio 2>/dev/null`" ] || [ "`which pipewire 2>/dev/null`" ]; then
  pavucontrol &
else
  alsawizard &
fi
}
export -f func_sound_manager

# main dialog
export WizardWizard='
<window title="'$(gettext 'Puppy Setup')'" icon-name="gtk-preferences" default_width="500" window-position="1" >
<vbox space-expand="true" space-fill="true"> 
  <vbox margin="2" space-expand="false" space-fill="false">
  '$HEADER'
  </vbox>
  <vbox margin="2" spacing="10" space-expand="true" space-fill="true">
    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2">
        <label>'$(gettext 'Language / Country')'</label>
        <input file>'$ICONDIR'/country.svg</input><height>60</height><width>60</width>
        <action>/usr/sbin/countrywizard &</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Startup')'</label>
        <input file>'$ICONDIR'/startup_services.svg</input><height>60</height><width>60</width>
        <action>/usr/sbin/bootmanager &</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Mouse / Keyboard')'</label>
         <input file>'$ICONDIR'/mouse_keyboard.svg</input><height>60</height><width>60</width>
        <action>/usr/sbin/input-wizard &</action>
      </button>
    </hbox>
  
    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2">
        <label>'$(gettext 'Sound')'</label>
        <input file>'$ICONDIR'/sound.svg</input><height>60</height><width>60</width>
        <action>func_sound_manager &</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Menu Manager')'</label>
        <input file>'$APPDIR'/icons/menu.svg</input><height>60</height><width>60</width>
        <action>func_menu_manager &</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Graphics / Screen')'</label>
        <input file>'$ICONDIR'/graphics.svg</input><height>60</height><width>60</width>
        <action>/usr/sbin/xserverwizard &</action>
      </button>
    </hbox>

    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2">
        <label>'$(gettext 'Internet')'</label>
        <input file>'$ICONDIR'/internet_connect.svg</input><height>60</height><width>60</width>
        <action>/usr/sbin/connectwizard &</action>
      </button>
      <button image-position="2">
        <sensitive>'$(command -v cupsd > /dev/null && echo true || echo false)'</sensitive>
        <label>'$(gettext 'Printer')'</label>
        <input file>'$ICONDIR'/print.svg</input><height>60</height><width>60</width>
        <action>/usr/sbin/cups_shell &</action>
      </button>
      <button image-position="2">
        <label>'$(gettext 'Date / Time')'</label>
        <input file>'$ICONDIR'/date_time.svg</input><height>60</height><width>60</width>
        <action>/usr/local/jwmdesk/timewizard &</action>
      </button>
    </hbox>
  </vbox>

  <hseparator space-expand="false" space-fill="false"></hseparator>

  <hbox space-expand="false" space-fill="false">
      '$menu_checkbox'
      <button use-underline="true">
        <label>'$(gettext '_Quit')'</label>
        <input file>/usr/local/jwmdesk/icons/quit.svg</input><height>22</height><width>22</width>
        <action>exit:quit_now</action>
      </button>
  </hbox>
 </vbox>
</window>'

$GTKDIALOG -p WizardWizard --styles=/tmp/jwmdesk/gtkrc_xml_info.css

unset WizardWizard
