- vlc_mutex_lock(&p_playlist->pp_items[i_item]->lock);
-
- p_playlist->pp_items[i_item]->psz_uri = strdup([[o_uri_txt stringValue] cString]);
- p_playlist->pp_items[i_item]->psz_name = strdup([[o_title_txt stringValue] cString]);
- playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
-
- vlc_mutex_unlock(&p_playlist->pp_items[i_item]->lock);
- val.b_bool = VLC_TRUE;
- var_Set( p_playlist,"int-change",val );
- vlc_object_release ( p_playlist );
- }
- [self togglePlaylistInfoPanel:self];
-
-}
+ return ![[[VLCMain sharedInstance] getPlaylist] isSelectionEmpty];
+ }
+
+ return TRUE;
+}
+
+@end
+
+@implementation VLCInfo (NSTableDataSource)
+
+- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
+{
+ return (item == nil) ? [rootItem numberOfChildren] : [item numberOfChildren];
+}
+
+- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
+ return ([item numberOfChildren] > 0);
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
+{
+ return (item == nil) ? [rootItem childAtIndex:index] : (id)[item childAtIndex:index];
+}
+
+- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
+{
+ if ([[tableColumn identifier] isEqualToString:@"0"])
+ {
+ return (item == nil) ? @"" : (id)[item name];
+ }
+ else
+ {
+ return (item == nil) ? @"" : (id)[item value];
+ }
+}
+
+
+@end
+
+@implementation VLCInfoTreeItem
+
+#define IsALeafNode ((id)-1)
+
+- (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id
+ parent:(VLCInfoTreeItem *)o_parent_item
+{
+ self = [super init];
+
+ if( self != nil )
+ {
+ o_name = [o_item_name copy];
+ o_value = [o_item_value copy];
+ i_object_id = i_id;
+ o_parent = o_parent_item;
+ p_item = [[[VLCMain sharedInstance] getInfo] item];
+ o_children = nil;
+ }
+ return( self );
+}
+
+- (id)init
+{
+ return [self initWithName:@"main" value:@"" ID:-1 parent:nil];
+}
+
+- (void)dealloc
+{
+ if( o_children != IsALeafNode ) [o_children release];
+ [o_name release];
+ [o_value release];
+ if( p_item ) vlc_gc_decref( p_item );
+ [super dealloc];
+}
+
+/* Creates and returns the array of children
+ * Loads children incrementally */
+- (NSArray *)children
+{
+ if( !p_item ) return nil;
+
+ if (o_children == NULL)
+ {
+ int i;
+
+ if( i_object_id == -1 )
+ {
+ vlc_mutex_lock( &p_item->lock );
+ o_children = [[NSMutableArray alloc] initWithCapacity: p_item->i_categories];
+ for (i = 0 ; i < p_item->i_categories ; i++)
+ {
+ NSString * name = [NSString stringWithUTF8String: p_item->pp_categories[i]->psz_name];
+ VLCInfoTreeItem * item = [[VLCInfoTreeItem alloc] initWithName:name value:@"" ID:i parent:self];
+ [item autorelease];
+ [o_children addObject:item];
+ }
+ vlc_mutex_unlock( &p_item->lock );
+ }
+ else if( o_parent->i_object_id == -1 )
+ {
+ vlc_mutex_lock( &p_item->lock );
+ info_category_t * cat = p_item->pp_categories[i_object_id];
+ o_children = [[NSMutableArray alloc] initWithCapacity: cat->i_infos];
+ for (i = 0 ; i < cat->i_infos ; i++)
+ {
+ NSString * name = [NSString stringWithUTF8String: cat->pp_infos[i]->psz_name];
+ NSString * value = [NSString stringWithUTF8String: cat->pp_infos[i]->psz_value ? : ""];
+ VLCInfoTreeItem * item = [[VLCInfoTreeItem alloc] initWithName:name value:value ID:i parent:self];
+ [item autorelease];
+ [o_children addObject:item];
+ }
+ vlc_mutex_unlock( &p_item->lock );
+ }
+ else
+ {
+ o_children = IsALeafNode;
+ }
+ }
+ return o_children;
+}
+
+- (NSString *)name
+{
+ return [[o_name retain] autorelease];
+}
+
+- (NSString *)value
+{
+ return [[o_value retain] autorelease];
+}
+
+- (void)refresh
+{
+ if( p_item ) vlc_gc_decref( p_item );
+ p_item = [[[VLCMain sharedInstance] getInfo] item];
+ if( o_children != NULL )
+ {
+ [o_children release];
+ o_children = NULL;
+ }
+}
+
+- (VLCInfoTreeItem *)childAtIndex:(int)i_index {
+ return [[self children] objectAtIndex:i_index];
+}
+
+- (int)numberOfChildren {
+
+ id i_tmp = [self children];
+ return ( i_tmp == IsALeafNode ) ? (-1) : (int)[i_tmp count];
+}