#!/bin/bash
#Pmusic
#Copyright 2008, 2009
#Sigmund Berglund - Valåmoen, Norway.

#------------------------------
#This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2.

#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <http://www.gnu.org/licenses/>.
#------------------------------

VERSION="0.5.4" #REMEMBER to set version in $APPDIR/pmusicrc and version upgrade
export AUDIO_FORMATS="\.aiff|\.aac|\.ape|\.au|\.flac|\.gsm|\.m4a|\.mp3|\.mp4|\.ogg|\.ra|\.shn|\.wav|\.wma"
mkdir $HOME/.pmusic > /dev/null 2>&1
mkdir $HOME/.pmusic/tmp > /dev/null 2>&1
export WORKDIR=$HOME/.pmusic/tmp
mkdir $WORKDIR/generated_playlists > /dev/null 2>&1
APPDIR="`dirname $0`"
[ "$APPDIR" = "." ] && APPDIR="`pwd`"
export APPDIR="$APPDIR"
[ ! -f $WORKDIR/pmusic-ffmpeg_output ] && echo "pmusic_stop" > $WORKDIR/pmusic-ffmpeg_output #to ensure text in progressbar
export CONFIG=$HOME/.pmusic/pmusicrc
if [ "`which gtkdialog3 2> /dev/null`" ]; then export GTKDIALOG="gtkdialog3"; else export GTKDIALOG="gtkdialog"; fi #puppy specific

#parameters
while [ $# != 0 ]; do
	I=1
	while [ $I -le `echo $# | wc -c` ]; do
		if [ "`echo $1 | grep -iE "$AUDIO_FORMATS""|\.dir|\.m3u|\.pls"`" ]; then 
			export INDEX="$1"
			export LOC506="$1" #LOC variables is not yet defined
			if [ ! "$ADD_FILE" ]; then $APPDIR/func_store_playlist; $APPDIR/func -new; fi
			$APPDIR/func -add
			#if [ "`ps | grep aplay`" ] && [ "`ps | grep ffmpeg`" ]; then exit; fi #Pmusic is playing, do not load new gui
		elif [ `echo $1 | grep a` ]; then ADD_FILE=true; export ADD_AFTER_SELECTION=false
		elif [ `echo $1 | grep v` ]; then echo Pmusic $VERSION; exit
		elif [ `echo $1 | grep h` ]; then
echo 'Usage: pmusic [OPTION] [FILE]

Options
  -a          Add [FILE] to playlist instead of playing it.
  -h          Show this help message
  -v          Show Pmusic version
  
Supported formats (with working alsa and ffmpeg):'"
$AUDIO_FORMATS"
  			exit
		fi
		shift
		I=$[$I+1]
	done
done
#kill older instances if gtkdialog didn't quit properly
$APPDIR/func_kill -start
#version upgrade
if [ ! -f $CONFIG ]; then cp -f $APPDIR/pmusicrc $HOME/.pmusic/pmusicrc; fi #no config --> copy 
CURRENT_VERSION=`grep VERSION $CONFIG 2> /dev/null`
if [ `echo $CURRENT_VERSION  | sed -e s/^.*\=//g | tr -d "."` -lt 054 > /dev/null 2>&1 ]; then #Older than 0.5.4
	cp -f $APPDIR/pmusicrc $HOME/.pmusic/pmusicrc
fi
#---
. $CONFIG
#set browser
if [ "`which defaultbrowser 2> /dev/null`" ]; then export BROWSER=defaultbrowser
	elif [ "`which hv3 2> /dev/null`" ]; then export BROWSER=hv3
	elif [ "`which dillo 2> /dev/null`" ]; then export BROWSER=dillo
	elif [ "`which mozilla 2> /dev/null`" ]; then export BROWSER=mozilla
	elif [ "`which opera 2> /dev/null`" ]; then export BROWSER=opera
	elif [ "`which netscape 2> /dev/null`" ]; then export BROWSER=netscape
	elif [ "`which firefox 2> /dev/null`" ]; then export BROWSER=firefox
	elif [ "`which konqueror 2> /dev/null`" ]; then export BROWSER=konqueror
fi
#set language
if [ $LANGUAGE = auto ]; then
	ENVIRONMENT_LANG=`echo $LANG | sed "s/\(..\).*/\1/"` #detect environment language 
	case $ENVIRONMENT_LANG in
		da)	export LANGUAGE="danish" ;;
		de)	export LANGUAGE="german" ;;
		en)	export LANGUAGE="english" ;;
		es)	export LANGUAGE="spanish" ;;
		fi)	export LANGUAGE="finnish" ;;
		fr)	export LANGUAGE="french" ;;
		it)	export LANGUAGE="italian" ;;
		jp)	export LANGUAGE="japanese" ;;
		nb)	export LANGUAGE="norwegian" ;; #translation is norwegian bokmål
		nl)	export LANGUAGE="dutch" ;;
		nn)	export LANGUAGE="norwegian" ;; #Use norwegian bokmål, since there is no norwegian nynorsk
		pl) export LANGUAGE="polish";;
		ru)	export LANGUAGE="russian" ;;
		sv)	export LANGUAGE="swedish" ;;
		*)	export LANGUAGE="english" ;; #english for contries without translation
	esac
fi
. $APPDIR/locals/english #always run to fill gaps in translation
. $APPDIR/locals/$LANGUAGE 2> /dev/null
#define variables for gui
if [ -f $WORKDIR/pmusic-REPEAT ]; then
	REPEAT=`cat $WORKDIR/pmusic-REPEAT`
else
	REPEAT=false
fi
if [ -f $WORKDIR/pmusic-SHUFFLE ]; then
	SHUFFLE=`cat $WORKDIR/pmusic-SHUFFLE`
else
	SHUFFLE=false
fi
#define active playlist
case "`cat $WORKDIR/pmusic-PLAYLIST1234 2> /dev/null`" in
	playlist2)
		RADIO_PLAYLIST1=false
		RADIO_PLAYLIST2=true
		RADIO_PLAYLIST3=false
		RADIO_PLAYLIST4=false
		cp $WORKDIR/pmusic-playlist2 $WORKDIR/pmusic-playlist
		;;
	playlist3)
		RADIO_PLAYLIST1=false
		RADIO_PLAYLIST2=false
		RADIO_PLAYLIST3=true
		RADIO_PLAYLIST4=false
		cp $WORKDIR/pmusic-playlist3 $WORKDIR/pmusic-playlist
		;;
	playlist4)
		RADIO_PLAYLIST1=false
		RADIO_PLAYLIST2=false
		RADIO_PLAYLIST3=false
		RADIO_PLAYLIST4=true
		cp $WORKDIR/pmusic-playlist4 $WORKDIR/pmusic-playlist
		;;
	*)
		RADIO_PLAYLIST1=true
		RADIO_PLAYLIST2=false
		RADIO_PLAYLIST3=false
		RADIO_PLAYLIST4=false
		cp $WORKDIR/pmusic-playlist1 $WORKDIR/pmusic-playlist > /dev/null 2>&1
		;;
esac
#---
echo -e "\c" > $WORKDIR/pmusic-SELECTION
echo $HOME"/Pmusic.m3u" > $WORKDIR/pmusic-last_added_playlist

export Pmusic_lyrics="
<window title=\"Pmusic - $LOC144\" icon-name=\"gtk-media-stop\">
<vbox>
 <frame $LOC_ARTIST - $LOC_TITLE>
  <hbox>
   <entry>
    <variable>LYRICS_SONG</variable>
    <input>cat $WORKDIR/pmusic-ffmpeg_NOW_PLAYING</input>
    <width>100</width><height>30</height>
   </entry>
   <button>
    <label>$LOC320</label>
    <action>refresh:LYRICS_SONG</action>
   </button>
   <button>
    <label>www</label>
    <input file stock=\"gtk-find\"></input>
    <action>. $APPDIR/func -lyrics_search</action>
    <action>refresh:LYRICS</action>
   </button>
  </hbox>
  <edit>
   <variable>LYRICS</variable>
   <input file>$WORKDIR/pmusic-lyrics</input>
   <width>325</width><height>275</height>
  </edit>
 </frame>
 <hbox>
  <button>
   <label>$LOC231</label>
   <input file icon=\"gtk-cancel\"></input>
   <action type=\"closewindow\">Pmusic_lyrics</action>
  </button>
 </hbox>
</vbox>
</window>"


export Pmusic_add="
<window title=\"Pmusic - $LOC220\" icon-name=\"gtk-media-stop\">
<vbox>
  <frame $LOC221>
  <hbox>
   <entry activates-default=\"true\">
    <variable>SEARCH</variable>
    <default>$LOC222</default>
    <width>200</width><height>30</height>
   </entry>
   <button can-default=\"true\" has-default=\"true\" use-stock=\"true\">
    <input file stock=\"gtk-find\"></input>
    <action>. $APPDIR/func -search</action>
    <action>clear:INDEX</action>
    <action>refresh:INDEX</action>
   </button>
  </hbox>
  <hbox>
   <button>
    <label>$LOC223</label>
    <action>. $APPDIR/func -index_songs</action>
    <action>clear:INDEX</action>
    <action>refresh:INDEX</action>
   </button>
   <button>
    <label>$LOC224</label>
    <action>. $APPDIR/func -index_playlists</action>
    <action>clear:INDEX</action>
    <action>refresh:INDEX</action>
   </button>
   <text><label>\"  \"</label></text>
   <button>
    <label>$LOC225</label>
    <action>. $APPDIR/func -index_recent</action>
    <action>clear:INDEX</action>
    <action>refresh:INDEX</action>
   </button>
   <button>
    <label>$LOC226</label>
    <action>. $APPDIR/func -index_most_played</action>
    <action>clear:INDEX</action>
    <action>refresh:INDEX</action>
   </button>
  </hbox>
  <table>
   <label>\"|$LOC227                                                                                                                                                                             \"</label>
   <variable>INDEX</variable>
   <input>cat $HOME/.pmusic/index</input>
   <height>219</height>
   <action>. $APPDIR/func -add</action>
   <action>refresh:PLAYLIST</action>
  </table>
 </frame>
  <hbox>
   <radiobutton>
    <label>$LOC228</label>
    <variable>ADD_AFTER_SELECTION</variable>
   </radiobutton>
   <radiobutton>
    <label>$LOC229</label>
    <variable>ADD_TAIL</variable>
   </radiobutton>
  </hbox>
 <hbox>
  <button>
   <input file icon=\"gtk-add\"></input>
   <label>$LOC232</label>
   <action>$APPDIR/func -add_random</action>
   <action>refresh:PLAYLIST</action>
  </button>
  <button>
   <input file icon=\"gtk-add\"></input>
   <label>$LOC230</label>
   <action>$APPDIR/func -add_all</action>
   <action>refresh:PLAYLIST</action>
  </button>
  <button>
   <input file icon=\"gtk-refresh\"></input>
   <label>$LOC104...</label>
   <action>$APPDIR/func -update_index &</action>
  </button>
 </hbox>
</vbox>
</window>"

export pmusic_open="
<window title=\"Pmusic - $LOC240\" icon-name=\"gtk-media-stop\">
 <vbox>
  <chooser>
   <height>500</height><width>600</width>
   <variable>INDEX</variable>
  </chooser>
  <hbox>
   <radiobutton>
    <label>$LOC228</label>
    <variable>ADD_AFTER_SELECTION</variable>
   </radiobutton>
   <radiobutton>
    <label>$LOC229</label>
    <variable>ADD_TAIL</variable>
   </radiobutton>
  </hbox>
  <hbox>
   <button>
    <label>$LOC230</label>
    <action>$APPDIR/func -open_all</action>
    <action>refresh:PLAYLIST</action>
   </button>
   <text><label>\"  \"</label></text>
   <button>
    <input file icon=\"gtk-cancel\"></input>
    <label>$LOC231</label>
    <action type=\"closewindow\">Pmusic_open</action>
   </button>
   <button can-default=\"true\" has-default=\"true\" use-stock=\"true\">
    <input file icon=\"gtk-apply\"></input>
    <label>$LOC241</label>
    <action>. $APPDIR/func -add</action>
    <action>refresh:PLAYLIST</action>
   </button>
  </hbox>
 </vbox>
</window>"

export Pmusic_about="
<window title=\"Pmusic - about\" icon-name=\"gtk-media-stop\">
 <vbox>
  <notebook labels=\"About|License|Credits\">
   <vbox>
    <text><label>\"\"</label></text>
    <progressbar>
     <input>echo 50; echo \"Pmusic             $VERSION\"</input>
    </progressbar>
    <text use-markup=\"true\"><label>\"<b>Sigmund Berglund, Copyright 2008</b>\"</label></text>
    <text><label>\"\"</label></text>
    <text><label>\"\"</label></text>
    <button>
     <label>\"http://www.murga-linux.com/puppy/viewtopic.php?t=31206\"</label>
     <action>$BROWSER http://www.murga-linux.com/puppy/viewtopic.php?t=31206 &</action>
    </button>
   </vbox>
   <vbox>
    <text use-markup=\"true\"><label>\"Pmusic is released under the <b>GNU General Public License</b> (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.\"</label></text>
    <text use-markup=\"true\"><label>\"This program is distributed in the hope that it will be useful, but <b>WITHOUT ANY WARRANTY</b>. See the GNU General Public License homepage for more details.\"</label></text>
    <hbox>
     <button>
      <label>\"http://www.gnu.org/licenses/\"</label>
      <action>$BROWSER http:\/\/www.gnu.org\/licenses\/</action>
     </button>
    </hbox>
   </vbox>
   <vbox>
    <edit><default>\"Translators:
French - Jean-Jacques Moulinier (esmourguit)
German - Thorsten Köbe (aragon)
Italian - Angelo Gemmi
Polish - Robert Wojewódzki (robwoj44)
Spanish - (wow), (bernard)

Others:
Raymond Levang for core design ideas
\"</default></edit>
   </vbox>
  </notebook>
  <hbox>
   <button can-default=\"true\" has-default=\"true\" use-stock=\"true\">
    <input file icon=\"gtk-apply\"></input>
    <label>Ok</label>
    <action type=\"closewindow\">Pmusic_about</action>
   </button>
  </hbox>
 </vbox>
</window>"

if [ $SHOW_MULTIPLE_PLAYLISTS = true ]; then
	GUI_MULTIPLE_PLAYLISTS="
  <hbox>
   <radiobutton draw_indicator=\"false\">
   	<label>\"$PLAYLIST1_NAME\"</label>
    <variable>RADIO_PLAYLIST1</variable>
    <default>$RADIO_PLAYLIST1</default>
    <action>echo playlist1 > $WORKDIR/pmusic-PLAYLIST1234</action>
    <action>$APPDIR/func -show_playlist1234</action>
    <action>Refresh:PLAYLIST</action>
   </radiobutton>
   <radiobutton draw_indicator=\"false\">
   	<label>\"$PLAYLIST2_NAME\"</label>
    <variable>RADIO_PLAYLIST2</variable>
    <default>$RADIO_PLAYLIST2</default>
    <action>echo playlist2 > $WORKDIR/pmusic-PLAYLIST1234</action>
    <action>$APPDIR/func -show_playlist1234</action>
    <action>Refresh:PLAYLIST</action>
   </radiobutton>
   <radiobutton draw_indicator=\"false\">
   	<label>\"$PLAYLIST3_NAME\"</label>
    <variable>RADIO_PLAYLIST3</variable>
    <default>$RADIO_PLAYLIST3</default>
    <action>echo playlist3 > $WORKDIR/pmusic-PLAYLIST1234</action>
    <action>$APPDIR/func -show_playlist1234</action>
    <action>Refresh:PLAYLIST</action>
   </radiobutton>
   <radiobutton draw_indicator=\"false\">
   	<label>\"$PLAYLIST4_NAME\"</label>
    <variable>RADIO_PLAYLIST4</variable>
    <default>$RADIO_PLAYLIST4</default>
    <action>echo playlist4 > $WORKDIR/pmusic-PLAYLIST1234</action>
    <action>$APPDIR/func -show_playlist1234</action>
    <action>Refresh:PLAYLIST</action>
   </radiobutton>
  </hbox>"
else
	GUI_MULTIPLE_PLAYLISTS=""
fi

if [ $SHOW_PLAYLIST = false ]; then
	GUI_PLAYLIST=""
else
	GUI_PLAYLIST="
  <tree  headers_visible=\"false\" exported_column=\"3\" rules_hint=\"true\">
   <label>Nr|Song|length|Path</label>
   <height>245</height>
   <input>cat $WORKDIR/pmusic-playlist</input>
   <variable>PLAYLIST</variable>
   <action signal=\"button-release-event\">echo \$PLAYLIST > $WORKDIR/pmusic-SELECTION</action>
   <action signal=\"button-release-event\">echo \$PLAYLIST > $WORKDIR/pmusic-PLAYLIST</action>
   <action>echo \$PLAYLIST > $WORKDIR/pmusic-SELECTION</action>
   <action>echo \$PLAYLIST > $WORKDIR/pmusic-PLAYLIST</action>
   <action>echo 0 > $WORKDIR/pmusic-SS</action>
   <action>$APPDIR/func -stop</action>
   <action>$APPDIR/func -playing &</action>
  </tree>
  <hbox>
   <checkbox>
    <label>$LOC200</label>
    <variable>REPEAT</variable>
    <default>$REPEAT</default>
    <action>$APPDIR/func -repeat</action>
   </checkbox>
   <checkbox>
    <label>$LOC201</label>
    <variable>SHUFFLE</variable>
    <default>$SHUFFLE</default>
    <action>$APPDIR/func -shuffle</action>
   </checkbox>
   <button>
    <input file stock=\"gtk-undo\"></input>
	<action signal=\"enter\">echo 'undo' > $WORKDIR/pmusic-progressbar_status</action>
	<action signal=\"leave\">echo 'progress' > $WORKDIR/pmusic-progressbar_status</action>
    <action>. $APPDIR/func -undo</action>
    <action>Refresh:PLAYLIST</action>
   </button>
   <button>
    <input file stock=\"gtk-redo\"></input>
	<action signal=\"enter\">echo 'redo' > $WORKDIR/pmusic-progressbar_status</action>
	<action signal=\"leave\">echo 'progress' > $WORKDIR/pmusic-progressbar_status</action>
    <action>. $APPDIR/func -redo</action>
    <action>Refresh:PLAYLIST</action>
   </button>
   <text><label>\"  \"</label></text>
   <button>
    <input file stock=\"gtk-go-up\"></input>
    <action>. $APPDIR/func -up</action>
    <action>Refresh:PLAYLIST</action>
   </button>
   <button>
    <input file stock=\"gtk-go-down\"></input>
    <action>. $APPDIR/func -down</action>
    <action>Refresh:PLAYLIST</action>
   </button>
   <button>
    <input file stock=\"gtk-remove\"></input>
    <action>. $APPDIR/func -remove_from_list</action>
    <action>Refresh:PLAYLIST</action>
   </button>
   <button>
    <input file stock=\"gtk-add\"></input>
    <action>$APPDIR/func -update_index_check</action>
    <action type=\"launch\">Pmusic_add</action>
   </button>
  </hbox>"
fi

if [ $SHOW_PROGRESSBAR = true ]; then
	GUI_PROGRESSBAR="
<progressbar>
 <label>\" \"</label>
 <input>"'while [ "$(ps | grep -v while | grep -i pmusic)" ] ; do if [ "`cat '"$WORKDIR"'/pmusic-ffmpeg_output 2> /dev/null`" ]; then nice -18 '"$APPDIR"'/func_progressbar; sleep 1; fi; done'"</input>
</progressbar>"
#<hbox homogeneous=\"true\">
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 5</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 15</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 25</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 35</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 45</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 55</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 65</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 75</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 85</action>
# </button>
# <button>
#  <input file>$APPDIR/unknown.png</input>
#  <action>$APPDIR/func -slide 95</action>
# </button>
#</hbox>"
else
	GUI_PROGRESSBAR=""
fi

#theme
if [ -f "$APPDIR/themes/$THEME/icon_play.png" ]; then
	ICON_BUTTON_BACK="<input file>$APPDIR/themes/$THEME/icon_back.png</input>"
	ICON_BUTTON_REWIND="<input file>$APPDIR/themes/$THEME/icon_rewind.png</input>"
	ICON_BUTTON_STOP="<input file>$APPDIR/themes/$THEME/icon_stop.png</input>"
	ICON_BUTTON_PLAY="<input file>$APPDIR/themes/$THEME/icon_play.png</input>"
	ICON_BUTTON_FORWARD="<input file>$APPDIR/themes/$THEME/icon_forward.png</input>"
	ICON_BUTTON_NEXT="<input file>$APPDIR/themes/$THEME/icon_next.png</input>"
else
	ICON_BUTTON_BACK="<input file stock=\"gtk-media-previous\"></input>"
	ICON_BUTTON_REWIND="<input file stock=\"gtk-media-rewind\"></input>"
	ICON_BUTTON_STOP="<input file stock=\"gtk-media-stop\"></input>"
	ICON_BUTTON_PLAY="<input file stock=\"gtk-media-play\"></input>"
	ICON_BUTTON_FORWARD="<input file stock=\"gtk-media-forward\"></input>"
	ICON_BUTTON_NEXT="<input file stock=\"gtk-media-next\"></input>"
fi

main_gui () {
export Pmusic="
<window title=\"Pmusic $VERSION\" icon-name=\"gtk-media-stop\">
<vbox>
 <menubar>
  <menu>
   <menuitem icon=\"gtk-open\">
    <label>$LOC101...</label>
    <action type=\"launch\">pmusic_open</action>
   </menuitem>
   <menuitem icon=\"gtk-save\">
    <label>$LOC102...</label>
    <action>. $APPDIR/func -save</action>
   </menuitem>
   <separator></separator>
   <menuitem icon=\"gtk-preferences\">
    <label>$LOC103...</label>
    <action>$APPDIR/func -preferences &</action>
   </menuitem>
   <menuitem icon=\"gtk-refresh\">
    <label>$LOC104...</label>
    <action>$APPDIR/func -update_index &</action>
   </menuitem>
   <separator></separator>
   <menuitem icon=\"gtk-quit\">
    <label>$LOC_QUIT</label>
    <action type=\"exit\">quit</action>
   </menuitem>
   <label>$LOC100</label>
  </menu>
  
  
  <menu>
   <menuitem icon=\"gtk-clear\">
    <label>$LOC111</label>
    <action>$APPDIR/func_store_playlist</action>
    <action>$APPDIR/func -new</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-add\">
    <label>$LOC112...</label>
    <action>$APPDIR/func -update_index_check</action>
    <action type=\"launch\">Pmusic_add</action>
   </menuitem>
   <menuitem icon=\"gtk-remove\">
    <label>$LOC113</label>
    <action>. $APPDIR/func -remove_from_list</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-goto-top\">
    <label>$LOC114</label>
    <action>. $APPDIR/func -to_top</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-go-up\">
    <label>$LOC115</label>
    <action>. $APPDIR/func -up</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-go-down\">
    <label>$LOC116</label>
    <action>. $APPDIR/func -down</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-goto-bottom\">
    <label>$LOC117</label>
    <action>. $APPDIR/func -to_bottom</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <separator></separator>
   <menuitem icon=\"gtk-undo\">
    <label>$LOC118</label>
    <action>. $APPDIR/func -undo</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-redo\">
    <label>$LOC119</label>
    <action>. $APPDIR/func -redo</action>
    <action>refresh:PLAYLIST</action>
   </menuitem>
   <label>$LOC110</label>
  </menu>


  <menu>
   <menuitem icon=\"gtk-info\">
    <label>$LOC131...</label>
    <action>$APPDIR/func -song_info</action>
   </menuitem>
   <separator></separator>
   <menuitem icon=\"gtk-convert\">
    <label>$LOC132...</label>
    <action>$APPDIR/func -rename</action>
    <action>Refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-copy\">
    <label>$LOC133...</label>
    <action>$APPDIR/func -copy</action>
    <action>Refresh:PLAYLIST</action>
   </menuitem>
   <menuitem icon=\"gtk-delete\">
    <label>$LOC134...</label>
    <action>$APPDIR/func -delete</action>
    <action>Refresh:PLAYLIST</action>
   </menuitem>
  <label>$LOC130</label>
  </menu>

  <menu>
   <menuitem icon=\"gtk-id3\">
    <label>$LOC141...</label>
    <action>pmetatagger &</action>
   </menuitem>
   <menuitem icon=\"gtk-copy\">
    <label>$LOC142...</label>
    <action>$APPDIR/func -copy_files &</action>
   </menuitem>
   <menuitem icon=\"gtk-cdrom\">
    <label>$LOC143...</label>
    <action>$APPDIR/func -burn &</action>
   </menuitem>
   <separator></separator>
   <menuitem icon=\"gtk-new\">
    <label>$LOC144...</label>
    <action type=\"launch\">Pmusic_lyrics</action>
   </menuitem>
   <label>$LOC140</label>
  </menu>

  <menu>
   <menuitem>
    <label>$LOC151</label>
    <action>$APPDIR/func -play</action>
   </menuitem>
   <menuitem>
    <label>$LOC152</label>
    <action>$APPDIR/func -stop</action>
   </menuitem>
   <menuitem>
    <label>$LOC153</label>
    <action>$APPDIR/func -next</action>
   </menuitem>
   <menuitem>
    <label>$LOC154</label>
    <action>$APPDIR/func -back</action>
   </menuitem>
   <separator></separator>
   <menuitem>
    <label>$LOC155...</label>
    <action>$APPDIR/func -jump_to</action>
   </menuitem>
   <menuitem>
    <label>$LOC156</label>
    <action>$APPDIR/func -forward</action>
   </menuitem>
   <menuitem>
    <label>$LOC157</label>
    <action>$APPDIR/func -rewind</action>
   </menuitem>
   <label>$LOC150</label>
  </menu>

   <menu>
    <menuitem icon=\"gtk-about\">
     <label>$LOC191...</label>
     <action type=\"launch\">Pmusic_about</action>
    </menuitem>
    <label>$LOC190</label>
   </menu>
 </menubar>

 <hbox homogeneous=\"true\">
  <vbox>
   <hbox>
    <button>
     $ICON_BUTTON_BACK
     <action>$APPDIR/func -back</action>
    </button>
    <button>
     $ICON_BUTTON_REWIND
     <action>$APPDIR/func -rewind</action>
    </button>
    <button>
     $ICON_BUTTON_STOP
     <action>$APPDIR/func -stop</action>
    </button>
    <button>
     $ICON_BUTTON_PLAY
     <action>$APPDIR/func -play</action>
    </button>
    <button>
     $ICON_BUTTON_FORWARD
     <action>$APPDIR/func -forward</action>
    </button>
    <button>
     $ICON_BUTTON_NEXT
     <action>$APPDIR/func -next</action>
    </button>
   </hbox>
  </vbox>
 </hbox>
$GUI_PROGRESSBAR
$GUI_MULTIPLE_PLAYLISTS
$GUI_PLAYLIST
</vbox>
</window>"
#GTK-theme
if [ "`grep ONLY_THIS $APPDIR/themes/$THEME/themerc 2> /dev/null | grep '=true'`" ]; then 
	export GTK2_RC_FILES="$APPDIR/themes/$THEME/gtkrc"
else
	if [ -f $HOME/.gtkrc-2.0 ]; then
		export GTK2_RC_FILES="$HOME/.gtkrc-2.0" #get active theme
	fi
	if [ -f /etc/gtk-2.0/gtkrc ]; then GTK_OLD_PUPPY=':/etc/gtk-2.0/gtkrc'; fi #/etc/gtk-2.0/gtkrc is for < Puppy4
	export GTK2_RC_FILES="$GTK2_RC_FILES$GTK_OLD_PUPPY:$APPDIR/themes/$THEME/gtkrc"
fi
#---
I=$IFS; IFS=""
for STATEMENTS in $($GTKDIALOG --program=Pmusic); do
	eval $STATEMENTS
done
IFS=$I
if [ $EXIT ]; then
	for I in `ps | grep pmusic | grep while | awk '{print $1}'`; do kill -9 $I; done
	for I in `ps | grep Pmusic | grep gtkdialog | awk '{print $1}'`; do kill -9 $I; done
	for I in `ps | grep pmusic | grep progress | awk '{print $1}'`; do kill -9 $I; done
	for I in `ps | grep pmusic | grep playing | awk '{print $1}'`; do kill -9 $I; done
	exit 0
fi
}
main_gui