1 /*****************************************************************************
2 * playlist.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: playlist.m,v 1.1 2002/08/04 17:23:43 sam 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
53 /*****************************************************************************
54 * VLCPlaylist implementation
55 *****************************************************************************/
56 @implementation VLCPlaylist
60 [o_table_view setTarget: self];
61 [o_table_view setDelegate: self];
62 [o_table_view setDataSource: self];
64 [o_table_view setDoubleAction: @selector(doubleClick:)];
66 [o_table_view registerForDraggedTypes:
67 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
69 [o_panel setTitle: _NS("Playlist")];
70 [o_btn_close setTitle: _NS("Close")];
73 - (BOOL)tableView:(NSTableView *)o_tv
74 shouldEditTableColumn:(NSTableColumn *)o_tc
80 - (NSDragOperation)tableView:(NSTableView*)o_tv
81 validateDrop:(id <NSDraggingInfo>)info
82 proposedRow:(int)i_row
83 proposedDropOperation:(NSTableViewDropOperation)operation
85 return( NSDragOperationPrivate );
88 - (BOOL)tableView:(NSTableView*)o_tv
89 acceptDrop:(id <NSDraggingInfo>)info
91 dropOperation:(NSTableViewDropOperation)operation
94 NSPasteboard * o_pasteboard;
96 o_pasteboard = [info draggingPasteboard];
98 if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
100 o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType];
102 [self appendArray: o_values atPos: i_row];
106 [o_table_view reloadData];
115 - (void)tableView:(NSTableView *)o_tv willDisplayCell:(id)o_cell
116 forTableColumn:(NSTableColumn *)o_tc row:(int)i_row
118 [o_cell setDrawsBackground: YES];
122 [o_cell setBackgroundColor:
123 [NSColor colorWithDeviceRed: 0.937255
130 [o_cell setBackgroundColor: [NSColor whiteColor]];
134 - (IBAction)doubleClick:(id)sender
136 NSTableView * o_tv = sender;
137 intf_thread_t * p_intf = [NSApp getIntf];
138 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
141 if( p_playlist == NULL )
146 playlist_Goto( p_playlist, [o_tv clickedRow] );
148 vlc_object_release( p_playlist );
151 - (void)appendArray:(NSArray*)o_array atPos:(int)i_pos
155 NSEnumerator * o_enum;
156 intf_thread_t * p_intf = [NSApp getIntf];
157 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
160 if( p_playlist == NULL )
165 if( p_intf->p_sys->b_loop )
167 playlist_Delete( p_playlist, p_playlist->i_size - 1 );
171 o_enum = [o_array objectEnumerator];
172 while( ( o_value = [o_enum nextObject] ) )
176 int i_mode = i_items == 0 ? PLAYLIST_INSERT | PLAYLIST_GO :
179 playlist_Add( p_playlist, [o_value fileSystemRepresentation],
180 i_mode, i_pos == -1 ? PLAYLIST_END : i_pos + i_items );
182 o_url = [NSURL fileURLWithPath: o_value];
185 [[NSDocumentController sharedDocumentController]
186 noteNewRecentDocumentURL: o_url];
192 if( p_intf->p_sys->b_loop )
194 playlist_Add( p_playlist, "vlc:loop",
195 PLAYLIST_APPEND, PLAYLIST_END );
198 vlc_object_release( p_playlist );
203 @implementation VLCPlaylist (NSTableDataSource)
205 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
208 intf_thread_t * p_intf = [NSApp getIntf];
209 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
212 if( p_playlist != NULL )
214 i_count = p_playlist->i_size;
215 vlc_object_release( p_playlist );
221 - (id)tableView:(NSTableView *)o_tv
222 objectValueForTableColumn:(NSTableColumn *)o_tc
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 )
235 vlc_mutex_lock( &p_playlist->object_lock );
236 o_value = [NSString stringWithCString:
237 p_playlist->pp_items[i_row]->psz_name];
238 vlc_mutex_unlock( &p_playlist->object_lock );
240 vlc_object_release( p_playlist );