#!/bin/bash
. mpvfunc
v=161217 #sfs
#gtkdialog examp: conditional_actions - движок

no="$HOME/.config/mpvgui.conf"
#if [ "`cat $no`" = "true" ];then
    #mpv --profile=pseudo-gui "$@" &
##[ -f "$no" ] &&   exit
#fi

[ "`pgrep -f "gtkdialog --program=MPVGUI"`" ] && exit #(ntf -e "MPV. Панель управления" "уже запущена" &) && exit
#sleep 0.5
XML='<window title="MPV. Панель управления v.'$v'" resizable="false" icon-name="mpv">
<vbox>
#<hbox>

# <chooser>
# <variable>CHOOSER</variable>
#  <default>/home/'`sfsusr`'</default>
#  <width>550</width>
#  <height>250</height>
#  </chooser>
<hbox>
<pixmap><height>48</height><width>48</width><input file icon="mpv"></input></pixmap>
'
XXX='\
 <frame Файл>
  <hbox>
    <pixmap><height>24</height><width>24</width><input file icon="gtk-file"></input></pixmap>

    <button tooltip-text="Выбрать (ввести, перетащить в окно MPV) файл или каталог, ввести URL">
     <input file stock="gtk-open"></input>
     <action>pidof mpv || MPV</action>
     <action>LFILE &</action>
#     <action>echo "loadfile \"`ntf -c "Выберите (введите)" "файл (URL) или перетащите каталог в окно MPV"`"\" >$FIFO</action>
#     <action>echo "loadfile \"`ntf -f "*" "Выберите (введите)" "файл (URL) или перетащите каталог в окно MPV"`"\" >$FIFO</action>
#     <action>echo "loadfile `ntf -f "*" "Выберите (введите)" "файл, каталог или введите URL"`" >$FIFO</action>
    </button>

    <button tooltip-text="Загрузить плейлист в MPV">
     <input file stock="gtk-index"></input>
     <action>pidof mpv || MPV</action>
     <action>LLIST &</action>
#     <action>echo "loadlist `ntf -f "*" "Загрузить плейлист"`" >$FIFO</action>
#     <action>f=`ntf -f "*.m3u|*.m3u8" "Загрузить плейлист"`" >$FIFO </action>
#     <action>echo "loadlist "$f"" >$FIFO</action>
#     <action>ntf -i $f</action>
    </button>

    <button tooltip-text="Просмотреть плейлист">
     <input file stock="gtk-find"></input>
     <action>pidof mpv || MPV</action>
#     <action>ntf -i "`cat "/home/'`sfsusr`'/.config/.mpvlist"`"</action>
     <action>pkill -f "yad --title Проигрыватель плейлиста.m3u"</action>
#     <action>pgrep -f "yad --title Проигрыватель плейлиста.m3u" ||  m3u-gui "`cat "/home/'`sfsusr`'/.config/.mpvlist"`" &</action>
     <action>m3u-gui "`cat /tmp/mpv.list`" &</action>
    </button>


  </hbox>
 </frame>
'

XML=''$XML'
 <frame Контраст>
  <hbox>
    <pixmap><height>24</height><width>24</width><input file icon="quality_3"></input></pixmap>

    <button tooltip-text="Hotkey: 1">
     <input file stock="gtk-remove"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress 1" >$FIFO</action>
    </button>

    <button tooltip-text="Hotkey: 2">
     <input file stock="gtk-add"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress 2" >$FIFO</action>
    </button>

  </hbox>
 </frame>

 <frame Яркость>
  <hbox>
    <pixmap><height>24</height><width>24</width><input file icon="execute"></input></pixmap>

    <button tooltip-text="Hotkey: 3">
     <input file stock="gtk-remove"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress 3" >$FIFO</action>
    </button>

    <button tooltip-text="Hotkey: 4">
     <input file stock="gtk-add"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress 4" >$FIFO</action>
    </button>

  </hbox>
 </frame>

 <frame Звук>
  <hbox>
    <pixmap><height>24</height><width>24</width><input file icon="speaker_3"></input></pixmap>

    <button tooltip-text="Hotkey: 9">
     <input file stock="gtk-remove"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress 9" >$FIFO</action>
    </button>

    <button tooltip-text="Hotkey: 0">
     <input file stock="gtk-add"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress 0" >$FIFO</action>
    </button>

    <button tooltip-text="Выключить. Hotkey: m">
     <input file icon="speaker_0"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress m" >$FIFO</action>
    </button>

  </hbox>
 </frame>


#			<hseparator></hseparator>
#			<vseparator></vseparator>
#			<hseparator></hseparator>

  </hbox>
# <frame>
  <hbox>
 <hbox space-expand="1">
# <hbox fill="true" expand="true">
#<pixmap><height>48</height><width>48</width><input file icon="mpv"></input></pixmap>
#    <vbox>

#    <button tooltip-text="Не запускать эту панель. 
#Для восстановления запуска панели 
#удалите файл '$no'">
#     <input file icon="gtk-no"></input>
##     <action>ntf -i "NO changed to '$no'"</action>
#     <action>echo true >'$no'</action>
#     <action>[ "`cat '$no'`" = "true" ] && kill `pgrep -f "gtkdialog --program=MPVGUI"`</action>
#    </button>

  <text use-markup="true" wrap="false">
    <label>
#Перетащите медиафайл (каталог) в окно MPV
"<small>Для управления используйте OSC 
(прозрачное меню) в окне MPV</small>"
    </label>
  </text>


#    </vbox>
 </hbox>
 <hbox>

# <frame Управление>
  <hbox>

    <button tooltip-text="Запустить mpv">
     <input file icon="mpv"></input>
     <action>pidof mpv && WM || MPV</action>
    </button>

    <button tooltip-text="Закрыть mpv">
     <input file stock="gtk-stop"></input>
     <action>echo "quit" >$FIFO</action>
    </button>

    <button tooltip-text="Снимок экрана. Hotkey: s">
     <input file icon="graphics"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "screenshot" >$FIFO</action>
    </button>

    <button tooltip-text="Автоматическое гашение экрана">
     <input file icon="screen_resolution"></input>
     <action>dpms &</action>
    </button>

    <button tooltip-text="Информация о медиафайле. Hotkey: I,o">
     <input file stock="gtk-info"></input>
     <action>pidof mpv && WM || MPV</action>
     <action>echo "keypress I" >$FIFO</action>
     <action>sleep 1</action>
     <action>echo "keypress o" >$FIFO</action>
#     <action>sleep 1</action>
#     <action>echo "print-text "`xset q |grep "DPMS is " |tr " " "_"`"" >$FIFO</action>
    </button>

    <button tooltip-text="Информация о MPV">
     <input file stock="gtk-about"></input>
     <action>MPVINFO</action>
    </button>

  </hbox>
# </frame>

  <hbox>
    <button tooltip-text="Справка. 
Перетащите медиафайл (каталог) в окно MPV
Для управления используйте OSC 
(прозрачное меню) в окне MPV">
     <input file stock="gtk-help"></input>
     <action>HLP</action>
    </button>

#  <button ok></button>
#  <button cancel></button>
       <button tooltip-text="Закрыть панель">
        <input file stock="gtk-quit"></input>
#        <label>Выход</label>
       </button>

  </hbox>

  </hbox>
</hbox>
# </frame>
## </hbox>
</vbox>
</window>'
export MPVGUI="`echo "$XML" | sed -e 's/#.*//'`"
  INF="`gtkdialog --program=MPVGUI --geometry=+9900+9990 |grep =`"
#  INF="`gtkdialog --geometry=+0+0 --program=MPVGUI |grep =`"
  eval "${INF}"
  #ntf -w "$INF" &
  [ "$EXIT" = "Cancel" ] && exit
  #mpv "${CHOOSER}" &
#else
#  MPV "$f" &
#fi
#rm "/home/`sfsusr`/.config/.mpvlist"