Wednesday, November 11, 2009

wbar theme manager




1. Set DEFAULT_THEME name in script which is a link to an available theme
2. Set TEMPLATE theme in script which should be a working set of icons correspondent with your .wbar configuration file
3. /usr/share/wbar/iconpack directory should be writable by you or you have to run this script as root (sudo)
4. To add new theme select NEW_THEME item at the top of the list in zenity wndow
5. To reset the themes after changing .wbar select RESET_THEME item of the list window



#!/bin/bash
# Copyright (C) 2008 Nayanajit Mahendra Laxaman mail: nmlaxaman@gmail.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.

WBAR_THEME_ROOT="/usr/share/wbar/iconpack"
DEFAULT_THEME="dreamdock"
TEMPLATE="$WBAR_THEME_ROOT/dream"
THEME_ROOT="/usr/share/icons"

ICONS=$( cat ~/.wbar | grep i: | awk '{printf $2" "}' | uniq )
N_ICONS=$(cat ~/.wbar | grep i: |wc -l)
EPOCH=$((100/$N_ICONS))
PROGRESS=0
DEFAULE="gnome"

THEME=''

function select_theme(){
THEMES=$(ls $WBAR_THEME_ROOT | grep -v -e $DEFAULT_THEME -e $TEMPLATE | awk '{printf " FALSE "$1}')
NEW_THEME=$(zenity --width=300 --height=270 --list --radiolist --column "Select" --column "Theme" TRUE NEW_THEME FALSE RESET_THEMES `echo $THEMES` );
echo $NEW_THEME;
}

function new_theme_select(){
cd $THEME_ROOT
NEW_THEME=$( zenity --file-selection --directory $THEME_ROOT --title="Choose an icon theme from /usr/share/icons/" )
NEW_THEME=$( basename $NEW_THEME )
if [ ! -z "$NEW_THEME" ] 2> /dev/null
then

if [[ -e $THEME_ROOT/$NEW_THEME ]]
then
echo $NEW_THEME
else
zenity --warning --text="Theme not found "
exit 1;
fi
else
zenity --warning --text="No theme given "
exit 1;
fi
}


function generate_theme(){
mkdir $WBAR_THEME_ROOT/$THEME
cd $WBAR_THEME_ROOT/$THEME
for ICON in $ICONS
do

PROGRESS=$(($PROGRESS+$EPOCH))
echo $PROGRESS

ICON=$( basename $ICON )

FILE=$( find $THEME_ROOT/$THEME -iname $ICON | grep -i 'scalable' | head -1)

if [[ $FILE == '' ]]
then
FILE=$( find $THEME_ROOT/$DEFAULT -iname $ICON | grep -i 'scalable' | head -1)
fi

if [[ $FILE == '' ]]
then
FILE=$TEMPLATE/$ICON
fi
cp -L $FILE $ICON
done
}

THEME=$( select_theme )

if [[ $THEME == 'RESET_THEMES' ]]
then
N_THEMES=$( ls $WBAR_THEME_ROOT | grep -v -e $DEFAULT_THEME -e $TEMPLATE | wc -l)
EPOCH=$((100/$N_THEMES))
PROGRESS=0

for theme in $( ls $WBAR_THEME_ROOT | grep -v -e $DEFAULT_THEME -e $TEMPLATE )
do
PROGRESS=$(($PROGRESS+$EPOCH))
echo $PROGRESS

THEME=$theme
generate_theme
done | zenity --progress --title="Resetting wbar icon themes" --text="Be patient\nIt will take some time to reset icon themes..." --auto-close

exit 1;
fi

if [[ $THEME == 'NEW_THEME' ]]
then
THEME=$( new_theme_select )
if [[ $? == 0 ]]
then
generate_theme | zenity --progress --title="Generating wbar icon theme" --text="Be patient\nIt will take some time to generate icon theme..." --auto-close
fi
exit 1;
fi

if [[ $THEME == '' ]]
then
zenity --warning --text="Theme not changed"
exit 1;
else
cd $WBAR_THEME_ROOT
rm $DEFAULT_THEME
ln -s $THEME $DEFAULT_THEME
fi

No comments:

Post a Comment