#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org

START=65
CFGFILE=/tmp/kissdx.conf

create_configfile() {
	local signature pidfile characterset \
		picturetargetwidth picturetargetheight picturemaxzoompercent \
		enablehiddenfilestext enablehiddenfilesminutes \
		listhiddenentries displaysequencenumbers
	local path_audio path_video path_picture
	local files_audio files_video files_picture files_iso
	local subtitles_filemapping
	local recentfiles_foldername recentfiles_max
	local kml_forwardurl

	echo '### AUTOGENERATED CONFIGURATION FILE - DO NOT EDIT ###' > $CFGFILE
	echo '### Edit /etc/config/kissdx to make changes to setup ###' >> $CFGFILE
	echo '' >> $CFGFILE

	config_get signature server signature
	config_get pidfile server pidfile
	config_get characterset server characterset
	config_get picturetargetwidth server picturetargetwidth
	config_get picturetargetheight server picturetargetheight
	config_get picturemaxzoompercent server picturemaxzoompercent
	config_get enablehiddenfilestext server enablehiddenfilestext
	config_get enablehiddenfilesminutes server enablehiddenfilesminutes
	config_get listhiddenentries server listhiddenentries
	config_get displaysequencenumbers server displaysequencenumbers

	config_get path_audio paths audio
	config_get path_video paths video
	config_get path_picture paths picture

	config_get files_audio files audio
	config_get files_video files video
	config_get files_picture files picture
	config_get files_iso files iso

	config_get subtitles_filemapping subtitles filemapping

	config_get recentfiles_foldername recentfiles foldername
	config_get recentfiles_max recentfiles max

	config_get kml_forwardurl kml forwardurl

	echo 'serversignature		= ' $signature >> $CFGFILE
	echo '#listenaddress		= 192.168.1.2' >> $CFGFILE
	echo '#networktimeoutinterval	= 3600' >> $CFGFILE
	echo '#adminserver_port	= 8003' >> $CFGFILE
	echo 'configautoload		= no' >> $CFGFILE
	echo '#dvdaccessmethod	= libdvdnav' >> $CFGFILE
	echo '#renamefiletypes	= ts:mpg,wav:mp3' >> $CFGFILE
	echo 'pidfilepath		= ' $pidfile >> $CFGFILE
	echo '#persistentstoragepath	= /tmp/kissdx' >> $CFGFILE
	echo '#server_character_set	= CP850' >> $CFGFILE
	echo '#client_character_set	= ISO-8859-1' >> $CFGFILE
	echo 'config_character_set	= ' $characterset >> $CFGFILE
	echo 'playlist_character_set	= ' $characterset >> $CFGFILE
	echo 'displaysequencenumbers	= ' $displaysequencenumbers >> $CFGFILE
	echo '' >> $CFGFILE
	echo '# 0 = caching disabled, -1 = no limit or amount of pictures in cache' >> $CFGFILE
	echo 'picturecachesize 	= 0' >> $CFGFILE
	echo '#picturecachetrimminginterval = 10' >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'audiopath		= ' $path_audio >> $CFGFILE
	echo 'videopath		= ' $path_video >>  $CFGFILE
	echo 'picturepath		= ' $path_picture >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'audiofileextensions	= ' $files_audio >> $CFGFILE
	echo 'videofileextensions	= ' $files_video >> $CFGFILE
	echo 'picturefileextensions	= ' $files_picture >> $CFGFILE
	echo 'isofileextensions	= ' $files_iso >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'listhiddenentries	= ' $listhiddenentries >> $CFGFILE
	echo 'enablehiddenfilestext	= ' $enablehiddenfilestext >> $CFGFILE
	echo 'enablehiddenfilesminutes = ' $enablehiddenfilesminutes >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'picturetargetwidth	= ' $picturetargetwidth >> $CFGFILE
	echo 'picturetargetheight	= ' $picturetargetheight >> $CFGFILE
	echo 'picturemaxzoompercent	= ' $picturemaxzoompercent >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'subtitlefilemapping	= ' $subtitles_filemapping >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'recentlyusedfoldername	= ' $recentfiles_foldername >> $CFGFILE
	echo 'max_recent_files	= ' $recentfiles_max >> $CFGFILE
	echo '' >> $CFGFILE
	echo 'kmlforwardurl		= ' $kml_forwardurl >> $CFGFILE
	echo '' >> $CFGFILE
	echo '#pretrigger		= /usr/bin/kissd-pretrigger' >> $CFGFILE
	echo '#posttrigger		= /usr/bin/kissd-posttrigger' >> $CFGFILE
	echo '#directorypretrigger	= /usr/bin/kissddirpretrigger' >> $CFGFILE
	echo '#directoryposttrigger	= /usr/bin/kisdddirposttrigger' >> $CFGFILE	
}

start () {
	config_load kissdx
	create_configfile
	/usr/bin/kissdx -c $CFGFILE -d
}

stop() {
	killall -9 kissdx
}
