#!/bin/sh
if [ -f /home/$USER/.config/alteratio/setup-complete ]
then
exit 0
fi

#################################################################
###             make directories that do not exist            ###
#################################################################
### make directory if not found ###
if [ -d /home/$USER/.config/autostart ]
then
echo "found"
else
mkdir /home/$USER/.config/autostart
fi
### make directory if not found ###
if [ -d /home/$USER/.kde4 ]
then
echo "found"
else
mkdir /home/$USER/.kde4
fi
### make directory if not found ###
if [ -d /home/$USER/.kde4/share ]
then
echo "found"
else
mkdir /home/$USER/.kde4/share
fi
### make directory if not found ###
if [ -d /home/$USER/.kde4/share/config ]
then
echo "found"
else
mkdir /home/$USER/.kde4/share/config
fi
### make directory if not found ###
if [ -d /home/$USER/.config/alteratio ]
then
echo "found"
else
mkdir /home/$USER/.config/alteratio
fi
### make directory if not found ###
if [ -d /home/$USER/.config/lxpanel ]
then
echo "found"
else
mkdir /home/$USER/.config/lxpanel
fi
### make directory if not found ###
if [ -d /home/$USER/.config/lxpanel/LXDE ]
then
echo "found"
else
mkdir /home/$USER/.config/lxpanel/Alteratio
fi
### make directory if not found ###
if [ -d /home/$USER/.config/lxpanel/LXDE/panels ]
then
echo "found"
else
mkdir /home/$USER/.config/lxpanel/Alteratio/panels
fi
### make directory if not found ###
if [ -d /home/$USER/.config/xfce4 ]
then
echo "found"
else
mkdir /home/$USER/.config/xfce4
fi
### make directory if not found ###
if [ -d /home/$USER/.config/xfce4/panel ]
then
echo "found"
else
mkdir /home/$USER/.config/xfce4/panel
fi


#################################################################
###                    write default theme                    ###
#################################################################
### input global defaults ###
configfile=$(cat /usr/share/alteratio/conf/default-theme.s7t)
### write default.cfg ###
cat > /home/$USER/.config/alteratio/theme.s7t << EOF
$configfile
EOF


#################################################################
###        write KDE config file for application theme        ###
#################################################################
configfile=$(cat /etc/kde4/share/config/kdeglobals)
cat > /home/$USER/.kde4/share/config/kdeglobals << EOF
$configfile
EOF


#################################################################
###        make qt/kde applications use the gtk theme         ###
#################################################################
configfile=$(cat /usr/share/alteratio/conf/Trolltech.conf)
cat > /home/$USER/.config/Trolltech.conf << EOF
$configfile
EOF


#################################################################
###               input user configuration files              ###
#################################################################
source /home/$USER/.config/alteratio/theme.s7t


#################################################################
###                 rewrite whisker menu config               ###
#################################################################
cat > /home/$USER/.config/xfce4/panel/whiskermenu-1.rc << EOF
favorites=firefox.desktop,kde4-kolourpaint.desktop,galculator.desktop,abiword.desktop,leafpad.desktop,xfce4-terminal.desktop,lxtask.desktop
recent=leafpad.desktop,firefox.desktop
button-title=Applications Menu
button-icon=xfce4-whiskermenu
button-single-row=false
show-button-title=false
show-button-icon=true
launcher-show-name=true
launcher-show-description=false
item-icon-size=2
hover-switch-category=true
category-icon-size=1
load-hierarchy=false
favorites-in-recent=true
display-recent-default=false
position-search-alternate=true
position-commands-alternate=false
position-categories-alternate=false
menu-width=356
menu-height=503
command-settings=xfce4-settings-manager
show-command-settings=true
command-lockscreen=xflock4
show-command-lockscreen=false
command-switchuser=gdmflexiserver
show-command-switchuser=false
command-logout=xfce4-session-logout
show-command-logout=true
command-menueditor=menulibre
show-command-menueditor=false
search-actions=4

[action0]
name=Man Pages
pattern=#
command=exo-open --launch TerminalEmulator man %s
regex=false

[action1]
name=Wikipedia
pattern=!w
command=exo-open --launch WebBrowser http://en.wikipedia.org/wiki/%u
regex=false

[action2]
name=Run in Terminal
pattern=!
command=exo-open --launch TerminalEmulator %s
regex=false

[action3]
name=Open URI
pattern=^(file|http|https):\\/\\/(.*)$
command=exo-open \\0
regex=true
EOF


#################################################################
###                   display welcome screen                  ###
#################################################################
action=$(yad --image=/usr/share/alteratio/images/welcome-screen.png --center --fullscreen \
--window-icon=gtk-preferences \
--button="Choose new theme with Theme Manager:2" \
--button="Close:1" \
--title 'Alteratio Setup')
ret=$?
if [ $ret = 2 ] 
then
theme-manager
fi


#################################################################
###              write setup finished flag file               ###
#################################################################
cat > /home/$USER/.config/alteratio/setup-complete << EOF
v0.8.0
EOF & exit 0