1 /*****************************************************************************
2 r playlistinfo.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Benjamin Pracht <bigben at videolan dot org>
8 * Felix Kühne <fkuehne at videolan dot org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
30 #include "playlistinfo.h"
33 /*****************************************************************************
34 * VLCPlaylistInfo Implementation
35 *****************************************************************************/
37 @implementation VLCInfo
46 o_statUpdateTimer = nil;
53 [o_info_window setExcludedFromWindowsMenu: TRUE];
55 [o_info_window setTitle: _NS("Information")];
56 [o_uri_lbl setStringValue: _NS("URI")];
57 [o_title_lbl setStringValue: _NS("Title")];
58 [o_author_lbl setStringValue: _NS("Author")];
59 [o_btn_ok setTitle: _NS("OK")];
60 [o_btn_cancel setTitle: _NS("Cancel")];
62 [[o_tab_view tabViewItemAtIndex: 0] setLabel: _NS("General")];
63 [[o_tab_view tabViewItemAtIndex: 1] setLabel: _NS("Advanced Information")];
64 [[o_tab_view tabViewItemAtIndex: 2] setLabel: _NS("Statistics")];
65 [o_tab_view selectTabViewItemAtIndex: 0];
67 /* constants defined in vlc_meta.h */
68 [o_genre_lbl setStringValue: _NS(VLC_META_GENRE)];
69 [o_copyright_lbl setStringValue: _NS(VLC_META_COPYRIGHT)];
70 [o_collection_lbl setStringValue: _NS(VLC_META_COLLECTION)];
71 [o_seqNum_lbl setStringValue: _NS(VLC_META_SEQ_NUM)];
72 [o_description_lbl setStringValue: _NS(VLC_META_DESCRIPTION)];
73 [o_rating_lbl setStringValue: _NS(VLC_META_RATING)];
74 [o_date_lbl setStringValue: _NS(VLC_META_DATE)];
75 [o_language_lbl setStringValue: _NS(VLC_META_LANGUAGE)];
76 [o_nowPlaying_lbl setStringValue: _NS(VLC_META_NOW_PLAYING)];
77 [o_publisher_lbl setStringValue: _NS(VLC_META_PUBLISHER)];
80 [o_input_box setTitle: _NS("Input")];
81 [o_read_bytes_lbl setStringValue: _NS("Read at media")];
82 [o_input_bitrate_lbl setStringValue: _NS("Input bitrate")];
83 [o_demux_bytes_lbl setStringValue: _NS("Demuxed")];
84 [o_demux_bitrate_lbl setStringValue: _NS("Stream bitrate")];
86 [o_video_box setTitle: _NS("Video")];
87 [o_video_decoded_lbl setStringValue: _NS("Decoded blocks")];
88 [o_displayed_lbl setStringValue: _NS("Displayed frames")];
89 [o_lost_frames_lbl setStringValue: _NS("Lost frames")];
91 [o_sout_box setTitle: _NS("Streaming")];
92 [o_sent_packets_lbl setStringValue: _NS("Sent packets")];
93 [o_sent_bytes_lbl setStringValue: _NS("Sent bytes")];
94 [o_sent_bitrate_lbl setStringValue: _NS("Send rate")];
96 [o_audio_box setTitle: _NS("Audio")];
97 [o_audio_decoded_lbl setStringValue: _NS("Decoded blocks")];
98 [o_played_abuffers_lbl setStringValue: _NS("Played buffers")];
99 [o_lost_abuffers_lbl setStringValue: _NS("Lost buffers")];
104 /* make sure that the timer is released in any case */
105 if( [o_statUpdateTimer isValid] )
106 [o_statUpdateTimer invalidate];
108 if ( o_statUpdateTimer )
109 [o_statUpdateTimer release];
117 /* since dealloc isn't called with enabled GC on 10.5, we need this to prevent core crashes */
118 if( [o_statUpdateTimer isValid] )
119 [o_statUpdateTimer invalidate];
124 - (IBAction)togglePlaylistInfoPanel:(id)sender
126 if( [o_info_window isVisible] )
128 [self windowShouldClose: nil];
129 [o_info_window orderOut: sender];
133 p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
134 [self initPanel:sender];
138 - (IBAction)toggleInfoPanel:(id)sender
140 if( [o_info_window isVisible] )
142 [self windowShouldClose: nil];
143 [o_info_window orderOut: sender];
147 intf_thread_t * p_intf = VLCIntf;
148 playlist_t * p_playlist = pl_Yield( p_intf );
150 p_item = p_playlist->status.p_item;
151 vlc_object_release( p_playlist );
153 [self initPanel:sender];
157 - (void)initPanel:(id)sender
159 BOOL b_stats = config_GetInt(VLCIntf, "stats");
162 o_statUpdateTimer = [NSTimer scheduledTimerWithTimeInterval: 1
163 target: self selector: @selector(updateStatistics:)
164 userInfo: nil repeats: YES];
165 [o_statUpdateTimer fire];
166 [o_statUpdateTimer retain];
170 if( [o_tab_view numberOfTabViewItems] > 2 )
171 [o_tab_view removeTabViewItem: [o_tab_view tabViewItemAtIndex: 2]];
175 [o_info_window makeKeyAndOrderFront: sender];
180 /* make sure that we got the current item and not an outdated one */
181 intf_thread_t * p_intf = VLCIntf;
182 playlist_t * p_playlist = pl_Yield( p_intf );
184 p_item = p_playlist->status.p_item;
185 vlc_object_release( p_playlist );
187 /* check whether our item is valid, because we would crash if not */
188 if(! [self isItemInPlaylist: p_item] ) return;
190 vlc_mutex_lock( &p_item->p_input->lock );
193 if( p_item->p_input->psz_uri )
195 [o_uri_txt setStringValue:
196 ([NSString stringWithUTF8String:p_item->p_input->psz_uri] == nil ) ?
197 [NSString stringWithCString:p_item->p_input->psz_uri] :
198 [NSString stringWithUTF8String:p_item->p_input->psz_uri]];
201 vlc_mutex_unlock( &p_item->p_input->lock );
203 /* fill the other fields */
204 [self setMeta: input_item_GetTitle( p_item->p_input ) forLabel: o_title_txt];
205 [self setMeta: input_item_GetArtist( p_item->p_input ) forLabel: o_author_txt];
206 [self setMeta: input_item_GetAlbum( p_item->p_input ) forLabel: o_collection_txt];
207 [self setMeta: input_item_GetTrackNum( p_item->p_input ) forLabel: o_seqNum_txt];
208 [self setMeta: input_item_GetGenre( p_item->p_input ) forLabel: o_genre_txt];
209 [self setMeta: input_item_GetCopyright( p_item->p_input ) forLabel: o_copyright_txt];
210 [self setMeta: input_item_GetRating( p_item->p_input ) forLabel: o_rating_txt];
211 [self setMeta: input_item_GetPublisher( p_item->p_input ) forLabel: o_publisher_txt];
212 [self setMeta: input_item_GetNowPlaying( p_item->p_input ) forLabel: o_nowPlaying_txt];
213 [self setMeta: input_item_GetLanguage( p_item->p_input ) forLabel: o_language_txt];
214 [self setMeta: input_item_GetDate( p_item->p_input ) forLabel: o_date_txt];
216 /* reload the advanced table */
217 [[VLCInfoTreeItem rootItem] refresh];
218 [o_outline_view reloadData];
220 /* update the stats once to display p_item change faster */
221 [self updateStatistics: nil];
224 - (void)setMeta: (char *)psz_meta forLabel: (id)theItem
226 if( psz_meta != NULL && *psz_meta)
227 [theItem setStringValue:
228 ([NSString stringWithUTF8String:psz_meta] == nil ) ?
229 [NSString stringWithCString:psz_meta] :
230 [NSString stringWithUTF8String:psz_meta]];
232 [theItem setStringValue: @"-"];
235 - (void)updateStatistics:(NSTimer*)theTimer
237 if( [self isItemInPlaylist: p_item] )
239 /* we can only do that if there's a valid input around */
241 vlc_mutex_lock( &p_item->p_input->p_stats->lock );
244 [o_read_bytes_txt setStringValue: [NSString stringWithFormat:
245 @"%8.0f kB", (float)(p_item->p_input->p_stats->i_read_bytes)/1000]];
246 [o_input_bitrate_txt setStringValue: [NSString stringWithFormat:
247 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_input_bitrate)*8000]];
248 [o_demux_bytes_txt setStringValue: [NSString stringWithFormat:
249 @"%8.0f kB", (float)(p_item->p_input->p_stats->i_demux_read_bytes)/1000]];
250 [o_demux_bitrate_txt setStringValue: [NSString stringWithFormat:
251 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_demux_bitrate)*8000]];
254 [o_video_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
255 p_item->p_input->p_stats->i_decoded_video]];
256 [o_displayed_txt setStringValue: [NSString stringWithFormat: @"%5i",
257 p_item->p_input->p_stats->i_displayed_pictures]];
258 [o_lost_frames_txt setStringValue: [NSString stringWithFormat: @"%5i",
259 p_item->p_input->p_stats->i_lost_pictures]];
262 [o_sent_packets_txt setStringValue: [NSString stringWithFormat: @"%5i",
263 p_item->p_input->p_stats->i_sent_packets]];
264 [o_sent_bytes_txt setStringValue: [NSString stringWithFormat: @"%8.0f kB",
265 (float)(p_item->p_input->p_stats->i_sent_bytes)/1000]];
266 [o_sent_bitrate_txt setStringValue: [NSString stringWithFormat:
267 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_send_bitrate*8)*1000]];
270 [o_audio_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
271 p_item->p_input->p_stats->i_decoded_audio]];
272 [o_played_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
273 p_item->p_input->p_stats->i_played_abuffers]];
274 [o_lost_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
275 p_item->p_input->p_stats->i_lost_abuffers]];
277 vlc_mutex_unlock( &p_item->p_input->p_stats->lock );
281 - (IBAction)infoCancel:(id)sender
283 [self windowShouldClose: nil];
284 [o_info_window orderOut: self];
288 - (IBAction)infoOk:(id)sender
290 intf_thread_t * p_intf = VLCIntf;
291 playlist_t * p_playlist = pl_Yield( p_intf );
294 if( [self isItemInPlaylist: p_item] )
296 vlc_mutex_lock( &p_item->p_input->lock );
298 p_item->p_input->psz_uri = strdup( [[o_uri_txt stringValue] UTF8String] );
299 p_item->p_input->psz_name = strdup( [[o_title_txt stringValue] UTF8String] );
300 vlc_mutex_unlock( &p_item->p_input->lock );
301 input_item_SetArtist( p_item->p_input, [[o_author_txt stringValue] UTF8String] );
303 val.b_bool = VLC_TRUE;
304 var_Set( p_playlist, "intf-change", val );
306 vlc_object_release( p_playlist );
307 [self windowShouldClose: nil];
308 [o_info_window orderOut: self];
311 - (playlist_item_t *)getItem
316 - (BOOL)isItemInPlaylist:(playlist_item_t *)p_local_item
318 intf_thread_t * p_intf = VLCIntf;
319 playlist_t * p_playlist = pl_Yield( p_intf );
322 for( i = 0 ; i < p_playlist->all_items.i_size ; i++ )
324 if( ARRAY_VAL( p_playlist->all_items, i ) == p_local_item )
326 vlc_object_release( p_playlist );
330 vlc_object_release( p_playlist );
334 - (BOOL)windowShouldClose:(id)sender
336 if( [o_statUpdateTimer isValid] )
337 [o_statUpdateTimer invalidate];
339 if( o_statUpdateTimer )
340 [o_statUpdateTimer release];
347 @implementation VLCInfo (NSMenuValidation)
349 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
351 BOOL bEnabled = TRUE;
353 intf_thread_t * p_intf = VLCIntf;
354 input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
357 if( [[o_mi title] isEqualToString: _NS("Information")] )
359 if( p_input == NULL )
364 if( p_input ) vlc_object_release( p_input );
371 @implementation VLCInfo (NSTableDataSource)
373 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
375 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
378 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
379 return ([item numberOfChildren] > 0);
382 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
384 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : (id)[item childAtIndex:index];
387 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
389 if ([[tableColumn identifier] isEqualToString:@"0"])
391 return (item == nil) ? @"" : (id)[item getName];
395 return (item == nil) ? @"" : (id)[item getValue];
402 @implementation VLCInfoTreeItem
404 static VLCInfoTreeItem *o_root_item = nil;
406 #define IsALeafNode ((id)-1)
408 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
414 o_name = [o_item_name copy];
415 o_value = [o_item_value copy];
417 o_parent = o_parent_item;
418 if( [[VLCMain sharedInstance] getInfo] != nil )
419 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
426 + (VLCInfoTreeItem *)rootItem {
427 if( o_root_item == nil )
428 o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
434 if( o_children != IsALeafNode ) [o_children release];
439 /* Creates and returns the array of children
440 * Loads children incrementally */
441 - (NSArray *)children
443 if (o_children == NULL)
447 if( [[[VLCMain sharedInstance] getInfo] isItemInPlaylist: p_item] )
449 if( self == o_root_item )
451 vlc_mutex_lock( &p_item->p_input->lock );
452 o_children = [[NSMutableArray alloc] initWithCapacity:
453 p_item->p_input->i_categories];
454 for (i = 0 ; i < p_item->p_input->i_categories ; i++)
456 [o_children addObject:[[VLCInfoTreeItem alloc]
457 initWithName: [NSString stringWithUTF8String:
458 p_item->p_input->pp_categories[i]->psz_name]
463 vlc_mutex_unlock( &p_item->p_input->lock );
465 else if( o_parent == o_root_item )
467 vlc_mutex_lock( &p_item->p_input->lock );
468 o_children = [[NSMutableArray alloc] initWithCapacity:
469 p_item->p_input->pp_categories[i_object_id]->i_infos];
471 for (i = 0 ; i < p_item->p_input->pp_categories[i_object_id]->i_infos ; i++)
473 [o_children addObject:[[VLCInfoTreeItem alloc]
474 initWithName: [NSString stringWithUTF8String:
475 p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_name]
476 value: [NSString stringWithUTF8String:
477 p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_value]
481 vlc_mutex_unlock( &p_item->p_input->lock );
485 o_children = IsALeafNode;
492 - (NSString *)getName
497 - (NSString *)getValue
502 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
503 return [[self children] objectAtIndex:i_index];
506 - (int)numberOfChildren {
507 id i_tmp = [self children];
508 return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
511 /*- (int)selectedPlaylistItem
518 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
519 if( o_children != NULL )
521 [o_children release];