#!/bin/sh
#(c) 01micko ... 01micko@gmail.com
#released under LGPL http://www.gnu.org/copyleft/lesser.html
###AS IS #NO WARRANTY ###
# 28.02.11 rodin.s i18n

export TEXTDOMAIN=pupradio
export TEXTDOMAINDIR=/usr/share/locale
export OUTPUT_CHARSET=UTF-8
eval_gettext () {
  local myMESSAGE=$(gettext "$1")
  eval echo \"$myMESSAGE\"
}
export LANGORG=$LANG


APP_DIR="`dirname $0`"
[ "$APP_DIR" = "." ] && APP_DIR="`pwd`"
export APP_DIR="$APP_DIR"

#first run finds a player
CUR_PLAYER=`cat $APP_DIR/config`
DEF_PLAYER="/usr/local/bin/defaultmediaplayer"
MPLAY=`grep "mplayer" $DEF_PLAYER`
GPLAY=`grep -w "gxineshell" $DEF_PLAYER`
XPLAY=`grep -w "xine" $DEF_PLAYER`
XXPLAY=`grep -w "xineshell" $DEF_PLAYER`

if [ "$CUR_PLAYER" = "PLAYER=" ];then
	if [ "$MPLAY" != "" ];then echo "PLAYER=mplayer" > $APP_DIR/config;fi
	if [ "$GPLAY" != "" ];then echo "PLAYER=gxine" > $APP_DIR/config;fi
	if [ "$XPLAY" != "" ];then echo "PLAYER=xine" > $APP_DIR/config;fi
	if [ "$XXPLAY" != "" ];then echo "PLAYER=xine" > $APP_DIR/config;fi
fi

BOOK_DIR=$APP_DIR/bookmarks

TBOOK_DIR=$APP_DIR/tbookmarks

. $APP_DIR/stations

. $APP_DIR/tel-stations

. $APP_DIR/config

RECORD_APP=`which precord`
#if [ "$RECORD_APP" != "" ]; then 
REC_TIP="$(gettext 'Record with Precord')"
ACTIONR="precord &"
#else REC_TIP="Please install Precord to enable recording feature"
#		ACTIONR="xmessage -center  -timeout 15 \"please install Precord from http://www.murga-linux.com/puppy/viewtopic.php?t=49907\" &"
#fi
export RECORD_APP




MPLAYER=`which mplayer`
GXINE=`which gxine`
XINE=`which xine`
GMPLAYER=`which gnome-mplayer`
VLC=`which vlc`

echo "" > $APP_DIR/playerlist
if [ "$MPLAYER" != "" ]; then echo "mplayer" >> $APP_DIR/playerlist ; fi
if [ "$GXINE" != "" ]; then echo "gxine" >> $APP_DIR/playerlist ; fi
if [ "$XINE" != "" ]; then echo "xine" >> $APP_DIR/playerlist ; fi
if [ "$GMPLAYER" != "" ]; then echo "gnome-mplayer" >> $APP_DIR/playerlist ; fi
if [ "$VLC" != "" ]; then echo "vlc" >> $APP_DIR/playerlist ; fi

echo `cat $APP_DIR/playerlist` > $APP_DIR/players
PLAYERLINE=`cat $APP_DIR/players`

#dpup uses Ogle at the moment , need to choose player 
FIRST_RUN=`cat $APP_DIR/config`
if [  "$FIRST_RUN" = "PLAYER=" ] ; then yaf-splash -font "8x16" -margin 4 -outline 0 -bg yellow -timeout 3 -text "Please choose a player" &
fi

PLAYERS="<item>$PLAYER</item>"
for I in $PLAYERLINE ; do PLAYERS=`echo "$PLAYERS<item>$I</item>"`; done

BOOKS=`ls $BOOK_DIR | awk '{print $1}'`
echo "$BOOKS" > $BOOK_DIR/.bookmark-list
BOOKLINE=`cat $BOOK_DIR/.bookmark-list`

for I in $BOOKLINE ; do BOOKMARKS=`echo "$BOOKMARKS<item>$I</item>"`; done

TBOOKS=`ls $TBOOK_DIR`
echo "$TBOOKS" > $TBOOK_DIR/.tbookmark-list
TBOOKLINE=`cat $TBOOK_DIR/.tbookmark-list`

for I in $TBOOKLINE ; do TBOOKMARKS=`echo "$TBOOKMARKS<item>$I</item>"`; done

export PUPRADIO="
<window title=\"$(gettext 'pupRadio')\">
 <vbox>
 
  <notebook labels=\"$(gettext 'pupRadio|pupTelly')\">
   <vbox>
  
 <vbox> 
 <hbox>
 
  <frame $(gettext 'Presets')>

  <hbox homogeneous=\"true\">
    <button label=\" 1: $CH1\"  width-request=\"200\" xalign=\"0\" tooltip-text=\"$(gettext 'Click a button!')\">
     <action>. $APP_DIR/func 1</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 2: $CH2\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 2</action>
    </button>
  </hbox>
  <hbox homogeneous=\"true\">
    <button label=\" 3: $CH3\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 3</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 4: $CH4\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 4</action>
    </button>
  </hbox>
  </frame>
  
  <frame>
    <hbox homogeneous=\"true\">
    <button label=\" 5: $CH5\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 5</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 6: $CH6\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 6</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">  
    <button label=\" 7: $CH7\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 7</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 8: $CH8\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func 8</action>
    </button>
   </hbox>

  </frame>
  </hbox>
 </vbox>
 
 <hbox height-request=\"180\">
  <frame>
   <hbox homogeneous=\"true\">
    <text width-request=\"450\" use-markup=\"true\"><label>\"$(gettext 'Please select a Name for your station, the URL and save as a <b>Preset</b> or <b>Play Now!</b> or save as a <b>Bookmark</b>')\"</label></text>
   </hbox>
   <hbox homogeneous=\"true\">
    <text><label>$(gettext 'Name')</label></text>
     <entry tooltip-text=\"$(gettext 'Please enter a name for your Preset radio station')\">
     <variable>STATION</variable>
    </entry>
    <text><label>URL</label></text>
    <entry tooltip-text=\"$(gettext 'Please enter or copy and paste the URL for your radio station')\">
	 <variable>RSURL</variable>
    </entry>
   </hbox> 
   <hbox homogeneous=\"true\">
    <text><label>$(gettext 'Preset No')</label></text>
    <combobox width-request=\"50\">
     <variable>RNUMBER</variable>
     <item>1</item>
     <item>2</item>
     <item>3</item>
     <item>4</item>
     <item>5</item>
     <item>6</item>
     <item>7</item>
     <item>8</item>
    </combobox>
    <button tooltip-text=\"$(gettext 'Click to save your  radio station as a Preset') \">
     <label>$(gettext 'Save your Preset')</label>
     <input file stock=\"gtk-apply\"></input>
     <action>. $APP_DIR/func apply</action>
     <action>. $APP_DIR/func restart</action>
    </button>
    <button tooltip-text=\"$(gettext 'Click to play  radio station without saving') \">
     <label>$(gettext 'Play Now!')</label>
     <input file stock=\"gtk-media-play\"></input>
     <action>. $APP_DIR/func playnow</action>
    </button>"

if [ "$RECORD_APP" != "" ];then PUPRADIO=${PUPRADIO}"
    <button tooltip-text=\"$REC_TIP\">
     <label>$(gettext 'Record')</label>
     <input file stock=\"gtk-media-record\"></input>
     <action>$ACTIONR</action>
    </button>"
fi
PUPRADIO=${PUPRADIO}"   
   </hbox>
   <hbox homogeneous=\"true\">
    <text><label>$(gettext 'Bookmarks')</label></text>
    <combobox width-request=\"150\">
     <variable>PLAYSTATION</variable>
 $BOOKMARKS
    </combobox>
     <button tooltip-text=\"$(gettext 'Click to save  radio station Bookmark. Please note that names with spaces will be truncated to the first word') \">
     <label>$(gettext 'Save Bookmark')</label>
     <input file stock=\"gtk-save\"></input>
     <action>. $APP_DIR/func radd</action>
     <action>. $APP_DIR/func restart</action>
    </button>
    <button tooltip-text=\"$(gettext 'Click to play  radio station Bookmark') \">
     <label>$(gettext 'Play Bookmark')</label>
     <input file stock=\"gtk-media-play\"></input>
     <action>. $APP_DIR/func rplay</action>
    </button>
   </hbox>
  </frame>
  </hbox>
 </vbox>
 
 <vbox>
   
 <vbox> 
 <hbox>
  <frame $(gettext 'Presets')>
   <hbox homogeneous=\"true\">
    <button label=\" 1: $TCH1\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T1</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 2: $TCH2\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T2</action>
    </button>
   </hbox>
   <hbox homogeneous=\"true\">
    <button label=\" 3: $TCH3\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T3</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 4: $TCH4\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T4</action>
    </button>
   </hbox>
  </frame>
  <frame>
   <hbox homogeneous=\"true\">
    <button label=\" 5: $TCH5\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T5</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 6: $TCH6\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T6</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">  
    <button label=\" 7: $TCH7\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T7</action>
    </button>
	</hbox>
	<hbox homogeneous=\"true\">
    <button label=\" 8: $TCH8\" width-request=\"200\" xalign=\"0\">
     <action>. $APP_DIR/func T8</action>
    </button>
   </hbox>
   </frame>
  </hbox>
 </vbox>

 <hbox height-request=\"180\">
  <frame>
   <hbox homogeneous=\"true\">
    <text width-request=\"450\" use-markup=\"true\"><label>\"$(gettext 'Please select a Name for your channel, the URL and save as a <b>Preset</b> or <b>Watch Now!</b> or save as a <b>Bookmark</b>')\"</label></text>
   </hbox>
   <hbox homogeneous=\"true\">
    <text><label>$(gettext 'Name')</label></text>
    <entry tooltip-text=\"$(gettext 'Please enter a name for your telly channel')\">
     <variable>CHANNEL</variable>
    </entry>
    <text><label>URL</label></text>
    <entry tooltip-text=\"$(gettext 'Please enter or copy and paste the URL for your telly channel')\">
     <variable>SURL</variable>
    </entry>
   </hbox>
   <hbox homogeneous=\"true\">
    <text><label>$(gettext 'Preset No')</label></text>
    <combobox width-request=\"50\">
     <variable>NUMBER</variable>
     <item>1</item>
     <item>2</item>
     <item>3</item>
     <item>4</item>
     <item>5</item>
     <item>6</item>
     <item>7</item>
     <item>8</item>
    </combobox>
    <button tooltip-text=\"$(gettext 'Click to save your  telly channel as a Preset') \">
     <label>$(gettext 'Save Preset')</label>
     <input file stock=\"gtk-apply\"></input>
     <action>. $APP_DIR/func Tapply</action>
     <action>. $APP_DIR/func restart</action>
    </button>
    <button tooltip-text=\"$(gettext 'Click to watch your telly channel without saving') \">
     <label>$(gettext 'Watch Now!')</label>
     <input file stock=\"gtk-media-play\"></input>
     <action>. $APP_DIR/func Tplaynow</action>
    </button>
    <text use-markup=\"true\"><label>\"<b>F</b> $(gettext 'toggles fullscreen')\"</label></text>
   </hbox>
   <hbox homogeneous=\"true\">
    <text><label>$(gettext 'Bookmarks')</label></text>
    <combobox width-request=\"150\">
     <variable>PLAYCHANNEL</variable>
 $TBOOKMARKS
    </combobox>
    <button tooltip-text=\"$(gettext 'Click to save telly channel Bookmark. Please note that names with spaces will be truncated to the first word') \">
     <label>$(gettext 'Save Bookmark')</label>
     <input file stock=\"gtk-save\"></input>
     <action>. $APP_DIR/func tadd</action>
     <action>. $APP_DIR/func restart</action>
    </button>
    <button tooltip-text=\"$(gettext 'Click to watch telly channel Bookmark')\">
     <label>$(gettext 'Play Bookmark')</label>
     <input file stock=\"gtk-media-play\"></input>
     <action>. $APP_DIR/func tplay</action>
    </button>
   </hbox>
   </frame>
  </hbox>
  </vbox>
 </notebook>
   <hbox>
    <text><label>$(gettext 'Preferred Player')</label></text>
    <combobox width-request=\"100\">
     <variable>PLAYER</variable>
 $PLAYERS
    </combobox>
   </hbox>
   <hbox>
   <button tooltip-text=\"$(gettext 'General Help')\">
       <label>$(gettext 'Help')</label>
        <input file stock=\"gtk-help\"></input>
        <action>$APP_DIR/func help</action>
    </button>
    <button tooltip-text=\"$(gettext 'Click to open your browser and browse a radio stream archive site')\">
       <label>$(gettext 'Radio www')</label>
        <input file>/usr/local/lib/X11/mini-icons/mini-audiovol.xpm</input>
        <action>defaultbrowser http://www.mikesradioworld.com/ &</action>
    </button>
    <button tooltip-text=\"$(gettext 'Click to open your browser and browse a TV stream archive site')\">
       <label>$(gettext 'Telly www')</label>
       <input file>/usr/local/lib/X11/mini-icons/mini-display.xpm</input>
        <action>defaultbrowser  http://watch.squidtv.net/ &</action>
    </button>
    <button>
     <label>$(gettext 'Stop')</label>
     <input file stock=\"gtk-stop\"></input>
     <action>. $APP_DIR/func stop</action>
    </button>
    <button>
     <label>$(gettext 'Quit')</label>
     <input file stock=\"gtk-quit\"></input>
     <action>. $APP_DIR/func quit</action>
     <action>EXIT:ok</action>
    </button>
  </hbox>
 </vbox>
</window>
"

gtkdialog3 -p PUPRADIO --geometry 670x440



unset PUPRADIO

exit
