1 /*****************************************************************************
2 * VLCMediaArrayController.m: NSArrayController subclass specific to media
4 *****************************************************************************
5 * Copyright (C) 2007 Pierre d'Herbemont
6 * Copyright (C) 2007 the VideoLAN team
9 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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.
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.
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 *****************************************************************************/
26 #import "VLCMediaArrayController.h"
29 @implementation VLCMediaArrayController
30 @synthesize contentMediaList;
33 /******************************************************************************
34 * VLCMediaArrayController (NSTableViewDataSource)
36 @implementation VLCMediaArrayController (NSTableViewDataSource)
38 /* Dummy implementation, because that seems to be needed */
39 - (int)numberOfRowsInTableView:(NSTableView *)tableView
44 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn
50 /* Implement drag and drop */
51 - (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info
52 proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
54 return [contentMediaList isReadOnly] || op == NSTableViewDropOn ? NSDragOperationNone : NSDragOperationGeneric;
57 - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
58 row:(int)row dropOperation:(NSTableViewDropOperation)operation
62 NSArray *droppedItems = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
64 droppedItems = [[info draggingPasteboard] propertyListForType:NSURLPboardType];
66 NSAssert( contentMediaList, @"No contentMediaList" );
68 for (i = 0; i < [droppedItems count]; i++)
70 NSString * filename = [droppedItems objectAtIndex:i];
71 VLCMedia *media = [VLCMedia mediaWithPath:filename];
72 [contentMediaList lock];
73 [contentMediaList insertMedia:media atIndex:row];
74 [contentMediaList unlock];
79 - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
81 NSMutableArray *array = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
82 int i = [rowIndexes firstIndex];
84 [array addObject:[[contentMediaList mediaAtIndex:i] url]];
85 } while ((i = [rowIndexes indexGreaterThanIndex:i]) != NSNotFound);
87 [pboard declareTypes:[NSArray arrayWithObject:@"VLCMediaURLType"] owner:self];
88 [pboard setPropertyList:array forType:@"VLCMediaURLType"];