1 /*****************************************************************************
2 r playlistinfo.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2006 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];
114 - (IBAction)togglePlaylistInfoPanel:(id)sender
116 if( [o_info_window isVisible] )
118 [self windowShouldClose: nil];
119 [o_info_window orderOut: sender];
123 p_item = [[[VLCMain sharedInstance] getPlaylist] selectedPlaylistItem];
124 [self initPanel:sender];
128 - (IBAction)toggleInfoPanel:(id)sender
130 if( [o_info_window isVisible] )
132 [self windowShouldClose: nil];
133 [o_info_window orderOut: sender];
137 intf_thread_t * p_intf = VLCIntf;
138 playlist_t * p_playlist = pl_Yield( p_intf );
140 p_item = p_playlist->status.p_item;
141 vlc_object_release( p_playlist );
143 [self initPanel:sender];
147 - (void)initPanel:(id)sender
149 BOOL b_stats = config_GetInt(VLCIntf, "stats");
152 o_statUpdateTimer = [NSTimer scheduledTimerWithTimeInterval: 1
153 target: self selector: @selector(updateStatistics:)
154 userInfo: nil repeats: YES];
155 [o_statUpdateTimer fire];
156 [o_statUpdateTimer retain];
160 if( [o_tab_view numberOfTabViewItems] > 2 )
161 [o_tab_view removeTabViewItem: [o_tab_view tabViewItemAtIndex: 2]];
165 [o_info_window makeKeyAndOrderFront: sender];
170 /* make sure that we got the current item and not an outdated one */
171 intf_thread_t * p_intf = VLCIntf;
172 playlist_t * p_playlist = pl_Yield( p_intf );
174 p_item = p_playlist->status.p_item;
175 vlc_object_release( p_playlist );
177 /* check whether our item is valid, because we would crash if not */
178 if(! [self isItemInPlaylist: p_item] ) return;
180 vlc_mutex_lock( &p_item->p_input->lock );
183 if( p_item->p_input->psz_uri )
185 [o_uri_txt setStringValue:
186 ([NSString stringWithUTF8String:p_item->p_input->psz_uri] == nil ) ?
187 [NSString stringWithCString:p_item->p_input->psz_uri] :
188 [NSString stringWithUTF8String:p_item->p_input->psz_uri]];
191 /* fill the other fields */
192 #define p_m p_item->p_input->p_meta
193 [self setMeta: p_m->psz_title forLabel: o_title_txt];
194 [self setMeta: p_m->psz_artist forLabel: o_author_txt];
195 [self setMeta: p_m->psz_album forLabel: o_collection_txt];
196 [self setMeta: p_m->psz_tracknum forLabel: o_seqNum_txt];
197 [self setMeta: p_m->psz_genre forLabel: o_genre_txt];
198 [self setMeta: p_m->psz_copyright forLabel: o_copyright_txt];
199 [self setMeta: p_m->psz_rating forLabel: o_rating_txt];
200 [self setMeta: p_m->psz_publisher forLabel: o_publisher_txt];
201 [self setMeta: p_m->psz_nowplaying forLabel: o_nowPlaying_txt];
202 [self setMeta: p_m->psz_language forLabel: o_language_txt];
203 [self setMeta: p_m->psz_date forLabel: o_date_txt];
205 vlc_mutex_unlock( &p_item->p_input->lock );
207 /* reload the advanced table */
208 [[VLCInfoTreeItem rootItem] refresh];
209 [o_outline_view reloadData];
211 /* update the stats once to display p_item change faster */
212 [self updateStatistics: nil];
215 - (void)setMeta: (char *)psz_meta forLabel: (id)theItem
217 if( psz_meta != NULL && *psz_meta)
218 [theItem setStringValue:
219 ([NSString stringWithUTF8String:psz_meta] == nil ) ?
220 [NSString stringWithCString:psz_meta] :
221 [NSString stringWithUTF8String:psz_meta]];
223 [theItem setStringValue: @"-"];
226 - (void)updateStatistics:(NSTimer*)theTimer
228 if( [self isItemInPlaylist: p_item] )
230 /* we can only do that if there's a valid input around */
232 vlc_mutex_lock( &p_item->p_input->p_stats->lock );
235 [o_read_bytes_txt setStringValue: [NSString stringWithFormat:
236 @"%8.0f kB", (float)(p_item->p_input->p_stats->i_read_bytes)/1000]];
237 [o_input_bitrate_txt setStringValue: [NSString stringWithFormat:
238 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_input_bitrate)*8000]];
239 [o_demux_bytes_txt setStringValue: [NSString stringWithFormat:
240 @"%8.0f kB", (float)(p_item->p_input->p_stats->i_demux_read_bytes)/1000]];
241 [o_demux_bitrate_txt setStringValue: [NSString stringWithFormat:
242 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_demux_bitrate)*8000]];
245 [o_video_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
246 p_item->p_input->p_stats->i_decoded_video]];
247 [o_displayed_txt setStringValue: [NSString stringWithFormat: @"%5i",
248 p_item->p_input->p_stats->i_displayed_pictures]];
249 [o_lost_frames_txt setStringValue: [NSString stringWithFormat: @"%5i",
250 p_item->p_input->p_stats->i_lost_pictures]];
253 [o_sent_packets_txt setStringValue: [NSString stringWithFormat: @"%5i",
254 p_item->p_input->p_stats->i_sent_packets]];
255 [o_sent_bytes_txt setStringValue: [NSString stringWithFormat: @"%8.0f kB",
256 (float)(p_item->p_input->p_stats->i_sent_bytes)/1000]];
257 [o_sent_bitrate_txt setStringValue: [NSString stringWithFormat:
258 @"%6.0f kb/s", (float)(p_item->p_input->p_stats->f_send_bitrate*8)*1000]];
261 [o_audio_decoded_txt setStringValue: [NSString stringWithFormat: @"%5i",
262 p_item->p_input->p_stats->i_decoded_audio]];
263 [o_played_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
264 p_item->p_input->p_stats->i_played_abuffers]];
265 [o_lost_abuffers_txt setStringValue: [NSString stringWithFormat: @"%5i",
266 p_item->p_input->p_stats->i_lost_abuffers]];
268 vlc_mutex_unlock( &p_item->p_input->p_stats->lock );
272 - (IBAction)infoCancel:(id)sender
274 [self windowShouldClose: nil];
275 [o_info_window orderOut: self];
279 - (IBAction)infoOk:(id)sender
281 intf_thread_t * p_intf = VLCIntf;
282 playlist_t * p_playlist = pl_Yield( p_intf );
285 if( [self isItemInPlaylist: p_item] )
287 vlc_mutex_lock( &p_item->p_input->lock );
289 p_item->p_input->psz_uri = strdup( [[o_uri_txt stringValue] UTF8String] );
290 p_item->p_input->psz_name = strdup( [[o_title_txt stringValue] UTF8String] );
291 vlc_meta_SetArtist( p_item->p_input->p_meta, [[o_author_txt stringValue] UTF8String] )
292 vlc_mutex_unlock( &p_item->p_input->lock );
294 val.b_bool = VLC_TRUE;
295 var_Set( p_playlist, "intf-change", val );
297 vlc_object_release( p_playlist );
298 [self windowShouldClose: nil];
299 [o_info_window orderOut: self];
302 - (playlist_item_t *)getItem
307 - (BOOL)isItemInPlaylist:(playlist_item_t *)p_local_item
309 intf_thread_t * p_intf = VLCIntf;
310 playlist_t * p_playlist = pl_Yield( p_intf );
313 for( i = 0 ; i < p_playlist->all_items.i_size ; i++ )
315 if( ARRAY_VAL( p_playlist->all_items, i ) == p_local_item )
317 vlc_object_release( p_playlist );
321 vlc_object_release( p_playlist );
325 - (BOOL)windowShouldClose:(id)sender
327 if( [o_statUpdateTimer isValid] )
328 [o_statUpdateTimer invalidate];
330 if( o_statUpdateTimer )
331 [o_statUpdateTimer release];
338 @implementation VLCInfo (NSMenuValidation)
340 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
342 BOOL bEnabled = TRUE;
344 intf_thread_t * p_intf = VLCIntf;
345 input_thread_t * p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
348 if( [[o_mi title] isEqualToString: _NS("Information")] )
350 if( p_input == NULL )
355 if( p_input ) vlc_object_release( p_input );
362 @implementation VLCInfo (NSTableDataSource)
364 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
366 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
369 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
370 return ([item numberOfChildren] > 0);
373 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
375 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : (id)[item childAtIndex:index];
378 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
380 if ([[tableColumn identifier] isEqualToString:@"0"])
382 return (item == nil) ? @"" : (id)[item getName];
386 return (item == nil) ? @"" : (id)[item getValue];
393 @implementation VLCInfoTreeItem
395 static VLCInfoTreeItem *o_root_item = nil;
397 #define IsALeafNode ((id)-1)
399 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
405 o_name = [o_item_name copy];
406 o_value = [o_item_value copy];
408 o_parent = o_parent_item;
409 if( [[VLCMain sharedInstance] getInfo] != nil )
410 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
417 + (VLCInfoTreeItem *)rootItem {
418 if( o_root_item == nil )
419 o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
425 if( o_children != IsALeafNode ) [o_children release];
430 /* Creates and returns the array of children
431 * Loads children incrementally */
432 - (NSArray *)children
434 if (o_children == NULL)
438 if( [[[VLCMain sharedInstance] getInfo] isItemInPlaylist: p_item] )
440 if( self == o_root_item )
442 vlc_mutex_lock( &p_item->p_input->lock );
443 o_children = [[NSMutableArray alloc] initWithCapacity:
444 p_item->p_input->i_categories];
445 for (i = 0 ; i < p_item->p_input->i_categories ; i++)
447 [o_children addObject:[[VLCInfoTreeItem alloc]
448 initWithName: [NSString stringWithUTF8String:
449 p_item->p_input->pp_categories[i]->psz_name]
454 vlc_mutex_unlock( &p_item->p_input->lock );
456 else if( o_parent == o_root_item )
458 vlc_mutex_lock( &p_item->p_input->lock );
459 o_children = [[NSMutableArray alloc] initWithCapacity:
460 p_item->p_input->pp_categories[i_object_id]->i_infos];
462 for (i = 0 ; i < p_item->p_input->pp_categories[i_object_id]->i_infos ; i++)
464 [o_children addObject:[[VLCInfoTreeItem alloc]
465 initWithName: [NSString stringWithUTF8String:
466 p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_name]
467 value: [NSString stringWithUTF8String:
468 p_item->p_input->pp_categories[i_object_id]->pp_infos[i]->psz_value]
472 vlc_mutex_unlock( &p_item->p_input->lock );
476 o_children = IsALeafNode;
483 - (NSString *)getName
488 - (NSString *)getValue
493 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
494 return [[self children] objectAtIndex:i_index];
497 - (int)numberOfChildren {
498 id i_tmp = [self children];
499 return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
502 /*- (int)selectedPlaylistItem
509 p_item = [[[VLCMain sharedInstance] getInfo] getItem];
510 if( o_children != NULL )
512 [o_children release];