/*           MOOD KLUDGES :-) ©1996 Alex Stansfield                */
/*                                                                 */
/* Add cool kludges into the message to describe your moods today  */
/*     _    _    ___  _  _                                         */
/*    /_\  ( )  (  _)( )( ) Fidonet:- 2:254/524.15  .------------. */
/*   /_X_\ ((__  ) _) >)(<  AmigaNet:- 39:139/1.15  | Team AMIGA | */
/*  (_) (_)(___)(___)(_)(_) AmNet:- 69:102/10.15    `------------' */
/*                                                PGP Key avalible */
/*        EMail:- Kurt@darkside.demon.co.uk                        */
/*                                                                 */

MSGORIGIN = 'Mood Kludges :-)'
TEMP = 'T:spot.kludge.temp1'
TEMP2 = 'T:spot.kludge.temp2'

address spot
options results

WinDi.trd_top=0
WinDi.trd_left=1
WinDi.trd_width=0
WinDi.trd_height=1
WinDi.trd_left2=0
WinDi.trd_top2=0
WinDi.trd_width2=0
WinDi.trd_height2=0
WinDi.trd_zoomed=0 
 
IF ~SHOW('LIBRARIES','tritonrexx.library') THEN DO
	IF ~EXISTS('LIBS:tritonrexx.library') THEN DO
		'requestnotify TITLE "Arrrrggggg" PROMPT "Hey!!! Mood Kludges needs TritonRexx.library"'
		exit
	END
	IF ~ADDLIB('tritonrexx.library',10,-30,0) THEN DO
		say "triton rexx unopened"
	      EXIT
	END
end

tags = 		windowid(1),
		windowtitle('Mood Kludges v1.0') WindowDimensions(WinDi),
                windowflags('TRWF_NOSIZEGADGET'),
                screentitle('Mood Kludges v1.0 ©1996 Alex Stansfield'),
                pubscreenname('SPOT'),
                'VertGroupA',
		'TROB_Button 0 TRAT_Text "'Add Kludge'" TRAT_ID "'add'"',
		'EndGroup',
		'EndProject',

app = tr_createapp('TRCA_Name Buttons')

if app~='00000000'x then do
	window=tr_openproject(app,tags)
	if window~='00000000'x then do
		do forever
			CALL READ
			do while tr_handlemsg(app,'event')
				if event.trm_class = 'TRMS_ACTION' then do
					CALL ADDKLUDGE
				end
				if event.trm_class='TRMS_CLOSEWINDOW' then CALL ENDS
				end
			end
		end 
	end
end

ADDKLUDGE:

'ismessages'
if rc = 5 then do
	'requestnotify TITLE "Mood Kludges :-)" "Use from message window only ..."'
	RETURN
	end

/* Save the msg */
'saveascii TO 'TEMP' OVERWRITE NOHEADER NOTEARLINE NOORIGIN NOKLUDGES' 

/* Get Header details */

/* Get To Name */
'getto'
TO_NAME = result
/* Get To Address */
'gettoaddress'
TO_ADD = result
/* Get the subject */
'getsubject'
TO_SUB = result

/* Ask what mood your in */
'RequestString TITLE "Mood Kludges" PROMPT "What is your mood today then?"'
If RC>0 Then RETURN
KLUDGE = '01'x'MOOD: 'result''

/* Read the text */
IF OPEN(temptext,temp,'Read') ~= 1 THEN
	DO
		requestdata = 'PROMPT "Could not open' tempfile1 'for reading.."'
		'requestnotify' requestdata
		SIGNAL exit
	END

Text = READCH(temptext,60000)
CALL CLOSE temptext

/* Add the Kludge */
	IF OPEN(tempkludge,temp2,'Write') ~= 1 THEN
		DO
			requestdata = 'PROMPT "Could not open' temp 'for writing.."'
			'requestnotify' requestdata
			SIGNAL exit
		END
	CALL WRITELN(tempkludge,kludge)
	CALL WRITECH(tempkludge,text) /* Add the text */
	CALL CLOSE tempkludge

/* Write message back */
'write  TO "'TO_NAME'" SUBJECT "'TO_SUB'" TOADDR "'TO_ADD'" ORIGIN "'MSGORIGIN'" FILE "'TEMP2'" NOSIG NOEDIT NOGUI'

/* Delete the temp files */

Address Command 'Delete >NIL:' TEMP2
Address Command 'Delete >NIL:' temp


/* Delete Original Message ? */
'requestresponse TITLE "Delete?" PROMPT "Delete Original Message?" GADGETS "_Good idea|_No Thanx" CENTER'

if rc=1 then do
'deletemessage NOREQ NODELKEEP'
end

/* Go back */
RETURN

READ: /* Read though the message looking for the kludge */
'ismessages' /* see if it is messages screen */
if result ~=5 then
	do
	'getareaname'
               newarea = result
	'getmessagenum'
	newnum = result
	if ((newnum~=oldnum) | (oldarea~=newarea)) & (newnum~=newarea) then do
		/* to see if the message number or area had changed - it's a different message */
		oldnum=newnum  /* reset the variables */
		oldarea=newarea
		'getfrom' 
		name = result /* Blokey who sent it */
		'getkludge MOOD' /* look for the MOOD: kludge */
		if rc=0 then /* if there is one then ... */
			do
			parse var result "MOOD:" feeling /* see what the feeling is */
			'requestnotify TITLE "Mood Kludge" PROMPT "'name' is'feeling'"' /* Print it up */ 
		end
	end
end
RETURN /* Go back */

ENDS: /* Quit the Script */
'requestresponse TITLE "Quit?" PROMPT "Are you Sure you want to Quit?" GADGETS "_Sure am|_No Way" CENTER'
if rc=1 then do
call tr_closeproject(window)
call tr_deleteapp(app)
exit(0)
end
RETURN
