Commit 6fba236c authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

macosx/framework: Correctly set the children of the nodes.

parent d206ed68
...@@ -43,19 +43,30 @@ ...@@ -43,19 +43,30 @@
@end @end
@implementation VLCMediaListAspectNode @implementation VLCMediaListAspectNode
- (id)init
{
if(self = [super init])
{
media = nil;
children = nil;
}
return self;
}
- (void)dealloc
{
[media release];
[children release];
[super dealloc];
}
@synthesize media; @synthesize media;
@synthesize children; @synthesize children;
- (BOOL)isLeaf - (BOOL)isLeaf
{ {
return self.children == NULL; return self.children == nil;
} }
-(void)dealloc
{
[self.children release];
[super dealloc];
}
@end @end
@implementation VLCMediaListAspect (KeyValueCodingCompliance) @implementation VLCMediaListAspect (KeyValueCodingCompliance)
...@@ -113,6 +124,24 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * ...@@ -113,6 +124,24 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void *
[parentMediaList release]; [parentMediaList release];
[super dealloc]; [super dealloc];
} }
- (void)release
{
@synchronized(self)
{
if([self retainCount] <= 1)
{
/* We must make sure we won't receive new event after an upcoming dealloc
* We also may receive a -retain in some event callback that may occcur
* Before libvlc_event_detach. So this can't happen in dealloc */
libvlc_event_manager_t * p_em = libvlc_media_list_view_event_manager(p_mlv);
libvlc_event_detach(p_em, libvlc_MediaListViewItemDeleted, HandleMediaListViewItemDeleted, self, NULL);
libvlc_event_detach(p_em, libvlc_MediaListViewItemAdded, HandleMediaListViewItemAdded, self, NULL);
}
[super release];
}
}
- (NSString *)description - (NSString *)description
{ {
NSMutableString * content = [NSMutableString string]; NSMutableString * content = [NSMutableString string];
...@@ -155,6 +184,12 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * ...@@ -155,6 +184,12 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void *
{ {
VLCMediaListAspectNode * node = [[[VLCMediaListAspectNode alloc] init] autorelease]; VLCMediaListAspectNode * node = [[[VLCMediaListAspectNode alloc] init] autorelease];
[node setMedia:[self mediaAtIndex: index]]; [node setMedia:[self mediaAtIndex: index]];
libvlc_media_list_view_t * p_sub_mlv = libvlc_media_list_view_children_for_item([self libVLCMediaListView], [node.media libVLCMediaDescriptor], NULL);
if( p_sub_mlv )
{
[node setChildren:[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_sub_mlv]];
libvlc_media_list_view_release(p_sub_mlv);
}
return node; return node;
} }
...@@ -218,6 +253,8 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * ...@@ -218,6 +253,8 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void *
VLCMediaListAspectNode * node = [[[VLCMediaListAspectNode alloc] init] autorelease]; VLCMediaListAspectNode * node = [[[VLCMediaListAspectNode alloc] init] autorelease];
[node setMedia:[VLCMedia mediaWithLibVLCMediaDescriptor: p_md]]; [node setMedia:[VLCMedia mediaWithLibVLCMediaDescriptor: p_md]];
[node setChildren: p_sub_mlv ? [VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_sub_mlv] : nil]; [node setChildren: p_sub_mlv ? [VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_sub_mlv] : nil];
if( p_sub_mlv ) NSAssert(![node isLeaf], @"Not leaf");
[cachedNode addObject:node]; [cachedNode addObject:node];
libvlc_media_descriptor_release(p_md); libvlc_media_descriptor_release(p_md);
if( p_sub_mlv ) libvlc_media_list_view_release(p_sub_mlv); if( p_sub_mlv ) libvlc_media_list_view_release(p_sub_mlv);
...@@ -266,7 +303,17 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * ...@@ -266,7 +303,17 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void *
VLCMedia * media = [args objectForKey:@"media"]; VLCMedia * media = [args objectForKey:@"media"];
VLCMediaListAspectNode * node = [[[VLCMediaListAspectNode alloc] init] autorelease]; VLCMediaListAspectNode * node = [[[VLCMediaListAspectNode alloc] init] autorelease];
[node setMedia:media]; [node setMedia:media];
[node setChildren:[self childrenAtIndex:index]];
/* Set the sub media list view we enventually have */
libvlc_media_list_view_t * p_sub_mlv = libvlc_media_list_view_children_for_item([self libVLCMediaListView], [media libVLCMediaDescriptor], NULL);
if( p_sub_mlv )
{
[node setChildren:[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_sub_mlv]];
libvlc_media_list_view_release(p_sub_mlv);
NSAssert(![node isLeaf], @"Not leaf");
}
/* Sanity check */ /* Sanity check */
if( index && index > [cachedNode count] ) if( index && index > [cachedNode count] )
index = [cachedNode count]; index = [cachedNode count];
......
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