#!/bin/sh
#Knocked together by smokey01 on 15 Mar 2015.
#Complicated by CatDude on 16 Mar 2015.

counter () {
	count=`wc -l < /tmp/slack-desc2`
	echo $count
	while [ $count -le 5 ]
	do
	# Add a line until we reach a count of 6
	  echo "$NAME:" >> /tmp/slack-desc2
	# Add one to the count number
	  count=`expr $count + 1`
	done	
}
export -f counter

createfile () {
	echo $NAME: "$NAME $VERSION ($SHORTDESC)" > slack-desc
	echo $NAME: >> slack-desc
	
	echo "$LONGDESC1" > /tmp/slack-desc	
	fold -w 70 -s /tmp/slack-desc | head -n 6 | sed "s/^/$NAME: /" > /tmp/slack-desc2
	counter		
	
	cat /tmp/slack-desc2 >> slack-desc
	echo $NAME: >> slack-desc
	echo $NAME: "$HOMEPAGE" >> slack-desc
	echo $NAME: >> slack-desc	
}
export -f createfile

[ -z $GTKDIALOG ] && GTKDIALOG=gtkdialog

MAIN_DIALOG='
<window resizable="false" window-position="1" width-request="600" title="Slackware Description Creator - 2.0">
	<vbox>
	
	<menubar>
			<menu label="_File" use-underline="true">
				<menuitem stock-id="gtk-about">
				<action>Xdialog --title "About" --msgbox "Slackware Description Creator\nWritten by\nSmokey01 and CatDude\non the\n17 March 2015" 10 40</action>
				</menuitem>
				<menuitem stock-id="gtk-quit" accel-key="0x51" accel-mods="4">
					<action>exit:Quit</action>
				</menuitem>
			</menu>
	</menubar>
	<hbox>
		<text><label>"Name of package:   "</label></text>
		<entry tooltip-text="Enter the name of your package" max-length="70">
			<default>geany</default>
			<variable>NAME</variable>
		</entry>
	</hbox>
	
	<hbox>
		<text><label>"Version:                    "</label></text>
		<entry tooltip-text="Enter the version number EG: 1.24.1" max-length="70">
			<default>1.24.1</default>
			<variable>VERSION</variable>
		</entry>
	</hbox>
	<hbox>
		<text><label>"Short Description:    "</label></text>
		<entry tooltip-text="Type a short description. Brackets will surround the text in the slack-desc file." max-length="70">
			<default>Text Editor</default>
			<variable>SHORTDESC</variable>
		</entry>
	</hbox>
	<hbox>
		<text><label>Long Description:     </label></text>
		<edit tooltip-text="Restrict the amount of text to fit in this box otherwise your text may be truncated. Text size is dependent on your theme."wrap-mode="2">
		<variable>LONGDESC1</variable>
		</edit>
	</hbox>
	<hbox>
		<text><label>"Homepage:              "</label></text>
		<entry tooltip-text="Enter the software web address like: http://www.geany.org" max-length="70">
		<default>http://www.geany.org/</default>
		<variable>HOMEPAGE</variable>
		</entry>
	</hbox>
	<hbox>
		<button tooltip-text="View and/or edit the slack-desc file in Geany">
		<input file stock="gtk-edit"></input>
		<label>Edit/View</label>
		<action>geany slack-desc</action>
		</button>
		<button tooltip-text="Create a slack-desc file in the current directory">
		<input file stock="gtk-ok"></input>
        <label>Create</label>
        <action>createfile</action>
        </button>	
		<button tooltip-text="Quits the application">
		<input file stock="gtk-quit"></input>
		<label>Quit</label>
		<action type="exit">exit</action>
		</button>
	</hbox>
	
	</vbox>
</window>
'
export MAIN_DIALOG

case $1 in
	-d | --dump) echo "$MAIN_DIALOG" ;;
	*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac

