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")];
90 [o_fps_lbl setStringValue: _NS("Frames per Second")];
92 [o_sout_box setTitle: _NS("Streaming")];
93 [o_sent_packets_lbl setStringValue: _NS("Sent packets")];
94 [o_sent_bytes_lbl setStringValue: _NS("Sent bytes")];
95 [o_sent_bitrate_lbl setStringValue: _NS("Send rate")];
97 [o_audio_box setTitle: _NS("Audio")];
98 [o_audio_decoded_lbl setStringValue: _NS("Decoded blocks")];
99 [o_played_abuffers_lbl setStringValue: _NS("Played buffers")];
100 [o_lost_abuffers_lbl setStringValue: _NS("Lost buffers")];
105 /* make sure that the timer is released in any case */
106 if( [o_statUpdateTimer isValid] )
107 [o_statUpdateTimer invalidate];
109 if ( o_statUpdateTimer )
110 [o_statUpdateTimer release];
115 - (IBAction)togglePlaylistInfoPanel:(id)sender
117 if( [o_info_window isVisible] )
119 [self windowShouldClose: nil];
120 [o_info_window orderOut: sender];
124 p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
125 [self initPanel:sender];
129 - (IBAction)toggleInfoPanel:(id)sender
131 if( [o_info_window isVisible] )
133 [self windowShouldClose: nil];
134 [o_info_window orderOut: sender];
138 intf_thread_t * p_intf = VLCIntf;
139 playlist_t * p_playlist = pl_Yield( p_intf );
141 p_item = p_playlist->status.p_item;
142 vlc_object_release( p_playlist );
144 [self initPanel:sender];
148 - (void)initPanel:(id)sender
150 BOOL b_stats = config_GetInt(VLCIntf, "stats");
153 o_statUpdateTimer = [NSTimer scheduledTimerWithTimeInterval: 1
154 target: self selector: @selector(updateStatistics:)
155 userInfo: nil repeats: YES];
156 [o_statUpdateTimer fire];
157 [o_statUpdateTimer retain];
161 if( [o_tab_view numberOfTabViewItems] > 2 )
162 [o_tab_view removeTabViewItem: [o_tab_view tabViewItemAtIndex: 2]];
166 [o_info_window makeKeyAndOrderFront: sender];
171 /* make sure that we got the current item and not an outdated one */
172 intf_thread_t * p_intf = VLCIntf;
173 playlist_t * p_playlist = pl_Yield( p_intf );
175 p_item = p_playlist->status.p_item;
176 vlc_object_release( p_playlist );
178 /* check whether our item is valid, because we would crash if not */
179 if(! [self isItemInPlaylist: p_item] ) return;
182 char *psz_uri = input_item_GetURI( p_item->p_input );
185 [o_uri_txt setStringValue: [NSString stringWithUTF8String:psz_uri]];
189 #define SET( foo, bar ) \
190 char *psz_##foo = input_item_Get##bar ( p_item->p_input ); \
191 [self setMeta: psz_##foo forLabel: o_##foo##_txt]; \
194 /* fill the other fields */
196 SET( author, Artist );
197 SET( collection, Album );
198 SET( seqNum, TrackNum );
200 SET( copyright, Copyright );
201 SET( rating, Rating );
202 SET( publisher, Publisher );
203 SET( nowPlaying, NowPlaying );
204 SET( language, Language );
209 /* reload the advanced table */
210 [[VLCInfoTreeItem rootItem] refresh];
211 [o_outline_view reloadData];
213 /* update the stats once to display p_item change faster */
214 [self updateStatistics: nil];
217 - (void)setMeta: (char *)psz_meta forLabel: (id)theItem
219 if( psz_meta != NULL && *psz_meta)
220 [theItem setStringValue: [NSString stringWithUTF8String:psz_meta]];
222 [theItem setStringValue: @"-"];
225 - (void)updateStatistics:(NSTimer*)theTimer
227 if( [self isItemInPlaylist: p_item] )
229 /* we can only do that if there's a valid input around */
231 vlc_mutex_lock( &p_item->p_input->p_stats->lock );
234 [o_read_bytes_txt setStringValue: [NSString stringWithFormat:
235 @"%8.0f kB", (float)(p_item->p_input->p_stats->i_read_bytes)/1000]];
236 [o_input_bitrate_txt setStringValue: [NSString stringWithFormat:
237 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_input_bitrate)*8000]];
238 [o_demux_bytes_txt setStringValue: [NSString stringWithFormat:
239 @"%8.0f kB", (float)(p_item->p_input->p_stats->i_demux_read_bytes)/1000]];
240 [o_demux_bitrate_txt setStringValue: [NSString stringWithFormat:
241 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_demux_bitrate)*8000]];
244 [o_video_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
245 p_item->p_input->p_stats->i_decoded_video]];
246 [o_displayed_txt setStringValue: [NSString stringWithFormat: @"%5i",
247 p_item->p_input->p_stats->i_displayed_pictures]];
248 [o_lost_frames_txt setStringValue: [NSString stringWithFormat: @"%5i",
249 p_item->p_input->p_stats->i_lost_pictures]];
252 [o_sent_packets_txt setStringValue: [NSString stringWithFormat: @"%5i",
253 p_item->p_input->p_stats->i_sent_packets]];
254 [o_sent_bytes_txt setStringValue: [NSString stringWithFormat: @"%8.0f kB",
255 (float)(p_item->p_input->p_stats->i_sent_bytes)/1000]];
256 [o_sent_bitrate_txt setStringValue: [NSString stringWithFormat:
257 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_send_bitrate*8)*1000]];
260 [o_audio_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
261 p_item->p_input->p_stats->i_decoded_audio]];
262 [o_played_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
263 p_item->p_input->p_stats->i_played_abuffers]];
264 [o_lost_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
265 p_item->p_input->p_stats->i_lost_abuffers]];
267 vlc_mutex_unlock( &p_item->p_input->p_stats->lock );
271 - (IBAction)infoCancel:(id)sender
273 [self windowShouldClose: nil];
274 [o_info_window orderOut: self];
278 - (IBAction)infoOk:(id)sender
280 intf_thread_t * p_intf = VLCIntf;
281 playlist_t * p_playlist = pl_Yield( p_intf );
284 if( [self isItemInPlaylist: p_item] )
286 input_item_SetName( p_item->p_input, (char*)
287 [[o_title_txt stringValue] UTF8String] );
288 input_item_SetURI( p_item->p_input, (char*)
289 [[o_uri_txt stringValue] UTF8String] );
290 input_item_SetArtist( p_item->p_input, (char*)
291 [[o_author_txt stringValue] UTF8String] );
293 val.b_bool = VLC_TRUE;
294 var_Set( p_playlist, "intf-change", val );
296 vlc_object_release( p_playlist );
297 [self windowShouldClose: nil];
298 [o_info_window orderOut: self];
301 - (playlist_item_t *)getItem
306 - (BOOL)isItemInPlaylist:(playlist_item_t *)p_local_item
308 intf_thread_t * p_intf = VLCIntf;
309 playlist_t * p_playlist = pl_Yield( p_intf );
312 for( i = 0 ; i < p_playlist->all_items.i_size ; i++ )
314 if( ARRAY_VAL( p_playlist->all_items, i ) == p_local_item )
316 vlc_object_release( p_playlist );
320 vlc_object_release( p_playlist );
324 - (BOOL)windowShouldClose:(id)sender
326 if( [o_statUpdateTimer isValid] )
327 [o_statUpdateTimer invalidate];
329 if( o_statUpdateTimer )
330 [o_statUpdateTimer release];
337 @implementation VLCInfo (NSMenuValidation)
339 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
341 BOOL bEnabled = TRUE;
343 intf_thread_t * p_intf = VLCIntf;
344 input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
347 if( [[o_mi title] isEqualToString: _NS("Information")] )
349 if( p_input == NULL )
354 if( p_input ) vlc_object_release( p_input );
361 @implementation VLCInfo (NSTableDataSource)
363 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
365 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
368 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
369 return ([item numberOfChildren] > 0);
372 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
374 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : (id)[item childAtIndex:index];
377 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
379 if ([[tableColumn identifier] isEqualToString:@"0"])
381 return (item == nil) ? @"" : (id)[item getName];
385 return (item == nil) ? @"" : (id)[item getValue];
392 @implementation VLCInfoTreeItem
394 static VLCInfoTreeItem *o_root_item = nil;
396 #define IsALeafNode ((id)-1)
398 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
404 o_name = [o_item_name copy];
405 o_value = [o_item_value copy];
407 o_parent = o_parent_item;
408 if( [[VLCMain sharedInstance] getInfo] != nil )
409 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
416 + (VLCInfoTreeItem *)rootItem {
417 if( o_root_item == nil )
418 o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
424 if( o_children != IsALeafNode ) [o_children release];
429 /* Creates and returns the array of children
430 * Loads children incrementally */
431 - (NSArray *)children
433 if (o_children == NULL)
437 if( [[[VLCMain sharedInstance] getInfo] isItemInPlaylist: p_item] )
439 if( self == o_root_item )
441 vlc_mutex_lock( &p_item->p_input->lock );
442 o_children = [[NSMutableArray alloc] initWithCapacity:
443 p_item->p_input->i_categories];
444 for (i = 0 ; i < p_item->p_input->i_categories ; i++)
446 [o_children addObject:[[VLCInfoTreeItem alloc]
447 initWithName: [NSString stringWithUTF8String:
448 p_item->p_input->pp_categories[i]->psz_name]
453 vlc_mutex_unlock( &p_item->p_input->lock );
455 else if( o_parent == o_root_item )
457 vlc_mutex_lock( &p_item->p_input->lock );
458 o_children = [[NSMutableArray alloc] initWithCapacity:
459 p_item->p_input->pp_categories[i_object_id]->i_infos];
461 for (i = 0 ; i < p_item->p_input->pp_categories[i_object_id]->i_infos ; i++)
463 [o_children addObject:[[VLCInfoTreeItem alloc]
464 initWithName: [NSString stringWithUTF8String:
465 p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_name]
466 value: [NSString stringWithUTF8String:
467 p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_value ? : ""]
471 vlc_mutex_unlock( &p_item->p_input->lock );
475 o_children = IsALeafNode;
482 - (NSString *)getName
487 - (NSString *)getValue
492 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
493 return [[self children] objectAtIndex:i_index];
496 - (int)numberOfChildren {
497 id i_tmp = [self children];
498 return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
503 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
504 if( o_children != NULL )
506 [o_children release];