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 (MasterViewBindings)
33 @implementation VLCMediaDiscoverer (MasterViewBindings)
36 [VLCMediaDiscoverer setKeys:[NSArray arrayWithObject:@"running"] triggerChangeNotificationsForDependentKey:@"currentlyFetchingItems"];
39 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
41 /* Thanks to Julien Robert, we'll have some nice auto triggered KVO event from here */
42 static NSDictionary * dict = nil;
45 dict = [[NSDictionary dictionaryWithObjectsAndKeys:
46 [NSSet setWithObject:@"discoveredMedia.flatAspect"], @"childrenInMasterViewForDetailView",
49 return [dict objectForKey: key];
52 /* General shortcuts */
53 - (BOOL)currentlyFetchingItems
55 return [self isRunning];
59 static NSImage * sdImage = nil;
61 sdImage = [[NSImage imageNamed:@"applications-internet.png"] retain];
65 /* MasterView specific bindings */
66 - (NSArray *)childrenInMasterView
70 - (NSString *)descriptionInMasterView
72 return [self localizedName];
74 - (VLCMediaListAspect *)childrenInMasterViewForDetailView
76 return [[self discoveredMedia] flatAspect];
78 - (BOOL)editableInMasterView
82 - (BOOL)selectableInMasterView
87 /* VideoView specific bindings */
88 - (NSArray *)childrenInVideoView
90 return [[[self discoveredMedia] flatAspect] valueForKeyPath:@"media"];
93 - (NSString *)descriptionInVideoView
95 return [self localizedName];
104 /******************************************************************************
105 * VLCMedia (VLCAppBindings)
107 @implementation VLCMedia (VLCAppBindings)
109 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
111 /* Thanks to Julien Robert, we'll have some nice auto triggered KVO event from here */
112 static NSDictionary * dict = nil;
115 dict = [[NSDictionary dictionaryWithObjectsAndKeys:
116 [NSSet setWithObject:@"subitems.hierarchicalNodeAspect.media"], @"childrenInMasterView",
117 [NSSet setWithObject:@"metaDictionary.title"], @"descriptionInMasterView",
118 [NSSet setWithObject:@"subitems.flatAspect"], @"childrenInMasterViewForDetailView",
119 [NSSet setWithObject:@"metaDictionary.title"], @"descriptionInVideoView",
120 [NSSet setWithObject:@"state"], @"stateAsImage",
123 return [dict objectForKey: key];
126 /* MasterView specific bindings */
127 - (NSArray *)childrenInMasterView
129 return [[[self subitems] hierarchicalNodeAspect] valueForKeyPath:@"media"];
131 - (void)setDescriptionInMasterView:(NSString *)description
133 NSLog(@"unimplemented: meta edition");
135 - (NSString *)descriptionInMasterView
137 return [[self metaDictionary] objectForKey:@"title"];
139 - (VLCMediaListAspect *)childrenInMasterViewForDetailView
141 return [[self subitems] flatAspect];
143 - (BOOL)editableInMasterView
147 - (BOOL)selectableInMasterView
151 - (BOOL)currentlyFetchingItems
157 static NSImage * playlistImage = nil;
159 playlistImage = [[NSImage imageNamed:@"type_playlist.png"] retain];
160 return playlistImage;
163 /* VideoView specific bindings */
164 - (NSArray *)childrenInVideoView
166 return [[[self subitems] flatAspect] valueForKeyPath:@"media"];
168 - (NSString *)descriptionInVideoView
170 return [[self metaDictionary] objectForKey:@"title"];
173 /* DetailList specific bindings */
174 - (NSImage *)stateAsImage
176 static NSImage * playing = nil;
177 static NSImage * error = nil;
180 playing = [[NSImage imageNamed:@"volume_high.png"] retain];
182 error = [[NSImage imageNamed:@"dialog-error.png"] retain];
184 if( [self state] == VLCMediaStatePlaying )
186 else if( [self state] == VLCMediaStateBuffering )
188 else if( [self state] == VLCMediaStateError )
195 @implementation VLCMediaPlayer (VLCAppBindings)
198 [self setKeys:[NSArray arrayWithObjects:@"playing", @"media", nil] triggerChangeNotificationsForDependentKey:@"description"];
201 - (NSString *)description
204 return [self valueForKeyPath:@"media.metaDictionary.title"];
206 return @"VLC Media Player";