aboutsummaryrefslogtreecommitdiffhomepage
path: root/example/mac/macExample/macExample/AppDelegate.m
diff options
context:
space:
mode:
Diffstat (limited to 'example/mac/macExample/macExample/AppDelegate.m')
-rw-r--r--example/mac/macExample/macExample/AppDelegate.m114
1 files changed, 110 insertions, 4 deletions
diff --git a/example/mac/macExample/macExample/AppDelegate.m b/example/mac/macExample/macExample/AppDelegate.m
index 8f89fe10..12c744e8 100644
--- a/example/mac/macExample/macExample/AppDelegate.m
+++ b/example/mac/macExample/macExample/AppDelegate.m
@@ -8,16 +8,122 @@
#import "AppDelegate.h"
-@implementation AppDelegate
+#import <MailCore/MailCore.h>
-- (void)dealloc
+#import "MCTMsgListViewController.h"
+
+@interface AppDelegate () <NSTextFieldDelegate>
+
+@end
+
+@implementation AppDelegate {
+ MCOIMAPSession * _session;
+ MCOIMAPOperation * _checkOp;
+}
+
+- (void) dealloc
{
[super dealloc];
}
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+- (void) awakeFromNib
+{
+ [_loginTextField setDelegate:self];
+ [_passwordTextField setDelegate:self];
+}
+
+- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+ [self _updateState];
+
+ NSString * login = [[NSUserDefaults standardUserDefaults] stringForKey:@"Login"];
+ NSString * password = [[NSUserDefaults standardUserDefaults] stringForKey:@"Password"];
+
+ if (([login length] == 0) || ([password length] == 0)) {
+ [_accountWindow makeKeyAndOrderFront:nil];
+ }
+ else {
+ [_loginTextField setStringValue:login];
+ [_passwordTextField setStringValue:password];
+ }
+}
+
+- (void) accountLogin:(id)sender
+{
+ NSString * login = [_loginTextField stringValue];
+ NSString * password = [_passwordTextField stringValue];
+
+ NSLog(@"try login");
+ _session = [[MCOIMAPSession alloc] init];
+ [_session setHostname:@"imap.gmail.com"];
+ [_session setPort:993];
+ [_session setUsername:login];
+ [_session setPassword:password];
+ [_session setConnectionType:MCOConnectionTypeTLS];
+ _checkOp = [[_session checkAccountOperation] retain];
+ NSLog(@"start op");
+ [_checkOp start:^(NSError * error) {
+ [_accountWindow orderOut:nil];
+
+ NSString * login = [_loginTextField stringValue];
+ NSString * password = [_passwordTextField stringValue];
+ [[NSUserDefaults standardUserDefaults] setObject:login forKey:@"Login"];
+ [[NSUserDefaults standardUserDefaults] setObject:password forKey:@"Password"];
+
+ [_checkOp release];
+ _checkOp = nil;
+ [_session release];
+ _session = nil;
+
+ [self _updateState];
+
+ NSLog(@"op done %@", error);
+
+ [_msgListViewController connect];
+ }];
+
+ [self _updateState];
+}
+
+- (void) accountCancel:(id)sender
+{
+ [_checkOp cancel];
+ [_checkOp release];
+ _checkOp = nil;
+ [_session release];
+ _session = nil;
+
+ [self _updateState];
+}
+
+- (void) _updateState
+{
+ if (_checkOp == nil) {
+ [_loginTextField setEnabled:YES];
+ [_passwordTextField setEnabled:YES];
+ NSString * login = [_loginTextField stringValue];
+ NSString * password = [_passwordTextField stringValue];
+ if (([login length] > 0) && ([password length] > 0)) {
+ [_loginButton setEnabled:YES];
+ }
+ else {
+ [_loginButton setEnabled:NO];
+ }
+ [_cancelButton setEnabled:NO];
+ [_progressView stopAnimation:nil];
+ }
+ else {
+ [_loginTextField setEnabled:NO];
+ [_passwordTextField setEnabled:NO];
+ [_loginButton setEnabled:NO];
+ [_cancelButton setEnabled:YES];
+ [_progressView startAnimation:nil];
+ }
+}
+
+- (void) controlTextDidChange:(NSNotification *)aNotification
{
- // Insert code here to initialize your application
+ [self _updateState];
}
@end