#!/bin/sh
#
#    Copyright (C) 2021-2023  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=12

. ./config

# Rebrand logo
rm desktop/usr-share/kubuntu-circle-128.png
cp $DATA/TrisquelLogo.png desktop/usr-share/
cp $DATA/TrisquelLogo.png desktop/kubuntu-logo.png
sed 's/kubuntu-circle-128\.png/TrisquelLogo\.png/' -i $(find -name 'kcm-about-distrorc')

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

# customize main menu
sed 's/kickoff/kicker/g' -i desktop/theme/layout-templates/org.triskel.desktop.defaultPanel/contents/layout.js
sed '/^kicker/d' -i desktop/theme/layout-templates/org.triskel.desktop.defaultPanel/contents/layout.js
/bin/sed '/plasma.kicker/s|$|\
kicker.currentConfigGroup = ["Shortcuts"]\
kicker.writeConfig("global", "Alt+F1")\
kicker.currentConfigGroup = ["Configuration/General"]\
kicker.writeConfig("customButtonImage", "/usr/share/pixmaps/trisquel.svg")\
kicker.writeConfig("limitDepth", "true")\
kicker.writeConfig("showIconsRootLevel", "true")\
kicker.writeConfig("useCustomButtonImage", "true")|' -i desktop/theme/layout-templates/org.triskel.desktop.defaultPanel/contents/layout.js

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

# Custom favorite apps on main menu
sed -i '/FavoriteURLs/s|FavoriteURLs=preferred.*|FavoriteURLs=preferred://browser,icedove.desktop,libreoffice-startcenter.desktop,org.kde.kcalc.desktop,org.kde.dolphin.desktop,systemsettings.desktop,org.kde.konsole.desktop,trisquel-app-install.desktop|' desktop/etc/xdg/kickoffrc

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=Aramo
defaultFileSuffix=.jpg
defaultWidth=5120
defaultHeight=2880

[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=Noto Sans,10,-1,0,50,0,0,0,0,0,Regular
menuFont=Noto Sans,10,-1,0,50,0,0,0,0,0,Regular
smallestReadableFont=Noto Sans,8,-1,0,50,0,0,0,0,0,Regular
toolBarFont=Noto Sans,10,-1,0,50,0,0,0,0,0,Regular
XftAntialias=true
XftHintStyle=hintslight
XftSubPixel=rgb

[WM]
activeFont=Noto Sans,10,-1,5,75,0,0,0,0,0,Bold

[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
[kdeglobals][KDE]
widgetStyle=Breeze

[kdeglobals][General]
ColorScheme=Breeze

[kdeglobals][Icons]
Theme=breeze

[plasmarc][Theme]
name=breeze-dark

[Wallpaper]
Image=Aramo

[Desktop][org.kde.plasma.desktop]
Containment=org.kde.plasma.folder
EOF

cat << EOF > desktop/kf5-settings/ksmserverrc
[General]
loginMode=emptySession
EOF

cat << EOF > desktop/kf5-settings/ksplashrc
[KSplash]
Engine=none
Theme=none
EOF

cat << EOF > desktop/kf5-settings/kcminputrc
[Mouse]
cursorTheme=DMZ-White
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=Noto Sans 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="Noto Sans Regular"
}
widget_class "*" style "user-font"
gtk-font-name="Noto Sans 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/

# Use regular task manager instead of icon-only version
sed 's/plasma.icontasks/plasma.taskmanager/' -i desktop/theme/layout-templates/org.triskel.desktop.defaultPanel/contents/layout.js

changelog "Adapted for Triskel"

package

