1 /*****************************************************************************
2 * VLCAppBindings.m: Helpful addition code related to bindings uses
3 *****************************************************************************
4 * Copyright (C) 2007 Pierre d'Herbemont
5 * Copyright (C) 2007 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #import "VLCAppBindings.h"
27 /* This is globally a big hack to ease binding uses */
30 /******************************************************************************
31 * VLCMediaDiscoverer (CategoriesListBindings)
33 @implementation VLCMediaDiscoverer (CategoriesListBindings)
34 + (NSSet *)keyPathsForValuesAffectingCurrentlyFetchingItems
36 return [NSSet setWithObject:@"running"];
39 + (NSSet *)keyPathsForValuesAffectingChildrenInCategoriesListForDetailView
41 return [NSSet setWithObject:@"discoveredMedia.flatAspect"];
44 /* General shortcuts */
45 - (BOOL)currentlyFetchingItems
47 return [self isRunning];
51 static NSImage * sdImage = nil;
53 sdImage = [[NSImage imageNamed:@"applications-internet.png"] retain];
57 /* CategoriesList specific bindings */
58 - (NSArray *)childrenInCategoriesList
62 - (NSString *)descriptionInCategoriesList
64 return [self localizedName];
66 - (VLCMediaListAspect *)childrenInCategoriesListForDetailView
68 return [[self discoveredMedia] flatAspect];
70 - (BOOL)editableInCategoriesList
74 - (BOOL)selectableInCategoriesList
79 /* VideoView specific bindings */
80 - (NSArray *)childrenInVideoView
82 return [[[self discoveredMedia] flatAspect] valueForKeyPath:@"media"];
85 - (NSString *)descriptionInVideoView
87 return [self localizedName];
96 /******************************************************************************
97 * VLCMedia (VLCAppBindings)
99 @implementation VLCMedia (VLCAppBindings)
101 + (NSSet *)keyPathsForValuesAffectingChildrenInCategoriesList
103 return [NSSet setWithObject:@"subitems.hierarchicalNodeAspect.media"];
105 + (NSSet *)keyPathsForValuesAffectingDescriptionInCategoriesList
107 return [NSSet setWithObject:@"metaDictionary.title"];
109 + (NSSet *)keyPathsForValuesAffectingChildrenInCategoriesListForDetailView
111 return [NSSet setWithObject:@"subitems.flatAspect"];
113 + (NSSet *)keyPathsForValuesAffectingChildrenInDescriptionInVideoView
115 return [NSSet setWithObject:@"metaDictionary.title"];
117 + (NSSet *)keyPathsForValuesAffectingStateAsImage
119 return [NSSet setWithObject:@"state"];
122 /* CategoriesList specific bindings */
123 - (NSArray *)childrenInCategoriesList
125 return [[[self subitems] hierarchicalNodeAspect] valueForKeyPath:@"media"];
127 - (void)setDescriptionInCategoriesList:(NSString *)description
129 NSLog(@"unimplemented: meta edition");
131 - (NSString *)descriptionInCategoriesList
133 return [[self metaDictionary] objectForKey:@"title"];
135 - (VLCMediaListAspect *)childrenInCategoriesListForDetailView
137 return [[self subitems] flatAspect];
139 - (BOOL)editableInCategoriesList
143 - (BOOL)selectableInCategoriesList
147 - (BOOL)currentlyFetchingItems
153 static NSImage * playlistImage = nil;
155 playlistImage = [[NSImage imageNamed:@"type_playlist.png"] retain];
156 return playlistImage;
159 /* VideoView specific bindings */
160 - (NSArray *)childrenInVideoView
162 return [[[self subitems] flatAspect] valueForKeyPath:@"media"];
164 - (NSString *)descriptionInVideoView
166 return [[self metaDictionary] objectForKey:@"title"];
169 /* mediaListView specific bindings */
170 - (NSImage *)stateAsImage
172 static NSImage * playing = nil;
173 static NSImage * error = nil;
176 playing = [[NSImage imageNamed:@"volume_high.png"] retain];
178 error = [[NSImage imageNamed:@"dialog-error.png"] retain];
180 if( [self state] == VLCMediaStatePlaying )
182 else if( [self state] == VLCMediaStateBuffering )
184 else if( [self state] == VLCMediaStateError )
191 @implementation VLCMediaPlayer (VLCAppBindings)
192 + (NSSet *)keyPathsForValuesAffectingDescription
194 return [NSSet setWithObjects:@"playing", @"media", nil];
196 + (NSSet *)keyPathsForValuesAffectingStateAsButtonImage
198 return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
200 + (NSSet *)keyPathsForValuesAffectingStateAsButtonAlternateImage
202 return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
204 + (NSSet *)keyPathsForValuesAffectingStateAsFullScreenButtonImage
206 return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
208 + (NSSet *)keyPathsForValuesAffectingStateAsFullScreenButtonAlternateImage
210 return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
213 - (NSString *)description
216 return [self valueForKeyPath:@"media.metaDictionary.title"];
218 return @"VLC Media Player";
221 - (NSImage *)stateAsButtonImage
223 if([self state] == VLCMediaPlayerStatePlaying && [self canPause])
224 return [NSImage imageNamed:@"pause.png"];
225 else if( [self state] == VLCMediaPlayerStatePlaying )
226 return [NSImage imageNamed:@"stop.png"];
228 return [NSImage imageNamed:@"play.png"];
231 - (NSImage *)stateAsButtonAlternateImage
233 if([self state] == VLCMediaPlayerStatePlaying && [self canPause])
234 return [NSImage imageNamed:@"pause_blue.png"];
235 else if( [self state] == VLCMediaPlayerStatePlaying )
236 return [NSImage imageNamed:@"stop_blue.png"];
238 return [NSImage imageNamed:@"play_blue.png"];
241 - (NSImage *)stateAsFullScreenButtonImage
243 if([self state] == VLCMediaPlayerStatePlaying && [self canPause])
244 return [NSImage imageNamed:@"fs_pause.png"];
245 else if( [self state] == VLCMediaPlayerStatePlaying )
246 return [NSImage imageNamed:@"fs_stop.png"];
248 return [NSImage imageNamed:@"fs_play.png"];
251 - (NSImage *)stateAsFullScreenButtonAlternateImage
253 if([self state] == VLCMediaPlayerStatePlaying && [self canPause])
254 return [NSImage imageNamed:@"fs_pause_highlight.png"];
255 else if( [self state] == VLCMediaPlayerStatePlaying )
256 return [NSImage imageNamed:@"fs_stop_highlight.png"];
258 return [NSImage imageNamed:@"fs_play_highlight.png"];