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