#!/bin/sh

# This script sets up the live user's Gnome theme to something that
# resembles Microsoft Windows 8.

# Set claws-mail icon
CLAWSTHEMEDIR="$HOME/.claws-mail/themes/Windows8"
CLAWSCONFSECTION="\[Common\]"
CLAWSCONFLABEL="pixmap_theme_path"
# Create claws-mail theme
mkdir -p "$CLAWSTHEMEDIR"
cp /usr/share/icons/Windows8/apps/claws-mail.png "$CLAWSTHEMEDIR/claws_mail_icon.png"
echo > "$CLAWSTHEMEDIR/.claws_themeinfo" <<EOF 
Tails Windows 8
Tails Developers
EOF
# Apply claws-mail theme
# XXX: this will disable any user-defined theme stored in persistence
#      and the change will be permanent, even though it has no effect if the theme
#      doesn't exist, which should be the case if camouflage has not been enabled.
if [ -d "$HOME/.claws-mail" ]; then
    if grep "$CLAWSCONFLABEL" "$HOME/.claws-mail/clawsrc"; then
        sed -e "s;$CLAWSCONFLABEL=.*$;$CLAWSCONFLABEL=$CLAWSTHEMEDIR;" -i "$HOME/.claws-mail/clawsrc"
    else
        sed -e "/$CLAWSCONFSECTION/ a $CLAWSCONFLABEL=$CLAWSTHEMEDIR" -i "$HOME/.claws-mail/clawsrc"
    fi
fi

# Tor Browser
# Copy the file containing toolbars configurations
for browser in tor-browser unsafe-browser i2p-browser; do
    profile="${HOME}/.${browser}/profile.default"
    if [ -d "${profile}" ]; then
        cp /usr/share/tails/tor-browser-win8-theme/localstore.rdf \
            "${profile}"/localstore.rdf
        mkdir -p "${profile}"/preferences
        cp /usr/share/tails/tor-browser-win8-theme/theme.js \
            "${profile}"/preferences/0000camouflage.js
        mkdir -p "${profile}"/chrome
        cp /usr/share/tails/tor-browser-win8-theme/userChrome.css \
            "${profile}"/chrome/userChrome.css
    fi
done

# Remove Tails-specific desktop icons
rm --interactive=never -f ${HOME}/Desktop/*.desktop 2> /dev/null || true

# The part below is based on the XpGnome installation script, written
# by PhrankDaChicken, available from http://ubunut.online02.com/xpgnome

# Icon theme
gsettings set org.gnome.desktop.interface icon-theme Windows8

# Cursor theme
gsettings set org.gnome.desktop.interface cursor-theme Windows8

# GTK theme
gsettings set org.gnome.desktop.interface gtk-theme Windows8

# Metacity theme
gsettings set org.gnome.desktop.wm.preferences theme Windows8

# Toolbars - Icons Only
gsettings set org.gnome.desktop.interface toolbar-style icons

# Desktop Icons
gsettings set org.gnome.nautilus.desktop computer-icon-visible false
gsettings set org.gnome.nautilus.desktop home-icon-visible false
gsettings set org.gnome.nautilus.desktop network-icon-visible false
gsettings set org.gnome.nautilus.desktop trash-icon-visible true
gsettings set org.gnome.nautilus.desktop volumes-visible true
# FIXME: Localization needed below
gsettings set org.gnome.nautilus.desktop trash-icon-name "Recycle Bin"

# Background
gsettings set org.gnome.desktop.background picture-uri file:///usr/share/pixmaps/backgrounds/Windows8.jpg
gsettings set org.gnome.desktop.background picture-options stretched

# Only one workspace
gsettings set org.gnome.desktop.wm.preferences num-workspaces 1

# Panel
gsettings set org.gnome.gnome-panel.layout object-id-list "['menu-button', 'tor-browser-launcher', 'claws-launcher', 'pidgin-launcher', 'keepassx-launcher', 'gnome-terminal-launcher', 'window-list', 'notification-area', 'shutdown-helper', 'clock']"
gsettings set org.gnome.gnome-panel.layout toplevel-id-list "['bottom-panel']"
gsettings set org.gnome.desktop.lockdown disable-log-out true

# Window picker config
gsettings set org.gnome.window-picker-applet expand-task-list true

# Panel objects - there is no schema so we can't use gsettings
dconf write /org/gnome/gnome-panel/layout/objects/menu-button/object-iid '"PanelInternalFactory::MenuButton"'
dconf write /org/gnome/gnome-panel/layout/objects/menu-button/pack-index '0'
dconf write /org/gnome/gnome-panel/layout/objects/menu-button/pack-type '"start"'
dconf write /org/gnome/gnome-panel/layout/objects/menu-button/toplevel-id '"bottom-panel"'
dconf write /org/gnome/gnome-panel/layout/objects/window-list/object-iid '"WindowPickerFactory::WindowPicker"'
dconf write /org/gnome/gnome-panel/layout/objects/window-list/pack-index '1'
dconf write /org/gnome/gnome-panel/layout/objects/window-list/pack-type '"start"'
dconf write /org/gnome/gnome-panel/layout/objects/window-list/toplevel-id '"bottom-panel"'
dconf write /org/gnome/gnome-panel/layout/objects/notification-area/pack-index '2'
dconf write /org/gnome/gnome-panel/layout/objects/notification-area/pack-type '"end"'
dconf write /org/gnome/gnome-panel/layout/objects/notification-area/toplevel-id '"bottom-panel"'
dconf write /org/gnome/gnome-panel/layout/objects/shutdown-helper/pack-index '1'
dconf write /org/gnome/gnome-panel/layout/objects/shutdown-helper/pack-type '"end"'
dconf write /org/gnome/gnome-panel/layout/objects/shutdown-helper/toplevel-id '"bottom-panel"'
dconf write /org/gnome/gnome-panel/layout/objects/clock/pack-index '0'
dconf write /org/gnome/gnome-panel/layout/objects/clock/toplevel-id '"bottom-panel"'
dconf write /org/gnome/gnome-panel/layout/objects/clock/pack-type '"end"'

# Panel toplevels - there is no schema so we can't use gsettings.
# Note that the height must be set after adding the object to the
# panel since some of them, like window-picket-applet, seem to reset
# it.
dconf write /org/gnome/gnome-panel/layout/toplevels/bottom-panel/size '48'

# XXX Ugly restart hacks because this script runs too late
# Restart the panel
pkill gnome-panel
# Restart florence to make it use the right icon
pkill florence && florence &/usr/share/pixmaps/gpgApplet/48x48-grey/gpgApplet
# Mute and unmute volume to fix its icon
amixer set Master toggle
sleep 0.1
amixer set Master toggle


syntax highlighted by Code2HTML, v. 0.9.1