#!/bin/bash
########################################################################
#                                                                      #
#  YAD GUI FOR TERMINAL MUSIC CONTROL APP                              #
#  Depends on: yad and your desired music controller                   #
#                                                                      #
#  Made by Koentje  (remon@cobrasoft.nl)                               #
#                                                        version 1.0   #
########################################################################


# Window title
wtitle="Music Player"

# Window taskbar icon
# You can use a system icon or path to icon file
#wicon="gnomeradio"
wicon="./images/black-40x40/play.png"

# Window width (keep it small, resizes nicely around the buttons)
wwidth="50"

# Window height (keep it small, resizes nicely around the buttons)
wheight="50"



# Buttons horizontal or vertical
bpos="horizontal"

# Button icon size  (1/2/3/4/5)
bsize="3"



# Program to control the music
mapp="qmmp"

# Program option for previous song
mprev="--previous"

# Program option for next song
mnext="--next"

# Program option to play song
mplay="--play"

# Program option to stop song
mstop="--stop"

# Program option to pause song
mpause="--play-pause"



########################################################################
################### Below editing is at own risk !!! ###################
########################################################################

if [ "$bsize" = "1" ]; then
  bpath="./images/black-40x40"
elif [ "$bsize" = "2" ]; then
  bpath="./images/black-75x75"
elif [ "$bsize" = "3" ]; then
  bpath="./images/black-110x110"
elif [ "$bsize" = "4" ]; then
  bpath="./images/black-150x150"
elif [ "$bsize" = "5" ]; then
  bpath="./images/black-185x185"
else
  bpath="./images/black-75x75"
fi

if [ "$bpos" = "horizontal" ]; then
  input=$(yad --form \
          --width="$wwidth" --height="$wheight" --center\
          --title="$wtitle"\
          --window-icon=$wicon\
          --button=""!$bpath/prev.png!" Previous song ":"$mapp $mprev"\
          --button=""!$bpath/play.png!" Play song ":"$mapp $mplay"\
          --button=""!$bpath/pause.png!" Pause song ":"$mapp $mpause"\
          --button=""!$bpath/stop.png!" Stop song ":"$mapp $mstop"\
          --button=""!$bpath/next.png!" Next song ":"$mapp $mnext"\
          --buttons-layout=spread\
         )

  case $? in
    252)	# Escape
      echo "[ESC] key used"
      killall $(basename $0)
      exit
    ;;
    *)
      echo "$(basename $0): Exit nr $?"
    ;;
  esac

elif [ "$bpos" = "vertical" ]; then
  input=$(yad --form \
          --width="$wwidth" --height="$wheight" --center\
          --title="$wtitle"\
          --window-icon=$wicon\
          --field="!$bpath/prev.png! Previous song ":FBTN "$mapp $mprev"\
          --field="!$bpath/play.png! Play song ":FBTN "$mapp $mplay"\
          --field="!$bpath/pause.png! Pause song ":FBTN "$mapp $mpause"\
          --field="!$bpath/stop.png! Stop song ":FBTN "$mapp $mstop"\
          --field="!$bpath/next.png! Next song ":FBTN "$mapp $mnext"\
          --no-buttons\
         )

  case $? in
    252)	# Escape
      echo "Escaped."
      killall $(basename $0)
      exit
    ;;
    *)
      echo "$(basename $0): Exit nr $?"
    ;;
  esac

else
  echo "$(basename $0): Error in position, check settings!"
fi

killall $(basename $0)
exit
