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 = VLCIntf;
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->status.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 = VLCIntf;
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 = VLCIntf;
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 = VLCIntf;
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 = VLCIntf;
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 = VLCIntf;
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->status.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
393 NSMutableArray *o_selected;
396 intf_thread_t * p_intf = VLCIntf;
397 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
400 if( p_playlist == NULL )
405 o_selected = [NSMutableArray arrayWithArray:[[o_table_view selectedRowEnumerator] allObjects]];
406 c = (int)[o_selected count];
408 if (p_playlist->pp_items[[o_table_view selectedRow]]->b_enabled)
410 for( i = 0; i < c; i++ )
412 o_number = [o_selected lastObject];
413 i_row = [o_number intValue];
414 if( p_playlist->i_index == i_row && p_playlist->status.i_status )
416 playlist_Stop( p_playlist );
418 [o_selected removeObject: o_number];
419 playlist_Disable( p_playlist, i_row );
424 for( i = 0; i < c; i++ )
426 o_number = [o_selected lastObject];
427 i_row = [o_number intValue];
428 [o_selected removeObject: o_number];
429 playlist_Enable( p_playlist, i_row );
432 vlc_object_release( p_playlist );
433 [self playlistUpdated];
437 - (IBAction)enableGroup:(id)sender
440 intf_thread_t * p_intf = VLCIntf;
441 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
446 playlist_EnableGroup(p_playlist,
447 p_playlist->pp_items[[o_table_view selectedRow]]->i_group);
448 vlc_object_release(p_playlist);
453 - (IBAction)disableGroup:(id)sender
456 intf_thread_t * p_intf = VLCIntf;
457 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
462 playlist_DisableGroup(p_playlist,
463 p_playlist->pp_items[[o_table_view selectedRow]]->i_group);
464 vlc_object_release(p_playlist);
469 - (IBAction)selectAll:(id)sender
471 [o_table_view selectAll: nil];
475 - (IBAction)searchItem:(id)sender
478 NSString *o_current_name;
479 NSString *o_current_author;
481 intf_thread_t * p_intf = VLCIntf;
482 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
485 if( p_playlist == NULL )
489 if( [o_table_view numberOfRows] < 1 )
494 if( [o_table_view selectedRow] == [o_table_view numberOfRows]-1 )
500 i_current = [o_table_view selectedRow];
508 vlc_mutex_lock( &p_playlist->object_lock );
509 o_current_name = [NSString stringWithUTF8String:
510 p_playlist->pp_items[i_current]->input.psz_name];
511 psz_temp = playlist_GetInfo(p_playlist, i_current ,_("General"),_("Author") );
512 o_current_author = [NSString stringWithUTF8String: psz_temp];
514 vlc_mutex_unlock( &p_playlist->object_lock );
517 if( [o_current_name rangeOfString:[o_search_keyword stringValue] options:NSCaseInsensitiveSearch ].length ||
518 [o_current_author rangeOfString:[o_search_keyword stringValue] options:NSCaseInsensitiveSearch ].length )
520 [o_table_view selectRow: i_current byExtendingSelection: NO];
521 [o_table_view scrollRowToVisible: i_current];
524 if( i_current == [o_table_view numberOfRows] - 1 )
529 while (i_current != [o_table_view selectedRow]);
530 vlc_object_release( p_playlist );
534 - (IBAction)handlePopUp:(id)sender
537 intf_thread_t * p_intf = VLCIntf;
538 vlc_value_t val1,val2;
539 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
541 if( p_playlist == NULL )
546 switch ([o_loop_popup indexOfSelectedItem])
551 var_Set( p_playlist, "loop", val1 );
553 var_Set( p_playlist, "repeat", val1 );
554 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat One" ) );
559 var_Set( p_playlist, "repeat", val1 );
561 var_Set( p_playlist, "loop", val1 );
562 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat All" ) );
566 var_Get( p_playlist, "repeat", &val1 );
567 var_Get( p_playlist, "loop", &val2 );
568 if (val1.b_bool || val2.b_bool)
571 var_Set( p_playlist, "repeat", val1 );
572 var_Set( p_playlist, "loop", val1 );
573 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Repeat Off" ) );
577 vlc_object_release( p_playlist );
578 [self playlistUpdated];
582 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
585 intf_thread_t * p_intf = VLCIntf;
586 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
589 if( p_playlist == NULL )
594 for ( i_item = 0; i_item < (int)[o_array count]; i_item++ )
597 NSDictionary *o_one_item;
598 int j, i_total_options = 0, i_new_id = -1;
599 int i_mode = PLAYLIST_INSERT;
600 BOOL b_rem = FALSE, b_dir = FALSE;
601 NSString *o_uri, *o_name;
604 char **ppsz_options = NULL;
607 o_one_item = [o_array objectAtIndex: i_item];
608 o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
609 o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
610 o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
612 /* If no name, then make a guess */
613 if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
615 if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
616 [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
617 isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem )
619 /* All of this is to make sure CD's play when you D&D them on VLC */
620 /* Converts mountpoint to a /dev file */
623 buf = (struct statfs *) malloc (sizeof(struct statfs));
624 statfs( [o_uri fileSystemRepresentation], buf );
625 psz_dev = strdup(buf->f_mntfromname);
626 o_uri = [NSString stringWithCString: psz_dev ];
629 if( o_options && [o_options count] > 0 )
631 /* Count the input options */
632 i_total_options = [o_options count];
634 /* Allocate ppsz_options */
635 for( j = 0; j < i_total_options; j++ )
638 ppsz_options = (char **)malloc( sizeof(char *) * i_total_options );
640 ppsz_options[j] = strdup([[o_options objectAtIndex:j] UTF8String]);
645 i_new_id = playlist_AddExt( p_playlist, [o_uri fileSystemRepresentation],
646 [o_name UTF8String], i_mode,
647 i_position == -1 ? PLAYLIST_END : i_position + i_item,
648 0, (ppsz_options != NULL ) ? (const char **)ppsz_options : 0, i_total_options );
651 for( j = 0; j < i_total_options; j++ )
652 free( ppsz_options[j] );
653 if( ppsz_options ) free( ppsz_options ); */
655 /* Recent documents menu */
656 o_true_file = [NSURL fileURLWithPath: o_uri];
657 if( o_true_file != nil )
659 [[NSDocumentController sharedDocumentController]
660 noteNewRecentDocumentURL: o_true_file];
663 if( i_item == 0 && !b_enqueue )
665 playlist_Goto( p_playlist, playlist_GetPositionById( p_playlist, i_new_id ) );
666 playlist_Play( p_playlist );
670 vlc_object_release( p_playlist );
673 - (void)playlistUpdated
675 vlc_value_t val1, val2;
676 intf_thread_t * p_intf = VLCIntf;
677 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
679 if( p_playlist != NULL )
681 var_Get( p_playlist, "random", &val1 );
682 [o_random_ckb setState: val1.b_bool];
684 var_Get( p_playlist, "repeat", &val1 );
685 var_Get( p_playlist, "loop", &val2 );
688 [o_loop_popup selectItemAtIndex:1];
692 [o_loop_popup selectItemAtIndex:2];
696 [o_loop_popup selectItemAtIndex:0];
698 vlc_object_release( p_playlist );
700 [o_table_view reloadData];
703 - (void)updateRowSelection
707 intf_thread_t * p_intf = VLCIntf;
708 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
711 if( p_playlist == NULL )
716 i_row = p_playlist->i_index;
717 vlc_object_release( p_playlist );
719 [o_table_view selectRow: i_row byExtendingSelection: NO];
720 [o_table_view scrollRowToVisible: i_row];
723 - (int)selectedPlaylistItem
725 return [o_table_view selectedRow];
728 - (NSMutableArray *)selectedPlaylistItemsList
730 return [NSMutableArray arrayWithArray:[[o_table_view
731 selectedRowEnumerator] allObjects]];
735 - (void)deleteGroup:(int)i_id
738 intf_thread_t * p_intf = VLCIntf;
739 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
747 /*first, change the group of all the items that belong to the group to
748 delete. Change it to the group with the smallest id.*/
750 /*search for the group with the smallest id*/
752 if(p_playlist->i_groups == 1)
754 msg_Warn(p_playlist,"Trying to delete last group, cancelling");
755 vlc_object_release(p_playlist);
759 for (i = 0 ; i<p_playlist->i_groups ; i++)
761 if((i_newgroup == 0 || i_newgroup > p_playlist->pp_groups[i]->i_id)
762 && p_playlist->pp_groups[i]->i_id != i_id)
764 i_newgroup = p_playlist->pp_groups[i]->i_id;
768 vlc_mutex_lock( &p_playlist->object_lock );
770 for (i = 0; i < p_playlist->i_size;i++)
772 if (p_playlist->pp_items[i]->i_group == i_id)
774 vlc_mutex_lock(&p_playlist->pp_items[i]->input.lock);
775 p_playlist->pp_items[i]->i_group = i_newgroup;
776 vlc_mutex_unlock(&p_playlist->pp_items[i]->input.lock);
779 vlc_mutex_unlock( &p_playlist->object_lock );
781 playlist_DeleteGroup( p_playlist, i_id );
783 vlc_object_release(p_playlist);
784 [self playlistUpdated];
789 - (NSColor *)getColor:(int)i_group
791 NSColor * o_color = nil;
792 switch ( i_group % 8 )
796 o_color = [NSColor colorWithDeviceRed:1.0 green:1.0 blue:1.0 alpha:1.0];
801 o_color = [NSColor colorWithDeviceRed:1.0 green:0.76471 blue:0.76471 alpha:1.0];
806 o_color = [NSColor colorWithDeviceRed:0.76471 green:0.76471 blue:1.0 alpha:1.0];
811 o_color = [NSColor colorWithDeviceRed:1.0 green:0.89804 blue:0.76471 alpha:1.0];
816 o_color = [NSColor colorWithDeviceRed:1.0 green:0.76471 blue:1.0 alpha:1.0];
821 o_color = [NSColor colorWithDeviceRed:0.76471 green:1.0 blue:0.76471 alpha:1.0];
826 o_color = [NSColor colorWithDeviceRed:0.76471 green:1.0 blue:1.0 alpha:1.0];
831 o_color = [NSColor colorWithDeviceRed:1.0 green:1.0 blue:0.76471 alpha:1.0];
839 @implementation VLCPlaylist (NSTableDataSource)
841 - (int)numberOfRowsInTableView:(NSTableView *)o_tv
844 intf_thread_t * p_intf = VLCIntf;
845 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
848 if( p_playlist != NULL )
850 vlc_mutex_lock( &p_playlist->object_lock );
851 i_count = p_playlist->i_size;
852 vlc_mutex_unlock( &p_playlist->object_lock );
853 vlc_object_release( p_playlist );
855 [o_status_field setStringValue: [NSString stringWithFormat:_NS("%i items in playlist"), i_count]];
859 - (id)tableView:(NSTableView *)o_tv
860 objectValueForTableColumn:(NSTableColumn *)o_tc
864 intf_thread_t * p_intf = VLCIntf;
865 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
868 if( p_playlist == NULL )
873 if( [[o_tc identifier] isEqualToString:@"0"] )
875 o_value = [NSString stringWithFormat:@"%i", i_row + 1];
877 else if( [[o_tc identifier] isEqualToString:@"1"] )
879 vlc_mutex_lock( &p_playlist->object_lock );
880 o_value = [NSString stringWithUTF8String:
881 p_playlist->pp_items[i_row]->input.psz_name];
882 if( o_value == NULL )
883 o_value = [NSString stringWithCString:
884 p_playlist->pp_items[i_row]->input.psz_name];
885 vlc_mutex_unlock( &p_playlist->object_lock );
887 else if( [[o_tc identifier] isEqualToString:@"2"] )
890 vlc_mutex_lock( &p_playlist->object_lock );
891 psz_temp = playlist_GetInfo( p_playlist, i_row ,_("Meta-information"),_("Artist") );
892 vlc_mutex_unlock( &p_playlist->object_lock );
894 if( psz_temp == NULL )
900 o_value = [NSString stringWithUTF8String: psz_temp];
901 if( o_value == NULL )
903 o_value = [NSString stringWithCString: psz_temp];
908 else if( [[o_tc identifier] isEqualToString:@"3"] )
910 char psz_duration[MSTRTIME_MAX_SIZE];
911 mtime_t dur = p_playlist->pp_items[i_row]->input.i_duration;
914 secstotimestr( psz_duration, dur/1000000 );
915 o_value = [NSString stringWithUTF8String: psz_duration];
919 o_value = @"-:--:--";
923 vlc_object_release( p_playlist );
928 - (void)tableView:(NSTableView *)o_tv
929 willDisplayCell:(id)o_cell
930 forTableColumn:(NSTableColumn *)o_tc
933 intf_thread_t * p_intf = VLCIntf;
934 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
939 if ((p_playlist->i_groups) > 1 )
941 [o_cell setDrawsBackground: VLC_TRUE];
942 [o_cell setBackgroundColor:
943 [self getColor:p_playlist->pp_items[i_rows]->i_group]];
947 [o_cell setDrawsBackground: VLC_FALSE];
950 if (!p_playlist->pp_items[i_rows]->b_enabled)
952 [o_cell setTextColor: [NSColor colorWithDeviceRed:0.3686 green:0.3686 blue:0.3686 alpha:1.0]];
956 [o_cell setTextColor:[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:1.0]];
958 vlc_object_release( p_playlist );
962 - (BOOL)tableView:(NSTableView *)o_tv
963 writeRows:(NSArray*)o_rows
964 toPasteboard:(NSPasteboard*)o_pasteboard
966 int i_rows = [o_rows count];
967 NSArray *o_filenames = [NSArray array];
969 [o_pasteboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:self];
970 [o_pasteboard setPropertyList:o_filenames forType:NSFilenamesPboardType];
973 i_moveRow = [[o_rows objectAtIndex:0]intValue];
979 - (NSDragOperation)tableView:(NSTableView*)o_tv
980 validateDrop:(id <NSDraggingInfo>)o_info
981 proposedRow:(int)i_row
982 proposedDropOperation:(NSTableViewDropOperation)o_operation
984 if ( o_operation == NSTableViewDropAbove )
986 if ( i_moveRow >= 0 )
988 if ( i_row != i_moveRow )
990 return NSDragOperationMove;
992 /* what if in the previous run, the row wasn't actually moved?
993 then we can't drop new files on this location */
994 return NSDragOperationNone;
996 return NSDragOperationGeneric;
998 return NSDragOperationNone;
1001 - (BOOL)tableView:(NSTableView*)o_tv
1002 acceptDrop:(id <NSDraggingInfo>)o_info
1003 row:(int)i_proposed_row
1004 dropOperation:(NSTableViewDropOperation)o_operation
1006 if ( i_moveRow >= 0 )
1008 if (i_moveRow != -1 && i_proposed_row != -1)
1010 intf_thread_t * p_intf = VLCIntf;
1011 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1014 if( p_playlist == NULL )
1020 playlist_Move( p_playlist, i_moveRow, i_proposed_row );
1022 vlc_object_release( p_playlist );
1024 [self playlistUpdated];
1030 NSPasteboard * o_pasteboard;
1031 o_pasteboard = [o_info draggingPasteboard];
1033 if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
1036 NSArray *o_array = [NSArray array];
1037 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType]
1038 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
1040 for( i = 0; i < (int)[o_values count]; i++)
1042 NSDictionary *o_dic;
1043 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
1044 o_array = [o_array arrayByAddingObject: o_dic];
1046 [self appendArray: o_array atPos: i_proposed_row enqueue:YES];
1051 [self updateRowSelection];
1054 /* Delegate method of NSWindow */
1055 - (void)windowWillClose:(NSNotification *)aNotification
1057 [o_btn_playlist setState: NSOffState];