-
Notifications
You must be signed in to change notification settings - Fork 0
/
EPAppController.m
124 lines (101 loc) · 3.88 KB
/
EPAppController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// EPAppController.m
// Degrees of Tweetdom
//
// Created by Simone Manganelli on 2008-08-22.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "EPAppController.h"
#import "EPBidirectionalCheckerController.h"
#import "EPTwittererChainFinderController.h"
#import "EPFriendRecommenderController.h"
#import "EPTwittererMapperController.h"
#import "EPFavoriteFinderController.h"
#import "EPOperationQueue.h"
@implementation EPAppController
- (id)init;
{
if (self = [super init]) {
arrayOfOperationQueues = [[NSMutableArray alloc] init];
}
return self;
}
- (void)dealloc;
{
[arrayOfOperationQueues release];
[super dealloc];
}
- (void)awakeFromNib;
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(operationQueueCreatedNotification:)
name:@"operationQueueCreated"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(operationQueueDeletedNotification:)
name:@"operationQueueDeleted"
object:nil];
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateActivityWindowStats)
userInfo:nil
repeats:YES];
}
// I decided to have multiple operation queues throughout the application because
// it made it easier in terms of design if I wanted to have a single activity
// window that was able to give stats on all operations (either I would've had to
// have objects be initialized with an appController pointer, or I would've had to
// post notifications for every single operation, which would have been prohibitively
// expensive)
// upsides: simpler design, no. of NSOperations can be separated out by specific
// task that's being performed; downsides: costlier to count all NSOperations across
// all queues, harder to control resources the app uses;
- (void)operationQueueCreatedNotification:(NSNotification *)notification;
{
[arrayOfOperationQueues addObject:[notification object]];
}
- (void)operationQueueDeletedNotification:(NSNotification *)notification;
{
[arrayOfOperationQueues removeObject:[notification object]];
}
- (void)updateActivityWindowStats;
{
[numberOfOperationQueuesTextField setStringValue:[[NSNumber numberWithInt:[arrayOfOperationQueues count]] stringValue]];
int NSOperationCount = 0;
EPOperationQueue *currentOperationQueue = nil;
for (currentOperationQueue in arrayOfOperationQueues) {
NSOperationCount += [[currentOperationQueue operations] count];
}
[numberOfNSOperationsTextField setStringValue:[[NSNumber numberWithInt:NSOperationCount] stringValue]];
}
- (IBAction)createNewBidirectionalCheckerWindow:(id)sender;
{
EPBidirectionalCheckerController *newBidirectionalController = [[EPBidirectionalCheckerController alloc] init];
[newBidirectionalController showWindow:self];
[newBidirectionalController release];
}
- (IBAction)createNewTwittererChainFinderWindow:(id)sender;
{
EPTwittererChainFinderController *newTwittererChainFinderController = [[EPTwittererChainFinderController alloc] init];
[newTwittererChainFinderController showWindow:self];
[newTwittererChainFinderController release];
}
- (IBAction)createNewFriendRecommenderWindow:(id)sender;
{
EPFriendRecommenderController *newFriendRecommenderController = [[EPFriendRecommenderController alloc] init];
[newFriendRecommenderController showWindow:self];
[newFriendRecommenderController release];
}
- (IBAction)createNewTwittererMapperWindow:(id)sender;
{
EPTwittererMapperController *newTwittererMapperController = [[EPTwittererMapperController alloc] init];
[newTwittererMapperController showWindow:self];
[newTwittererMapperController release];
}
- (IBAction)createNewFavoriteFinderWindow:(id)sender;
{
EPFavoriteFinderController *newFavoriteFinderController = [[EPFavoriteFinderController alloc] init];
[newFavoriteFinderController showWindow:self];
[newFavoriteFinderController release];
}
@end