Commit 13d8a3f1 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/VLCMediaListAspect.m: Update the cachedMedia array.

parent c721c836
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
@interface VLCMediaListAspect (Private) @interface VLCMediaListAspect (Private)
/* Initializers */ /* Initializers */
- (void)initInternalMediaListView; - (void)initInternalMediaListView;
- (void)mediaListViewItemAdded:(NSDictionary *)args;
- (void)mediaListViewItemRemoved:(NSNumber *)index;
@end @end
@implementation VLCMediaListAspect (KeyValueCodingCompliance) @implementation VLCMediaListAspect (KeyValueCodingCompliance)
...@@ -52,16 +55,22 @@ static void HandleMediaListViewItemAdded(const libvlc_event_t *event, void *user ...@@ -52,16 +55,22 @@ static void HandleMediaListViewItemAdded(const libvlc_event_t *event, void *user
{ {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id self = user_data; id self = user_data;
int index = event->u.media_list_view_item_added.index; [[VLCEventManager sharedManager] callOnMainThreadObject:self
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"media"]; withMethod:@selector(mediaListViewItemAdded:)
withArgumentAsObject:[NSDictionary dictionaryWithObjectsAndKeys:
[VLCMedia mediaWithLibVLCMediaDescriptor:event->u.media_list_item_added.item], @"media",
[NSNumber numberWithInt:event->u.media_list_item_added.index], @"index",
nil]];
[pool release]; [pool release];
} }
static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * user_data) static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * user_data)
{ {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id self = user_data; id self = user_data;
int index = event->u.media_list_view_item_deleted.index; [[VLCEventManager sharedManager] callOnMainThreadObject:self
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"media"]; withMethod:@selector(mediaListViewItemRemoved:)
withArgumentAsObject:[NSNumber numberWithInt:event->u.media_list_item_deleted.index]];
[pool release]; [pool release];
} }
...@@ -142,5 +151,22 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void * ...@@ -142,5 +151,22 @@ static void HandleMediaListViewItemDeleted( const libvlc_event_t * event, void *
libvlc_event_attach( p_em, libvlc_MediaListViewItemDeleted, HandleMediaListViewItemDeleted, self, &e ); libvlc_event_attach( p_em, libvlc_MediaListViewItemDeleted, HandleMediaListViewItemDeleted, self, &e );
quit_on_exception( &e ); quit_on_exception( &e );
} }
- (void)mediaListViewItemAdded:(NSDictionary *)args
{
int index = [[args objectForKey:@"index"] intValue];
VLCMedia * media = [args objectForKey:@"media"];
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"media"];
[cachedMedia insertObject:media atIndex:index];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"media"];
}
- (void)mediaListViewItemRemoved:(NSNumber *)index
{
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"];
[cachedMedia removeObjectAtIndex:[index intValue]];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"];
}
@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