#!/bin/bash

# called by wizardwizard
# 210415 radky: adjust for JWMdesk
# 211031 radky: new GUI format

export TEXTDOMAIN=ptimewizard
export OUTPUT_CHARSET=UTF-8

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

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

# set header
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/jwm_menu_icons/date_time.svg
ICON_HEIGHT=60
MSG_1="<b><span size='"'x-large'"'>$(gettext "Time Wizard")</span></b>"
MSG_2="<b>$(gettext "Date and time configuration")</b>"
ALIGN=center # center or left
HEADER="
   <hbox height-request="'"${BOX_HEIGHT}"'">
   $(. $APPDIR/xml_info_jwmdesk "$ICON" "$ICON_HEIGHT" "$MSG_1" "$MSG_2" "$ALIGN")
   </hbox>"

# define button commands
[ "`which PupClockset 2>/dev/null`" ] && clock_cmd=PupClockset || clock_cmd=/usr/local/jwmdesk/clock

[ -f /usr/local/psync/psync ] && psync_cmd=/usr/local/psync/psync
[ ! "$psync_cmd" ] && [ "`which psync 2>/dev/null`" ] && psync_cmd=psync
[ -f /etc/psync.servers ] && psync_cmd=/usr/local/jwmdesk/psync
[ ! "$psync_cmd" ] && [ -f /usr/sbin/qsync ] && psync_cmd=/usr/sbin/qsync

# gui
export TimeWizard='
<window title="'$(gettext "Time Wizard")'" icon-name="gtk-connect" window-position="1" resizable="false">
 <vbox space-expand="true" space-fill="true">
  <vbox margin="2">
  '${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" tooltip-text=" '$(gettext 'Set date and time')' ">
        <label>'$(gettext 'Date & Time')'</label>
        <input file>'$ICONDIR'/date_time.svg</input><height>42</height><width>42</width>
        <action>set-time-for-puppy &</action>
      </button>
      <button image-position="2" tooltip-text=" '$(gettext 'Set timezone')' ">
        <label>'$(gettext 'Timezone')'</label>
        <input file>'$ICONDIR'/country_timezone.svg</input><height>42</height><width>42</width>
        <action>timezone-set &</action>
      </button>
    </hbox>

    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2" tooltip-text=" '$(gettext 'Set hardware-clock type')' ">
        <label>'$(gettext 'Hardware Clock')'</label>
        <input file>'$ICONDIR'/clock.svg</input><height>42</height><width>42</width>
        <action>set_hwclock_type &</action>
      </button>
      <button image-position="2" tooltip-text=" '$(gettext 'Set tray-clock format')' ">
        <label>'$(gettext 'Tray Clock')'</label>
        <input file>'$ICONDIR'/clock_digital.svg</input><height>42</height><width>42</width>
        <action>'$clock_cmd' &</action>
      </button>
    </hbox>

    <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
      <button image-position="2" tooltip-text=" '$(gettext 'Syncronize with time-server')' ">
        <label>'$(gettext 'Sync')'</label>
        <input file>'$ICONDIR'/clock_countdown.svg</input><height>42</height><width>42</width>
        <action>'$psync_cmd' &</action>
      </button>
      <button image-position="2" tooltip-text=" '$(gettext 'Task scheduler')' ">
        <sensitive>'$(which pschedule 2>/dev/null && echo true || echo false)'</sensitive>
        <label>'$(gettext 'Schedule')'</label>
        <input file>'$ICONDIR'/execute_interval.svg</input><height>42</height><width>42</width>
        <action>pschedule &</action>
      </button>
    </hbox>

  </vbox>

  <hseparator></hseparator>

  <hbox space-expand="false" space-fill="false">
      <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 TimeWizard --styles=/tmp/jwmdesk/gtkrc_xml_info.css

unset TimeWizard
