//
//  aPropos.m
//  Agence
//
//  Created by Olivier Savard on 11-02-08.
//  Copyright 2011 OSInfo Informatique. All rights reserved.
//

#import "aPropos.h"
#import "AgenceAppDelegate.h"



@implementation aPropos
@synthesize label;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    self.title = @"À propos..";
	self.label.text = @"À propos de SC Agence... SC pour Savard-Charbonneau sont deux jeunes et talentueux concepteurs qui ne connaissent pas encore grand chose mais qui n'attendent rien pour créer des applications qui se démarquent des autres en étant proches de l'utilisateur et en répondant aux besoins de ce dernier.  Utiliser une application SC c'est une expérience en soit!  Alors, bonne expérience!";
	[super viewDidLoad];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
-(void) showEmailModalView:(NSArray *)recipients subject:(NSString *)subject body:(NSString *)body {
	
	MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
	picker.mailComposeDelegate = self; // &lt;- very important step if you want feedbacks on what the user did with your email sheet
	
	[picker setSubject:subject];
	NSArray *array = [[NSArray alloc] initWithArray:recipients];
	
	[array release];
	[picker setToRecipients:recipients];
	// Fill out the email body text
	[picker setMessageBody:body isHTML:YES]; // depends. Mostly YES, unless you want to send it as plain text (boring)
	
	picker.navigationBar.barStyle = UIBarStyleBlack; // choose your style, unfortunately, Translucent colors behave quirky.
	
	[self presentModalViewController:picker animated:YES];
	[picker release];
	
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{ 
	// Notifies users about errors associated with the interface
	switch (result)
	{
		case MFMailComposeResultCancelled:
			break;
		case MFMailComposeResultSaved:
			break;
		case MFMailComposeResultSent:
			break;
		case MFMailComposeResultFailed:
			break;
			
		default:
		{
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Sending Failed - Unknown Error :-("
														   delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
			[alert show];
			[alert release];
		}
			
			break;
	}
	[self dismissModalViewControllerAnimated:YES];
}


-(IBAction)showActionSheet:(id)sender {
	AgenceAppDelegate * appDelegate = (AgenceAppDelegate *)[[UIApplication sharedApplication] delegate];
	UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Nous rejoindre" delegate:self cancelButtonTitle:@"Annuler" 
											  destructiveButtonTitle:nil otherButtonTitles:@"Support technique", @"Commentaires", nil];
	popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
	[popupQuery showFromTabBar:appDelegate.tabBarController.tabBar];
	[popupQuery release];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
	NSString *recipient1 = @"osinfo@videotron.ca";
	NSString *recipient2 = @"marc@integrales.ca";
	if (buttonIndex == 0) //Support technique
	{
		NSArray *recipients = [[NSArray alloc] initWithObjects:recipient1, nil];
		NSString *subject = @"Problème avec l'application SC Agence";
		NSString *body = @"Bonjour, alors que j'utilisais votre application Agence j'ai rencontré ce problème:";
		[self showEmailModalView:recipients subject:subject body:body];
		[recipients release];
	} 
	else if (buttonIndex == 1) //Commentaires
	{
		NSArray *recipients = [[NSArray alloc] initWithObjects:recipient1,recipient2, nil];
		NSString *subject = @"Commentaires à propos de l'application SC Agence";
		NSString *body = @"Bonjour, alors que j'utilisais votre application Agence j'ai souhaité partager avec vous quelques commentaires.";
		[self showEmailModalView:recipients subject:subject body:body];
		[recipients release];

	} 
	
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
