1 /*****************************************************************************
2 * playlistinfo.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
5 * $Id: playlistinfo.m 7015 2004-03-08 15:22:58Z bigben $
7 * Authors: Benjmaib 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include "playlistinfo.h"
32 /*****************************************************************************
33 * VLCPlaylistInfo Implementation
34 *****************************************************************************/
36 @implementation VLCPlaylistInfo
41 [o_info_window setExcludedFromWindowsMenu: TRUE];
43 [o_info_window setTitle: _NS("Properties")];
44 [o_uri_lbl setStringValue: _NS("URI")];
45 [o_title_lbl setStringValue: _NS("Title")];
46 [o_author_lbl setStringValue: _NS("Author")];
47 [o_btn_info_ok setTitle: _NS("OK")];
48 [o_btn_info_cancel setTitle: _NS("Cancel")];
51 - (IBAction)togglePlaylistInfoPanel:(id)sender
53 intf_thread_t * p_intf = [NSApp getIntf];
54 playlist_t * p_playlist;
56 if( [o_info_window isVisible] )
58 [o_info_window orderOut: sender];
62 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
67 /*fill uri / title / author info */
68 int i_item = [o_vlc_playlist selectedPlaylistItem];
69 [o_uri_txt setStringValue:
70 ([NSString stringWithUTF8String:p_playlist->
71 pp_items[i_item]->psz_uri] == nil ) ?
72 [NSString stringWithCString:p_playlist->
73 pp_items[i_item]->psz_uri] :
74 [NSString stringWithUTF8String:p_playlist->
75 pp_items[i_item]->psz_uri]];
77 [o_title_txt setStringValue:
78 ([NSString stringWithUTF8String:p_playlist->
79 pp_items[i_item]->psz_name] == nil ) ?
80 [NSString stringWithCString:p_playlist->
81 pp_items[i_item]->psz_name] :
82 [NSString stringWithUTF8String:p_playlist->
83 pp_items[i_item]->psz_name]];
85 [o_author_txt setStringValue:[NSString stringWithUTF8String: playlist_GetInfo(p_playlist, i_item ,_("General"),_("Author") )]];
87 [[VLCInfoTreeItem rootItem] refresh];
88 [o_outline_view reloadData];
89 vlc_object_release( p_playlist );
91 [o_info_window makeKeyAndOrderFront: sender];
95 - (IBAction)infoCancel:(id)sender
97 [self togglePlaylistInfoPanel:self];
101 - (IBAction)infoOk:(id)sender
103 int i_item = [o_vlc_playlist selectedPlaylistItem];
104 intf_thread_t * p_intf = [NSApp getIntf];
105 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
111 vlc_mutex_lock(&p_playlist->pp_items[i_item]->lock);
113 p_playlist->pp_items[i_item]->psz_uri = strdup([[o_uri_txt stringValue] cString]);
114 p_playlist->pp_items[i_item]->psz_name = strdup([[o_title_txt stringValue] cString]);
115 playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
117 vlc_mutex_unlock(&p_playlist->pp_items[i_item]->lock);
118 val.b_bool = VLC_TRUE;
119 var_Set( p_playlist,"intf-change",val );
120 vlc_object_release ( p_playlist );
122 [self togglePlaylistInfoPanel:self];
128 @implementation VLCPlaylistInfo (NSTableDataSource)
130 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
132 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
135 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
136 return ([item numberOfChildren] > 0);
139 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
141 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
144 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
146 if ([[tableColumn identifier] isEqualToString:@"0"])
148 return (item == nil) ? @"" : (id)[item getName];
152 return (item == nil) ? @"" : (id)[item getValue];
158 @implementation VLCInfoTreeItem
160 static VLCInfoTreeItem *o_root_item = nil;
162 #define IsALeafNode ((id)-1)
164 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
171 i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
172 o_name = [o_item_name copy];
173 o_value = [o_item_value copy];
175 o_parent = o_parent_item;
180 + (VLCInfoTreeItem *)rootItem {
181 if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
187 if (o_children != IsALeafNode) [o_children release];
192 /* Creates and returns the array of children
193 * Loads children incrementally */
194 - (NSArray *)children
196 if (o_children == NULL)
198 intf_thread_t * p_intf = [NSApp getIntf];
199 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
207 if (self == o_root_item)
209 o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->i_categories];
210 for (i = 0 ; i<p_playlist->pp_items[i_item]->i_categories ; i++)
212 [o_children addObject:[[VLCInfoTreeItem alloc]
213 initWithName: [NSString stringWithUTF8String:
214 p_playlist->pp_items[i_item]->pp_categories[i]
221 else if (o_parent == o_root_item)
223 o_children = [[NSMutableArray alloc] initWithCapacity:
224 p_playlist->pp_items[i_item]->
225 pp_categories[i_object_id]->i_infos];
226 for (i = 0 ; i<p_playlist->pp_items[i_item]->
227 pp_categories[i_object_id]->i_infos ; i++)
229 [o_children addObject:[[VLCInfoTreeItem alloc]
230 initWithName: [NSString stringWithUTF8String:
231 p_playlist->pp_items[i_item]->
232 pp_categories[i_object_id]->
233 pp_infos[i]->psz_name]
234 value: [NSString stringWithUTF8String:
235 p_playlist->pp_items[i_item]->
236 pp_categories[i_object_id]->
237 pp_infos[i]->psz_value]
244 o_children = IsALeafNode;
247 vlc_object_release(p_playlist);
253 - (NSString *)getName
258 - (NSString *)getValue
263 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
264 return [[self children] objectAtIndex:i_index];
267 - (int)numberOfChildren {
268 id i_tmp = [self children];
269 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
272 - (int)selectedPlaylistItem
279 if (o_children != NULL)
281 [o_children release];
284 i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];