Commit 82397876 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: fix runtime exception and clean-up code

parent 56bc5203
/*****************************************************************************
* playlistinfo.h: MacOS X interface module
*****************************************************************************
* Copyright (C) 2002-2012 VLC authors and VideoLAN
* Copyright (C) 2002-2015 VLC authors and VideoLAN
* $Id$
*
* Authors: Benjamin Pracht <bigben at videolan dot org>
......@@ -94,15 +94,8 @@
IBOutlet id o_video_lbl;
IBOutlet id o_video_decoded_lbl;
IBOutlet id o_video_decoded_txt;
VLCInfoTreeItem * rootItem;
input_item_t * p_item;
BOOL b_awakeFromNib;
BOOL b_stats;
}
@property (readonly) input_item_t * item;
@property (readonly) input_item_t *item;
- (void)updateCocoaWindowLevel:(NSInteger)i_level;
- (void)initPanel;
......@@ -112,7 +105,7 @@
- (IBAction)downloadCoverArt:(id)sender;
- (void)initMediaPanelStats;
- (void)updatePanelWithItem:(input_item_t *)_p_item;
- (void)setMeta: (char *)meta forLabel: (id)theItem;
- (void)setMeta:(char *)meta forLabel:(id)theItem;
- (void)updateMetadata;
- (void)updateStatistics;
......@@ -120,21 +113,12 @@
@end
@interface VLCInfoTreeItem : NSObject
{
NSString *o_name;
NSString *o_value;
int i_object_id;
input_item_t * p_item;
VLCInfoTreeItem *o_parent;
NSMutableArray *o_children;
}
@property (readonly) int numberOfChildren;
@property (readonly) NSString * name;
@property (readonly) NSString * value;
@property (readonly) NSString *name;
@property (readonly) NSString *value;
- (VLCInfoTreeItem *)childAtIndex:(NSUInteger)i_index;
- (void)refresh;
@end
/*****************************************************************************
r playlistinfo.m: MacOS X interface module
*****************************************************************************
* Copyright (C) 2002-2012 VLC authors and VideoLAN
* Copyright (C) 2002-2015 VLC authors and VideoLAN
* $Id$
*
* Authors: Benjamin Pracht <bigben at videolan dot org>
......@@ -36,6 +36,17 @@
* VLCPlaylistInfo Implementation
*****************************************************************************/
@interface VLCInfo ()
{
VLCInfoTreeItem *rootItem;
input_item_t *p_item;
BOOL b_awakeFromNib;
BOOL b_stats;
}
@end
@implementation VLCInfo
static VLCInfo *_o_sharedInstance = nil;
......@@ -423,24 +434,36 @@ error:
@end
@implementation VLCInfoTreeItem
@interface VLCInfoTreeItem ()
{
NSString *_name;
NSString *_value;
int i_object_id;
input_item_t * p_item;
VLCInfoTreeItem *_parent;
NSMutableArray *_children;
BOOL _isALeafNode;
}
@synthesize name = o_name, value = o_value;
@end
@implementation VLCInfoTreeItem
#define IsALeafNode ((id)-1)
@synthesize name = _name, value = _value;
- (id)initWithName: (NSString *)o_item_name value: (NSString *)o_item_value ID: (int)i_id
parent:(VLCInfoTreeItem *)o_parent_item
- (id)initWithName:(NSString *)item_name
value:(NSString *)item_value
ID:(int)i_id
parent:(VLCInfoTreeItem *)parent_item
{
self = [super init];
if (self != nil) {
o_name = [o_item_name copy];
o_value = [o_item_value copy];
_name = [item_name copy];
_value = [item_value copy];
i_object_id = i_id;
o_parent = o_parent_item;
_parent = parent_item;
p_item = [(VLCInfo *)[[VLCMain sharedInstance] info] item];
o_children = nil;
}
return self;
}
......@@ -452,48 +475,60 @@ error:
- (void)dealloc
{
if (o_children != IsALeafNode) [o_children release];
[o_name release];
[o_value release];
if (p_item) vlc_gc_decref(p_item);
if (_children)
[_children release];
[_name release];
[_value release];
if (p_item)
vlc_gc_decref(p_item);
[super dealloc];
}
/* Creates and returns the array of children
* Loads children incrementally */
- (NSArray *)children
- (void)_updateChildren
{
if (!p_item)
return nil;
if (o_children == NULL) {
o_children = [[NSMutableArray alloc] init];
if (i_object_id == -1) {
vlc_mutex_lock(&p_item->lock);
for (int i = 0 ; i < p_item->i_categories ; i++) {
NSString * name = [NSString stringWithUTF8String:p_item->pp_categories[i]->psz_name];
VLCInfoTreeItem * item = [[VLCInfoTreeItem alloc] initWithName:name value:@"" ID:i parent:self];
[item autorelease];
[o_children addObject:item];
}
vlc_mutex_unlock(&p_item->lock);
return;
if (_children != nil)
return;
_children = [[NSMutableArray alloc] init];
if (i_object_id == -1) {
vlc_mutex_lock(&p_item->lock);
for (int i = 0 ; i < p_item->i_categories ; i++) {
NSString * name = [NSString stringWithUTF8String:p_item->pp_categories[i]->psz_name];
VLCInfoTreeItem * item = [[VLCInfoTreeItem alloc]
initWithName:name
value:@""
ID:i
parent:self];
[item autorelease];
[_children addObject:item];
}
else if (o_parent->i_object_id == -1) {
vlc_mutex_lock(&p_item->lock);
info_category_t * cat = p_item->pp_categories[i_object_id];
for (int i = 0 ; i < cat->i_infos ; i++) {
NSString * name = [NSString stringWithUTF8String:cat->pp_infos[i]->psz_name];
NSString * value = [NSString stringWithUTF8String:cat->pp_infos[i]->psz_value ? : ""];
VLCInfoTreeItem * item = [[VLCInfoTreeItem alloc] initWithName:name value:value ID:i parent:self];
[item autorelease];
[o_children addObject:item];
}
vlc_mutex_unlock(&p_item->lock);
vlc_mutex_unlock(&p_item->lock);
_isALeafNode = NO;
}
else if (_parent->i_object_id == -1) {
vlc_mutex_lock(&p_item->lock);
info_category_t * cat = p_item->pp_categories[i_object_id];
for (int i = 0 ; i < cat->i_infos ; i++) {
NSString * name = [NSString stringWithUTF8String:cat->pp_infos[i]->psz_name];
NSString * value = [NSString stringWithUTF8String:cat->pp_infos[i]->psz_value ? : ""];
VLCInfoTreeItem * item = [[VLCInfoTreeItem alloc]
initWithName:name
value:value
ID:i
parent:self];
[item autorelease];
[_children addObject:item];
}
else
o_children = IsALeafNode;
vlc_mutex_unlock(&p_item->lock);
_isALeafNode = NO;
}
return o_children;
else
_isALeafNode = YES;
}
- (void)refresh
......@@ -501,20 +536,25 @@ error:
if (p_item)
vlc_gc_decref(p_item);
p_item = [(VLCInfo *)[[VLCMain sharedInstance] info] item];
p_item = [[VLCInfo sharedInstance] item];
[o_children release];
o_children = nil;
[_children release];
_children = nil;
}
- (VLCInfoTreeItem *)childAtIndex:(NSUInteger)i_index {
return [[self children] objectAtIndex:i_index];
- (VLCInfoTreeItem *)childAtIndex:(NSUInteger)i_index
{
return [_children objectAtIndex:i_index];
}
- (int)numberOfChildren {
- (int)numberOfChildren
{
[self _updateChildren];
if (_isALeafNode)
return -1;
id i_tmp = [self children];
return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
return [_children count];
}
@end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment