#!/bin/sh

########################################################################
###                 check to see if needs to run                     ###
########################################################################
if [ -f /home/$USER/.config/alteratio/config ]
then
exit 0
else
rm /home/tux/.config/dconf/user
echo "found"
fi


########################################################################
###                      resize nautilus icons                       ###
########################################################################
dconf write /org/gnome/nautilus/icon-view/thumbnail-size "48"
dconf write /org/gnome/nautilus/icon-view/default-zoom-level "'small'"


########################################################################
###              set min max close buttons to the right              ###
########################################################################
gsettings set org.gnome.settings-daemon.plugins.xsettings overrides "{'Gtk/DecorationLayout': <':minimize,maximize,close'>}"


########################################################################
###                         input theme file                         ###
########################################################################
source /usr/share/themes/Alteratio/alteratio/Alteratio.alteratio
dconf load / < /usr/share/alteratio/alteratio.dconf

########################################################################
###               change theme file variables if needed              ###
########################################################################
if [ $system_icon = "default" ]
then
system_icon="$theme_dir"
fi

if [ $system_widget = "default" ]
then
system_widget="$theme_dir"
fi

if [ $system_cursor = "default" ]
then
system_cursor="$theme_dir"
fi


########################################################################
###               make needed directories if not found               ###
########################################################################
### 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/dconf ]
then
echo "found"
else
mkdir /home/$USER/.config/dconf
fi


########################################################################
###                            copy config                           ###
########################################################################
cp /usr/share/alteratio/user /home/$USER/.config/dconf/user


########################################################################
###                           set gtk theme                          ###
########################################################################
gsettings set org.gnome.desktop.interface gtk-theme "$system_widget"


########################################################################
###                         set icon theme                           ###
########################################################################
gsettings set org.gnome.desktop.interface icon-theme "$system_icon"


########################################################################
###                        set mouse theme                           ###
########################################################################
gsettings set org.gnome.desktop.interface cursor-theme "$system_cursor"


########################################################################
###                          set KDE icons                           ###
########################################################################
configfile=$(cat /usr/share/alteratio/conf/kdeglobals2)
cat > /home/$USER/.kde4/share/config/kdeglobals << EOF
$configfile
EOF
sed -i s/ICONTHEMENAME/"$system_icon"/g /home/$USER/.kde4/share/config/kdeglobals


#################################################################
###        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


########################################################################
###                          set wallpapers                          ###
########################################################################
gsettings set org.gnome.desktop.background picture-uri "file://$system_background"


########################################################################
###                        write config file                         ###
########################################################################
cat > /home/$USER/.config/alteratio/config << EOF
done
EOF


########################################################################
###                       reload panel and exit                      ###
########################################################################
budgie-panel --replace & exit 0
