]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlistinfo.m
* get rid of useless code (group doesn't exist anymore)
[vlc] / modules / gui / macosx / playlistinfo.m
1 /*****************************************************************************
2  r playlistinfo.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2002-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Benjamin Pracht <bigben at videolan dot org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #include "intf.h"
29 #include "playlistinfo.h"
30 #include "playlist.h"
31
32 /*****************************************************************************
33  * VLCPlaylistInfo Implementation
34  *****************************************************************************/
35
36 @implementation VLCInfo
37
38 - (id)init
39 {
40     self = [super init];
41
42     if( self != nil )
43     {
44         i_item = -1;
45         o_selected = NULL;
46     }
47     return( self );
48 }
49
50 - (void)dealloc
51 {
52     [o_selected release];
53     [super dealloc];
54 }
55
56 - (void)awakeFromNib
57 {
58     [o_info_window setExcludedFromWindowsMenu: TRUE];
59
60     [o_info_window setTitle: _NS("Properties")];
61     [o_uri_lbl setStringValue: _NS("URI")];
62     [o_title_lbl setStringValue: _NS("Title")];
63     [o_author_lbl setStringValue: _NS("Author")];
64     [o_btn_ok setTitle: _NS("OK")];
65     [o_btn_cancel setTitle: _NS("Cancel")];
66 }
67
68 - (IBAction)togglePlaylistInfoPanel:(id)sender
69 {
70     if( [o_info_window isVisible] )
71     {
72         [o_info_window orderOut: sender];
73     }
74     else
75     {
76         i_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
77         o_selected = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItemsList];
78         [o_selected retain];
79         [self initPanel:sender];
80     }
81 }
82
83 - (IBAction)toggleInfoPanel:(id)sender
84 {
85     if( [o_info_window isVisible] )
86     {
87         [o_info_window orderOut: sender];
88     }
89     else
90     {
91         intf_thread_t * p_intf = VLCIntf;
92         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
93                                           FIND_ANYWHERE );
94
95         if (p_playlist)
96         {
97             i_item = p_playlist->i_index;
98             o_selected = [NSMutableArray arrayWithObject:
99                             [NSNumber numberWithInt:i_item]];
100             [o_selected retain];
101             vlc_object_release(p_playlist);
102         }
103         [self initPanel:sender];
104     }
105 }
106
107 - (void)initPanel:(id)sender
108 {
109     intf_thread_t * p_intf = VLCIntf;
110     playlist_t * p_playlist;
111
112     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
113                                           FIND_ANYWHERE );
114
115
116     if( p_playlist )
117     {
118         char *psz_temp;
119
120         /*fill uri / title / author info */
121         [o_uri_txt setStringValue:
122             ([NSString stringWithUTF8String:p_playlist->
123                pp_items[i_item]->input.psz_uri] == nil ) ?
124             [NSString stringWithCString:p_playlist->
125                 pp_items[i_item]->input.psz_uri] :
126             [NSString stringWithUTF8String:p_playlist->
127                 pp_items[i_item]->input.psz_uri]];
128
129         [o_title_txt setStringValue:
130             ([NSString stringWithUTF8String:p_playlist->
131                 pp_items[i_item]->input.psz_name] == nil ) ?
132             [NSString stringWithCString:p_playlist->
133                 pp_items[i_item]->input.psz_name] :
134             [NSString stringWithUTF8String:p_playlist->
135                 pp_items[i_item]->input.psz_name]];
136
137         psz_temp = playlist_GetInfo( p_playlist, i_item ,_("General"),_("Author") );
138         [o_author_txt setStringValue: [NSString stringWithUTF8String: psz_temp]];
139         free( psz_temp );
140
141         [[VLCInfoTreeItem rootItem] refresh];
142         [o_outline_view reloadData];
143
144         vlc_object_release( p_playlist );
145     }
146     [o_info_window makeKeyAndOrderFront: sender];
147 }
148
149 - (IBAction)infoCancel:(id)sender
150 {
151     [o_info_window orderOut: self];
152 }
153
154
155 - (IBAction)infoOk:(id)sender
156 {
157     int c;
158     intf_thread_t * p_intf = VLCIntf;
159     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
160                                           FIND_ANYWHERE );
161     vlc_value_t val;
162
163     if (p_playlist)
164     {
165         vlc_mutex_lock(&p_playlist->pp_items[i_item]->input.lock);
166
167         p_playlist->pp_items[i_item]->input.psz_uri =
168             strdup([[o_uri_txt stringValue] cString]);
169         p_playlist->pp_items[i_item]->input.psz_name =
170             strdup([[o_title_txt stringValue] cString]);
171         playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
172
173         c = (int)[o_selected count];
174         vlc_mutex_unlock(&p_playlist->pp_items[i_item]->input.lock);
175         val.b_bool = VLC_TRUE;
176         var_Set( p_playlist,"intf-change",val );
177         vlc_object_release ( p_playlist );
178     }
179     [o_info_window orderOut: self];
180 }
181
182 - (int)getItem
183 {
184     return i_item;
185 }
186
187 @end
188
189 @implementation VLCInfo (NSMenuValidation)
190
191 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
192 {
193     BOOL bEnabled = TRUE;
194
195     intf_thread_t * p_intf = VLCIntf;
196     input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
197                                                        FIND_ANYWHERE );
198
199     if( [[o_mi title] isEqualToString: _NS("Info")] )
200     {
201         if( p_input == NULL )
202         {
203             bEnabled = FALSE;
204         }
205     }
206     if( p_input ) vlc_object_release( p_input );
207
208     return( bEnabled );
209 }
210
211 @end
212
213 @implementation VLCInfo (NSTableDataSource)
214
215 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
216 {
217     return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
218 }
219
220 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
221     return ([item numberOfChildren] > 0);
222 }
223
224 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
225 {
226     return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
227 }
228
229 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
230 {
231     if ([[tableColumn identifier] isEqualToString:@"0"])
232     {
233         return (item == nil) ? @"" : (id)[item getName];
234     }
235     else
236     {
237         return (item == nil) ? @"" : (id)[item getValue];
238     }
239 }
240
241
242 @end
243
244 @implementation VLCInfoTreeItem
245
246 static VLCInfoTreeItem *o_root_item = nil;
247
248 #define IsALeafNode ((id)-1)
249
250 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
251 {
252     self = [super init];
253
254     if( self != nil )
255     {
256         o_name = [o_item_name copy];
257         o_value = [o_item_value copy];
258         i_object_id = i_id;
259         o_parent = o_parent_item;
260         i_item = [[[VLCMain sharedInstance] getInfo] getItem];
261     }
262     return( self );
263 }
264
265 + (VLCInfoTreeItem *)rootItem {
266     if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
267     return o_root_item;
268 }
269
270 - (void)dealloc
271 {
272     if (o_children != IsALeafNode) [o_children release];
273     [o_name release];
274     [super dealloc];
275 }
276
277 /* Creates and returns the array of children
278  * Loads children incrementally */
279 - (NSArray *)children
280 {
281     if (o_children == NULL)
282     {
283         intf_thread_t * p_intf = VLCIntf;
284         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
285                                           FIND_ANYWHERE );
286         int i;
287
288         if (p_playlist)
289         {
290             if (i_item > -1)
291             {
292                 if (self == o_root_item)
293                 {
294                     o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->input.i_categories];
295                     for (i = 0 ; i<p_playlist->pp_items[i_item]->input.i_categories ; i++)
296                     {
297                         [o_children addObject:[[VLCInfoTreeItem alloc]
298                             initWithName: [NSString stringWithUTF8String:
299                                 p_playlist->pp_items[i_item]->input.
300                                 pp_categories[i]->psz_name]
301                             value: @""
302                             ID: i
303                             parent: self]];
304                     }
305                 }
306                 else if (o_parent == o_root_item)
307                 {
308                     o_children = [[NSMutableArray alloc] initWithCapacity:
309                         p_playlist->pp_items[i_item]->input.
310                         pp_categories[i_object_id]->i_infos];
311                     for (i = 0 ; i<p_playlist->pp_items[i_item]->input.
312                            pp_categories[i_object_id]->i_infos ; i++)
313                     {
314                         [o_children addObject:[[VLCInfoTreeItem alloc]
315                         initWithName: [NSString stringWithUTF8String:
316                                 p_playlist->pp_items[i_item]->input.
317                                 pp_categories[i_object_id]->
318                                 pp_infos[i]->psz_name]
319                             value: [NSString stringWithUTF8String:
320                                 p_playlist->pp_items[i_item]->input.
321                                 pp_categories[i_object_id]->
322                                 pp_infos[i]->psz_value]
323                             ID: i
324                             parent: self]];
325                     }
326                 }
327                 else
328                 {
329                     o_children = IsALeafNode;
330                 }
331             }
332             vlc_object_release(p_playlist);
333         }
334     }
335     return o_children;
336 }
337
338 - (NSString *)getName
339 {
340     return o_name;
341 }
342
343 - (NSString *)getValue
344 {
345     return o_value;
346 }
347
348 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
349     return [[self children] objectAtIndex:i_index];
350 }
351
352 - (int)numberOfChildren {
353     id i_tmp = [self children];
354     return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
355 }
356
357 /*- (int)selectedPlaylistItem
358 {
359     return i_item;
360 }
361 */
362 - (void)refresh
363 {
364     i_item = [[[VLCMain sharedInstance] getInfo] getItem];
365     if (o_children != NULL)
366     {
367         [o_children release];
368         o_children = NULL;
369     }
370 }
371
372 @end
373