VLCPLItem.m 2.17 KB
Newer Older
1
/*****************************************************************************
2
 * VLCPLItem.m: MacOS X interface module
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *****************************************************************************
 * Copyright (C) 2014 VLC authors and VideoLAN
 * $Id$
 *
 * 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.
 *****************************************************************************/

22
#import "VLCPLItem.h"
23 24 25 26 27

#include <vlc_playlist.h>
#include <vlc_input_item.h>

#pragma mark -
28

29
@implementation VLCPLItem
30

31
- (id)initWithPlaylistItem:(playlist_item_t *)p_item;
32 33 34
{
    self = [super init];
    if(self) {
35
        _plItemId = p_item->i_id;
36

37 38
        _input = p_item->p_input;
        input_item_Hold(_input);
39 40 41 42 43 44 45 46
        _children = [[NSMutableArray alloc] init];
    }

    return self;
}

- (void)dealloc
{
47
    input_item_Release(_input);
48 49
}

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
// own hash and isEqual methods are important to retain expandable state
// when items are moved / recreated
- (NSUInteger)hash
{
    return (NSUInteger)[self plItemId];
}

- (BOOL)isEqual:(id)other
{
    if (other == self)
        return YES;
    if (!other || ![other isKindOfClass:[self class]])
        return NO;
    return [self plItemId] == [other plItemId];
}
65 66 67 68 69 70 71 72 73 74 75

- (BOOL)isLeaf
{
    return [_children count] == 0;
}

- (void)clear
{
    [_children removeAllObjects];
}

76
- (void)addChild:(VLCPLItem *)item atPos:(int)pos
77 78
{
    [_children insertObject:item atIndex:pos];
79
    [item setParent: self];
80 81 82

}

83
- (void)deleteChild:(VLCPLItem *)child
84
{
85
    [child setParent:nil];
86 87 88 89
    [_children removeObject:child];
}

@end