pkgname=linhes-theme
pkgver=8.6.1
pkgrel=1
pkgdesc="Default LinHES MythTV theme"
arch=('x86_64')
license=('GPL2')
url="http://linhes.org/"

patches=('readme.txt.patch' 'osd.xml.patch' 'base.xml.patch' 'browser-ui.xml.patch'
         'config-ui.xml.patch' 'controls-ui.xml.patch' 'menu-ui-vert.xml.patch'
         'music-base.xml.patch' 'music-ui.xml.patch' 'musicsettings-ui.xml.patch'
         'mytharchive-ui.xml.patch' 'mythburn-ui.xml.patch'
         'mythnative-ui.xml.patch'
         'notification-ui.xml.patch' 'qtlook.txt.patch'
         'recordings-ui.xml.patch' 'schedule-ui.xml.patch' 'settings-ui.xml.patch'
         'status-ui.xml.patch' 'stream-ui.xml.patch' 'video-ui.xml.patch'
         'weather-ui.xml.patch')

#The LinHES theme is based on TintedGlass 4.56 by Harley Peters
source=(`echo ${patches[@]:0}` 'themeinfo.xml' 'install-ui.xml' 'osd_subtitle.xml'
        'bubble_background.png' 'preview.png' 'blank_coverart.png'
        'gg-left-arrow-large.png' 'gg-right-arrow-large.png'
        'checkmark.png' 'error.png' 'gears.png' 'question.png' 'warning.png'
        'image-ui.xml' 'standardsetting-ui.xml'
        'LHLogo.png' 'LHLogoAndText.png')
install=$pkgname.install

prepare() {
    _gitroot="https://github.com/MythTV-Themes/TintedGlass.git"
    _gitname="TintedGlass"
    _gitbranch="fixes/0.27"

    cd $srcdir
    if [ -d $_gitname ]
    then
        cd $_gitname 
        git checkout $_gitbranch
        git pull
        msg "TintedGlass local files updated."
    else
        git clone -b $_gitbranch $_gitroot
        msg "TintedGlass git checkout done."
    fi
}

package() {
    THEMEROOT=usr/share/mythtv/themes

    msg "Copying theme to package"
    mkdir -p $pkgdir/$THEMEROOT/LinHES/
    rsync -arp --exclude .git* --delete-excluded $srcdir/TintedGlass/* $pkgdir/$THEMEROOT/LinHES/

    msg "--------------------------applying patches------------------------------"
    cd $pkgdir/$THEMEROOT/LinHES/
    for i in `echo ${patches[@]:0}`
    do
        echo applying $i
        patch -N -i ${srcdir}/$i || return 1
        echo "-----------------------------"
    done
    cd $startdir
    msg "--------------------------done applying patches-------------------------"

    msg "Copy *.xml and adding backgrounds and images for LinHES"
    rsync -pL $srcdir/*.xml $pkgdir/$THEMEROOT/LinHES/
    rm -r $pkgdir/$THEMEROOT/LinHES/images/backgrounds/*
    rm -r $pkgdir/$THEMEROOT/LinHES/osd.xml.alt
    rsync -pL $srcdir/bubble_background.png $pkgdir/$THEMEROOT/LinHES/images/backgrounds/background.png
    rsync -pL $srcdir/blank_coverart.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/gg-left-arrow-large.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/gg-right-arrow-large.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/checkmark.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/error.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/gears.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/question.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/warning.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/preview.png $pkgdir/$THEMEROOT/LinHES/

    rsync -pL $srcdir/LHLogo.png $pkgdir/$THEMEROOT/LinHES/images/
    rsync -pL $srcdir/LHLogoAndText.png $pkgdir/$THEMEROOT/LinHES/images/

    #remove old htmls directory
    rm -r $pkgdir/$THEMEROOT/LinHES/htmls

    #vertical menu
    mv $pkgdir/$THEMEROOT/LinHES/menu-ui-vert.xml $pkgdir/$THEMEROOT/LinHES/menu-ui.xml

    msg "Modifying yellows and blue to LinHES yellow and blue"
    #yellow
    grep -lr '#d9d900' $pkgdir/$THEMEROOT/LinHES/ | xargs -r sed -i "s/\#d9d900/\#ebb81c/g"
    #darkyellow
    grep -lr '#CCCC29' $pkgdir/$THEMEROOT/LinHES/ | xargs -r sed -i "s/\#CCCC29/\#ebb81c/g"
    #blue
    grep -lr '#3a9ade' $pkgdir/$THEMEROOT/LinHES/ | xargs -r sed -i "s/\#3a9ade/\#0072bc/g"

    msg "Modifying fonts to Overlock"
    grep -lr 'DejaVu Sans' $pkgdir/$THEMEROOT/LinHES/ | xargs -r sed -i "s/\DejaVu Sans/\Overlock/g"

    msg "Updating themeinfo.xml version number"
    sed -i "s/MAJ_VER/${pkgver//.}/" $pkgdir/$THEMEROOT/LinHES/themeinfo.xml
    sed -i "s/MIN_VER/${pkgrel}/" $pkgdir/$THEMEROOT/LinHES/themeinfo.xml
}
md5sums=('2dca856c2a4d1f959473512c94e43b60'
         '7ad16012e4c5f9419089e42c539fe6af'
         '31cd00ab3f10329a15f238dbe2b43708'
         'd1d54968a2297924673d9653f707df33'
         '25ff929dc4aca3b2a0bd38d9ded5a6b8'
         '26a6db272dee225b9e4dc282f1494e51'
         'b90b745c72a057c78ebd0b6f2c5530b9'
         'a0ea2d3e386c0b483b31aa1a2703f9eb'
         '8f8c27146e11954f60913da6d1fce073'
         '09806f2e1d1e6050cc0d10cc6c5daf36'
         'cf259052229f42646d7f37023ec55f44'
         '52bb1c1a6c693adc8c04227fb124955a'
         '643e7d548587b8742ed5accb6d736257'
         'dd1e013e806efc26049ea89637a51f83'
         '9fe3371a8b964a7028126405cfaa330b'
         '9eb628e751ad0cccc199779b5b23ac16'
         '373e1fd01ba18640992bd5d2e7fd7bfe'
         '384871202030f41148536e2e89bb1801'
         '8efbd524cef4dd3f5fbe5b7d5ad854f0'
         '8312aff444945f80a76100696c81cb2e'
         'f62b200729eb9a69e3929f20f51d3d35'
         '4125880d1739b196a8041ecc3d773ee2'
         '5a8fb2a5f0e657d52be6f0a6a006ce72'
         '274b6f8cb5cd82c5ce28422decd7754b'
         'bfc32b9fa5dca3d46dd6f365ecb449b5'
         '326a71eb795b322a9ea26f116d890c87'
         '8fcd0acc11f4db33a9442949fb1a293d'
         '699e3abe05523f454db3561bfc08b4b2'
         'c3b17c90d85e9e9908d194570f2da3ac'
         '39c3c560ed4d8779326f4e63861d8f33'
         '60cb915909c477dbc2e18233ee6424d9'
         '30ea7d2001b8562177b8f85f34f050a2'
         'e8dee86a10ce7c4423a97305b38b4668'
         'e8ac15e38b3dc99c9e889e439ba356de'
         'e8cf0d3a55ba3be47deae55c05432141'
         '3f600b966bd813dd27f620762ddb3ac8'
         '4f9e4db179e80eb96a202d319f1b835c'
         'b51ef0cbf8ed2d3a8c1a8257a89aceff'
         '09ad14842f828b7a8d24070ec8214fe5')
