-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNetworkCamera.m
More file actions
160 lines (132 loc) · 4.29 KB
/
Copy pathNetworkCamera.m
File metadata and controls
160 lines (132 loc) · 4.29 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// NetworkCamera.m
// Gawker
//
// Created by Phil Piwonka on 7/30/05.
// Copyright 2005 Phil Piwonka. All rights reserved.
//
#import "NetworkCamera.h"
#import "CameraController.h"
#import "NetworkCameraController.h"
#import "PreferenceController.h"
#import "ImageTransitionView.h"
#import "CameraStatusView.h"
@interface NetworkCamera (PrivateMethods)
- (NSString *)connectMessage;
- (NSString *)connectErrorMessage;
- (NSString *)connectSuccessMessage;
@end
@implementation NetworkCamera
- (id)initWithIp:(NSString *)address port:(UInt16)aPort
{
self = [super initWithWindowNibName:@"NetworkCamera"];
if (self) {
openOnConnect = NO;
ipAddress = [address retain];
remotePort = aPort;
camController = [[NetworkCameraController alloc] initWithIp:ipAddress
port:remotePort
delegate:self];
icon = [[NSImage imageNamed:@"internet.png"] retain];
[[self window] setTitle:ipAddress];
}
return self;
}
- (id)init
{
return [self initWithIp:nil port:0];
}
- (void)awakeFromNib
{
[super awakeFromNib];
[imageTransitionView setAnimate:YES];
[passwordHeader setStringValue:[NSString stringWithFormat:@"Password required to view %@",
ipAddress]];
[passwordIcon setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
}
- (void)setSourceEnabled:(BOOL)enable openWindow:(BOOL)open
{
hasConnected = NO;
[super setSourceEnabled:enable openWindow:open];
}
- (void)dealloc
{
NSLog(@"NetworkCamera -dealloc");
[ipAddress release];
[super dealloc];
}
- (IBAction)passwordOk:(id)sender
{
[[camController imageSource] usePassword:[passwordFromUser stringValue]];
[passwordWindow close];
}
- (IBAction)passwordCancel:(id)sender
{
[[camController imageSource] usePassword:nil];
[passwordWindow close];
}
@end
@implementation NetworkCamera (PrivateMethods)
- (NSString *)connectMessage
{
return [NSString stringWithFormat:@"Connecting to %@...",
ipAddress];
}
- (NSString *)connectErrorMessage
{
NSString *connection = (hasConnected) ? @"Disconnected from"
: @"Could not connect to";
return [NSString stringWithFormat:@"%@ %@ - %@",
connection,
ipAddress,
[self sourceDescription]];
}
- (NSString *)connectSuccessMessage
{
return [NSString stringWithFormat:@"Connected to %@ - %@",
ipAddress,
[self sourceDescription]];
}
- (void)windowDidLoad
{
[[self window] setFrameAutosaveName:@"NetworkCamera"];
}
- (void)windowDidMove:(NSNotification *)note
{
[[self window] saveFrameUsingName:@"NetworkCamera"];
[super windowDidMove:note];
}
@end
@implementation NetworkCamera (DelegateMethods)
- (void)cameraController:(CameraController *)controller
hasNewImage:(NSImage *)anImage
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL doFancyTransitions = [defaults boolForKey:WNKDoFancyTransitionsKey];
[imageTransitionView setAnimate:doFancyTransitions];
[imageTransitionView setImage:anImage];
[nc postNotificationName:@"UpdateCameraTable" object:self];
}
- (void)cameraControllerConnected:(CameraController *)controller
{
hasConnected = YES;
[super cameraControllerConnected:controller];
}
- (void)cameraControllerNewDescription:(CameraController *)controller
{
[[self window] setTitle:[NSString stringWithFormat:@"%@ - %@",
[camController sourceSubDescription],
[camController sourceDescription]]];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"UpdateCameraTable" object:self];
[nc postNotificationName:@"EnabledStatusChanged" object:self];
}
- (void)cameraControllerNeedsPassword:(CameraController *)controller
{
NSLog(@"in cameraControllerNeedsPassword:");
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"UpdateCameraTable" object:self];
[passwordWindow makeKeyAndOrderFront:nil];
}
@end