-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDBRadioWindowController.m
187 lines (154 loc) · 5.13 KB
/
DBRadioWindowController.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// DBRadioWindowController.m
// Vidi
//
// Created by Mitz Pettel on Feb 22 2003.
// Copyright (c) 2003 Mitz Pettel. All rights reserved.
//
#import "DBRadioWindowController.h"
#import "DBTVChannel.h"
#import "DBVidi.h"
const float kExtraWindowHeight = 100.0f;
@implementation DBRadioWindowController
- (id)initWithVidi:(DBVidi *)object
{
self = [super initWithVidi:object];
if (self)
_temporaryChannel = [[DBTVChannel alloc] initWithFrequency:90000000 inputSource:DBRadioInput name:@"" volume:1.0 logo:nil];
return self;
}
- (NSString *)mediumWindowNibName
{
return @"Radio";
}
- (NSString *)mediumWindowFrameAutosaveName
{
return @"radio";
}
- (void)windowDidLoad
{
NSRect frame;
[super windowDidLoad];
_isInEditMode = [[NSUserDefaults standardUserDefaults] boolForKey:DBRadioEditingSettingMode];
[[self window] setShowsResizeIndicator:NO];
[editModeView retain];
frame = [editModeView frame];
if (!_isInEditMode)
frame.origin.y += kExtraWindowHeight;
[editModeView setFrameOrigin:frame.origin];
[editModeView removeFromSuperview];
[channelPopUp retain];
[channelsTable setTarget:self];
[channelsTable setDoubleAction:@selector(editChannelName:)];
[frequencyStepper setIncrement:0.05];
if ( _isInEditMode ) {
[channelPopUp removeFromSuperview];
[[[self window] contentView] addSubview:editModeView positioned:NSWindowBelow relativeTo:muteButton];
}
}
- (void)dealloc
{
[_temporaryChannel release];
[editModeView release];
[channelPopUp release];
[super dealloc];
}
- (void)updateChannelDetails
{
DBTVChannel *channel = [_vidi selectedChannel];
[super updateChannelDetails];
[frequencyStepper setFloatValue:[channel frequency] / 1000000.0];
[frequencyTextField takeFloatValueFrom:frequencyStepper];
}
- (NSMenu *)menuWithChannels
{
NSMenu *menu = [super menuWithChannels];
[menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:NSLocalizedString(@"Edit Stations", @"menu item") action:@selector(toggleEditMode:) keyEquivalent:@""];
return menu;
}
- (void)toggleEditMode:(id)sender
{
NSRect frame = [[self window] frame];
_isInEditMode = !_isInEditMode;
if (_isInEditMode) {
frame.size.height += kExtraWindowHeight;
frame.origin.y -= kExtraWindowHeight;
[channelPopUp removeFromSuperview];
[[self window] setFrame:frame display:YES animate:YES];
[[[self window] contentView] addSubview:editModeView positioned:NSWindowBelow relativeTo:muteButton];
} else {
[editModeView removeFromSuperview];
frame.size.height -= kExtraWindowHeight;
frame.origin.y += kExtraWindowHeight;
[[self window] setFrame:frame display:YES animate:YES];
[self channelSelectionChanged];
[[[self window] contentView] addSubview:channelPopUp];
[[self window] makeFirstResponder:[[self window] initialFirstResponder]];
}
[[NSUserDefaults standardUserDefaults] setBool:_isInEditMode forKey:DBRadioEditingSettingMode];
}
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
{
[self toggleEditMode:nil];
return NO;
}
- (IBAction)takeChannelFrequencyFrom:(id)sender
{
int frequency = [sender floatValue] * 1000000;
if (_isInEditMode || ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask))
[[[self vidi] selectedChannel] setFrequency:frequency];
else {
DBTVChannel *channel = [[self vidi] channelForFrequency:frequency];
if (channel == nil) {
// no matching channel
channel = _temporaryChannel;
[channel setFrequency:frequency];
}
[[self vidi] selectChannel:channel];
}
}
- (DBTVChannel *)newChannel
{
return [DBTVChannel channelWithFrequency:[[[self vidi] selectedChannel] frequency] inputSource:DBRadioInput name:NSLocalizedString( @"new station", @"name for new radio station" ) volume:1.0 logo:nil];
}
- (IBAction)addClicked:(id)sender
{
[super addClicked:sender];
[self editChannelName:nil];
}
- (IBAction)editChannelName:(id)sender
{
[channelsTable editColumn:0 row:[[self vidi] indexOfSelectedChannel] withEvent:nil select:YES];
}
- (void)recordingStarted
{
[super recordingStarted];
if ( _isInEditMode )
[self toggleEditMode:nil];
}
#pragma mark NSObject (NSTableViewDelegate)
- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
int row = [channelsTable selectedRow];
[removeButton setEnabled:row != -1 && [[[self vidi] channels] count] > 1 && ![[self vidi] isRecording]];
if (row != -1)
[[self vidi] selectChannelAtIndex:row];
else {
[_temporaryChannel setFrequency:[[[self vidi] selectedChannel] frequency]];
[[self vidi] selectChannel:_temporaryChannel];
}
}
#pragma mark NSObject (NSWindowDelegate)
- (void)windowWillClose:(NSNotification *)notification
{
if (_blinkerTimer)
[_blinkerTimer invalidate];
[self autorelease];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
{
return [sender frame].size;
}
@end