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
51 [o_info_window setExcludedFromWindowsMenu: TRUE];
53 [o_info_window setTitle: _NS("Properties")];
54 [o_uri_lbl setStringValue: _NS("URI")];
55 [o_title_lbl setStringValue: _NS("Title")];
56 [o_author_lbl setStringValue: _NS("Author")];
57 [o_btn_ok setTitle: _NS("OK")];
58 [o_btn_cancel setTitle: _NS("Cancel")];
61 - (IBAction)togglePlaylistInfoPanel:(id)sender
63 if( [o_info_window isVisible] )
65 [o_info_window orderOut: sender];
69 p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
70 [self initPanel:sender];
74 - (IBAction)toggleInfoPanel:(id)sender
76 if( [o_info_window isVisible] )
78 [o_info_window orderOut: sender];
82 intf_thread_t * p_intf = VLCIntf;
83 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
88 p_item = p_playlist->status.p_item;
89 vlc_object_release( p_playlist );
91 [self initPanel:sender];
95 - (void)initPanel:(id)sender
98 vlc_mutex_lock( &p_item->input.lock );
100 /*fill uri / title / author info */
101 if( p_item->input.psz_uri )
103 [o_uri_txt setStringValue:
104 ([NSString stringWithUTF8String:p_item->input.psz_uri] == nil ) ?
105 [NSString stringWithCString:p_item->input.psz_uri] :
106 [NSString stringWithUTF8String:p_item->input.psz_uri]];
109 if( p_item->input.psz_name )
111 [o_title_txt setStringValue:
112 ([NSString stringWithUTF8String:p_item->input.psz_name] == nil ) ?
113 [NSString stringWithCString:p_item->input.psz_name] :
114 [NSString stringWithUTF8String:p_item->input.psz_name]];
116 vlc_mutex_unlock( &p_item->input.lock );
118 psz_temp = vlc_input_item_GetInfo( &p_item->input, _("Meta-information"), _("Artist") );
122 [o_author_txt setStringValue: [NSString stringWithUTF8String: psz_temp]];
127 [[VLCInfoTreeItem rootItem] refresh];
128 [o_outline_view reloadData];
130 [o_info_window makeKeyAndOrderFront: sender];
133 - (IBAction)infoCancel:(id)sender
135 [o_info_window orderOut: self];
139 - (IBAction)infoOk:(id)sender
141 intf_thread_t * p_intf = VLCIntf;
142 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
146 if ([self isItemInPlaylist: p_item] )
148 vlc_mutex_lock( &p_item->input.lock );
150 p_item->input.psz_uri = strdup( [[o_uri_txt stringValue] UTF8String] );
151 p_item->input.psz_name = strdup( [[o_title_txt stringValue] UTF8String] );
152 vlc_mutex_unlock( &p_item->input.lock );
153 vlc_input_item_AddInfo( &p_item->input, _("Meta-information"), _("Artist"), [[o_author_txt stringValue] UTF8String]);
155 val.b_bool = VLC_TRUE;
156 var_Set( p_playlist, "intf-change", val );
159 [o_info_window orderOut: self];
162 - (playlist_item_t *)getItem
167 - (BOOL)isItemInPlaylist:(playlist_item_t *)p_local_item
169 intf_thread_t * p_intf = VLCIntf;
170 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
174 if( p_playlist == NULL )
179 for( i = 0 ; i < p_playlist->i_size ; i++ )
181 if( p_playlist->pp_items[i] == p_local_item )
183 vlc_object_release( p_playlist );
187 vlc_object_release( p_playlist );
193 @implementation VLCInfo (NSMenuValidation)
195 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
197 BOOL bEnabled = TRUE;
199 intf_thread_t * p_intf = VLCIntf;
200 input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
203 if( [[o_mi title] isEqualToString: _NS("Info")] )
205 if( p_input == NULL )
210 if( p_input ) vlc_object_release( p_input );
217 @implementation VLCInfo (NSTableDataSource)
219 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
221 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
224 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
225 return ([item numberOfChildren] > 0);
228 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
230 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
233 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
235 if ([[tableColumn identifier] isEqualToString:@"0"])
237 return (item == nil) ? @"" : (id)[item getName];
241 return (item == nil) ? @"" : (id)[item getValue];
248 @implementation VLCInfoTreeItem
250 static VLCInfoTreeItem *o_root_item = nil;
252 #define IsALeafNode ((id)-1)
254 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
260 o_name = [o_item_name copy];
261 o_value = [o_item_value copy];
263 o_parent = o_parent_item;
264 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
269 + (VLCInfoTreeItem *)rootItem {
270 if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
276 if( o_children != IsALeafNode ) [o_children release];
281 /* Creates and returns the array of children
282 * Loads children incrementally */
283 - (NSArray *)children
285 if (o_children == NULL)
289 if( [[[VLCMain sharedInstance] getInfo] isItemInPlaylist: p_item] )
291 if( self == o_root_item )
293 vlc_mutex_lock( &p_item->input.lock );
294 o_children = [[NSMutableArray alloc] initWithCapacity:
295 p_item->input.i_categories];
296 for (i = 0 ; i < p_item->input.i_categories ; i++)
298 [o_children addObject:[[VLCInfoTreeItem alloc]
299 initWithName: [NSString stringWithUTF8String:
300 p_item->input.pp_categories[i]->psz_name]
305 vlc_mutex_unlock( &p_item->input.lock );
307 else if( o_parent == o_root_item )
309 vlc_mutex_lock( &p_item->input.lock );
310 o_children = [[NSMutableArray alloc] initWithCapacity:
311 p_item->input.pp_categories[i_object_id]->i_infos];
313 for (i = 0 ; i < p_item->input.pp_categories[i_object_id]->i_infos ; i++)
315 [o_children addObject:[[VLCInfoTreeItem alloc]
316 initWithName: [NSString stringWithUTF8String:
317 p_item->input.pp_categories[i_object_id]->pp_infos[i]->psz_name]
318 value: [NSString stringWithUTF8String:
319 p_item->input.pp_categories[i_object_id]->pp_infos[i]->psz_value]
323 vlc_mutex_unlock( &p_item->input.lock );
327 o_children = IsALeafNode;
334 - (NSString *)getName
339 - (NSString *)getValue
344 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
345 return [[self children] objectAtIndex:i_index];
348 - (int)numberOfChildren {
349 id i_tmp = [self children];
350 return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
353 /*- (int)selectedPlaylistItem
360 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
361 if( o_children != NULL )
363 [o_children release];