⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playlist.m

📁 video linux conference
💻 M
📖 第 1 页 / 共 3 页
字号:
            }            i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:                            [NSString stringWithFormat: @"%p",                            [[o_result objectAtIndex: [o_result count] - 1 ]                            pointerValue]]]];        }        if( i_row > -1 )        {            [o_outline_view selectRow:i_row byExtendingSelection: NO];            [o_outline_view scrollRowToVisible: i_row];        }    }    vlc_object_release( p_playlist );}- (NSMenu *)menuForEvent:(NSEvent *)o_event{    NSPoint pt;    vlc_bool_t b_rows;    vlc_bool_t b_item_sel;    pt = [o_outline_view convertPoint: [o_event locationInWindow]                                                 fromView: nil];    b_item_sel = ( [o_outline_view rowAtPoint: pt] != -1 &&                   [o_outline_view selectedRow] != -1 );    b_rows = [o_outline_view numberOfRows] != 0;    [o_mi_play setEnabled: b_item_sel];    [o_mi_delete setEnabled: b_item_sel];    [o_mi_selectall setEnabled: b_rows];    [o_mi_info setEnabled: b_item_sel];    return( o_ctx_menu );}- (playlist_item_t *)selectedPlaylistItem{    return [[o_outline_view itemAtRow: [o_outline_view selectedRow]]                                                                pointerValue];}- (void)outlineView: (NSTableView*)o_tv                  didClickTableColumn:(NSTableColumn *)o_tc{    int i_mode = 0, i_type;    intf_thread_t *p_intf = VLCIntf;    playlist_view_t *p_view;    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    /* Check whether the selected table column header corresponds to a       sortable table column*/    if( !( o_tc == o_tc_name || o_tc == o_tc_author ) )    {        vlc_object_release( p_playlist );        return;    }    p_view = playlist_ViewFind( p_playlist, i_current_view );    if( o_tc_sortColumn == o_tc )    {        b_isSortDescending = !b_isSortDescending;    }    else    {        b_isSortDescending = VLC_FALSE;    }    if( o_tc == o_tc_name )    {        i_mode = SORT_TITLE;    }    else if( o_tc == o_tc_author )    {        i_mode = SORT_AUTHOR;    }    if( b_isSortDescending )    {        i_type = ORDER_REVERSE;    }    else    {        i_type = ORDER_NORMAL;    }    vlc_mutex_lock( &p_playlist->object_lock );    playlist_RecursiveNodeSort( p_playlist, p_view->p_root, i_mode, i_type );    vlc_mutex_unlock( &p_playlist->object_lock );    vlc_object_release( p_playlist );    [self playlistUpdated];    o_tc_sortColumn = o_tc;    [o_outline_view setHighlightedTableColumn:o_tc];    if( b_isSortDescending )    {        [o_outline_view setIndicatorImage:o_descendingSortingImage                                                        inTableColumn:o_tc];    }    else    {        [o_outline_view setIndicatorImage:o_ascendingSortingImage                                                        inTableColumn:o_tc];    }}- (void)outlineView:(NSOutlineView *)outlineView                                willDisplayCell:(id)cell                                forTableColumn:(NSTableColumn *)tableColumn                                item:(id)item{    playlist_t *p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,                                          FIND_ANYWHERE );    id o_playing_item;    if( !p_playlist ) return;    o_playing_item = [o_outline_dict objectForKey:                [NSString stringWithFormat:@"%p",  p_playlist->status.p_item]];    if( [self isValueItem: o_playing_item inNode: item] ||                                                [o_playing_item isEqual: item] )    {        [cell setFont: [NSFont boldSystemFontOfSize: 0]];    }    else    {        [cell setFont: [NSFont systemFontOfSize: 0]];    }    vlc_object_release( p_playlist );}@end@implementation VLCPlaylist (NSOutlineViewDataSource)/* return the number of children for Obj-C pointer item */ /* DONE */- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item{    int i_return = 0;    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );    if( p_playlist == NULL || outlineView != o_outline_view )        return 0;    if( item == nil )    {        /* root object */        playlist_view_t *p_view;        p_view = playlist_ViewFind( p_playlist, i_current_view );        if( p_view && p_view->p_root )        {            i_return = p_view->p_root->i_children;            if( i_current_view == VIEW_CATEGORY )            {                i_return--; /* remove the GENERAL item from the list */                i_return += p_playlist->p_general->i_children; /* add the items of the general node */            }        }    }    else    {        playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];        if( p_item )            i_return = p_item->i_children;    }    vlc_object_release( p_playlist );        if( i_return <= 0 )        i_return = 0;        return i_return;}/* return the child at index for the Obj-C pointer item */ /* DONE */- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item{    playlist_item_t *p_return = NULL;    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );    NSValue *o_value;    if( p_playlist == NULL )        return nil;    if( item == nil )    {        /* root object */        playlist_view_t *p_view;        p_view = playlist_ViewFind( p_playlist, i_current_view );        if( p_view && p_view->p_root ) p_return = p_view->p_root->pp_children[index];                if( i_current_view == VIEW_CATEGORY )        {            if( p_playlist->p_general->i_children && index >= 0 && index < p_playlist->p_general->i_children )            {                p_return = p_playlist->p_general->pp_children[index];            }            else if( p_view && p_view->p_root && index >= 0 && index - p_playlist->p_general->i_children < p_view->p_root->i_children )            {                p_return = p_view->p_root->pp_children[index - p_playlist->p_general->i_children + 1];                            }        }    }    else    {        playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];        if( p_item && index < p_item->i_children && index >= 0 )            p_return = p_item->pp_children[index];    }        if( p_playlist->i_size >= 2 )    {        [o_status_field setStringValue: [NSString stringWithFormat:                    _NS("%i items in playlist"), p_playlist->i_size]];    }    else    {        if( p_playlist->i_size == 0 )        {            [o_status_field setStringValue: [NSString stringWithFormat:                    _NS("no items in playlist"), p_playlist->i_size]];        }        else        {            [o_status_field setStringValue: [NSString stringWithFormat:                    _NS("1 item in playlist"), p_playlist->i_size]];        }    }    vlc_object_release( p_playlist );    o_value = [[NSValue valueWithPointer: p_return] retain];    [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p", p_return]];    return o_value;}/* is the item expandable */- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item{    int i_return = 0;    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );    if( p_playlist == NULL )        return NO;    if( item == nil )    {        /* root object */        playlist_view_t *p_view;        p_view = playlist_ViewFind( p_playlist, i_current_view );        if( p_view && p_view->p_root ) i_return = p_view->p_root->i_children;                if( i_current_view == VIEW_CATEGORY )        {            i_return--;            i_return += p_playlist->p_general->i_children;        }    }    else    {        playlist_item_t *p_item = (playlist_item_t *)[item pointerValue];        if( p_item )            i_return = p_item->i_children;    }    vlc_object_release( p_playlist );    if( i_return <= 0 )        return NO;    else        return YES;}/* retrieve the string values for the cells */- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)o_tc byItem:(id)item{    id o_value = nil;    intf_thread_t *p_intf = VLCIntf;    playlist_t *p_playlist;    playlist_item_t *p_item;        if( item == nil || ![item isKindOfClass: [NSValue class]] ) return( @"error" );        p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                               FIND_ANYWHERE );    if( p_playlist == NULL )    {        return( @"error" );    }    p_item = (playlist_item_t *)[item pointerValue];    if( p_item == NULL )    {        vlc_object_release( p_playlist );        return( @"error");    }    if( [[o_tc identifier] isEqualToString:@"1"] )    {        o_value = [NSString stringWithUTF8String:            p_item->input.psz_name];        if( o_value == NULL )            o_value = [NSString stringWithCString:                p_item->input.psz_name];    }    else if( [[o_tc identifier] isEqualToString:@"2"] )    {        char *psz_temp;        psz_temp = vlc_input_item_GetInfo( &p_item->input ,_("Meta-information"),_("Artist") );        if( psz_temp == NULL )            o_value = @"";        else        {            o_value = [NSString stringWithUTF8String: psz_temp];            if( o_value == NULL )            {                o_value = [NSString stringWithCString: psz_temp];            }            free( psz_temp );        }    }    else if( [[o_tc identifier] isEqualToString:@"3"] )    {        char psz_duration[MSTRTIME_MAX_SIZE];        mtime_t dur = p_item->input.i_duration;        if( dur != -1 )        {            secstotimestr( psz_duration, dur/1000000 );            o_value = [NSString stringWithUTF8String: psz_duration];        }        else        {            o_value = @"-:--:--";        }    }    vlc_object_release( p_playlist );    return( o_value );}/* Required for drag & drop and reordering */- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard{/*    unsigned int i;    for( i = 0 ; i < [items count] ; i++ )    {        if( [outlineView levelForItem: [items objectAtIndex: i]] == 0 )        {            return NO;        }    }*/    return NO;}- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index{    NSPasteboard *o_pasteboard = [info draggingPasteboard];    if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )    {        return NSDragOperationGeneric;    }    return NSDragOperationNone;}- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index{    playlist_t * p_playlist =  vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );    NSPasteboard *o_pasteboard = [info draggingPasteboard];    if( !p_playlist ) return NO;    if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )    {        int i;        playlist_item_t *p_node = [item pointerValue];        NSArray *o_array = [NSArray array];        NSArray *o_values = [[o_pasteboard propertyListForType:                                        NSFilenamesPboardType]                                sortedArrayUsingSelector:                                        @selector(caseInsensitiveCompare:)];        for( i = 0; i < (int)[o_values count]; i++)        {            NSDictionary *o_dic;            o_dic = [NSDictionary dictionaryWithObject:[o_values                        objectAtIndex:i] forKey:@"ITEM_URL"];            o_array = [o_array arrayByAddingObject: o_dic];        }        if ( item == nil )        {            [self appendArray: o_array atPos: index enqueue: YES];        }        else if( p_node->i_children == -1 )        {            int i_counter;            playlist_item_t *p_real_node = NULL;            for( i_counter = 0 ; i_counter < p_node->i_parents ; i_counter++ )            {                if( p_node->pp_parents[i_counter]->i_view == i_current_view )                {                    p_real_node = p_node->pp_parents[i_counter]->p_parent;                    break;                }                if( i_counter == p_node->i_parents )                {                    return NO;                }            }            [self appendNodeArray: o_array inNode: p_real_node                atPos: index inView: i_current_view enqueue: YES];        }        else        {            [self appendNodeArray: o_array inNode: p_node                atPos: index inView: i_current_view enqueue: YES];        }        vlc_object_release( p_playlist );        return YES;    }    vlc_object_release( p_playlist );    return NO;}/* Delegate method of NSWindow *//*- (void)windowWillClose:(NSNotification *)aNotification{    [o_btn_playlist setState: NSOffState];}*/@end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -