1 /*****************************************************************************
2 * playlist.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <hartman at videolan dot org>
9 * Benjamin Pracht <bigben at videolab dot 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* malloc(), free() */
30 #include <sys/param.h> /* for MAXPATHLEN */
33 #include <sys/mount.h>
41 /*****************************************************************************
42 * VLCPlaylistView implementation
43 *****************************************************************************/
44 @implementation VLCPlaylistView
46 - (NSMenu *)menuForEvent:(NSEvent *)o_event
48 return( [[self delegate] menuForEvent: o_event] );
51 - (void)keyDown:(NSEvent *)o_event
55 NSMutableArray *o_to_delete;
58 playlist_t * p_playlist;
59 intf_thread_t * p_intf = [NSApp getIntf];
61 if( [[o_event characters] length] )
63 key = [[o_event characters] characterAtIndex: 0];
66 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
69 if ( p_playlist == NULL )
76 case NSDeleteCharacter:
77 case NSDeleteFunctionKey:
78 case NSDeleteCharFunctionKey:
79 case NSBackspaceCharacter:
80 o_to_delete = [NSMutableArray arrayWithArray:[[self selectedRowEnumerator] allObjects]];
81 c = [o_to_delete count];
83 for( i = 0; i < c; i++ ) {
84 o_number = [o_to_delete lastObject];
85 i_row = [o_number intValue];
87 if( p_playlist->i_index == i_row && p_playlist->i_status )
89 playlist_Stop( p_playlist );
91 [o_to_delete removeObject: o_number];
92 [self deselectRow: i_row];
93 playlist_Delete( p_playlist, i_row );
99 [super keyDown: o_event];
103 if( p_playlist != NULL )
105 vlc_object_release( p_playlist );
112 /*****************************************************************************
113 * VLCPlaylist implementation
114 *****************************************************************************/
115 @implementation VLCPlaylist
129 [o_table_view setTarget: self];
130 [o_table_view setDelegate: self];
131 [o_table_view setDataSource: self];
133 [o_table_view setDoubleAction: @selector(playItem:)];
135 [o_table_view registerForDraggedTypes:
136 [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
137 [o_table_view setIntercellSpacing: NSMakeSize (0.0, 1.0)];
138 [o_window setExcludedFromWindowsMenu: TRUE];
141 // [o_tbv_info setDataSource: [VLCInfoDataSource init]];
143 /* We need to check whether _defaultTableHeaderSortImage exists, since it
144 belongs to an Apple hidden private API, and then can "disapear" at any time*/
146 if( [[NSTableView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] )
148 o_ascendingSortingImage = [[NSTableView class] _defaultTableHeaderSortImage];
152 o_ascendingSortingImage = nil;
155 if( [[NSTableView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] )
157 o_descendingSortingImage = [[NSTableView class] _defaultTableHeaderReverseSortImage];
161 o_descendingSortingImage = nil;
165 [self playlistUpdated];
170 [o_window setTitle: _NS("Playlist")];
171 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
172 [o_mi_play setTitle: _NS("Play")];
173 [o_mi_delete setTitle: _NS("Delete")];
174 [o_mi_selectall setTitle: _NS("Select All")];
175 [o_mi_toggleItemsEnabled setTitle: _NS("Item Enabled")];
176 [o_mi_enableGroup setTitle: _NS("Enable all group items")];
177 [o_mi_disableGroup setTitle: _NS("Disable all group items")];
178 [o_mi_info setTitle: _NS("Properties")];
180 [[o_tc_name headerCell] setStringValue:_NS("Name")];
181 [[o_tc_author headerCell] setStringValue:_NS("Author")];
182 [[o_tc_duration headerCell] setStringValue:_NS("Duration")];
183 [o_random_ckb setTitle: _NS("Random")];
184 [o_search_button setTitle: _NS("Search")];
185 [o_btn_playlist setToolTip: _NS("Playlist")];
186 [[o_loop_popup itemAtIndex:0] setTitle: _NS("Standard Play")];
187 [[o_loop_popup itemAtIndex:1] setTitle: _NS("Repeat One")];
188 [[o_loop_popup itemAtIndex:2] setTitle: _NS("Repeat All")];
191 - (void) tableView:(NSTableView*)o_tv
192 didClickTableColumn:(NSTableColumn *)o_tc
194 intf_thread_t * p_intf = [NSApp getIntf];
195 playlist_t *p_playlist =
196 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
199 int max = [[o_table_view tableColumns] count];
202 if( p_playlist == NULL )
207 if( o_tc_sortColumn == o_tc )
209 b_isSortDescending = !b_isSortDescending;
211 else if( o_tc == o_tc_name || o_tc == o_tc_author ||
214 b_isSortDescending = VLC_FALSE;
215 [o_table_view setHighlightedTableColumn:o_tc];
216 o_tc_sortColumn = o_tc;
217 for( i=0 ; i<max ; i++ )
219 [o_table_view setIndicatorImage:nil inTableColumn:[[o_table_view tableColumns] objectAtIndex:i]];
223 if( o_tc_id == o_tc && !b_isSortDescending )
225 playlist_SortID( p_playlist , ORDER_NORMAL );
226 [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
228 else if( o_tc_name == o_tc && !b_isSortDescending )
230 playlist_SortTitle( p_playlist , ORDER_NORMAL );
231 [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
233 else if( o_tc_author == o_tc && !b_isSortDescending )
235 playlist_SortAuthor( p_playlist , ORDER_NORMAL );
236 [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
238 else if( o_tc_id == o_tc && b_isSortDescending )
240 playlist_SortID( p_playlist , ORDER_REVERSE );
241 [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc];
243 else if( o_tc_name == o_tc && b_isSortDescending )
245 playlist_SortTitle( p_playlist , ORDER_REVERSE );
246 [o_table_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
248 else if( o_tc_author == o_tc && b_isSortDescending )
250 playlist_SortAuthor( p_playlist , ORDER_REVERSE );
251 [o_table_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc];
253 vlc_object_release( p_playlist );
254 [self playlistUpdated];
258 - (BOOL)tableView:(NSTableView *)o_tv
259 shouldEditTableColumn:(NSTableColumn *)o_tc
265 - (NSMenu *)menuForEvent:(NSEvent *)o_event
267 intf_thread_t * p_intf = [NSApp getIntf];
268 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
271 bool b_itemstate = FALSE;
275 vlc_bool_t b_item_sel;
277 pt = [o_table_view convertPoint: [o_event locationInWindow]
279 b_item_sel = ( [o_table_view rowAtPoint: pt] != -1 &&
280 [o_table_view selectedRow] != -1 );
281 b_rows = [o_table_view numberOfRows] != 0;
283 [o_mi_play setEnabled: b_item_sel];
284 [o_mi_delete setEnabled: b_item_sel];
285 [o_mi_selectall setEnabled: b_rows];
286 [o_mi_info setEnabled: b_item_sel];
287 [o_mi_toggleItemsEnabled setEnabled: b_item_sel];
288 [o_mi_enableGroup setEnabled: b_item_sel];
289 [o_mi_disableGroup setEnabled: b_item_sel];
293 b_itemstate = ([o_table_view selectedRow] > -1) ?
294 p_playlist->pp_items[[o_table_view selectedRow]]->b_enabled : FALSE;
295 vlc_object_release(p_playlist);
298 [o_mi_toggleItemsEnabled setState: b_itemstate];
300 return( o_ctx_menu );
303 - (IBAction)toggleWindow:(id)sender
305 if( [o_window isVisible] )
307 [o_window orderOut:sender];
308 [o_btn_playlist setState:NSOffState];
312 [o_window makeKeyAndOrderFront:sender];
313 [o_btn_playlist setState:NSOnState];
317 - (IBAction)savePlaylist:(id)sender
319 intf_thread_t * p_intf = [NSApp getIntf];
320 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
323 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
324 NSString * o_name = [NSString stringWithFormat: @"%@.m3u", _NS("Untitled")];
325 [o_save_panel setTitle: _NS("Save Playlist")];
326 [o_save_panel setPrompt: _NS("Save")];
328 if( [o_save_panel runModalForDirectory: nil
329 file: o_name] == NSOKButton )
331 playlist_Export( p_playlist, [[o_save_panel filename] fileSystemRepresentation], "export-m3u" );
336 - (IBAction)playItem:(id)sender
338 intf_thread_t * p_intf = [NSApp getIntf];
339 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
342 if( p_playlist != NULL )
344 playlist_Goto( p_playlist, [o_table_view selectedRow] );
345 vlc_object_release( p_playlist );
349 - (IBAction)deleteItems:(id)sender
352 NSMutableArray *o_to_delete;
355 intf_thread_t * p_intf = [NSApp getIntf];
356 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
359 if( p_playlist == NULL )
364 o_to_delete = [NSMutableArray arrayWithArray:[[o_table_view selectedRowEnumerator] allObjects]];
365 c = (int)[o_to_delete count];
367 for( i = 0; i < c; i++ ) {
368 o_number = [o_to_delete lastObject];
369 i_row = [o_number intValue];
371 if( p_playlist->i_index == i_row && p_playlist->i_status )
373 playlist_Stop( p_playlist );
375 [o_to_delete removeObject: o_number];
376 [o_table_view deselectRow: i_row];
377 playlist_Delete( p_playlist, i_row );
380 vlc_object_release( p_playlist );
382 /* this is actually duplicity, because the intf.m manage also updates the view
383 * when the playlist changes. we do this on purpose, because else there is a
384 * delay of .5 sec or so when we delete an item */
385 [self playlistUpdated];
386 [self updateRowSelection];
389 - (IBAction)toggleItemsEnabled:(id)sender
392 NSMutableArray *o_selected;
395 intf_thread_t * p_intf = [NSApp getIntf];
396 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
399 if( p_playlist == NULL )
404 o_selected = [NSMutableArray arrayWithArray:[[o_table_view selectedRowEnumerator] allObjects]];
405 c = (int)[o_selected count];
407 if (p_playlist->pp_items[[o_table_view selectedRow]]->b_enabled)
409 for( i = 0; i < c; i++ )
411 o_number = [o_selected lastObject];
412 i_row = [o_number intValue];
413 if( p_playlist->i_index == i_row && p_playlist->i_status )
415 playlist_Stop( p_playlist );
417 [o_selected removeObject: o_number];
418 playlist_Disable( p_playlist, i_row );
423 for( i = 0; i < c; i++ )
425 o_number = [o_selected lastObject];
426 i_row = [o_number intValue];
427 [o_selected removeObject: o_number];
428 playlist_Enable( p_playlist, i_row );
431 vlc_object_release( p_playlist );
432 [self playlistUpdated];
435 - (IBAction)enableGroup:(id)sender
437 intf_thread_t * p_intf = [NSApp getIntf];
438 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
443 playlist_EnableGroup(p_playlist,
444 p_playlist->pp_items[[o_table_view selectedRow]]->i_group);
445 vlc_object_release(p_playlist);
449 - (IBAction)disableGroup:(id)sender
451 intf_thread_t * p_intf = [NSApp getIntf];
452 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
457 playlist_DisableGroup(p_playlist,
458 p_playlist->pp_items[[o_table_view selectedRow]]->i_group);
459 vlc_object_release(p_playlist);
463 - (IBAction)selectAll:(id)sender
465 [o_table_view selectAll: nil];
469 - (IBAction)searchItem:(id)sender
472 NSString *o_current_name;
473 NSString *o_current_author;
475 intf_thread_t * p_intf = [NSApp getIntf];
476 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
479 if( p_playlist == NULL )
483 if( [o_table_view numberOfRows] < 1 )
488 if( [o_table_view selectedRow] == [o_table_view numberOfRows]-1 )
494 i_current = [o_table_view selectedRow];
502 vlc_mutex_lock( &p_playlist->object_lock );
503 o_current_name = [NSString stringWithUTF8String:
504 p_playlist->pp_items[i_current]->input.psz_name];
505 psz_temp = playlist_GetInfo(p_playlist, i_current ,_("General"),_("Author") );
506 o_current_author = [NSString stringWithUTF8String: psz_temp];
508 vlc_mutex_unlock( &p_playlist->object_lock );
511 if( [o_current_name rangeOfString:[o_search_keyword stringValue] options:NSCaseInsensitiveSearch ].length ||
512 [o_current_author rangeOfString:[o_search_keyword stringValue] options:NSCaseInsensitiveSearch ].length )
514 [o_table_view selectRow: i_current byExtendingSelection: NO];
515 [o_table_view scrollRowToVisible: i_current];
518 if( i_current == [o_table_view numberOfRows] - 1 )
523 while (i_current != [o_table_view selectedRow]);
524 vlc_object_release( p_playlist );
528 - (IBAction)handlePopUp:(id)sender
531 intf_thread_t * p_intf = [NSApp getIntf];
532 vlc_value_t val1,val2;
533 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
535 if( p_playlist == NULL )
540 switch ([o_loop_popup indexOfSelectedItem])
545 var_Set( p_playlist, "loop", val1 );
547 var_Set( p_playlist, "repeat", val1 );
548 vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat One" ) );
553 var_Set( p_playlist, "repeat", val1 );
555 var_Set( p_playlist, "loop", val1 );
556 vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat All" ) );
560 var_Get( p_playlist, "repeat", &val1 );
561 var_Get( p_playlist, "loop", &val2 );
562 if (val1.b_bool || val2.b_bool)
565 var_Set( p_playlist, "repeat", val1 );
566 var_Set( p_playlist, "loop", val1 );
567 vout_OSDMessage( p_intf, SOLO_CHAN, _( "Repeat Off" ) );
571 vlc_object_release( p_playlist );
572 [self playlistUpdated];
576 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
579 intf_thread_t * p_intf = [NSApp getIntf];
580 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
583 if( p_playlist == NULL )
588 for ( i_item = 0; i_item < (int)[o_array count]; i_item++ )
591 NSDictionary *o_one_item;
592 int j, i_total_options = 0, i_new_id = -1;
593 int i_mode = PLAYLIST_INSERT;
594 BOOL b_rem = FALSE, b_dir = FALSE;
595 NSString *o_uri, *o_name;
598 char **ppsz_options = NULL;
601 o_one_item = [o_array objectAtIndex: i_item];
602 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
603 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
604 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
606 /* If no name, then make a guess */
607 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
609 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
610 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
611 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
613 /* All of this is to make sure CD's play when you D&D them on VLC */
614 /* Converts mountpoint to a /dev file */
617 buf = (struct statfs *) malloc (sizeof(struct statfs));
618 statfs( [o_uri fileSystemRepresentation], buf );
619 psz_dev = strdup(buf->f_mntfromname);
620 o_uri = [NSString stringWithCString: psz_dev ];
623 if( o_options && [o_options count] > 0 )
625 /* Count the input options */
626 i_total_options = [o_options count];
628 /* Allocate ppsz_options */
629 for( j = 0; j < i_total_options; j++ )
632 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
634 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
639 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
640 [o_name UTF8String], i_mode,
641 i_position == -1 ? PLAYLIST_END : i_position + i_item,
642 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
645 for( j = 0; j < i_total_options; j++ )
646 free( ppsz_options[j] );
647 if( ppsz_options ) free( ppsz_options ); */
649 /* Recent documents menu */
650 o_true_file = [NSURL fileURLWithPath: o_uri];
651 if( o_true_file != nil )
653 [[NSDocumentController sharedDocumentController]
654 noteNewRecentDocumentURL: o_true_file];
657 if( i_item == 0 && !b_enqueue )
659 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
660 playlist_Play( p_playlist );
664 vlc_object_release( p_playlist );
667 - (void)playlistUpdated
669 vlc_value_t val1, val2;
670 intf_thread_t * p_intf = [NSApp getIntf];
671 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
673 if( p_playlist != NULL )
675 var_Get( p_playlist, "random", &val1 );
676 [o_random_ckb setState: val1.b_bool];
678 var_Get( p_playlist, "repeat", &val1 );
679 var_Get( p_playlist, "loop", &val2 );
682 [o_loop_popup selectItemAtIndex:1];
686 [o_loop_popup selectItemAtIndex:2];
690 [o_loop_popup selectItemAtIndex:0];
692 vlc_object_release( p_playlist );
694 [o_table_view reloadData];
697 - (void)updateRowSelection
701 intf_thread_t * p_intf = [NSApp getIntf];
702 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
705 if( p_playlist == NULL )
710 i_row = p_playlist->i_index;
711 vlc_object_release( p_playlist );
713 [o_table_view selectRow: i_row byExtendingSelection: NO];
714 [o_table_view scrollRowToVisible: i_row];
717 - (int)selectedPlaylistItem
719 return [o_table_view selectedRow];
722 - (NSMutableArray *)selectedPlaylistItemsList
724 return [NSMutableArray arrayWithArray:[[o_table_view
725 selectedRowEnumerator] allObjects]];
729 - (void)deleteGroup:(int)i_id
731 intf_thread_t * p_intf = [NSApp getIntf];
732 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
740 /*first, change the group of all the items that belong to the group to
741 delete. Change it to the group with the smallest id.*/
743 /*search for the group with the smallest id*/
745 if(p_playlist->i_groups == 1)
747 msg_Warn(p_playlist,"Trying to delete last group, cancelling");
748 vlc_object_release(p_playlist);
752 for (i = 0 ; i<p_playlist->i_groups ; i++)
754 if((i_newgroup == 0 || i_newgroup > p_playlist->pp_groups[i]->i_id)
755 && p_playlist->pp_groups[i]->i_id != i_id)
757 i_newgroup = p_playlist->pp_groups[i]->i_id;
761 vlc_mutex_lock( &p_playlist->object_lock );
763 for (i = 0; i < p_playlist->i_size;i++)
765 if (p_playlist->pp_items[i]->i_group == i_id)
767 vlc_mutex_lock(&p_playlist->pp_items[i]->input.lock);
768 p_playlist->pp_items[i]->i_group = i_newgroup;
769 vlc_mutex_unlock(&p_playlist->pp_items[i]->input.lock);
772 vlc_mutex_unlock( &p_playlist->object_lock );
774 playlist_DeleteGroup( p_playlist, i_id );
776 vlc_object_release(p_playlist);
777 [self playlistUpdated];
781 - (NSColor *)getColor:(int)i_group
783 NSColor * o_color = nil;
784 switch ( i_group % 8 )
788 o_color = [NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:1.0];
793 o_color = [NSColor colorWithDeviceRed:1.0 green:0.76471 blue:0.76471 alpha:1.0];
798 o_color = [NSColor colorWithDeviceRed:0.76471 green:0.76471 blue:1.0 alpha:1.0];
803 o_color = [NSColor colorWithDeviceRed:1.0 green:0.89804 blue:0.76471 alpha:1.0];
808 o_color = [NSColor colorWithDeviceRed:1.0 green:0.76471 blue:1.0 alpha:1.0];
813 o_color = [NSColor colorWithDeviceRed:0.76471 green:1.0 blue:0.76471 alpha:1.0];
818 o_color = [NSColor colorWithDeviceRed:0.76471 green:1.0 blue:1.0 alpha:1.0];
823 o_color = [NSColor colorWithDeviceRed:1.0 green:1.0 blue:0.76471 alpha:1.0];
831 @implementation VLCPlaylist (NSTableDataSource)
833 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
836 intf_thread_t * p_intf = [NSApp getIntf];
837 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
840 if( p_playlist != NULL )
842 vlc_mutex_lock( &p_playlist->object_lock );
843 i_count = p_playlist->i_size;
844 vlc_mutex_unlock( &p_playlist->object_lock );
845 vlc_object_release( p_playlist );
847 [o_status_field setStringValue: [NSString stringWithFormat:_NS("%i items in playlist"), i_count]];
851 - (id)tableView:(NSTableView *)o_tv
852 objectValueForTableColumn:(NSTableColumn *)o_tc
856 intf_thread_t * p_intf = [NSApp getIntf];
857 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
860 if( p_playlist == NULL )
865 if( [[o_tc identifier] isEqualToString:@"0"] )
867 o_value = [NSString stringWithFormat:@"%i", i_row + 1];
869 else if( [[o_tc identifier] isEqualToString:@"1"] )
871 vlc_mutex_lock( &p_playlist->object_lock );
872 o_value = [NSString stringWithUTF8String:
873 p_playlist->pp_items[i_row]->input.psz_name];
874 if( o_value == NULL )
875 o_value = [NSString stringWithCString:
876 p_playlist->pp_items[i_row]->input.psz_name];
877 vlc_mutex_unlock( &p_playlist->object_lock );
879 else if( [[o_tc identifier] isEqualToString:@"2"] )
882 vlc_mutex_lock( &p_playlist->object_lock );
883 psz_temp = playlist_GetInfo( p_playlist, i_row ,_("General"),_("Author") );
884 vlc_mutex_unlock( &p_playlist->object_lock );
886 if( psz_temp == NULL )
892 o_value = [NSString stringWithUTF8String: psz_temp];
893 if( o_value == NULL )
895 o_value = [NSString stringWithCString: psz_temp];
900 else if( [[o_tc identifier] isEqualToString:@"3"] )
902 char psz_duration[MSTRTIME_MAX_SIZE];
903 mtime_t dur = p_playlist->pp_items[i_row]->input.i_duration;
906 secstotimestr( psz_duration, dur/1000000 );
907 o_value = [NSString stringWithUTF8String: psz_duration];
911 o_value = @"-:--:--";
915 vlc_object_release( p_playlist );
920 - (void)tableView:(NSTableView *)o_tv
921 willDisplayCell:(id)o_cell
922 forTableColumn:(NSTableColumn *)o_tc
925 intf_thread_t * p_intf = [NSApp getIntf];
926 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
930 if ((p_playlist->i_groups) > 1 )
932 [o_cell setDrawsBackground: VLC_TRUE];
933 [o_cell setBackgroundColor:
934 [self getColor:p_playlist->pp_items[i_rows]->i_group]];
938 [o_cell setDrawsBackground: VLC_FALSE];
941 if (!p_playlist->pp_items[i_rows]->b_enabled)
943 [o_cell setTextColor: [NSColor colorWithDeviceRed:0.3686 green:0.3686 blue:0.3686 alpha:1.0]];
947 [o_cell setTextColor:[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:1.0]];
949 vlc_object_release( p_playlist );
953 - (BOOL)tableView:(NSTableView *)o_tv
954 writeRows:(NSArray*)o_rows
955 toPasteboard:(NSPasteboard*)o_pasteboard
957 int i_rows = [o_rows count];
958 NSArray *o_filenames = [NSArray array];
960 [o_pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self];
961 [o_pasteboard setPropertyList:o_filenames forType:NSFilenamesPboardType];
964 i_moveRow = [[o_rows objectAtIndex:0]intValue];
970 - (NSDragOperation)tableView:(NSTableView*)o_tv
971 validateDrop:(id <NSDraggingInfo>)o_info
972 proposedRow:(int)i_row
973 proposedDropOperation:(NSTableViewDropOperation)o_operation
975 if ( o_operation == NSTableViewDropAbove )
977 if ( i_moveRow >= 0 )
979 if ( i_row != i_moveRow )
981 return NSDragOperationMove;
983 /* what if in the previous run, the row wasn't actually moved?
984 then we can't drop new files on this location */
985 return NSDragOperationNone;
987 return NSDragOperationGeneric;
989 return NSDragOperationNone;
992 - (BOOL)tableView:(NSTableView*)o_tv
993 acceptDrop:(id <NSDraggingInfo>)o_info
994 row:(int)i_proposed_row
995 dropOperation:(NSTableViewDropOperation)o_operation
997 if ( i_moveRow >= 0 )
999 if (i_moveRow != -1 && i_proposed_row != -1)
1001 intf_thread_t * p_intf = [NSApp getIntf];
1002 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1005 if( p_playlist == NULL )
1011 playlist_Move( p_playlist, i_moveRow, i_proposed_row );
1013 vlc_object_release( p_playlist );
1015 [self playlistUpdated];
1021 NSPasteboard * o_pasteboard;
1022 o_pasteboard = [o_info draggingPasteboard];
1024 if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1027 NSArray *o_array = [NSArray array];
1028 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1029 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
1031 for( i = 0; i < (int)[o_values count]; i++)
1033 NSDictionary *o_dic;
1034 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
1035 o_array = [o_array arrayByAddingObject: o_dic];
1037 [self appendArray: o_array atPos: i_proposed_row enqueue:YES];
1042 [self updateRowSelection];
1045 /* Delegate method of NSWindow */
1046 - (void)windowWillClose:(NSNotification *)aNotification
1048 [o_btn_playlist setState: NSOffState];