]> git.sesse.net Git - vlc/blob - modules/gui/macosx/playlist.m
* ./modules/*: moved plugins to the new tree. Yet untested builds include
[vlc] / modules / gui / macosx / playlist.m
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 $
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <sys/param.h>                                    /* for MAXPATHLEN */
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/intf.h>
33
34 #include <Cocoa/Cocoa.h> 
35
36 #include "intf.h"
37 #include "playlist.h"
38
39 /*****************************************************************************
40  * VLCPlaylistView implementation 
41  *****************************************************************************/
42 @implementation VLCPlaylistView
43
44 - (NSMenu *)menuForEvent:(NSEvent *)o_event
45 {
46     /* TODO */
47
48     return( nil );
49 }
50
51 @end
52
53 /*****************************************************************************
54  * VLCPlaylist implementation 
55  *****************************************************************************/
56 @implementation VLCPlaylist
57
58 - (void)awakeFromNib
59 {
60     [o_table_view setTarget: self];
61     [o_table_view setDelegate: self];
62     [o_table_view setDataSource: self];
63
64     [o_table_view setDoubleAction: @selector(doubleClick:)];
65
66     [o_table_view registerForDraggedTypes: 
67         [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
68
69     [o_panel setTitle: _NS("Playlist")];
70     [o_btn_close setTitle: _NS("Close")];
71 }
72
73 - (BOOL)tableView:(NSTableView *)o_tv 
74                   shouldEditTableColumn:(NSTableColumn *)o_tc
75                   row:(int)i_row
76 {
77     return( NO );
78 }
79
80 - (NSDragOperation)tableView:(NSTableView*)o_tv 
81                    validateDrop:(id <NSDraggingInfo>)info 
82                    proposedRow:(int)i_row 
83                    proposedDropOperation:(NSTableViewDropOperation)operation
84 {
85     return( NSDragOperationPrivate );
86 }
87
88 - (BOOL)tableView:(NSTableView*)o_tv 
89                   acceptDrop:(id <NSDraggingInfo>)info 
90                   row:(int)i_row 
91                   dropOperation:(NSTableViewDropOperation)operation
92 {
93     NSArray * o_values;
94     NSPasteboard * o_pasteboard;
95
96     o_pasteboard = [info draggingPasteboard];
97
98     if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
99     {
100         o_values = [o_pasteboard propertyListForType: NSFilenamesPboardType];
101
102         [self appendArray: o_values atPos: i_row];
103
104         if( i_row != -1 )
105         {
106             [o_table_view reloadData];
107         }
108         
109         return( YES );
110     }
111
112     return( NO ); 
113 }
114
115 - (void)tableView:(NSTableView *)o_tv willDisplayCell:(id)o_cell
116                   forTableColumn:(NSTableColumn *)o_tc row:(int)i_row
117 {
118     [o_cell setDrawsBackground: YES];
119
120     if( i_row % 2 )
121     {
122         [o_cell setBackgroundColor: 
123             [NSColor colorWithDeviceRed: 0.937255 
124                                   green: 0.968627
125                                    blue: 1.0
126                                   alpha: 1.0]];
127     }
128     else
129     {
130         [o_cell setBackgroundColor: [NSColor whiteColor]];
131     }
132 }
133
134 - (IBAction)doubleClick:(id)sender
135 {
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,
139                                                        FIND_ANYWHERE );
140
141     if( p_playlist == NULL )
142     {
143         return;
144     }
145
146     playlist_Goto( p_playlist, [o_tv clickedRow] );
147
148     vlc_object_release( p_playlist );
149 }
150
151 - (void)appendArray:(NSArray*)o_array atPos:(int)i_pos
152 {
153     int i_items;
154     NSString * o_value;
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,
158                                                        FIND_ANYWHERE );
159
160     if( p_playlist == NULL )
161     {
162         return;
163     }
164
165     if( p_intf->p_sys->b_loop )
166     {
167         playlist_Delete( p_playlist, p_playlist->i_size - 1 );
168     }
169
170     i_items = 0;
171     o_enum = [o_array objectEnumerator];
172     while( ( o_value = [o_enum nextObject] ) )
173     {
174         NSURL * o_url;
175
176         int i_mode = i_items == 0 ? PLAYLIST_INSERT | PLAYLIST_GO :
177                                                    PLAYLIST_INSERT;
178
179         playlist_Add( p_playlist, [o_value fileSystemRepresentation],
180             i_mode, i_pos == -1 ? PLAYLIST_END : i_pos + i_items );
181
182         o_url = [NSURL fileURLWithPath: o_value];
183         if( o_url != nil )
184         { 
185             [[NSDocumentController sharedDocumentController]
186                 noteNewRecentDocumentURL: o_url]; 
187         }
188
189         i_items++;
190     }
191
192     if( p_intf->p_sys->b_loop )
193     {
194         playlist_Add( p_playlist, "vlc:loop",
195                       PLAYLIST_APPEND, PLAYLIST_END );
196     }
197
198     vlc_object_release( p_playlist );
199 }
200
201 @end
202
203 @implementation VLCPlaylist (NSTableDataSource)
204
205 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
206 {
207     int i_count = 0;
208     intf_thread_t * p_intf = [NSApp getIntf];
209     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
210                                                FIND_ANYWHERE );
211
212     if( p_playlist != NULL )
213     {
214         i_count = p_playlist->i_size;
215         vlc_object_release( p_playlist );
216     }
217
218     return( i_count );
219 }
220
221 - (id)tableView:(NSTableView *)o_tv 
222                 objectValueForTableColumn:(NSTableColumn *)o_tc 
223                 row:(int)i_row
224 {
225     id o_value = nil;
226     intf_thread_t * p_intf = [NSApp getIntf];
227     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
228                                                FIND_ANYWHERE );
229
230     if( p_playlist == NULL )
231     {
232         return( nil );
233     }
234
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 ); 
239
240     vlc_object_release( p_playlist );
241
242     return( o_value );
243 }
244
245 @end
246