#!/bin/sh
#
#    Copyright (C) 2016-2020  Ruben Rodriguez <ruben@trisquel.info>
#    Copyright (C)      2017  Mason Hock <mason@masonhock.com>
#
#    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=10

. ./config

# Remove the arrow in the main menu button
sed 's/"tooltip", tooltip,/"tooltip", "Trisquel",/; s/"has-arrow", TRUE,/"has-arrow", FALSE,/' -i mate-panel/panel-menu-button.c

# Custom layout
cat << EOF > data/panel-default-layout.layout
[Toplevel top]
orientation=bottom
expand=true
size=44

[Object menu]
locked=true
position=0
panel-right-stick=false
toplevel-id=top
object-type=menu

[Object files]
locked=true
position=20
launcher-location=caja.desktop
panel-right-stick=false
toplevel-id=top
object-type=launcher
menu-path=applications:/

[Object browser]
locked=true
position=30
launcher-location=/usr/share/applications/browser.desktop
panel-right-stick=false
toplevel-id=top
object-type=launcher
menu-path=applications:/

[Object windowlistapplet]
locked=true
position=40
panel-right-stick=false
toplevel-id=top
applet-iid=WnckletFactory::WindowListApplet
object-type=applet

[Object indicatorappletcomplete]
locked=true
position=20
panel-right-stick=true
toplevel-id=top
applet-iid=IndicatorAppletCompleteFactory::IndicatorAppletComplete
object-type=applet

[Object showdesktopapplet]
locked=true
position=0
panel-right-stick=true
toplevel-id=top
applet-iid=WnckletFactory::ShowDesktopApplet
object-type=applet
EOF

cp data/panel-default-layout.layout data/ubuntu.layout
mv data/ubuntu.layout data/trisquel.layout
sed 's/ubuntu/trisquel/' -i data/Makefile.am

cat << EOF > debian/mate-panel-layout-update.desktop
[Desktop Entry]
Name=Update MATE panel layout
Comment=Resets the MATE panel layout after a Trisquel release upgrade
Exec=/usr/share/mate-panel/layout-reset
Terminal=false
Type=Application
NoDisplay=true
OnlyShowIn=MATE;
Keywords=MATE;panel;
EOF

cat << EOF > debian/layout-reset
#!/bin/sh

RELEASE=\$(lsb_release -rs)

if [ ! -f \$HOME/.config/mate/panel2.d/trisquel\$RELEASE ] || \
     ! grep -q $VERSION \$HOME/.config/mate/panel2.d/trisquel\$RELEASE; then
  if dconf dump /org/mate/panel/ |grep -q Clock; then
    gsettings reset-recursively org.mate.panel
    sleep 1
  fi
  dconf write /org/mate/panel/toplevels/top/background/color "'rgba(0,0,0,0.5)'"
  [ -d \$HOME/.config/mate/panel2.d ] || mkdir -p \$HOME/.config/mate/panel2.d
  echo $VERSION > \$HOME/.config/mate/panel2.d/trisquel\$RELEASE
fi
EOF
chmod 755 debian/layout-reset

cat << EOF >> debian/mate-panel.install
debian/mate-panel-layout-update.desktop etc/xdg/autostart
debian/layout-reset usr/share/mate-panel
EOF

changelog "Changed default layout"

package