#!/bin/bash
##################################################################################
## Bashish, a console theme engine
## Copyright (C) 2010 Thomas Eriksson
##
## 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 Street, Fifth Floor, Boston, MA  02110-1301, USA.
##################################################################################
function _bashish_konsole_init
{
	return 0
	## kill bashish_dcop if running
	BASHISH_DCOP="$(cat ${HOME}/.bashish/system/konsole/gschemadir/$BASHISH_GSCHEMA/pid 2>/dev/null)"
	#ps "$BASHISH_DCOP" >/dev/null && case "`ps $BASHISH_DCOP 2>/dev/null`" in
	#*bashish*)
	#	kill "$BASHISH_DCOP"
	#esac
	
	## create gschema dir with two fifos
	mkdir -p "$HOME"/.bashish/tmp/${TTY#*/}/
	for FIFO in "$HOME"/.bashish/tmp/${TTY#*/}/reparse "$HOME"/.bashish/system/konsole/gschemadir/$BASHISH_GSCHEMA/title
	do
		test -p $FIFO || mkfifo $FIFO
	done

	## get the dcop session number
	IFS=,\)
	for BASHISH_SESSION in $KONSOLE_DCOP_SESSION;do :;done
	#tail -f $HOME/.bashish/tmp/${TTY#*/}/reparse|dcop --pipe konsole-$KONSOLE_PROCESS session-1 setSchema %1 &
	#tail -f $HOME/.bashish/tmp/${TTY#*/}/title|dcop --pipe konsole-$KONSOLE_PROCESS $BASHISH_SESSION renameSession %1 &

	## fork the bashish_dcop handler into the background
	"$BASHISHDIR"/bin/fork "$BASHISHDIR"/bin/bashish_dcop $BASHISH_GSCHEMA $PPID $BASHISH_SESSION

	### initialize konsole profile
	mkdir -p "$HOME"/.kde/share/apps/konsole/
	cp "$BASHISHDIR"/system/konsole/bashish.schema "$HOME"/.kde/share/apps/konsole/bashish$BASHISH_GSCHEMA.schema

	## the konsole_init function is only needed once
	## thus an empty placeholder can replace it
	function _bashish_konsole_init { :;}
}
