#!/bin/bash

# this simple script will try to port deKorator-0.1 themes tarball to deKorator-0.2 themes format,
# before u start make sure that in the tarball u would like to port the names of the folders inside
# r named: deco, buttons, masks, and exectly like that no Deco or dEcO will do, 
# if not so, extract the tarball change the folder names and compress it again.
# after that run the portDeK script by clicking it or by typing "sh ./portDek" in console and fallow the instructions. 


kdialog --msgbox "choose the theme tarball u woulk like to port."
THEME=`kdialog --getopenfilename $HOME ""`
echo $THEME

mkdir "$HOME/port"
ark --extract-to "$HOME/port" "$THEME"

#echo --------------------
#ls $HOME/port

SRCTHEMENAME=`ls "$HOME/port"`
#echo --------
#echo $SRCTHEMENAME
SRCTHEMEDIR="$HOME/port/$SRCTHEMENAME"
#echo $SRCTHEMEDIR

DSTTHEMENAME="$SRCTHEMENAME-theme"
#echo $DSTTHEMENAME
DSTTHEMEDIR="$HOME/deKtest/$DSTTHEMENAME"
echo $DSTTHEMEDIR

mkdir "$HOME/deKtest"
mkdir "$DSTTHEMEDIR"
mkdir "$DSTTHEMEDIR/deco"
mkdir "$DSTTHEMEDIR/buttons"
mkdir "$DSTTHEMEDIR/buttons/normal"
mkdir "$DSTTHEMEDIR/buttons/hover"
mkdir "$DSTTHEMEDIR/buttons/press"
mkdir "$DSTTHEMEDIR/masks"


# if test -f "$SRCTHEMEDIR/deco/topLeftCornerBg.png" ; then
# echo --------------
# fi 

#deco
#top
cp "$SRCTHEMEDIR/deco/topLeftCornerBg.png" "$DSTTHEMEDIR/deco/topLeftCornerBg.png"
cp "$SRCTHEMEDIR/deco/leftButtonsBg.png" "$DSTTHEMEDIR/deco/leftButtonsBg.png"
cp "$SRCTHEMEDIR/deco/leftTitleBg.png" "$DSTTHEMEDIR/deco/leftTitleBg.png"
cp "$SRCTHEMEDIR/deco/midTitleBg.png" "$DSTTHEMEDIR/deco/midTitleBg.png"
cp "$SRCTHEMEDIR/deco/rightTitleBg.png" "$DSTTHEMEDIR/deco/rightTitleBg.png"
cp "$SRCTHEMEDIR/deco/rightButtonsBg.png" "$DSTTHEMEDIR/deco/rightButtonsBg.png"
cp "$SRCTHEMEDIR/deco/topRightCornerBg.png" "$DSTTHEMEDIR/deco/topRightCornerBg.png"
#left
cp "$SRCTHEMEDIR/deco/leftFrameBg.png" "$DSTTHEMEDIR/deco/topLeftFrameBg.png"
cp "$SRCTHEMEDIR/deco/leftFrameBg.png" "$DSTTHEMEDIR/deco/midLeftFrameBg.png"
cp "$SRCTHEMEDIR/deco/leftFrameBg.png" "$DSTTHEMEDIR/deco/bottomLeftFrameBg.png"
#right
cp "$SRCTHEMEDIR/deco/rightFrameBg.png" "$DSTTHEMEDIR/deco/topRightFrameBg.png"
cp "$SRCTHEMEDIR/deco/rightFrameBg.png" "$DSTTHEMEDIR/deco/midRightFrameBg.png"
cp "$SRCTHEMEDIR/deco/rightFrameBg.png" "$DSTTHEMEDIR/deco/bottomRightFrameBg.png"
#bottom
cp "$SRCTHEMEDIR/deco/buttomLeftCornerBg.png" "$DSTTHEMEDIR/deco/leftBottomFrameBg.png"
cp "$SRCTHEMEDIR/deco/buttomFrameBg.png" "$DSTTHEMEDIR/deco/midBottomFrameBg.png"
cp "$SRCTHEMEDIR/deco/buttomRightCornerBg.png" "$DSTTHEMEDIR/deco/rightBottomFrameBg.png"


#buttons
#normal
cp "$SRCTHEMEDIR/buttons/buttonAboveDown.png" "$DSTTHEMEDIR/buttons/normal/buttonAboveDown.png"
cp "$SRCTHEMEDIR/buttons/buttonAbove.png" "$DSTTHEMEDIR/buttons/normal/buttonAbove.png"
cp "$SRCTHEMEDIR/buttons/buttonBelowDown.png" "$DSTTHEMEDIR/buttons/normal/buttonBelowDown.png"
cp "$SRCTHEMEDIR/buttons/buttonBelow.png" "$DSTTHEMEDIR/buttons/normal/buttonBelow.png"
cp "$SRCTHEMEDIR/buttons/buttonClose.png" "$DSTTHEMEDIR/buttons/normal/buttonClose.png"
cp "$SRCTHEMEDIR/buttons/buttonHelp.png" "$DSTTHEMEDIR/buttons/normal/buttonHelp.png"
cp "$SRCTHEMEDIR/buttons/buttonMax.png" "$DSTTHEMEDIR/buttons/normal/buttonMax.png"
cp "$SRCTHEMEDIR/buttons/buttonMax.png" "$DSTTHEMEDIR/buttons/normal/buttonRestore.png"
cp "$SRCTHEMEDIR/buttons/buttonMin.png" "$DSTTHEMEDIR/buttons/normal/buttonMin.png"
cp "$SRCTHEMEDIR/buttons/buttonShadeDown.png" "$DSTTHEMEDIR/buttons/normal/buttonShadeDown.png"
cp "$SRCTHEMEDIR/buttons/buttonShade.png" "$DSTTHEMEDIR/buttons/normal/buttonShade.png"
cp "$SRCTHEMEDIR/buttons/buttonStickyDown.png" "$DSTTHEMEDIR/buttons/normal/buttonStickyDown.png"
cp "$SRCTHEMEDIR/buttons/buttonSticky.png" "$DSTTHEMEDIR/buttons/normal/buttonSticky.png"

#hover
cp "$SRCTHEMEDIR/buttons/buttonAboveDown.png" "$DSTTHEMEDIR/buttons/hover/buttonAboveDownHover.png"
cp "$SRCTHEMEDIR/buttons/buttonAbove.png" "$DSTTHEMEDIR/buttons/hover/buttonAboveHover.png"
cp "$SRCTHEMEDIR/buttons/buttonBelowDown.png" "$DSTTHEMEDIR/buttons/hover/buttonBelowDownHover.png"
cp "$SRCTHEMEDIR/buttons/buttonBelow.png" "$DSTTHEMEDIR/buttons/hover/buttonBelowHover.png"
cp "$SRCTHEMEDIR/buttons/buttonClose.png" "$DSTTHEMEDIR/buttons/hover/buttonCloseHover.png"
cp "$SRCTHEMEDIR/buttons/buttonHelp.png" "$DSTTHEMEDIR/buttons/hover/buttonHelpHover.png"
cp "$SRCTHEMEDIR/buttons/buttonMax.png" "$DSTTHEMEDIR/buttons/hover/buttonMaxHover.png"
cp "$SRCTHEMEDIR/buttons/buttonMax.png" "$DSTTHEMEDIR/buttons/hover/buttonRestoreHover.png"
cp "$SRCTHEMEDIR/buttons/buttonMin.png" "$DSTTHEMEDIR/buttons/hover/buttonMinHover.png"
cp "$SRCTHEMEDIR/buttons/buttonShadeDown.png" "$DSTTHEMEDIR/buttons/hover/buttonShadeDownHover.png"
cp "$SRCTHEMEDIR/buttons/buttonShade.png" "$DSTTHEMEDIR/buttons/hover/buttonShadeHover.png"
cp "$SRCTHEMEDIR/buttons/buttonStickyDown.png" "$DSTTHEMEDIR/buttons/hover/buttonStickyDownHover.png"
cp "$SRCTHEMEDIR/buttons/buttonSticky.png" "$DSTTHEMEDIR/buttons/hover/buttonStickyHover.png"

#press
cp "$SRCTHEMEDIR/buttons/buttonAboveDown.png" "$DSTTHEMEDIR/buttons/press/buttonAboveDownPress.png"
cp "$SRCTHEMEDIR/buttons/buttonAbove.png" "$DSTTHEMEDIR/buttons/press/buttonAbovePress.png"
cp "$SRCTHEMEDIR/buttons/buttonBelowDown.png" "$DSTTHEMEDIR/buttons/press/buttonBelowDownPress.png"
cp "$SRCTHEMEDIR/buttons/buttonBelow.png" "$DSTTHEMEDIR/buttons/press/buttonBelowPress.png"
cp "$SRCTHEMEDIR/buttons/buttonClose.png" "$DSTTHEMEDIR/buttons/press/buttonClosePress.png"
cp "$SRCTHEMEDIR/buttons/buttonHelp.png" "$DSTTHEMEDIR/buttons/press/buttonHelpPress.png"
cp "$SRCTHEMEDIR/buttons/buttonMax.png" "$DSTTHEMEDIR/buttons/press/buttonMaxPress.png"
cp "$SRCTHEMEDIR/buttons/buttonMax.png" "$DSTTHEMEDIR/buttons/press/buttonRestorePress.png"
cp "$SRCTHEMEDIR/buttons/buttonMin.png" "$DSTTHEMEDIR/buttons/press/buttonMinPress.png"
cp "$SRCTHEMEDIR/buttons/buttonShadeDown.png" "$DSTTHEMEDIR/buttons/press/buttonShadeDownPress.png"
cp "$SRCTHEMEDIR/buttons/buttonShade.png" "$DSTTHEMEDIR/buttons/press/buttonShadePress.png"
cp "$SRCTHEMEDIR/buttons/buttonStickyDown.png" "$DSTTHEMEDIR/buttons/press/buttonStickyDownPress.png"
cp "$SRCTHEMEDIR/buttons/buttonSticky.png" "$DSTTHEMEDIR/buttons/press/buttonStickyPress.png"


#masks
cp "$SRCTHEMEDIR/masks/topLeftCornerBitmap.png" "$DSTTHEMEDIR/masks/topLeftCornerBitmap.png"
cp "$SRCTHEMEDIR/masks/topRightCornerBitmap.png" "$DSTTHEMEDIR/masks/topRightCornerBitmap.png"
cp "$SRCTHEMEDIR/masks/buttomLeftCornerBitmap.png" "$DSTTHEMEDIR/masks/buttomLeftCornerBitmap.png"
cp "$SRCTHEMEDIR/masks/buttomRightCornerBitmap.png" "$DSTTHEMEDIR/masks/buttomRightCornerBitmap.png"



##mkdir "$HOME/test"

#cp -fr "$DSTTHEMEDIR" "$HOME/test" 
cd "$HOME/deKtest/"
tar czf "$DSTTHEMENAME.tar.gz" *

cp "$HOME/deKtest/$DSTTHEMENAME.tar.gz" $HOME

rm -fr "$HOME/port"
rm -fr "$HOME/deKtest/"

kdialog --msgbox "done, theme is located in your home dir."

exit 0 
