Spracherkennung für: .m vermutete Sprache: Masm {Masm[45] Cobol[36] ABAP[33]} [Methode: maximale Elemente, drei Dimensionen]
/*****************************************************************************
* VLCPlayQueueDataSource.m: MacOS X interface module
*****************************************************************************
* Copyright (C) 2019 VLC authors and VideoLAN
*
* Authors: Felix Paul Kühne <fkuehne # 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "VLCPlayQueueDataSource.h"
#import "extensions/NSPasteboardItem+VLCAdditions.h"
#import "extensions/NSString+Helpers.h"
#import "extensions/NSView+VLCAdditions.h"
#import "main/VLCMain.h"
#import "playqueue/VLCPlayQueueController.h"
#import "playqueue/VLCPlayQueueTableCellView.h"
#import "playqueue/VLCPlayQueueItem.h"
#import "playqueue/VLCPlayQueueModel.h"
#import "library/VLCInputItem.h"
#import "library/VLCLibraryDataTypes.h"
#import "views/VLCDragDropView.h"
#import "views/VLCFileDragRecognisingView.h"
static NSString *VLCPlayQueueCellIdentifier = @"VLCPlayQueueCellIdentifier";
@interface VLCPlayQueueDataSource ()
{
VLCPlayQueueModel *_playQueueModel;
}
@end
@implementation VLCPlayQueueDataSource
- (void)setPlayQueueController:(VLCPlayQueueController *)playQueueController
{
_playQueueController = playQueueController;
_playQueueModel = _playQueueController.playQueueModel;
}
- (void)setCounterTextField:(NSTextField *)counterTextField
{
_counterTextField = counterTextField;
self.counterTextField.stringValue =
[NSString stringWithFormat:@"%lu", _playQueueModel.numberOfPlayQueueItems];
}
- (void)prepareForUse
{
[_tableView registerForDraggedTypes:@[
VLCMediaLibraryMediaItemPasteboardType,
VLCMediaLibraryMediaItemUTI,
VLCPlaylistItemPasteboardType,
NSPasteboardTypeURL,
NSPasteboardTypeFileURL,
NSPasteboardTypeString,
NSFilenamesPboardType
]];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return _playQueueModel.numberOfPlayQueueItems;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
VLCPlayQueueTableCellView *cellView =
[tableView makeViewWithIdentifier:VLCPlayQueueCellIdentifier owner:self];
if (cellView == nil) {
cellView = [VLCPlayQueueTableCellView fromNibWithOwner:self];
if (cellView == nil) {
msg_Err(getIntf(), "Failed to load nib file to show playlist items");
return nil;
}
cellView.identifier = VLCPlayQueueCellIdentifier;
}
VLCPlayQueueItem * const item = [_playQueueModel playQueueItemAtIndex:row];
if (!item) {
msg_Err(getIntf(), "playlist model did not return an item for representation");
return cellView;
}
cellView.representedPlayQueueItem = item;
cellView.representsCurrentPlayQueueItem = _playQueueController.currentPlayQueueIndex == (size_t)row;
return cellView;
}
- (void)playQueueUpdated
{
const NSUInteger numberOfPlayQueueItems = _playQueueModel.numberOfPlayQueueItems;
self.dragDropView.hidden = numberOfPlayQueueItems > 0 ? YES : NO;
self.counterTextField.stringValue = [NSString stringWithFormat:@"%lu", numberOfPlayQueueItems];
[_tableView reloadData];
}
- (void)playQueueItemsInsertedAtIndex:(NSUInteger)index count:(NSUInteger)count
{
const NSUInteger numberOfPlayQueueItems = _playQueueModel.numberOfPlayQueueItems;
self.dragDropView.hidden = numberOfPlayQueueItems > 0 ? YES : NO;
self.counterTextField.stringValue = [NSString stringWithFormat:@"%lu", numberOfPlayQueueItems];
if (count == 0) {
return;
}
NSAssert(index <= numberOfPlayQueueItems - count,
@"Inserted play queue rows must be within the model bounds");
NSIndexSet * const indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(index, count)];
[_tableView insertRowsAtIndexes:indexes withAnimation:NSTableViewAnimationEffectNone];
}
- (void)playQueueItemsUpdatedAtIndex:(NSUInteger)index count:(NSUInteger)count
{
if (count == 0) {
return;
}
const NSUInteger numberOfPlayQueueItems = _playQueueModel.numberOfPlayQueueItems;
NSAssert(index <= numberOfPlayQueueItems - count,
@"Updated play queue rows must be within the model bounds");
NSIndexSet * const indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(index, count)];
[_tableView reloadDataForRowIndexes:indexes columnIndexes:[NSIndexSet indexSetWithIndex:0]];
}
- (id<NSPasteboardWriting>)tableView:(NSTableView *)tableView pasteboardWriterForRow:(NSInteger)row
{
NSPasteboardItem * const pboardItem = [[NSPasteboardItem alloc] init];
VLCPlayQueueItem * const playlistItem = [_playQueueModel playQueueItemAtIndex:row];
[pboardItem setString:[@(playlistItem.uniqueID) stringValue] forType:VLCPlaylistItemPasteboardType];
return pboardItem;
}
- (NSDragOperation)tableView:(NSTableView *)tableView
validateDrop:(id<NSDraggingInfo>)info
proposedRow:(NSInteger)row
proposedDropOperation:(NSTableViewDropOperation)dropOperation
{
// Make drops at the end of the table go to the end.
if (row == -1) {
row = tableView.numberOfRows;
dropOperation = NSTableViewDropAbove;
[tableView setDropRow:row dropOperation:dropOperation];
}
// We don't ever want to drop onto a row, only between rows.
if (dropOperation == NSTableViewDropOn) {
[tableView setDropRow:row + 1 dropOperation:NSTableViewDropAbove];
}
return NSDragOperationCopy;
}
- (BOOL)tableView:(NSTableView *)tableView
acceptDrop:(id<NSDraggingInfo>)info
row:(NSInteger)row
dropOperation:(NSTableViewDropOperation)dropOperation
{
NSString *encodedIDtoMove = [info.draggingPasteboard stringForType:VLCPlaylistItemPasteboardType];
if (encodedIDtoMove != nil) {
int64_t uniqueID = [encodedIDtoMove integerValue];
[_playQueueController moveItemWithID:uniqueID toPosition:row];
return YES;
}
/* Collect library media items from all pasteboard items.
* Table view drags create one NSPasteboardItem per selected row, so we
* must iterate all of them to capture every dragged item. */
NSMutableArray<VLCMediaLibraryMediaItem *> * const allMediaItems = [NSMutableArray array];
for (NSPasteboardItem * const pboardItem in info.draggingPasteboard.pasteboardItems) {
NSData *itemData = [pboardItem dataForType:VLCMediaLibraryMediaItemPasteboardType];
if (!itemData) {
itemData = [pboardItem dataForType:VLCMediaLibraryMediaItemUTI];
}
if (!itemData) {
continue;
}
NSArray<VLCMediaLibraryMediaItem *> * const items = [VLCMediaLibraryMediaItem mediaItemsFromPasteboardData:itemData];
if (items) {
[allMediaItems addObjectsFromArray:items];
}
}
/* Collection view drags write a single aggregated payload directly on the
* dragging pasteboard instead of creating one NSPasteboardItem per item. */
if (allMediaItems.count == 0) {
NSData *itemData = [info.draggingPasteboard dataForType:VLCMediaLibraryMediaItemPasteboardType];
if (!itemData) {
itemData = [info.draggingPasteboard dataForType:VLCMediaLibraryMediaItemUTI];
}
if (itemData) {
NSArray<VLCMediaLibraryMediaItem *> * const items = [VLCMediaLibraryMediaItem mediaItemsFromPasteboardData:itemData];
if (items) {
[allMediaItems addObjectsFromArray:items];
}
}
}
if (allMediaItems.count > 0) {
NSInteger insertionIndex = (NSInteger)row;
for (VLCMediaLibraryMediaItem * const mediaItem in allMediaItems) {
[_playQueueController addInputItem:mediaItem.inputItem.vlcInputItem
atPosition:insertionIndex
startPlayback:NO];
insertionIndex++;
}
return YES;
}
return [VLCFileDragRecognisingView
handlePasteboardFromDragSessionAsPlayQueueItems:info.draggingPasteboard];
}
- (NSArray<NSTableViewRowAction *> *)tableView:(NSTableView *)tableView
rowActionsForRow:(NSInteger)row
edge:(NSTableRowActionEdge)edge
{
if (edge == NSTableRowActionEdgeTrailing) {
VLCPlayQueueItem * const item = [_playQueueController.playQueueModel playQueueItemAtIndex:row];
if (item == nil) {
return @[];
}
NSTableViewRowAction * const removeAction =
[NSTableViewRowAction rowActionWithStyle:NSTableViewRowActionStyleDestructive
title:_NS("Remove from Play Queue")
handler:^(NSTableViewRowAction * const __unused action, const NSInteger row) {
NSIndexSet * const indices = [NSIndexSet indexSetWithIndex:row];
[_playQueueController removeItemsAtIndexes:indices];
}];
return @[removeAction];
}
return @[];
}
- (void)scrollToCurrentPlayQueueItem
{
[_tableView scrollRowToVisible:_playQueueController.currentPlayQueueIndex];
}
@end
[Dauer der Verarbeitung: 0.4 Sekunden, vorverarbeitet 2026-10-24]