Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##main.m
- #import <Foundation/Foundation.h>
- #import <CoreFoundation/CoreFoundation.h>
- #import "AppController.h"
- int main(int argc, char *argv[])
- {
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- AppController *app = [[AppController alloc] init];
- [app startRequest];
- NSCondition *condition = [[NSCondition alloc] init];
- [condition lock];
- while(app.working)
- {
- [condition wait];
- }
- [condition unlock];
- NSLog(@"Quitting");
- [app release];
- [pool drain];
- [condition release];
- return 0;
- }
- ##AppController.m
- #import "AppController.h"
- @implementation AppController
- @synthesize working;
- - (id)init
- {
- if(self = [super init])
- {
- data = [ [PreferencesData alloc] init];
- import = [ [ITUImport alloc] init];
- working = YES;
- }
- return self;
- }
- - (id)dealloc
- {
- [data release];
- [import release];
- }
- - (void)startRequest
- {
- NSLog(@"Starting request from AppController");
- import.delegate = self;
- import.username = [data getData:@"username"];
- import.password = [data getData:@"password"];
- import.lastId = [[data getData:@"lastid"] unsignedIntValue];
- import.uploadProgressDelegate = nil;
- //[NSThread detachNewThreadSelector:@selector(startRequest) toTarget:import withObject:nil];
- [import startRequest];
- }
- - (void)setStatus:(NSNumber*)status
- {
- NSLog(@"Set status: %d", [status intValue]);
- switch ([status intValue]) {
- case kImportComplete:
- working = NO;
- NSLog(@"Completed. Message: %@", import.returnData);
- break;
- case kImportError:
- working = NO;
- NSLog(@"Error. Message: %@", import.returnData);
- break;
- case kImportStatusMessagesNoNewElements:
- NSLog(@"There aren't new elements to be imported");
- break;
- case kImportStatusStarting:
- NSLog(@"Starting");
- break;
- case kImportStatusLoadingAddressBook:
- NSLog(@"Loading Address Book...");
- break;
- case kImportStatusReceivedAddressBook:
- NSLog(@"Parsing Address Book...");
- break;
- case kImportStatusPreparingData:
- NSLog(@"Preparing Data...");
- break;
- case kImportStatusUploading:
- NSLog(@"Uploading...");
- break;
- default:
- NSLog(@"Working...");
- break;
- }
- }
- @end
Add Comment
Please, Sign In to add comment