]> git.sesse.net Git - vlc/blob - projects/macosx/vlc_app/Sources/VLCMediaArrayController.m
34f8a3e2e0e9fad1cf05c1ff0f8cbe40093ecb4b
[vlc] / projects / macosx / vlc_app / Sources / VLCMediaArrayController.m
1 /*****************************************************************************
2  * VLCMediaArrayController.m: NSArrayController subclass specific to media
3  * list.
4  *****************************************************************************
5  * Copyright (C) 2007 Pierre d'Herbemont
6  * Copyright (C) 2007 the VideoLAN team
7  * $Id$
8  *
9  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #import "VLCMediaArrayController.h"
27
28
29 @implementation VLCMediaArrayController
30 @synthesize contentMediaList;
31 @end
32
33 /******************************************************************************
34  * VLCMediaArrayController (NSTableViewDataSource)
35  */
36 @implementation VLCMediaArrayController (NSTableViewDataSource)
37
38 /* Dummy implementation, because that seems to be needed */
39 - (int)numberOfRowsInTableView:(NSTableView *)tableView
40 {
41     return 0;
42 }
43
44 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
45                         row:(int)row
46 {
47     return nil;
48 }
49
50 /* Implement drag and drop */
51 - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info 
52                                  proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
53 {
54     return [contentMediaList isReadOnly] || op == NSTableViewDropOn ? NSDragOperationNone : NSDragOperationGeneric;
55 }
56
57 - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
58                           row:(int)row dropOperation:(NSTableViewDropOperation)operation
59 {
60     int i;
61     row = 0;
62     NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
63     if( !droppedItems )
64         droppedItems = [[info draggingPasteboard] propertyListForType:NSURLPboardType];
65
66     NSAssert( contentMediaList, @"No contentMediaList" );
67
68     for (i = 0; i < [droppedItems count]; i++)
69     {
70         NSString * filename = [droppedItems objectAtIndex:i];
71                 VLCMedia *media = [VLCMedia mediaWithPath:filename];
72         [contentMediaList lock];
73                 [contentMediaList insertMedia:media atIndex:row];
74         [contentMediaList unlock];
75     }
76     return YES;
77 }
78
79 - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
80 {
81     NSMutableArray *array = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
82     int i = [rowIndexes firstIndex];
83     do {
84         [array addObject:[[contentMediaList mediaAtIndex:i] url]];
85     } while ((i = [rowIndexes indexGreaterThanIndex:i]) != NSNotFound);
86
87     [pboard declareTypes:[NSArray arrayWithObject:@"VLCMediaURLType"] owner:self];
88     [pboard setPropertyList:array forType:@"VLCMediaURLType"];
89     return YES;
90 }
91 @end