1 /*****************************************************************************
2 * playlist.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: playlist.m,v 1.6 2003/01/29 11:34:11 jlj 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 #include <Cocoa/Cocoa.h>
39 /*****************************************************************************
40 * VLCPlaylistView implementation
41 *****************************************************************************/
42 @implementation VLCPlaylistView
44 - (NSMenu *)menuForEvent:(NSEvent *)o_event
46 return( [[self delegate] menuForEvent: o_event] );
49 - (void)keyDown:(NSEvent *)o_event
51 intf_thread_t * p_intf = [NSApp getIntf];
54 if( [[o_event characters] length] )
56 key = [[o_event characters] characterAtIndex: 0];
62 input_SetStatus( p_intf->p_sys->p_input , INPUT_STATUS_PAUSE );
66 [super keyDown: o_event];
73 /*****************************************************************************
74 * VLCPlaylist implementation
75 *****************************************************************************/
76 @implementation VLCPlaylist
80 [o_table_view setTarget: self];
81 [o_table_view setDelegate: self];
82 [o_table_view setDataSource: self];
84 [o_table_view setDoubleAction: @selector(playItem:)];
86 [o_table_view registerForDraggedTypes:
87 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
89 [o_mi_play setTitle: _NS("Play")];
90 [o_mi_delete setTitle: _NS("Delete")];
91 [o_mi_selectall setTitle: _NS("Select All")];
94 - (BOOL)tableView:(NSTableView *)o_tv
95 shouldEditTableColumn:(NSTableColumn *)o_tc
101 - (NSDragOperation)tableView:(NSTableView*)o_tv
102 validateDrop:(id <NSDraggingInfo>)info
103 proposedRow:(int)i_row
104 proposedDropOperation:(NSTableViewDropOperation)operation
106 return( NSDragOperationPrivate );
109 - (BOOL)tableView:(NSTableView*)o_tv
110 acceptDrop:(id <NSDraggingInfo>)info
112 dropOperation:(NSTableViewDropOperation)operation
115 NSPasteboard * o_pasteboard;
117 o_pasteboard = [info draggingPasteboard];
119 if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
121 o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType];
123 [self appendArray: o_values atPos: i_row enqueue:YES];
131 - (void)tableView:(NSTableView *)o_tv willDisplayCell:(id)o_cell
132 forTableColumn:(NSTableColumn *)o_tc row:(int)i_row
136 [o_cell setDrawsBackground: YES];
140 o_color = [[NSColor alternateSelectedControlColor]
141 highlightWithLevel: 0.90];
145 o_color = [o_tv backgroundColor];
148 [o_cell setBackgroundColor: o_color];
151 - (NSMenu *)menuForEvent:(NSEvent *)o_event
155 vlc_bool_t b_item_sel;
157 pt = [o_table_view convertPoint: [o_event locationInWindow]
159 b_item_sel = ( [o_table_view rowAtPoint: pt] != -1 &&
160 [o_table_view selectedRow] != -1 );
161 b_rows = [o_table_view numberOfRows] != 0;
163 [o_mi_play setEnabled: b_item_sel];
164 [o_mi_delete setEnabled: b_item_sel];
165 [o_mi_selectall setEnabled: b_rows];
167 return( o_ctx_menu );
170 - (IBAction)playItem:(id)sender
172 intf_thread_t * p_intf = [NSApp getIntf];
173 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
176 if( p_playlist == NULL )
181 playlist_Goto( p_playlist, [o_table_view selectedRow] );
183 vlc_object_release( p_playlist );
186 - (IBAction)deleteItems:(id)sender
190 intf_thread_t * p_intf = [NSApp getIntf];
191 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
194 if( p_playlist == NULL )
199 while( ( i_row = [o_table_view selectedRow] ) != -1 )
201 if( p_playlist->i_index == i_row && p_playlist->i_status )
203 playlist_Stop( p_playlist );
206 playlist_Delete( p_playlist, i_row );
208 [o_table_view deselectRow: i_row];
211 vlc_object_release( p_playlist );
213 [self playlistUpdated];
216 - (IBAction)selectAll:(id)sender
218 [o_table_view selectAll: nil];
221 - (void)appendArray:(NSArray*)o_array atPos:(int)i_pos enqueue:(BOOL)b_enqueue
225 NSEnumerator * o_enum;
226 intf_thread_t * p_intf = [NSApp getIntf];
227 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
230 if( p_playlist == NULL )
236 o_enum = [o_array objectEnumerator];
237 while( ( o_value = [o_enum nextObject] ) )
241 int i_mode = PLAYLIST_INSERT;
243 if (i_items == 0 && !b_enqueue)
244 i_mode |= PLAYLIST_GO;
246 playlist_Add( p_playlist, [o_value fileSystemRepresentation],
247 i_mode, i_pos == -1 ? PLAYLIST_END : i_pos + i_items );
249 o_url = [NSURL fileURLWithPath: o_value];
252 [[NSDocumentController sharedDocumentController]
253 noteNewRecentDocumentURL: o_url];
259 vlc_object_release( p_playlist );
261 [self playlistUpdated];
264 - (void)playlistUpdated
266 [o_table_view reloadData];
271 @implementation VLCPlaylist (NSTableDataSource)
273 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
276 intf_thread_t * p_intf = [NSApp getIntf];
277 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
280 if( p_playlist != NULL )
282 i_count = p_playlist->i_size;
283 vlc_object_release( p_playlist );
289 - (id)tableView:(NSTableView *)o_tv
290 objectValueForTableColumn:(NSTableColumn *)o_tc
294 intf_thread_t * p_intf = [NSApp getIntf];
295 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
298 if( p_playlist == NULL )
303 vlc_mutex_lock( &p_playlist->object_lock );
304 o_value = [NSString stringWithUTF8String:
305 p_playlist->pp_items[i_row]->psz_name];
306 vlc_mutex_unlock( &p_playlist->object_lock );
308 vlc_object_release( p_playlist );