1 /*****************************************************************************
2 r playlistinfo.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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")];
60 [[o_tab_view tabViewItemAtIndex: 0] setLabel: _NS("General")];
61 [[o_tab_view tabViewItemAtIndex: 1] setLabel: _NS("Advanced Information")];
62 [[o_tab_view tabViewItemAtIndex: 2] setLabel: _NS("Statistics")];
63 [o_tab_view selectTabViewItemAtIndex: 0];
65 /* constants defined in vlc_meta.h */
66 [o_genre_lbl setStringValue: _NS(VLC_META_GENRE)];
67 [o_copyright_lbl setStringValue: _NS(VLC_META_COPYRIGHT)];
68 [o_collection_lbl setStringValue: _NS(VLC_META_COLLECTION)];
69 [o_seqNum_lbl setStringValue: _NS(VLC_META_SEQ_NUM)];
70 [o_description_lbl setStringValue: _NS(VLC_META_DESCRIPTION)];
71 [o_rating_lbl setStringValue: _NS(VLC_META_RATING)];
72 [o_date_lbl setStringValue: _NS(VLC_META_DATE)];
73 [o_language_lbl setStringValue: _NS(VLC_META_LANGUAGE)];
74 [o_nowPlaying_lbl setStringValue: _NS(VLC_META_NOW_PLAYING)];
75 [o_publisher_lbl setStringValue: _NS(VLC_META_PUBLISHER)];
78 - (IBAction)togglePlaylistInfoPanel:(id)sender
80 if( [o_info_window isVisible] )
82 [o_info_window orderOut: sender];
86 p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
87 [self initPanel:sender];
91 - (IBAction)toggleInfoPanel:(id)sender
93 if( [o_info_window isVisible] )
95 [o_info_window orderOut: sender];
99 intf_thread_t * p_intf = VLCIntf;
100 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
105 p_item = p_playlist->status.p_item;
106 vlc_object_release( p_playlist );
108 [self initPanel:sender];
112 - (void)initPanel:(id)sender
115 vlc_mutex_lock( &p_item->input.lock );
117 /*fill uri / title / author info */
118 if( p_item->input.psz_uri )
120 [o_uri_txt setStringValue:
121 ([NSString stringWithUTF8String:p_item->input.psz_uri] == nil ) ?
122 [NSString stringWithCString:p_item->input.psz_uri] :
123 [NSString stringWithUTF8String:p_item->input.psz_uri]];
126 if( p_item->input.psz_name )
128 [o_title_txt setStringValue:
129 ([NSString stringWithUTF8String:p_item->input.psz_name] == nil ) ?
130 [NSString stringWithCString:p_item->input.psz_name] :
131 [NSString stringWithUTF8String:p_item->input.psz_name]];
133 vlc_mutex_unlock( &p_item->input.lock );
135 psz_temp = vlc_input_item_GetInfo( &p_item->input, _("Meta-information"), _("Artist") );
139 [o_author_txt setStringValue: [NSString stringWithUTF8String: psz_temp]];
143 /* fill the other fields */
144 [self setMeta: VLC_META_GENRE forLabel: o_genre_txt];
145 [self setMeta: VLC_META_COPYRIGHT forLabel: o_copyright_txt];
146 [self setMeta: VLC_META_COLLECTION forLabel: o_collection_txt];
147 [self setMeta: VLC_META_SEQ_NUM forLabel: o_seqNum_txt];
148 [self setMeta: VLC_META_DESCRIPTION forLabel: o_description_txt];
149 [self setMeta: VLC_META_RATING forLabel: o_rating_txt];
150 [self setMeta: VLC_META_DATE forLabel: o_date_txt];
151 [self setMeta: VLC_META_LANGUAGE forLabel: o_language_txt];
152 [self setMeta: VLC_META_NOW_PLAYING forLabel: o_nowPlaying_txt];
153 [self setMeta: VLC_META_PUBLISHER forLabel: o_publisher_txt];
155 /* reload the advanced table */
156 [[VLCInfoTreeItem rootItem] refresh];
157 [o_outline_view reloadData];
159 [o_info_window makeKeyAndOrderFront: sender];
162 - (void)setMeta: (char *)meta forLabel: (id)theItem
164 char *psz_meta = vlc_input_item_GetInfo( &p_item->input, \
165 _(VLC_META_INFO_CAT), _(meta) );
166 if( psz_meta != NULL && *psz_meta)
167 [theItem setStringValue: [NSString stringWithUTF8String: psz_meta]];
169 [theItem setStringValue: @"-"];
172 - (IBAction)infoCancel:(id)sender
174 [o_info_window orderOut: self];
178 - (IBAction)infoOk:(id)sender
180 intf_thread_t * p_intf = VLCIntf;
181 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
185 if( [self isItemInPlaylist: p_item] )
187 vlc_mutex_lock( &p_item->input.lock );
189 p_item->input.psz_uri = strdup( [[o_uri_txt stringValue] UTF8String] );
190 p_item->input.psz_name = strdup( [[o_title_txt stringValue] UTF8String] );
191 vlc_mutex_unlock( &p_item->input.lock );
192 vlc_input_item_AddInfo( &p_item->input, _("Meta-information"), _("Artist"), [[o_author_txt stringValue] UTF8String]);
194 val.b_bool = VLC_TRUE;
195 var_Set( p_playlist, "intf-change", val );
197 vlc_object_release( p_playlist );
198 [o_info_window orderOut: self];
201 - (playlist_item_t *)getItem
206 - (BOOL)isItemInPlaylist:(playlist_item_t *)p_local_item
208 intf_thread_t * p_intf = VLCIntf;
209 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
213 if( p_playlist == NULL )
218 for( i = 0 ; i < p_playlist->i_size ; i++ )
220 if( p_playlist->pp_items[i] == p_local_item )
222 vlc_object_release( p_playlist );
226 vlc_object_release( p_playlist );
232 @implementation VLCInfo (NSMenuValidation)
234 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
236 BOOL bEnabled = TRUE;
238 intf_thread_t * p_intf = VLCIntf;
239 input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
242 if( [[o_mi title] isEqualToString: _NS("Info")] )
244 if( p_input == NULL )
249 if( p_input ) vlc_object_release( p_input );
256 @implementation VLCInfo (NSTableDataSource)
258 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
260 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
263 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
264 return ([item numberOfChildren] > 0);
267 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
269 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
272 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
274 if ([[tableColumn identifier] isEqualToString:@"0"])
276 return (item == nil) ? @"" : (id)[item getName];
280 return (item == nil) ? @"" : (id)[item getValue];
287 @implementation VLCInfoTreeItem
289 static VLCInfoTreeItem *o_root_item = nil;
291 #define IsALeafNode ((id)-1)
293 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
299 o_name = [o_item_name copy];
300 o_value = [o_item_value copy];
302 o_parent = o_parent_item;
303 if( [[VLCMain sharedInstance] getInfo] != nil )
304 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
311 + (VLCInfoTreeItem *)rootItem {
312 if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
318 if( o_children != IsALeafNode ) [o_children release];
323 /* Creates and returns the array of children
324 * Loads children incrementally */
325 - (NSArray *)children
327 if (o_children == NULL)
331 if( [[[VLCMain sharedInstance] getInfo] isItemInPlaylist: p_item] )
333 if( self == o_root_item )
335 vlc_mutex_lock( &p_item->input.lock );
336 o_children = [[NSMutableArray alloc] initWithCapacity:
337 p_item->input.i_categories];
338 for (i = 0 ; i < p_item->input.i_categories ; i++)
340 [o_children addObject:[[VLCInfoTreeItem alloc]
341 initWithName: [NSString stringWithUTF8String:
342 p_item->input.pp_categories[i]->psz_name]
347 vlc_mutex_unlock( &p_item->input.lock );
349 else if( o_parent == o_root_item )
351 vlc_mutex_lock( &p_item->input.lock );
352 o_children = [[NSMutableArray alloc] initWithCapacity:
353 p_item->input.pp_categories[i_object_id]->i_infos];
355 for (i = 0 ; i < p_item->input.pp_categories[i_object_id]->i_infos ; i++)
357 [o_children addObject:[[VLCInfoTreeItem alloc]
358 initWithName: [NSString stringWithUTF8String:
359 p_item->input.pp_categories[i_object_id]->pp_infos[i]->psz_name]
360 value: [NSString stringWithUTF8String:
361 p_item->input.pp_categories[i_object_id]->pp_infos[i]->psz_value]
365 vlc_mutex_unlock( &p_item->input.lock );
369 o_children = IsALeafNode;
376 - (NSString *)getName
381 - (NSString *)getValue
386 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
387 return [[self children] objectAtIndex:i_index];
390 - (int)numberOfChildren {
391 id i_tmp = [self children];
392 return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
395 /*- (int)selectedPlaylistItem
402 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
403 if( o_children != NULL )
405 [o_children release];