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




#import "TranslationConfig.h"

@implementation TranslationConfig


// NAME: init
// PURPOSE: To initialise the data
// IMPORTS: nil
// EXPORTS: nil
// AUTHOR: Daniel Lee
// REMARKS: Used to ensure that the values are initialised properly.
// LAST MODIFIED: 05-04-2006

- (id) init
{
    NSString* data = [brailleGradeMenu stringValue];
	NSString* speakingText;

	// Fetch the cell which is currently being selected
	NSButtonCell* cCell = [translationDirectionMatrix selectedCell];
	// Fetch the title of the string
	NSString* selectedRadio = [cCell title];


	// Build up the language list and to set it to the interface so that
	// language switching is possible
	// Also, should be set to the current language of the system

    // This should actually go and look at the interface to get the correct values for language.
	language = @"English";


    // Initalise the translateToBraille variable

	if( [selectedRadio isEqualToString: @"Forward"] && !translateToBraile )
	{
	    speakingText = @"Direction of translation is now forward.";
		translateToBraile = YES;
	}
	// If the string is 'backward' and it is currently not translating backward
	else if( [selectedRadio isEqualToString: @"Backward"] && translateToBraile )
	{
	    speakingText = @"Direction of translation is now backward.";
		translateToBraile = NO;
	}
	else
	{
	    // How can there be nothing selected in the interface when the interface is
		// automatically set to a value?
	    translateToBraile = YES;
	}
	

    // Initialise the brailleGrade variable

	if( [data isEqualToString: @"0"] )
	{
		brailleGrade = 0;
	}
	else if( [data isEqualToString: @"1"] )
	{
        brailleGrade = 1;
	}
	else if( [data isEqualToString: @"2"] )
	{
		brailleGrade = 2;
	}
	else
	{
	    // How can there be nothing selected in the interface when the interface is
		// automatically set to a value?
	}


	//Call BrailleTranslator and create the table
	
	return self;
}


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

- (BOOL) translateToBraile
{
    return translateToBraile;
}


// NAME: brailleGrade
// PURPOSE: To export the data brailleGrade
// IMPORTS: nil
// EXPORTS: int brailleGrade
// AUTHOR: Daniel Lee
// 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
// AUTHOR: Daniel Lee
// 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
// AUTHOR: Daniel Lee
// REMARKS: None
// LAST MODIFIED: 06-04-2006

- (IBAction) setBrailleGrade: (id) sender
{
    NSString* data = [brailleGradeMenu stringValue];
	NSString* speakingText;
	
    // Tests the string for a certain value and also if the grade it is going
	// into is also not the one which is already set
	
	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
// AUTHOR: Daniel Lee
// 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
// AUTHOR: Daniel Lee
// 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, but for now is not required
// LAST MODIFIED: 05-04-2006 

- (IBAction) setTranslationDirection: (id) sender
{
    NSButtonCell* cCell;
	
	// Fetch the cell which is currently being selected
	cCell = [translationDirectionMatrix selectedCell];

	// Fetch the title of the string
	NSString* selectedRadio = [cCell title];
	NSString* speakingText;
	
	// If the string is 'forward' and it is currently not translating forward
	if( [selectedRadio isEqualToString: @"Forward"] && !translateToBraile )
	{
	    speakingText = @"Direction of translation is now forward.";
		translateToBraile = YES;
	}
	// If the string is 'backward' and it is currently not translating backward
	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.
		// Set speakingText to nothing so that the speechObject will not say anything

		speakingText = @"";
	    NSLog( @"Translation Direction unchanged" );
	}
	
    [speechObject speak:speakingText];
}


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

@end
