playlist.m
来自「VLC媒体播放程序」· M 代码 · 共 729 行 · 第 1/2 页
M
729 行
/***************************************************************************** * playlist.m: MacOS X interface module ***************************************************************************** * Copyright (C) 2002-2004 VideoLAN * $Id: playlist.m,v 1.58 2004/02/26 14:40:29 hartman Exp $ * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Derk-Jan Hartman <hartman at videolan dot org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <sys/param.h> /* for MAXPATHLEN */#include <string.h>#include <math.h>#include <sys/mount.h>#include <vlc_keys.h>#include "intf.h"#include "playlist.h"#include "controls.h"/***************************************************************************** * VLCPlaylistView implementation *****************************************************************************/@implementation VLCPlaylistView- (NSMenu *)menuForEvent:(NSEvent *)o_event{ return( [[self delegate] menuForEvent: o_event] );}- (void)keyDown:(NSEvent *)o_event{ unichar key = 0; int i, c, i_row; NSMutableArray *o_to_delete; NSNumber *o_number; playlist_t * p_playlist; intf_thread_t * p_intf = [NSApp getIntf]; if( [[o_event characters] length] ) { key = [[o_event characters] characterAtIndex: 0]; } p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if ( p_playlist == NULL ) { return; } switch( key ) { case NSDeleteCharacter: case NSDeleteFunctionKey: case NSDeleteCharFunctionKey: case NSBackspaceCharacter: o_to_delete = [NSMutableArray arrayWithArray:[[self selectedRowEnumerator] allObjects]]; c = [o_to_delete count]; for( i = 0; i < c; i++ ) { o_number = [o_to_delete lastObject]; i_row = [o_number intValue]; if( p_playlist->i_index == i_row && p_playlist->i_status ) { playlist_Stop( p_playlist ); } [o_to_delete removeObject: o_number]; [self deselectRow: i_row]; playlist_Delete( p_playlist, i_row ); } [self reloadData]; break; default: [super keyDown: o_event]; break; } if( p_playlist != NULL ) { vlc_object_release( p_playlist ); }}@end/***************************************************************************** * VLCPlaylist implementation *****************************************************************************/@implementation VLCPlaylist- (id)init{ self = [super init]; if ( self !=nil ) { i_moveRow = -1; } return self;}- (void)awakeFromNib{ [o_table_view setTarget: self]; [o_table_view setDelegate: self]; [o_table_view setDataSource: self]; [o_table_view setDoubleAction: @selector(playItem:)]; [o_table_view registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; [o_window setExcludedFromWindowsMenu: TRUE];/* We need to check whether _defaultTableHeaderSortImage exists, since it belongs to an Apple hidden private API, and then can "disapear" at any time*/ if( [[NSTableView class] respondsToSelector:@selector(_defaultTableHeaderSortImage)] ) { o_ascendingSortingImage = [[NSTableView class] _defaultTableHeaderSortImage]; } else { o_ascendingSortingImage = nil; } if( [[NSTableView class] respondsToSelector:@selector(_defaultTableHeaderReverseSortImage)] ) { o_descendingSortingImage = [[NSTableView class] _defaultTableHeaderReverseSortImage]; } else { o_descendingSortingImage = nil; } [self initStrings];}- (void)initStrings{ [o_window setTitle: _NS("Playlist")]; [o_mi_save_playlist setTitle: _NS("Save Playlist...")]; [o_mi_play setTitle: _NS("Play")]; [o_mi_delete setTitle: _NS("Delete")]; [o_mi_selectall setTitle: _NS("Select All")]; [[o_tc_name headerCell] setStringValue:_NS("Name")]; [[o_tc_author headerCell] setStringValue:_NS("Author")]; [[o_tc_duration headerCell] setStringValue:_NS("Duration")]; [o_random_ckb setTitle: _NS("Random")]; [o_loop_ckb setTitle: _NS("Repeat All")]; [o_repeat_ckb setTitle: _NS("Repeat One")]; [o_search_button setTitle: _NS("Search")]; [o_btn_playlist setToolTip: _NS("Playlist")];}- (void) tableView:(NSTableView*)o_tv didClickTableColumn:(NSTableColumn *)o_tc{ intf_thread_t * p_intf = [NSApp getIntf]; playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); int max = [[o_table_view tableColumns] count]; int i; if( p_playlist == NULL ) { return; } if( o_tc_sortColumn == o_tc ) { b_isSortDescending = !b_isSortDescending; } else if( o_tc == o_tc_name || o_tc == o_tc_author || o_tc == o_tc_id ) { b_isSortDescending = VLC_FALSE; [o_table_view setHighlightedTableColumn:o_tc]; o_tc_sortColumn = o_tc; for( i=0 ; i<max ; i++ ) { [o_table_view setIndicatorImage:nil inTableColumn:[[o_table_view tableColumns] objectAtIndex:i]]; } } if( o_tc_id == o_tc && !b_isSortDescending ) { playlist_SortID( p_playlist , ORDER_NORMAL ); [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc]; } else if( o_tc_name == o_tc && !b_isSortDescending ) { playlist_SortTitle( p_playlist , ORDER_NORMAL ); [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc]; } else if( o_tc_author == o_tc && !b_isSortDescending ) { playlist_SortAuthor( p_playlist , ORDER_NORMAL ); [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc]; } else if( o_tc_id == o_tc && b_isSortDescending ) { playlist_SortID( p_playlist , ORDER_REVERSE ); [o_table_view setIndicatorImage:o_ascendingSortingImage inTableColumn:o_tc]; } else if( o_tc_name == o_tc && b_isSortDescending ) { playlist_SortTitle( p_playlist , ORDER_REVERSE ); [o_table_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc]; } else if( o_tc_author == o_tc && b_isSortDescending ) { playlist_SortAuthor( p_playlist , ORDER_REVERSE ); [o_table_view setIndicatorImage:o_descendingSortingImage inTableColumn:o_tc]; } vlc_object_release( p_playlist ); [self playlistUpdated];}- (BOOL)tableView:(NSTableView *)o_tv shouldEditTableColumn:(NSTableColumn *)o_tc row:(int)i_row{ return( NO );}- (NSMenu *)menuForEvent:(NSEvent *)o_event{ NSPoint pt; vlc_bool_t b_rows; vlc_bool_t b_item_sel; pt = [o_table_view convertPoint: [o_event locationInWindow] fromView: nil]; b_item_sel = ( [o_table_view rowAtPoint: pt] != -1 && [o_table_view selectedRow] != -1 ); b_rows = [o_table_view numberOfRows] != 0; [o_mi_play setEnabled: b_item_sel]; [o_mi_delete setEnabled: b_item_sel]; [o_mi_selectall setEnabled: b_rows]; return( o_ctx_menu );}- (IBAction)toggleWindow:(id)sender{ if( [o_window isVisible] ) { [o_window orderOut:sender]; [o_btn_playlist setState:NSOffState]; } else { [o_window makeKeyAndOrderFront:sender]; [o_btn_playlist setState:NSOnState]; }}- (IBAction)savePlaylist:(id)sender{ intf_thread_t * p_intf = [NSApp getIntf]; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); NSSavePanel *o_save_panel = [NSSavePanel savePanel]; NSString * o_name = [NSString stringWithFormat: @"%@.m3u", _NS("Untitled")]; [o_save_panel setTitle: _NS("Save Playlist")]; [o_save_panel setPrompt: _NS("Save")]; if( [o_save_panel runModalForDirectory: nil file: o_name] == NSOKButton ) { playlist_Export( p_playlist, [[o_save_panel filename] fileSystemRepresentation], "export-m3u" ); }}- (IBAction)playItem:(id)sender{ intf_thread_t * p_intf = [NSApp getIntf]; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist != NULL ) { playlist_Goto( p_playlist, [o_table_view selectedRow] ); vlc_object_release( p_playlist ); }}- (IBAction)deleteItems:(id)sender{ int i, c, i_row; NSMutableArray *o_to_delete; NSNumber *o_number; intf_thread_t * p_intf = [NSApp getIntf]; playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } o_to_delete = [NSMutableArray arrayWithArray:[[o_table_view selectedRowEnumerator] allObjects]]; c = (int)[o_to_delete count]; for( i = 0; i < c; i++ ) { o_number = [o_to_delete lastObject]; i_row = [o_number intValue]; if( p_playlist->i_index == i_row && p_playlist->i_status ) { playlist_Stop( p_playlist ); } [o_to_delete removeObject: o_number]; [o_table_view deselectRow: i_row]; playlist_Delete( p_playlist, i_row ); } vlc_object_release( p_playlist ); /* this is actually duplicity, because the intf.m manage also updates the view * when the playlist changes. we do this on purpose, because else there is a * delay of .5 sec or so when we delete an item */ [self playlistUpdated]; [self updateRowSelection];}- (IBAction)selectAll:(id)sender{ [o_table_view selectAll: nil];}- (IBAction)searchItem:(id)sender{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?