1 /*****************************************************************************
2 r 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
40 [o_info_window setExcludedFromWindowsMenu: TRUE];
42 [o_info_window setTitle: _NS("Properties")];
43 [o_uri_lbl setStringValue: _NS("URI")];
44 [o_title_lbl setStringValue: _NS("Title")];
45 [o_author_lbl setStringValue: _NS("Author")];
46 [o_btn_info_ok setTitle: _NS("OK")];
47 [o_btn_info_cancel setTitle: _NS("Cancel")];
48 [o_group_lbl setStringValue: _NS("Group")];
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 */
69 int i_item = [o_vlc_playlist selectedPlaylistItem];
70 [o_uri_txt setStringValue:
71 ([NSString stringWithUTF8String:p_playlist->
72 pp_items[i_item]->input.psz_uri] == nil ) ?
73 [NSString stringWithCString:p_playlist->
74 pp_items[i_item]->input.psz_uri] :
75 [NSString stringWithUTF8String:p_playlist->
76 pp_items[i_item]->input.psz_uri]];
78 [o_title_txt setStringValue:
79 ([NSString stringWithUTF8String:p_playlist->
80 pp_items[i_item]->input.psz_name] == nil ) ?
81 [NSString stringWithCString:p_playlist->
82 pp_items[i_item]->input.psz_name] :
83 [NSString stringWithUTF8String:p_playlist->
84 pp_items[i_item]->input.psz_name]];
86 [o_author_txt setStringValue:
87 [NSString stringWithUTF8String:playlist_GetInfo
88 (p_playlist, i_item ,_("General"),_("Author") )]];
90 [[VLCInfoTreeItem rootItem] refresh];
91 [o_outline_view reloadData];
93 [o_group_cbx removeAllItems];
95 for (i = 0; i < p_playlist->i_groups ; i++)
97 [o_group_cbx addItemWithObjectValue:
98 [NSString stringWithUTF8String:
99 p_playlist->pp_groups[i]->psz_name]];
100 if (p_playlist->pp_items[i_item]->i_group == p_playlist
101 ->pp_groups[i]->i_id)
103 [o_group_cbx selectItemAtIndex:i];
107 [self handleGroup:self];
109 vlc_object_release( p_playlist );
111 [o_info_window makeKeyAndOrderFront: sender];
115 - (IBAction)infoCancel:(id)sender
117 [self togglePlaylistInfoPanel:self];
121 - (IBAction)infoOk:(id)sender
123 int i_item = [o_vlc_playlist selectedPlaylistItem];
124 intf_thread_t * p_intf = [NSApp getIntf];
125 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
131 vlc_mutex_lock(&p_playlist->pp_items[i_item]->input.lock);
133 p_playlist->pp_items[i_item]->input.psz_uri =
134 strdup([[o_uri_txt stringValue] cString]);
135 p_playlist->pp_items[i_item]->input.psz_name =
136 strdup([[o_title_txt stringValue] cString]);
137 playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
139 if ([[o_group_cbx stringValue] isEqual:
140 [o_group_cbx objectValueOfSelectedItem]])
142 p_playlist->pp_items[i_item]->i_group = p_playlist->
143 pp_groups[[o_group_cbx indexOfSelectedItem]]->i_id;
147 playlist_group_t * p_group = playlist_CreateGroup( p_playlist,
148 strdup([[o_group_cbx stringValue] cString]));
149 p_playlist->pp_items[i_item]->i_group = p_group->i_id;
153 vlc_mutex_unlock(&p_playlist->pp_items[i_item]->input.lock);
154 val.b_bool = VLC_TRUE;
155 var_Set( p_playlist,"intf-change",val );
156 vlc_object_release ( p_playlist );
158 [self togglePlaylistInfoPanel:self];
161 - (IBAction)handleGroup:(id)sender
163 intf_thread_t * p_intf = [NSApp getIntf];
164 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
169 if ([[o_group_cbx stringValue] isEqual:
170 [o_group_cbx objectValueOfSelectedItem]])
172 [o_group_color setBackgroundColor:[o_vlc_playlist
173 getColor: p_playlist->pp_groups[
174 [o_group_cbx indexOfSelectedItem]]->i_id]];
178 [o_group_color setBackgroundColor:[o_vlc_playlist
179 getColor:p_playlist->pp_groups[
180 [o_group_cbx numberOfItems] - 1]->i_id + 1]];
182 vlc_object_release(p_playlist);
188 @implementation VLCPlaylistInfo (NSTableDataSource)
190 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
192 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
195 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
196 return ([item numberOfChildren] > 0);
199 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
201 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
204 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
206 if ([[tableColumn identifier] isEqualToString:@"0"])
208 return (item == nil) ? @"" : (id)[item getName];
212 return (item == nil) ? @"" : (id)[item getValue];
218 @implementation VLCInfoTreeItem
220 static VLCInfoTreeItem *o_root_item = nil;
222 #define IsALeafNode ((id)-1)
224 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
231 i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
232 o_name = [o_item_name copy];
233 o_value = [o_item_value copy];
235 o_parent = o_parent_item;
240 + (VLCInfoTreeItem *)rootItem {
241 if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
247 if (o_children != IsALeafNode) [o_children release];
252 /* Creates and returns the array of children
253 * Loads children incrementally */
254 - (NSArray *)children
256 if (o_children == NULL)
258 intf_thread_t * p_intf = [NSApp getIntf];
259 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
267 if (self == o_root_item)
269 o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->input.i_categories];
270 for (i = 0 ; i<p_playlist->pp_items[i_item]->input.i_categories ; i++)
272 [o_children addObject:[[VLCInfoTreeItem alloc]
273 initWithName: [NSString stringWithUTF8String:
274 p_playlist->pp_items[i_item]->input.
275 pp_categories[i]->psz_name]
281 else if (o_parent == o_root_item)
283 o_children = [[NSMutableArray alloc] initWithCapacity:
284 p_playlist->pp_items[i_item]->input.
285 pp_categories[i_object_id]->i_infos];
286 for (i = 0 ; i<p_playlist->pp_items[i_item]->input.
287 pp_categories[i_object_id]->i_infos ; i++)
289 [o_children addObject:[[VLCInfoTreeItem alloc]
290 initWithName: [NSString stringWithUTF8String:
291 p_playlist->pp_items[i_item]->input.
292 pp_categories[i_object_id]->
293 pp_infos[i]->psz_name]
294 value: [NSString stringWithUTF8String:
295 p_playlist->pp_items[i_item]->input.
296 pp_categories[i_object_id]->
297 pp_infos[i]->psz_value]
304 o_children = IsALeafNode;
307 vlc_object_release(p_playlist);
313 - (NSString *)getName
318 - (NSString *)getValue
323 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
324 return [[self children] objectAtIndex:i_index];
327 - (int)numberOfChildren {
328 id i_tmp = [self children];
329 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
332 - (int)selectedPlaylistItem
339 if (o_children != NULL)
341 [o_children release];
344 i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];