// FILE:      TranslationConfig.m
// AUTHOR:    Daniel Lee
// PURPOSE:   To serve as a configuration object for the BrailleConverter
// REFERENCE: None. 
// COMMENTS:  
// REQUIRES:  TranslationConfig.h
// Last Mod:  23-03-2006




#import "TranslationConfig.h"

@implementation TranslationConfig




// NAME: init
// PURPOSE: To initialise the data
// IMPORTS: nil
// EXPORTS: nil
// REMARKS: Used to ensure that the values are initialised properly.
// LAST MODIFIED: 23-03-2006

- (id) init
{

    // This should actually go and look at the interface to get the correct values.
	language = @"English";
	translateToBraile = YES;
	brailleGrade = 0;
	
	return self;
}


// NAME: translateToBraille
// PURPOSE: To export the data translateToBraile
// IMPORTS: nil
// EXPORTS: BOOL translateToBraile
// REMARKS: 
// LAST MODIFIED: 23-03-2006 

- (BOOL) translateToBraile
{
    return translateToBraile;
}


// NAME: brailleGrade
// PURPOSE: To export the data brailleGrade
// IMPORTS: nil
// EXPORTS: int brailleGrade
// REMARKS: 
// LAST MODIFIED: 23-03-2006

- (int) brailleGrade
{
    return brailleGrade;
}


// NAME: language
// PURPOSE: To export the data language
// IMPORTS: nil
// EXPORTS: A copy of NSString language
// REMARKS: 
// LAST MODIFIED: 23-03-2006

- (NSString*) language
{
    NSString* returnLanguage;
	[returnLanguage initWithString: language];
    return returnLanguage;
}


// NAME: setBrailleGrade
// PURPOSE: To get the new grade value and set it if it has changed.
// IMPORTS: nil
// EXPORTS: nil
// REMARKS: None
// LAST MODIFIED: 21-03-2006

- (IBAction) setBrailleGrade: (id) sender
{
    NSString* data = [brailleGradeMenu stringValue];
	NSString* speakingText;
		
	if( [data isEqualToString: @"0"] && ( 0 == brailleGrade ) )
	{
	    speakingText = @"Grade 0 braille translation chosen.";
		brailleGrade = 0;
	}
	else if( [data isEqualToString: @"1"] && ( 1 == brailleGrade ) )
	{
	    speakingText = @"Grade 1 braille translation chosen.";
		brailleGrade = 1;
	}
	else if( [data isEqualToString: @"2"] && ( 2 == brailleGrade ) )
	{
        speakingText = @"Grade 2 braille translation chosen.";
		brailleGrade = 2;
	}
	else
	{
	    // If nothing matches, most likely scenario is that something was clicked
	    // but the braille grade was already chosen.
		
		speakingText = @"";
	    NSLog( @"Braille grade unchanged" );
	}

    [speechObject speak:speakingText];
}


// NAME: setLanguage
// PURPOSE: To set the new tables for translating to and from the new language
// IMPORTS: nil
// EXPORTS: nil
// REMARKS: 
// LAST MODIFIED: 21-03-2006

- (IBAction) setLanguage: (id) sender;
{
    // Get data from langaugeMenu
    // Do some testing and then using BrailleGrade to do the switching.
}


// NAME: setTranslationDirection
// PURPOSE: To set the new translation direction if it hasn't changed
// IMPORTS: nil
// EXPORTS: nil
// REMARKS: The reason why literals were used here was because the words were going to be the constants.
//          And if the words change on the interface, it will be easy to change it here since the
//          program is still quite small. This may change later on.
// LAST MODIFIED: 23-03-2006 

- (IBAction) setTranslationDirection: (id) sender
{
    NSButtonCell* cCell;
	cCell = [translationDirectionMatrix selectedCell];
	NSString* selectedRadio = [cCell title];
	NSString* speakingText;
	
	if( [selectedRadio isEqualToString: @"Forward"] && !translateToBraile )
	{
	    speakingText = @"Direction of translation is now forward.";
		translateToBraile = YES;
	}
	else if( [selectedRadio isEqualToString: @"Backward"] && translateToBraile )
	{
	    speakingText = @"Direction of translation is now backward.";
		translateToBraile = NO;
	}
	else
	{
	    // If nothing matches, most likely scenario is that something was clicked
	    // but the direction is the same at the new one.
		
		speakingText = @"";
	    NSLog( @"Translation Direction unchanged" );
	}
	
    [speechObject speak:speakingText];
}

- (void)delloc
{
    [speechObject release];
	[language release];
}

@end
