1 /*****************************************************************************
2 * playlist.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: playlist.m,v 1.10 2003/02/13 01:14:55 hartman Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <sys/param.h> /* for MAXPATHLEN */
34 /*****************************************************************************
35 * VLCPlaylistView implementation
36 *****************************************************************************/
37 @implementation VLCPlaylistView
39 - (NSMenu *)menuForEvent:(NSEvent *)o_event
41 return( [[self delegate] menuForEvent: o_event] );
44 - (void)keyDown:(NSEvent *)o_event
48 playlist_t * p_playlist;
49 intf_thread_t * p_intf = [NSApp getIntf];
51 if( [[o_event characters] length] )
53 key = [[o_event characters] characterAtIndex: 0];
56 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
59 if ( p_playlist == NULL )
67 vlc_mutex_lock( &p_playlist->object_lock );
68 if( p_playlist != NULL && p_playlist->p_input != NULL )
70 input_SetStatus( p_playlist->p_input, INPUT_STATUS_PAUSE );
72 vlc_mutex_unlock( &p_playlist->object_lock );
75 case NSDeleteCharacter:
76 case NSDeleteFunctionKey:
77 case NSDeleteCharFunctionKey:
78 case NSBackspaceCharacter:
79 while( ( i_row = [self selectedRow] ) != -1 )
81 if( p_playlist->i_index == i_row && p_playlist->i_status )
83 playlist_Stop( p_playlist );
86 playlist_Delete( p_playlist, i_row );
88 [self deselectRow: i_row];
94 [super keyDown: o_event];
98 if( p_playlist != NULL )
100 vlc_object_release( p_playlist );
106 /*****************************************************************************
107 * VLCPlaylist implementation
108 *****************************************************************************/
109 @implementation VLCPlaylist
113 [o_table_view setTarget: self];
114 [o_table_view setDelegate: self];
115 [o_table_view setDataSource: self];
117 [o_table_view setDoubleAction: @selector(playItem:)];
119 [o_table_view registerForDraggedTypes:
120 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
122 [o_mi_play setTitle: _NS("Play")];
123 [o_mi_delete setTitle: _NS("Delete")];
124 [o_mi_selectall setTitle: _NS("Select All")];
127 - (BOOL)tableView:(NSTableView *)o_tv
128 shouldEditTableColumn:(NSTableColumn *)o_tc
134 - (NSDragOperation)tableView:(NSTableView*)o_tv
135 validateDrop:(id <NSDraggingInfo>)info
136 proposedRow:(int)i_row
137 proposedDropOperation:(NSTableViewDropOperation)operation
139 return( NSDragOperationPrivate );
142 - (BOOL)tableView:(NSTableView*)o_tv
143 acceptDrop:(id <NSDraggingInfo>)info
145 dropOperation:(NSTableViewDropOperation)operation
148 NSPasteboard * o_pasteboard;
150 o_pasteboard = [info draggingPasteboard];
152 if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
154 o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType];
156 [self appendArray: o_values atPos: i_row enqueue:YES];
164 - (void)tableView:(NSTableView *)o_tv willDisplayCell:(id)o_cell
165 forTableColumn:(NSTableColumn *)o_tc row:(int)i_row
169 [o_cell setDrawsBackground: YES];
173 o_color = [[NSColor alternateSelectedControlColor]
174 highlightWithLevel: 0.90];
178 o_color = [o_tv backgroundColor];
181 [o_cell setBackgroundColor: o_color];
184 - (NSMenu *)menuForEvent:(NSEvent *)o_event
188 vlc_bool_t b_item_sel;
190 pt = [o_table_view convertPoint: [o_event locationInWindow]
192 b_item_sel = ( [o_table_view rowAtPoint: pt] != -1 &&
193 [o_table_view selectedRow] != -1 );
194 b_rows = [o_table_view numberOfRows] != 0;
196 [o_mi_play setEnabled: b_item_sel];
197 [o_mi_delete setEnabled: b_item_sel];
198 [o_mi_selectall setEnabled: b_rows];
200 return( o_ctx_menu );
203 - (IBAction)playItem:(id)sender
205 intf_thread_t * p_intf = [NSApp getIntf];
206 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
209 if( p_playlist == NULL )
214 playlist_Goto( p_playlist, [o_table_view selectedRow] );
216 vlc_object_release( p_playlist );
219 - (IBAction)deleteItems:(id)sender
223 intf_thread_t * p_intf = [NSApp getIntf];
224 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
227 if( p_playlist == NULL )
232 while( ( i_row = [o_table_view selectedRow] ) != -1 )
234 if( p_playlist->i_index == i_row && p_playlist->i_status )
236 playlist_Stop( p_playlist );
239 playlist_Delete( p_playlist, i_row );
241 [o_table_view deselectRow: i_row];
244 vlc_object_release( p_playlist );
246 /* this is actually duplicity, because the intf.m manage also updates the view
247 * when the playlist changes. we do this on purpose, because else there is a
248 * delay of .5 sec or so when we delete an item */
249 [self playlistUpdated];
252 - (IBAction)selectAll:(id)sender
254 [o_table_view selectAll: nil];
257 - (void)appendArray:(NSArray*)o_array atPos:(int)i_pos enqueue:(BOOL)b_enqueue
261 NSEnumerator * o_enum;
262 intf_thread_t * p_intf = [NSApp getIntf];
263 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
266 if( p_playlist == NULL )
272 o_enum = [o_array objectEnumerator];
273 while( ( o_value = [o_enum nextObject] ) )
277 int i_mode = PLAYLIST_INSERT;
279 if (i_items == 0 && !b_enqueue)
280 i_mode |= PLAYLIST_GO;
282 playlist_Add( p_playlist, [o_value fileSystemRepresentation],
283 i_mode, i_pos == -1 ? PLAYLIST_END : i_pos + i_items );
285 o_url = [NSURL fileURLWithPath: o_value];
288 [[NSDocumentController sharedDocumentController]
289 noteNewRecentDocumentURL: o_url];
295 vlc_object_release( p_playlist );
298 - (void)playlistUpdated
300 [o_table_view reloadData];
305 @implementation VLCPlaylist (NSTableDataSource)
307 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
310 intf_thread_t * p_intf = [NSApp getIntf];
311 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
314 if( p_playlist != NULL )
316 i_count = p_playlist->i_size;
317 vlc_object_release( p_playlist );
323 - (id)tableView:(NSTableView *)o_tv
324 objectValueForTableColumn:(NSTableColumn *)o_tc
328 intf_thread_t * p_intf = [NSApp getIntf];
329 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
332 if( p_playlist == NULL )
337 vlc_mutex_lock( &p_playlist->object_lock );
338 o_value = [[NSString stringWithUTF8String:
339 p_playlist->pp_items[i_row]->psz_name] lastPathComponent];
340 vlc_mutex_unlock( &p_playlist->object_lock );
342 vlc_object_release( p_playlist );