Commit 31bf40d0 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/VLCMediaList.m: Code cleanup and use Objective-C 2.0...

MacOSX/Framework/VLCMediaList.m: Code cleanup and use Objective-C 2.0 @property. (Patch by Enrique Osuna).
parent 3e27f238
...@@ -32,42 +32,100 @@ extern NSString * VLCMediaListItemDeleted; ...@@ -32,42 +32,100 @@ extern NSString * VLCMediaListItemDeleted;
@class VLCMediaList; @class VLCMediaList;
@class VLCMediaListAspect; @class VLCMediaListAspect;
// TODO: Documentation /**
* TODO: Documentation VLCMediaListDelegate
*/
@protocol VLCMediaListDelegate @protocol VLCMediaListDelegate
/**
* TODO: Documentation - [VLCMediaListDelegate mediaList:mediaAdded:atIndex:]
*/
- (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(int)index; - (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaListDelegate mediaList:mediaRemovedAtIndex:]
*/
- (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(int)index; - (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(int)index;
@end @end
// TODO: Documentation /**
* TODO: Documentation VLCMediaList
*/
@interface VLCMediaList : NSObject @interface VLCMediaList : NSObject
{ {
void * p_mlist; //< Internal instance of media list void * p_mlist; //< Internal instance of media list
id <VLCMediaListDelegate,NSObject> delegate; //< Delegate object id <VLCMediaListDelegate,NSObject> delegate; //< Delegate object
NSMutableArray *cachedMedia; /* We need that private copy because of Cocoa Bindings, that need to be working on first thread */ /* We need that private copy because of Cocoa Bindings, that need to be working on first thread */
VLCMediaListAspect * flatAspect; NSMutableArray * cachedMedia; //< Private copy of media objects.
VLCMediaListAspect * hierarchicalAspect; VLCMediaListAspect * flatAspect; //< TODO: Documentation VLCMediaList.flatAspect
VLCMediaListAspect * hierarchicalNodeAspect; VLCMediaListAspect * hierarchicalAspect; //< TODO: Documentation VLCMediaList.hierarchicalAspect
VLCMediaListAspect * hierarchicalNodeAspect; //< TODO: Documentation VLCMediaList.hierarchicalNodeAspect
} }
/* Properties */
- (void)setDelegate:(id)value;
- (id)delegate;
/* Operations */ /* Operations */
/**
* TODO: Documentation - [VLCMediaList lock]
*/
- (void)lock; - (void)lock;
/**
* TODO: Documentation - [VLCMediaList unlock]
*/
- (void)unlock; - (void)unlock;
/**
* TODO: Documentation - [VLCMediaList addMedia:]
*/
- (int)addMedia:(VLCMedia *)media; - (int)addMedia:(VLCMedia *)media;
/**
* TODO: Documentation - [VLCMediaList insertMedia:atIndex:]
*/
- (void)insertMedia:(VLCMedia *)media atIndex:(int)index; - (void)insertMedia:(VLCMedia *)media atIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaList removeMediaAtIndex:]
*/
- (void)removeMediaAtIndex:(int)index; - (void)removeMediaAtIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaList mediaAtIndex:]
*/
- (VLCMedia *)mediaAtIndex:(int)index; - (VLCMedia *)mediaAtIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaList indexOfMedia:]
*/
- (int)indexOfMedia:(VLCMedia *)media; - (int)indexOfMedia:(VLCMedia *)media;
- (int)count;
- (BOOL)isReadOnly; /* Properties */
/**
* TODO: Documentation VLCMediaList.count
*/
@property (readonly) int count;
/**
* TODO: Documentation VLCMediaList.delegate
*/
@property (assign) id delegate;
/**
* TODO: Documentation VLCMediaList.isReadOnly
*/
@property (readonly) BOOL isReadOnly;
/* Media list aspect */ /* Media list aspect */
- (VLCMediaListAspect *)hierarchicalAspect; /**
- (VLCMediaListAspect *)hierarchicalNodeAspect; * TODO: Documentation VLCMediaList.hierarchicalAspect
- (VLCMediaListAspect *)flatAspect; */
@property (readonly) VLCMediaListAspect * hierarchicalAspect;
/**
* TODO: Documentation VLCMediaList.hierarchicalNodeAspect
*/
@property (readonly) VLCMediaListAspect * hierarchicalNodeAspect;
/**
* TODO: Documentation VLCMediaList.flatAspect
*/
@property (readonly) VLCMediaListAspect * flatAspect;
@end @end
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include <vlc/libvlc.h> #include <vlc/libvlc.h>
/* Notification Messages */ /* Notification Messages */
NSString *VLCMediaListItemAdded = @"VLCMediaListItemAdded"; NSString * VLCMediaListItemAdded = @"VLCMediaListItemAdded";
NSString *VLCMediaListItemDeleted = @"VLCMediaListItemDeleted"; NSString * VLCMediaListItemDeleted = @"VLCMediaListItemDeleted";
// TODO: Documentation // TODO: Documentation
@interface VLCMediaList (Private) @interface VLCMediaList (Private)
...@@ -44,7 +44,7 @@ NSString *VLCMediaListItemDeleted = @"VLCMediaListItemDeleted"; ...@@ -44,7 +44,7 @@ NSString *VLCMediaListItemDeleted = @"VLCMediaListItemDeleted";
@end @end
/* libvlc event callback */ /* libvlc event callback */
static void HandleMediaListItemAdded(const libvlc_event_t *event, void *user_data) static void HandleMediaListItemAdded(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;
...@@ -67,19 +67,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -67,19 +67,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
[pool release]; [pool release];
} }
@implementation VLCMediaList (KeyValueCodingCompliance)
/* For the @"media" key */
- (int) countOfMedia
{
return [self count];
}
- (id) objectInMediaAtIndex:(int)i
{
return [self mediaAtIndex:i];
}
@end
@implementation VLCMediaList @implementation VLCMediaList
- (id)init - (id)init
{ {
...@@ -87,9 +74,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -87,9 +74,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{ {
// Create a new libvlc media list instance // Create a new libvlc media list instance
libvlc_exception_t p_e; libvlc_exception_t p_e;
libvlc_exception_init(&p_e); libvlc_exception_init( &p_e );
p_mlist = libvlc_media_list_new([VLCLibrary sharedInstance], &p_e); p_mlist = libvlc_media_list_new( [VLCLibrary sharedInstance], &p_e );
quit_on_exception(&p_e); quit_on_exception( &p_e );
// Initialize internals to defaults // Initialize internals to defaults
cachedMedia = [[NSMutableArray alloc] init]; cachedMedia = [[NSMutableArray alloc] init];
...@@ -119,7 +106,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -119,7 +106,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)dealloc - (void)dealloc
{ {
// Release allocated memory // Release allocated memory
libvlc_media_list_release(p_mlist); delegate = nil;
libvlc_media_list_release( p_mlist );
[cachedMedia release]; [cachedMedia release];
[flatAspect release]; [flatAspect release];
[hierarchicalAspect release]; [hierarchicalAspect release];
...@@ -129,7 +118,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -129,7 +118,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (NSString *)description - (NSString *)description
{ {
NSMutableString *content = [NSMutableString string]; NSMutableString * content = [NSMutableString string];
int i; int i;
for( i = 0; i < [self count]; i++) for( i = 0; i < [self count]; i++)
{ {
...@@ -138,16 +127,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -138,16 +127,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
return [NSString stringWithFormat:@"<%@ %p> {\n%@}", [self className], self, content]; return [NSString stringWithFormat:@"<%@ %p> {\n%@}", [self className], self, content];
} }
- (void)setDelegate:(id)value
{
delegate = value;
}
- (id)delegate
{
return delegate;
}
- (void)lock - (void)lock
{ {
libvlc_media_list_lock( p_mlist ); libvlc_media_list_lock( p_mlist );
...@@ -192,11 +171,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -192,11 +171,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
return [cachedMedia objectAtIndex:index]; return [cachedMedia objectAtIndex:index];
} }
- (int)count
{
return [cachedMedia count];
}
- (int)indexOfMedia:(VLCMedia *)media - (int)indexOfMedia:(VLCMedia *)media
{ {
libvlc_exception_t p_e; libvlc_exception_t p_e;
...@@ -207,6 +181,24 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -207,6 +181,24 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
return result; return result;
} }
/* KVC Compliance: For the @"media" key */
- (int)countOfMedia
{
return [self count];
}
- (id)objectInMediaAtIndex:(int)i
{
return [self mediaAtIndex:i];
}
- (int)count
{
return [cachedMedia count];
}
@synthesize delegate;
- (BOOL)isReadOnly - (BOOL)isReadOnly
{ {
libvlc_exception_t p_e; libvlc_exception_t p_e;
...@@ -222,8 +214,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -222,8 +214,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{ {
if( hierarchicalAspect ) if( hierarchicalAspect )
return hierarchicalAspect; return hierarchicalAspect;
libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_view( p_mlist, NULL ); libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_view( p_mlist, NULL );
hierarchicalAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv andMediaList:self] retain]; hierarchicalAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView:p_mlv andMediaList:self] retain];
libvlc_media_list_view_release( p_mlv ); libvlc_media_list_view_release( p_mlv );
return hierarchicalAspect; return hierarchicalAspect;
} }
...@@ -232,8 +225,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -232,8 +225,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{ {
if( hierarchicalNodeAspect ) if( hierarchicalNodeAspect )
return hierarchicalNodeAspect; return hierarchicalNodeAspect;
libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_node_view( p_mlist, NULL ); libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_node_view( p_mlist, NULL );
hierarchicalNodeAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv andMediaList:self] retain]; hierarchicalNodeAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView:p_mlv andMediaList:self] retain];
libvlc_media_list_view_release( p_mlv ); libvlc_media_list_view_release( p_mlv );
return hierarchicalNodeAspect; return hierarchicalNodeAspect;
} }
...@@ -242,8 +236,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -242,8 +236,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{ {
if( flatAspect ) if( flatAspect )
return flatAspect; return flatAspect;
libvlc_media_list_view_t * p_mlv = libvlc_media_list_flat_view( p_mlist, NULL ); libvlc_media_list_view_t * p_mlv = libvlc_media_list_flat_view( p_mlist, NULL );
flatAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv andMediaList:self] retain]; flatAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView:p_mlv andMediaList:self] retain];
libvlc_media_list_view_release( p_mlv ); libvlc_media_list_view_release( p_mlv );
return flatAspect; return flatAspect;
} }
...@@ -261,14 +256,15 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -261,14 +256,15 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
if( self = [super init] ) if( self = [super init] )
{ {
p_mlist = p_new_mlist; p_mlist = p_new_mlist;
libvlc_media_list_retain(p_mlist); libvlc_media_list_retain( p_mlist );
libvlc_media_list_lock(p_mlist); libvlc_media_list_lock( p_mlist );
cachedMedia = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count(p_mlist, NULL)]; cachedMedia = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count( p_mlist, NULL )];
int i, count = libvlc_media_list_count(p_mlist, NULL);
int i, count = libvlc_media_list_count( p_mlist, NULL );
for( i = 0; i < count; i++ ) for( i = 0; i < count; i++ )
{ {
libvlc_media_descriptor_t * p_md = libvlc_media_list_item_at_index(p_mlist, i, NULL); libvlc_media_descriptor_t * p_md = libvlc_media_list_item_at_index( p_mlist, i, NULL );
[cachedMedia addObject:[VLCMedia mediaWithLibVLCMediaDescriptor: p_md]]; [cachedMedia addObject:[VLCMedia mediaWithLibVLCMediaDescriptor:p_md]];
libvlc_media_descriptor_release(p_md); libvlc_media_descriptor_release(p_md);
} }
[self initInternalMediaList]; [self initInternalMediaList];
...@@ -288,9 +284,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use ...@@ -288,9 +284,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{ {
// Add event callbacks // Add event callbacks
libvlc_exception_t p_e; libvlc_exception_t p_e;
libvlc_exception_init(&p_e); libvlc_exception_init( &p_e );
libvlc_event_manager_t *p_em = libvlc_media_list_event_manager( p_mlist, &p_e ); libvlc_event_manager_t * p_em = libvlc_media_list_event_manager( p_mlist, &p_e );
libvlc_event_attach( p_em, libvlc_MediaListItemAdded, HandleMediaListItemAdded, self, &p_e ); libvlc_event_attach( p_em, libvlc_MediaListItemAdded, HandleMediaListItemAdded, self, &p_e );
libvlc_event_attach( p_em, libvlc_MediaListItemDeleted, HandleMediaListItemDeleted, self, &p_e ); libvlc_event_attach( p_em, libvlc_MediaListItemDeleted, HandleMediaListItemDeleted, self, &p_e );
......
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