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_btn_delete_group setTitle: _NS("Delete Group")];
49 [o_btn_add_group setTitle: _NS("Add Group")];
50 [o_group_lbl setStringValue: _NS("Group")];
53 - (IBAction)togglePlaylistInfoPanel:(id)sender
55 intf_thread_t * p_intf = [NSApp getIntf];
56 playlist_t * p_playlist;
58 if( [o_info_window isVisible] )
60 [o_info_window orderOut: sender];
64 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
69 /*fill uri / title / author info */
70 int i_item = [o_vlc_playlist selectedPlaylistItem];
71 [o_uri_txt setStringValue:
72 ([NSString stringWithUTF8String:p_playlist->
73 pp_items[i_item]->input.psz_uri] == nil ) ?
74 [NSString stringWithCString:p_playlist->
75 pp_items[i_item]->input.psz_uri] :
76 [NSString stringWithUTF8String:p_playlist->
77 pp_items[i_item]->input.psz_uri]];
79 [o_title_txt setStringValue:
80 ([NSString stringWithUTF8String:p_playlist->
81 pp_items[i_item]->input.psz_name] == nil ) ?
82 [NSString stringWithCString:p_playlist->
83 pp_items[i_item]->input.psz_name] :
84 [NSString stringWithUTF8String:p_playlist->
85 pp_items[i_item]->input.psz_name]];
87 [o_author_txt setStringValue:
88 [NSString stringWithUTF8String:playlist_GetInfo
89 (p_playlist, i_item ,_("General"),_("Author") )]];
91 [[VLCInfoTreeItem rootItem] refresh];
92 [o_outline_view reloadData];
94 [self createComboBox];
95 [self handleGroup:self];
97 vlc_object_release( p_playlist );
99 [o_info_window makeKeyAndOrderFront: sender];
103 - (IBAction)infoCancel:(id)sender
105 [self togglePlaylistInfoPanel:self];
109 - (IBAction)infoOk:(id)sender
112 int i_item = [o_vlc_playlist selectedPlaylistItem];
113 intf_thread_t * p_intf = [NSApp getIntf];
114 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
117 NSMutableArray * o_selected = [o_vlc_playlist selectedPlaylistItemsList];
123 vlc_mutex_lock(&p_playlist->pp_items[i_item]->input.lock);
125 p_playlist->pp_items[i_item]->input.psz_uri =
126 strdup([[o_uri_txt stringValue] cString]);
127 p_playlist->pp_items[i_item]->input.psz_name =
128 strdup([[o_title_txt stringValue] cString]);
129 playlist_ItemAddInfo(p_playlist->pp_items[i_item],_("General"),_("Author"), [[o_author_txt stringValue] cString]);
131 c = (int)[o_selected count];
133 if ([[o_group_cbx stringValue] isEqual:
134 [o_group_cbx objectValueOfSelectedItem]])
136 for (i = 0 ; i < c ; i++)
138 o_number = [o_selected lastObject];
139 i_row = [o_number intValue];
140 p_playlist->pp_items[i_row]->i_group = p_playlist->
141 pp_groups[[o_group_cbx indexOfSelectedItem]]->i_id;
142 [o_selected removeObject: o_number];
147 playlist_group_t * p_group = playlist_CreateGroup( p_playlist,
148 strdup([[o_group_cbx stringValue] cString]));
151 for (i = 0 ; i < c ; i++)
153 o_number = [o_selected lastObject];
154 i_row = [o_number intValue];
155 p_playlist->pp_items[i_row]->i_group = p_group->i_id;
156 [o_selected removeObject: o_number];
162 vlc_mutex_unlock(&p_playlist->pp_items[i_item]->input.lock);
163 val.b_bool = VLC_TRUE;
164 var_Set( p_playlist,"intf-change",val );
165 vlc_object_release ( p_playlist );
167 [self togglePlaylistInfoPanel:self];
170 - (IBAction)handleGroup:(id)sender
172 intf_thread_t * p_intf = [NSApp getIntf];
173 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
178 if ([[o_group_cbx stringValue] isEqual:
179 [o_group_cbx objectValueOfSelectedItem]])
181 [o_group_color setBackgroundColor:[o_vlc_playlist
182 getColor: p_playlist->pp_groups[
183 [o_group_cbx indexOfSelectedItem]]->i_id]];
187 [o_group_color setBackgroundColor:[o_vlc_playlist
188 getColor:p_playlist->pp_groups[
189 [o_group_cbx numberOfItems] - 1]->i_id + 1]];
191 vlc_object_release(p_playlist);
195 - (IBAction)deleteOutlineGroup:(id)sender
197 intf_thread_t * p_intf = [NSApp getIntf];
198 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
203 if ([[o_group_cbx stringValue] isEqual:
204 [o_group_cbx objectValueOfSelectedItem]])
206 [o_vlc_playlist deleteGroup:p_playlist->pp_groups[
207 [o_group_cbx indexOfSelectedItem]]->i_id];
208 [self createComboBox];
209 [self handleGroup:self];
210 [o_group_cbx reloadData];
214 msg_Warn(p_playlist,"Group doesn't exist, cannot delete");
216 vlc_object_release(p_playlist);
220 - (IBAction)createOutlineGroup:(id)sender;
222 intf_thread_t * p_intf = [NSApp getIntf];
223 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
227 playlist_CreateGroup( p_playlist,
228 strdup([[o_group_cbx stringValue] cString]));
229 [self createComboBox];
230 [o_group_cbx reloadData];
231 [o_vlc_playlist playlistUpdated];
232 vlc_object_release(p_playlist);
236 -(void)createComboBox
238 intf_thread_t * p_intf = [NSApp getIntf];
239 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
242 int i_item = [o_vlc_playlist selectedPlaylistItem];
244 [o_group_cbx removeAllItems];
248 for (i = 0; i < p_playlist->i_groups ; i++)
250 [o_group_cbx addItemWithObjectValue:
251 [NSString stringWithUTF8String:
252 p_playlist->pp_groups[i]->psz_name]];
253 if (p_playlist->pp_items[i_item]->i_group == p_playlist
254 ->pp_groups[i]->i_id)
256 [o_group_cbx selectItemAtIndex:i];
259 vlc_object_release(p_playlist);
266 @implementation VLCPlaylistInfo (NSTableDataSource)
268 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
270 return (item == nil) ? [[VLCInfoTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
273 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
274 return ([item numberOfChildren] > 0);
277 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
279 return (item == nil) ? [[VLCInfoTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
282 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
284 if ([[tableColumn identifier] isEqualToString:@"0"])
286 return (item == nil) ? @"" : (id)[item getName];
290 return (item == nil) ? @"" : (id)[item getValue];
296 @implementation VLCInfoTreeItem
298 static VLCInfoTreeItem *o_root_item = nil;
300 #define IsALeafNode ((id)-1)
302 - (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id parent:(VLCInfoTreeItem *)o_parent_item
309 i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];
310 o_name = [o_item_name copy];
311 o_value = [o_item_value copy];
313 o_parent = o_parent_item;
318 + (VLCInfoTreeItem *)rootItem {
319 if (o_root_item == nil) o_root_item = [[VLCInfoTreeItem alloc] initWithName:@"main" value: @"" ID: 0 parent:nil];
325 if (o_children != IsALeafNode) [o_children release];
330 /* Creates and returns the array of children
331 * Loads children incrementally */
332 - (NSArray *)children
334 if (o_children == NULL)
336 intf_thread_t * p_intf = [NSApp getIntf];
337 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
345 if (self == o_root_item)
347 o_children = [[NSMutableArray alloc] initWithCapacity:p_playlist->pp_items[i_item]->input.i_categories];
348 for (i = 0 ; i<p_playlist->pp_items[i_item]->input.i_categories ; i++)
350 [o_children addObject:[[VLCInfoTreeItem alloc]
351 initWithName: [NSString stringWithUTF8String:
352 p_playlist->pp_items[i_item]->input.
353 pp_categories[i]->psz_name]
359 else if (o_parent == o_root_item)
361 o_children = [[NSMutableArray alloc] initWithCapacity:
362 p_playlist->pp_items[i_item]->input.
363 pp_categories[i_object_id]->i_infos];
364 for (i = 0 ; i<p_playlist->pp_items[i_item]->input.
365 pp_categories[i_object_id]->i_infos ; i++)
367 [o_children addObject:[[VLCInfoTreeItem alloc]
368 initWithName: [NSString stringWithUTF8String:
369 p_playlist->pp_items[i_item]->input.
370 pp_categories[i_object_id]->
371 pp_infos[i]->psz_name]
372 value: [NSString stringWithUTF8String:
373 p_playlist->pp_items[i_item]->input.
374 pp_categories[i_object_id]->
375 pp_infos[i]->psz_value]
382 o_children = IsALeafNode;
385 vlc_object_release(p_playlist);
391 - (NSString *)getName
396 - (NSString *)getValue
401 - (VLCInfoTreeItem *)childAtIndex:(int)i_index {
402 return [[self children] objectAtIndex:i_index];
405 - (int)numberOfChildren {
406 id i_tmp = [self children];
407 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
410 - (int)selectedPlaylistItem
417 if (o_children != NULL)
419 [o_children release];
422 i_item = [[[NSApp delegate] getPlaylist] selectedPlaylistItem];