1 /*****************************************************************************
2 * playlist.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: playlist.m,v 1.8 2003/02/07 01:31:14 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 [self playlistUpdated];
249 - (IBAction)selectAll:(id)sender
251 [o_table_view selectAll: nil];
254 - (void)appendArray:(NSArray*)o_array atPos:(int)i_pos enqueue:(BOOL)b_enqueue
258 NSEnumerator * o_enum;
259 intf_thread_t * p_intf = [NSApp getIntf];
260 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
263 if( p_playlist == NULL )
269 o_enum = [o_array objectEnumerator];
270 while( ( o_value = [o_enum nextObject] ) )
274 int i_mode = PLAYLIST_INSERT;
276 if (i_items == 0 && !b_enqueue)
277 i_mode |= PLAYLIST_GO;
279 playlist_Add( p_playlist, [o_value fileSystemRepresentation],
280 i_mode, i_pos == -1 ? PLAYLIST_END : i_pos + i_items );
282 o_url = [NSURL fileURLWithPath: o_value];
285 [[NSDocumentController sharedDocumentController]
286 noteNewRecentDocumentURL: o_url];
292 vlc_object_release( p_playlist );
294 [self playlistUpdated];
297 - (void)playlistUpdated
299 [o_table_view reloadData];
304 @implementation VLCPlaylist (NSTableDataSource)
306 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
309 intf_thread_t * p_intf = [NSApp getIntf];
310 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
313 if( p_playlist != NULL )
315 i_count = p_playlist->i_size;
316 vlc_object_release( p_playlist );
322 - (id)tableView:(NSTableView *)o_tv
323 objectValueForTableColumn:(NSTableColumn *)o_tc
327 intf_thread_t * p_intf = [NSApp getIntf];
328 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
331 if( p_playlist == NULL )
336 vlc_mutex_lock( &p_playlist->object_lock );
337 o_value = [NSString stringWithUTF8String:
338 p_playlist->pp_items[i_row]->psz_name];
339 vlc_mutex_unlock( &p_playlist->object_lock );
341 vlc_object_release( p_playlist );