MacOSX/VLC_app: port the fullscreen zoom and the fspanel from gui/macosx to VLC_app.
[vlc.git] / extras / MacOSX / VLC_app / Sources / VLCAppBindings.m
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
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #import "VLCAppBindings.h"
26
27 /* This is globally a big hack to ease binding uses */
28
29
30 /******************************************************************************
31  * VLCMediaDiscoverer (CategoriesListBindings)
32  */
33 @implementation VLCMediaDiscoverer (CategoriesListBindings)
34 + (NSSet *)keyPathsForValuesAffectingCurrentlyFetchingItems
35 {
36     return [NSSet setWithObject:@"running"];
37 }
38
39 + (NSSet *)keyPathsForValuesAffectingChildrenInCategoriesListForDetailView
40 {
41     return [NSSet setWithObject:@"discoveredMedia.flatAspect"];
42 }
43
44 /* General shortcuts */
45 - (BOOL)currentlyFetchingItems
46 {
47     return [self isRunning];
48 }
49 - (NSImage *)image
50 {
51     static NSImage * sdImage = nil;
52     if( !sdImage )
53         sdImage = [[NSImage imageNamed:@"applications-internet.png"] retain];
54     return sdImage;
55 }
56
57 /* CategoriesList specific bindings */
58 - (NSArray *)childrenInCategoriesList
59 {
60     return nil;
61 }
62 - (NSString *)descriptionInCategoriesList
63 {
64     return [self localizedName];
65 }
66 - (VLCMediaListAspect *)childrenInCategoriesListForDetailView
67 {
68     return [[self discoveredMedia] flatAspect];
69 }
70 - (BOOL)editableInCategoriesList
71 {
72     return NO;
73 }
74 - (BOOL)selectableInCategoriesList
75 {
76     return YES;
77 }
78
79 /* VideoView specific bindings */
80 - (NSArray *)childrenInVideoView
81 {
82     return [[[self discoveredMedia] flatAspect] valueForKeyPath:@"media"];
83 }
84
85 - (NSString *)descriptionInVideoView
86 {
87     return [self localizedName];
88 }
89 - (BOOL)isLeaf
90 {
91     return YES;
92 }
93
94 @end
95
96 /******************************************************************************
97  * VLCMedia (VLCAppBindings)
98  */
99 @implementation VLCMedia (VLCAppBindings)
100
101 + (NSSet *)keyPathsForValuesAffectingChildrenInCategoriesList
102 {
103     return [NSSet setWithObject:@"subitems.hierarchicalNodeAspect.media"];
104 }
105 + (NSSet *)keyPathsForValuesAffectingDescriptionInCategoriesList
106 {
107     return [NSSet setWithObject:@"metaDictionary.title"];
108 }
109 + (NSSet *)keyPathsForValuesAffectingChildrenInCategoriesListForDetailView
110 {
111     return [NSSet setWithObject:@"subitems.flatAspect"];
112 }
113 + (NSSet *)keyPathsForValuesAffectingChildrenInDescriptionInVideoView
114 {
115     return [NSSet setWithObject:@"metaDictionary.title"];
116 }
117 + (NSSet *)keyPathsForValuesAffectingStateAsImage
118 {
119     return [NSSet setWithObject:@"state"];
120 }
121
122 /* CategoriesList specific bindings */
123 - (NSArray *)childrenInCategoriesList
124 {
125     return [[[self subitems] hierarchicalNodeAspect] valueForKeyPath:@"media"];
126 }
127 - (void)setDescriptionInCategoriesList:(NSString *)description
128 {
129     NSLog(@"unimplemented: meta edition");
130 }
131 - (NSString *)descriptionInCategoriesList
132 {
133     return [[self metaDictionary] objectForKey:@"title"];
134 }
135 - (VLCMediaListAspect *)childrenInCategoriesListForDetailView
136 {
137     return [[self subitems] flatAspect];
138 }
139 - (BOOL)editableInCategoriesList
140 {
141     return YES;
142 }
143 - (BOOL)selectableInCategoriesList
144 {
145     return YES;
146 }
147 - (BOOL)currentlyFetchingItems
148 {
149     return NO;
150 }
151 - (NSImage *)image
152 {
153     static NSImage * playlistImage = nil;
154     if( !playlistImage )
155         playlistImage = [[NSImage imageNamed:@"type_playlist.png"] retain];
156     return playlistImage;
157 }
158
159 /* VideoView specific bindings */
160 - (NSArray *)childrenInVideoView
161 {
162     return [[[self subitems] flatAspect] valueForKeyPath:@"media"];
163 }
164 - (NSString *)descriptionInVideoView
165 {
166     return [[self metaDictionary] objectForKey:@"title"];
167 }
168
169 /* mediaListView specific bindings */
170 - (NSImage *)stateAsImage
171 {
172     static NSImage * playing = nil;
173     static NSImage * error = nil;
174
175     if(!playing)
176         playing = [[NSImage imageNamed:@"volume_high.png"] retain];
177     if(!error)
178         error = [[NSImage imageNamed:@"dialog-error.png"] retain];
179
180     if( [self state] == VLCMediaStatePlaying )
181         return playing;
182     else if( [self state] == VLCMediaStateBuffering )
183         return playing;
184     else if( [self state] == VLCMediaStateError )
185         return error;
186
187     return nil;
188 }
189 @end
190
191 @implementation VLCMediaPlayer (VLCAppBindings)
192 + (NSSet *)keyPathsForValuesAffectingDescription
193 {
194     return [NSSet setWithObjects:@"playing", @"media", nil];
195 }
196 + (NSSet *)keyPathsForValuesAffectingStateAsButtonImage
197 {
198     return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
199 }
200 + (NSSet *)keyPathsForValuesAffectingStateAsButtonAlternateImage
201 {
202     return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
203 }
204 + (NSSet *)keyPathsForValuesAffectingStateAsFullScreenButtonImage
205 {
206     return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
207 }
208 + (NSSet *)keyPathsForValuesAffectingStateAsFullScreenButtonAlternateImage
209 {
210     return [NSSet setWithObjects:@"state", @"playing", @"canPause", nil];
211 }
212
213 - (NSString *)description
214 {
215     if([self media])
216         return [self valueForKeyPath:@"media.metaDictionary.title"];
217     else
218         return @"VLC Media Player";
219 }
220
221 - (NSImage *)stateAsButtonImage
222 {
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"];
227     else
228         return [NSImage imageNamed:@"play.png"];
229 }
230
231 - (NSImage *)stateAsButtonAlternateImage
232 {
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"];
237     else
238         return [NSImage imageNamed:@"play_blue.png"];
239 }
240
241 - (NSImage *)stateAsFullScreenButtonImage
242 {
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"];
247     else
248         return [NSImage imageNamed:@"fs_play.png"];
249 }
250
251 - (NSImage *)stateAsFullScreenButtonAlternateImage
252 {
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"];
257     else
258         return [NSImage imageNamed:@"fs_play_highlight.png"];
259 }
260
261 @end