Guest User

Untitled

a guest
Jun 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. ##main.m
  2. #import <Foundation/Foundation.h>
  3. #import <CoreFoundation/CoreFoundation.h>
  4.  
  5. #import "AppController.h"
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  10.  
  11. AppController *app = [[AppController alloc] init];
  12.  
  13. [app startRequest];
  14.  
  15. NSCondition *condition = [[NSCondition alloc] init];
  16.  
  17. [condition lock];
  18. while(app.working)
  19. {
  20. [condition wait];
  21. }
  22. [condition unlock];
  23.  
  24. NSLog(@"Quitting");
  25.  
  26. [app release];
  27. [pool drain];
  28. [condition release];
  29.  
  30. return 0;
  31. }
  32.  
  33.  
  34. ##AppController.m
  35. #import "AppController.h"
  36.  
  37.  
  38. @implementation AppController
  39.  
  40. @synthesize working;
  41.  
  42. - (id)init
  43. {
  44. if(self = [super init])
  45. {
  46. data = [ [PreferencesData alloc] init];
  47. import = [ [ITUImport alloc] init];
  48.  
  49. working = YES;
  50. }
  51. return self;
  52. }
  53.  
  54. - (id)dealloc
  55. {
  56. [data release];
  57. [import release];
  58. }
  59.  
  60. - (void)startRequest
  61. {
  62. NSLog(@"Starting request from AppController");
  63. import.delegate = self;
  64. import.username = [data getData:@"username"];
  65. import.password = [data getData:@"password"];
  66. import.lastId = [[data getData:@"lastid"] unsignedIntValue];
  67. import.uploadProgressDelegate = nil;
  68.  
  69. //[NSThread detachNewThreadSelector:@selector(startRequest) toTarget:import withObject:nil];
  70. [import startRequest];
  71. }
  72.  
  73. - (void)setStatus:(NSNumber*)status
  74. {
  75. NSLog(@"Set status: %d", [status intValue]);
  76.  
  77. switch ([status intValue]) {
  78. case kImportComplete:
  79. working = NO;
  80. NSLog(@"Completed. Message: %@", import.returnData);
  81. break;
  82.  
  83. case kImportError:
  84. working = NO;
  85. NSLog(@"Error. Message: %@", import.returnData);
  86. break;
  87.  
  88. case kImportStatusMessagesNoNewElements:
  89. NSLog(@"There aren't new elements to be imported");
  90. break;
  91.  
  92. case kImportStatusStarting:
  93. NSLog(@"Starting");
  94. break;
  95.  
  96. case kImportStatusLoadingAddressBook:
  97. NSLog(@"Loading Address Book...");
  98. break;
  99.  
  100. case kImportStatusReceivedAddressBook:
  101. NSLog(@"Parsing Address Book...");
  102. break;
  103.  
  104. case kImportStatusPreparingData:
  105. NSLog(@"Preparing Data...");
  106. break;
  107.  
  108. case kImportStatusUploading:
  109. NSLog(@"Uploading...");
  110. break;
  111.  
  112. default:
  113. NSLog(@"Working...");
  114. break;
  115. }
  116. }
  117.  
  118. @end
Add Comment
Please, Sign In to add comment