1 /*****************************************************************************
2 r playlistinfo.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
7 * Authors: Benjamin Pracht <bigben at videolan dot org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include "playlistinfo.h"
32 /*****************************************************************************
33 * VLCPlaylistInfo Implementation
34 *****************************************************************************/
36 @implementation VLCInfo
58 [o_info_window setExcludedFromWindowsMenu: TRUE];
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")];
68 - (IBAction)togglePlaylistInfoPanel:(id)sender
70 if( [o_info_window isVisible] )
72 [o_info_window orderOut: sender];
76 i_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
77 o_selected = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItemsList];
79 [self initPanel:sender];
83 - (IBAction)toggleInfoPanel:(id)sender
85 if( [o_info_window isVisible] )
87 [o_info_window orderOut: sender];
91 intf_thread_t * p_intf = VLCIntf;
92 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
97 i_item = p_playlist->i_index;
98 o_selected = [NSMutableArray arrayWithObject:
99 [NSNumber numberWithInt:i_item]];
101 vlc_object_release(p_playlist);
103 [self initPanel:sender];
107 - (void)initPanel:(id)sender
109 intf_thread_t * p_intf = VLCIntf;
110 playlist_t * p_playlist;
112 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
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]];
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]];
137 psz_temp = playlist_GetInfo( p_playlist, i_item ,_("General"),_("Author") );
138 [o_author_txt setStringValue: [NSString stringWithUTF8String: psz_temp]];
141 [[VLCInfoTreeItem rootItem] refresh];
142 [o_outline_view reloadData];
144 vlc_object_release( p_playlist );
146 [o_info_window makeKeyAndOrderFront: sender];
149 - (IBAction)infoCancel:(id)sender
151 [o_info_window orderOut: self];
155 - (IBAction)infoOk:(id)sender
158 intf_thread_t * p_intf = VLCIntf;
159 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
165 vlc_mutex_lock(&p_playlist->pp_items[i_item]->input.lock);
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]);
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 );
179 [o_info_window orderOut: self];
189 @implementation VLCInfo (NSMenuValidation)
191 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
193 BOOL bEnabled = TRUE;
195 intf_thread_t * p_intf = VLCIntf;
196 input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
199 if( [[o_mi title] isEqualToString: _NS("Info")] )
201 if( p_input == NULL )
206 if( p_input ) vlc_object_release( p_input );
213 @implementation VLCInfo (NSTableDataSource)
215 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
217 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
220 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
221 return ([item numberOfChildren] > 0);
224 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
226 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
229 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
231 if ([[tableColumn identifier] isEqualToString:@"0"])
233 return (item == nil) ? @"" : (id)[item getName];
237 return (item == nil) ? @"" : (id)[item getValue];
244 @implementation VLCInfoTreeItem
246 static VLCInfoTreeItem *o_root_item = nil;
248 #define IsALeafNode ((id)-1)
250 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
256 o_name = [o_item_name copy];
257 o_value = [o_item_value copy];
259 o_parent = o_parent_item;
260 i_item = [[[VLCMain sharedInstance] getInfo] getItem];
265 + (VLCInfoTreeItem *)rootItem {
266 if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
272 if (o_children != IsALeafNode) [o_children release];
277 /* Creates and returns the array of children
278 * Loads children incrementally */
279 - (NSArray *)children
281 if (o_children == NULL)
283 intf_thread_t * p_intf = VLCIntf;
284 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
292 if (self == o_root_item)
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++)
297 [o_children addObject:[[VLCInfoTreeItem alloc]
298 initWithName: [NSString stringWithUTF8String:
299 p_playlist->pp_items[i_item]->input.
300 pp_categories[i]->psz_name]
306 else if (o_parent == o_root_item)
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++)
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]
329 o_children = IsALeafNode;
332 vlc_object_release(p_playlist);
338 - (NSString *)getName
343 - (NSString *)getValue
348 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
349 return [[self children] objectAtIndex:i_index];
352 - (int)numberOfChildren {
353 id i_tmp = [self children];
354 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
357 /*- (int)selectedPlaylistItem
364 i_item = [[[VLCMain sharedInstance] getInfo] getItem];
365 if (o_children != NULL)
367 [o_children release];