forked from mitzpettel/Vidi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBTVChannel.m
156 lines (130 loc) · 4.04 KB
/
DBTVChannel.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
//
// DBTVChannel.m
// Vidi
//
// Created by Mitz Pettel on Sun Jan 26 2003.
// Copyright (c) 2002, 2003 Mitz Pettel. All rights reserved.
//
#import "DBTVChannel.h"
NSString * const DBTVFrequencyKey = @"frequency";
NSString * const DBTVNameKey = @"name";
NSString * const DBTVVolumeKey = @"volume";
NSString * const DBTVLogoKey = @"logo";
NSString * const DBTVInputSourceKey = @"input source";
NSString * const DBTVChannelChangedNotification = @"DBTVChannelChangedNotification";
@implementation DBTVChannel
+ (id)channelWithFrequency:(DBTVFrequency)freq inputSource:(DBDVInputSource)source name:(NSString *)string volume:(float)vol logo:(NSImage *)image
{
return [[[self alloc] initWithFrequency:freq inputSource:source name:string volume:vol logo:image] autorelease];
}
+ (id)channelWithFrequency:(DBTVFrequency)freq
{
return [[[self alloc] initWithFrequency:freq] autorelease];
}
+ (id)channelWithDictionary:(NSDictionary *)dict
{
return [[[self alloc] initWithDictionary:dict] autorelease];
}
- (id)initWithFrequency:(DBTVFrequency)freq inputSource:(DBDVInputSource)source name:(NSString *)string volume:(float)vol logo:(NSImage *)image
{
self = [super init];
if (self) {
_frequency = freq;
_name = [string retain];
_volume = vol;
_logo = [image retain];
_inputSource = source;
}
return self;
}
- (void)dealloc
{
[_name release];
[_logo release];
[super dealloc];
}
- (id)initWithFrequency:(DBTVFrequency)freq
{
return [self initWithFrequency:freq inputSource:DBTunerInput name:@"" volume:1.0 logo:NULL];
}
- (id)initWithDictionary:(NSDictionary *)dict
{
[self initWithFrequency:[[dict objectForKey:DBTVFrequencyKey] floatValue] inputSource:[[dict objectForKey:DBTVInputSourceKey] intValue] name:[dict objectForKey:DBTVNameKey] volume:[[dict objectForKey:DBTVVolumeKey] floatValue] logo:[[[NSImage alloc] initWithData:[dict objectForKey:DBTVLogoKey]] autorelease]];
return self;
}
- (NSDictionary *)dictionary
{
NSMutableDictionary *result;
result = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:[self frequency]], DBTVFrequencyKey,
[self name], DBTVNameKey,
[NSNumber numberWithFloat:[self volume]], DBTVVolumeKey,
[NSNumber numberWithInt:[self inputSource]], DBTVInputSourceKey,
nil
];
if ([self logo])
[result setObject:[[self logo] TIFFRepresentation] forKey:DBTVLogoKey];
return result;
}
- (NSDictionary *)dictionaryWithoutLogo
{
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:[self frequency]], DBTVFrequencyKey,
[self name], DBTVNameKey,
[NSNumber numberWithFloat:[self volume]], DBTVVolumeKey,
[NSNumber numberWithInt:[self inputSource]], DBTVInputSourceKey,
nil
];
}
- (void)setFrequency:(DBTVFrequency)freq
{
_frequency = freq;
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:DBTVChannelChangedNotification object:self] postingStyle:NSPostASAP coalesceMask:NSNotificationCoalescingOnSender forModes:nil];
}
- (DBTVFrequency)frequency
{
return _frequency;
}
- (void)setName:(NSString *)string
{
[_name autorelease];
_name = [string retain];
[self _sendChangeNotification];
}
- (NSString *)name
{
return _name;
}
- (void)setVolume:(float)vol
{
_volume = vol;
[self _sendChangeNotification];
}
- (float)volume
{
return _volume;
}
- (void)setInputSource:(DBDVInputSource)source
{
_inputSource = source;
[self _sendChangeNotification];
}
- (DBDVInputSource)inputSource
{
return _inputSource;
}
- (void)setLogo:(NSImage *)image
{
[_logo autorelease];
_logo = [image retain];
[self _sendChangeNotification];
}
- (NSImage *)logo
{
return _logo;
}
- (void)_sendChangeNotification
{
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:DBTVChannelChangedNotification object:self] postingStyle:NSPostWhenIdle coalesceMask:NSNotificationCoalescingOnSender forModes:nil];
}
@end