#!/bin/sh
#
#    Copyright (C) 2020  Ruben Rodriguez <ruben@trisquel.info>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#

VERSION=4
COMPONENT=main
. ./config

sed '/plymouth-theme-kubuntu-logo/,$d; /ttf-ubuntu/d' -i debian/control
sed 's/kubuntu-settings-desktop/triskel-settings-desktop/g; s/Kubuntu/Triskel/' -i debian/control
rm debian/plymouth* plymouth -r
rename s/kubuntu/triskel/ debian/*
find -type d -name '*kubuntu*' | xargs rename s/kubuntu/triskel/
find -type f -name '*kubuntu*' | xargs rename s/kubuntu/triskel/
rm desktop/etc/skel/.face

sed '/showAppsByName/s/true/false/' -i desktop/theme/layout-templates/org.triskel.desktop.defaultPanel/contents/layout.js
sed '/showAppsByName/akickoff.writeConfig("icon", "/usr/share/pixmaps/trisquel.svg")' -i desktop/theme/layout-templates/org.triskel.desktop.defaultPanel/contents/layout.js
sed 's|/usr/share/wallpapers/Next/contents/images/3200x2000.png|/usr/share/backgrounds/etiona.jpg|' -i ./debian/triskel-settings-desktop.postinst

replace kubuntu.org trisquel.info .
replace Kubuntu Triskel .
replace kubuntu triskel .

cat << EOF > desktop/theme/desktoptheme/triskel/metadata.desktop
[Desktop Entry]
Name=Triskel
Comment=Default Triskel theme

X-KDE-PluginInfo-Author=KDE Visual Design Group
X-KDE-PluginInfo-Email=kde-artists@kde.org
X-KDE-PluginInfo-Name=triskel
X-KDE-PluginInfo-Version=5.30
X-KDE-PluginInfo-Website=http://plasma.kde.org
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=LGPLv2+
X-KDE-PluginInfo-EnabledByDefault=true 
X-Plasma-API=5.0
 
[Wallpaper]
defaultWallpaperTheme=Etiona
defaultFileSuffix=.jpg
defaultWidth=4935
defaultHeight=3296

[ContrastEffect]
enabled=true
contrast=0.2
intensity=0.4
saturation=1.7
EOF

cat << EOF > desktop/kf5-settings/kdeglobals
[General]
fixed=Monospace,9,-1,0,50,0,0,0,0,0,Regular
font=Roboto,10,-1,0,50,0,0,0,0,0,Regular
menuFont=Roboto,10,-1,0,50,0,0,0,0,0,Regular
smallestReadableFont=Roboto,8,-1,0,50,0,0,0,0,0,Regular
toolBarFont=Roboto,10,-1,0,50,0,0,0,0,0,Regular
XftAntialias=true
XftHintStyle=hintslight
XftSubPixel=rgb

[WM]
activeFont=Roboto,10,-1,0,57,0,0,0,0,0,Medium

[KDE]
LookAndFeelPackage=org.triskel.desktop
SingleClick=false
EOF

cp -a $DATA/wallpaper wallpaper
echo 'wallpaper/*	usr/share/wallpapers/' >> debian/triskel-settings-desktop.install

sed 's/gtk-fallback-icon-theme=gnome/gtk-fallback-icon-theme=trisquel/' -i desktop/usr-share/settings.ini

cat << EOF >> desktop/theme/look-and-feel/org.triskel.desktop/contents/defaults
[ksplashrc][KSplash]
Engine=none
Theme=none
EOF

cat << EOF1 > debian/triskel-settings-desktop.preinst
#!/bin/sh

[ -d /etc/gtk-3.0 ] || mkdir /etc/gtk-3.0 && chmod 755 /etc/gtk-3.0
[ -d /etc/gtk-2.0 ] || mkdir /etc/gtk-2.0 && chmod 755 /etc/gtk-2.0

item="/etc/gtk-3.0/settings.ini"

grep -qi Breeze \$item && exit 0 || true
[ -f "\$item"".ubuntu" ] && exit 0 || true

dpkg-divert --package trisquel-desktop-common-data --add --rename --divert "\$item"".ubuntu" "\$item"

cat << EOF > \$item
[Settings]
gtk-theme-name = Breeze
gtk-icon-theme-name = Breeze
gtk-fallback-icon-theme = Trisquel
gtk-sound-theme-name = Trisquel
gtk-font-name=Sans Serif Regular 10
gtk-menu-images=1
gtk-button-images=1
gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
gtk-icon-sizes = panel-menu-bar=24,24
EOF

item="/etc/gtk-2.0/gtkrc"

grep -qi Breeze \$item && exit 0 || true

dpkg-divert --package trisquel-desktop-common-data --add --rename --divert "\$item"".ubuntu" "\$item"

cat << EOF > \$item
include "/usr/share/themes/Breeze/gtk-2.0/gtkrc"
style "user-font" 
{
        font_name="Sans Serif Regular"
}
widget_class "*" style "user-font"
gtk-font-name="Sans Serif Regular 10"
gtk-theme-name="Breeze"
gtk-icon-theme-name="breeze"
gtk-fallback-icon-theme="trisquel"
gtk-cursor-theme-name="Breeze_Snow"
gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
gtk-menu-images=1
gtk-button-images=1
gtk-primary-button-warps-slider=0
EOF

EOF1
chmod 755 debian/triskel-settings-desktop.preinst

sed '1s/triskel/kubuntu/' -i debian/control

cp $DATA/start.svgz desktop/theme/desktoptheme/triskel/icons/start.svgz
cp $DATA/fullscreenpreview.jpg $DATA/preview.png desktop/theme/look-and-feel/org.triskel.desktop/contents/previews/

changelog "Adapted for Triskel"

compile