2010-01-06 18:11:16 -06:00
|
|
|
//
|
|
|
|
// MGMContactWindow.m
|
|
|
|
// GeckoReporter
|
|
|
|
//
|
|
|
|
// Created by Mr. Gecko on 1/3/10.
|
|
|
|
// Copyright 2010 by Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MGMContactWindow.h"
|
|
|
|
#import "MGMReporter.h"
|
|
|
|
#import "MGMSender.h"
|
|
|
|
#import "MGMLocalized.h"
|
2010-06-03 19:41:31 -05:00
|
|
|
#import "MGMSystemInfo.h"
|
2010-01-06 18:11:16 -06:00
|
|
|
#import "MGMLog.h"
|
|
|
|
|
|
|
|
@implementation MGMContactWindow
|
2010-01-12 08:05:09 -06:00
|
|
|
+ (id)sharedContactWindow {
|
2010-01-06 18:11:16 -06:00
|
|
|
return [[self alloc] init];
|
|
|
|
}
|
|
|
|
- (id)init {
|
|
|
|
if (self = [super init]) {
|
|
|
|
if (![NSBundle loadNibNamed:@"MGMContactWindow" owner:self]) {
|
|
|
|
[self release];
|
|
|
|
self = nil;
|
|
|
|
} else {
|
|
|
|
NSUserDefaults *userDefautls = [NSUserDefaults standardUserDefaults];
|
|
|
|
if ([userDefautls objectForKey:MGMGRUserEmail])
|
|
|
|
[userEmailField setStringValue:[userDefautls objectForKey:MGMGRUserEmail]];
|
|
|
|
if ([userDefautls objectForKey:MGMGRUserName])
|
|
|
|
[userNameField setStringValue:[userDefautls objectForKey:MGMGRUserName]];
|
|
|
|
|
|
|
|
[mainWindow makeKeyAndOrderFront:self];
|
2010-05-05 17:09:21 -05:00
|
|
|
MGMSystemInfo *sysInfo = [[MGMSystemInfo new] autorelease];
|
|
|
|
if ([sysInfo isUIElement])
|
|
|
|
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
2010-01-06 18:11:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
MGMLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
if (mailSender!=nil)
|
|
|
|
[mailSender release];
|
|
|
|
if (mainWindow!=nil)
|
|
|
|
[mainWindow release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setButtonsEnabled:(BOOL)flag {
|
|
|
|
[sendButton setEnabled:flag];
|
|
|
|
[cancelButton setEnabled:flag];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close {
|
|
|
|
[mainWindow orderOut:self];
|
|
|
|
[self release];
|
|
|
|
self = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)send:(id)sender {
|
|
|
|
if ([[userEmailField stringValue] isEqualToString:@""] || [[userNameField stringValue] isEqualToString:@""]) {
|
|
|
|
NSAlert *theAlert = [[NSAlert new] autorelease];
|
|
|
|
[theAlert addButtonWithTitle:MGMLocalized(@"Ok", nil)];
|
|
|
|
[theAlert setMessageText:MGMLocalized(@"Fields not filled.", nil)];
|
|
|
|
[theAlert setInformativeText:MGMLocalized(@"Please be sure all fields are filled as all fields are required.", nil)];
|
|
|
|
[theAlert setAlertStyle:2];
|
|
|
|
[theAlert runModal];
|
|
|
|
} else {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:[userEmailField stringValue] forKey:MGMGRUserEmail];
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:[userNameField stringValue] forKey:MGMGRUserName];
|
|
|
|
if (mailSender==nil) {
|
2010-01-12 08:05:09 -06:00
|
|
|
mailSender = [MGMSender new];
|
2010-01-06 18:11:16 -06:00
|
|
|
[mailSender sendMessage:[[messageView textStorage] string] subject:[subjectPopUp titleOfSelectedItem] delegate:self];
|
|
|
|
}
|
|
|
|
[sendButton setTitle:MGMLocalized(@"Sending...", nil)];
|
|
|
|
[self setButtonsEnabled:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- (IBAction)cancel:(id)sender {
|
|
|
|
[self close];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendError:(NSError *)error {
|
|
|
|
NSAlert *theAlert = [[NSAlert new] autorelease];
|
|
|
|
[theAlert addButtonWithTitle:MGMLocalized(@"Ok", nil)];
|
|
|
|
[theAlert setMessageText:MGMLocalized(@"Error could not send message.", nil)];
|
|
|
|
[theAlert setInformativeText:[error localizedDescription]];
|
|
|
|
[theAlert setAlertStyle:2];
|
|
|
|
[theAlert runModal];
|
|
|
|
[self setButtonsEnabled:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendFinished:(NSString *)received {
|
|
|
|
MGMLog(@"%@", received);
|
|
|
|
[self close];
|
|
|
|
}
|
|
|
|
@end
|