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;
@class VLCMediaList;
@class VLCMediaListAspect;
// TODO: Documentation
/**
* TODO: Documentation VLCMediaListDelegate
*/
@protocol VLCMediaListDelegate
/**
* TODO: Documentation - [VLCMediaListDelegate mediaList:mediaAdded:atIndex:]
*/
- (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaListDelegate mediaList:mediaRemovedAtIndex:]
*/
- (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(int)index;
@end
// TODO: Documentation
/**
* TODO: Documentation VLCMediaList
*/
@interface VLCMediaList : NSObject
{
void * p_mlist; //< Internal instance of media list
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 */
VLCMediaListAspect * flatAspect;
VLCMediaListAspect * hierarchicalAspect;
VLCMediaListAspect * hierarchicalNodeAspect;
void * p_mlist; //< Internal instance of media list
id <VLCMediaListDelegate,NSObject> delegate; //< Delegate object
/* We need that private copy because of Cocoa Bindings, that need to be working on first thread */
NSMutableArray * cachedMedia; //< Private copy of media objects.
VLCMediaListAspect * flatAspect; //< TODO: Documentation VLCMediaList.flatAspect
VLCMediaListAspect * hierarchicalAspect; //< TODO: Documentation VLCMediaList.hierarchicalAspect
VLCMediaListAspect * hierarchicalNodeAspect; //< TODO: Documentation VLCMediaList.hierarchicalNodeAspect
}
/* Properties */
- (void)setDelegate:(id)value;
- (id)delegate;
/* Operations */
/**
* TODO: Documentation - [VLCMediaList lock]
*/
- (void)lock;
/**
* TODO: Documentation - [VLCMediaList unlock]
*/
- (void)unlock;
/**
* TODO: Documentation - [VLCMediaList addMedia:]
*/
- (int)addMedia:(VLCMedia *)media;
/**
* TODO: Documentation - [VLCMediaList insertMedia:atIndex:]
*/
- (void)insertMedia:(VLCMedia *)media atIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaList removeMediaAtIndex:]
*/
- (void)removeMediaAtIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaList mediaAtIndex:]
*/
- (VLCMedia *)mediaAtIndex:(int)index;
/**
* TODO: Documentation - [VLCMediaList indexOfMedia:]
*/
- (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 */
- (VLCMediaListAspect *)hierarchicalAspect;
- (VLCMediaListAspect *)hierarchicalNodeAspect;
- (VLCMediaListAspect *)flatAspect;
/**
* TODO: Documentation VLCMediaList.hierarchicalAspect
*/
@property (readonly) VLCMediaListAspect * hierarchicalAspect;
/**
* TODO: Documentation VLCMediaList.hierarchicalNodeAspect
*/
@property (readonly) VLCMediaListAspect * hierarchicalNodeAspect;
/**
* TODO: Documentation VLCMediaList.flatAspect
*/
@property (readonly) VLCMediaListAspect * flatAspect;
@end
......@@ -30,8 +30,8 @@
#include <vlc/libvlc.h>
/* Notification Messages */
NSString *VLCMediaListItemAdded = @"VLCMediaListItemAdded";
NSString *VLCMediaListItemDeleted = @"VLCMediaListItemDeleted";
NSString * VLCMediaListItemAdded = @"VLCMediaListItemAdded";
NSString * VLCMediaListItemDeleted = @"VLCMediaListItemDeleted";
// TODO: Documentation
@interface VLCMediaList (Private)
......@@ -44,7 +44,7 @@ NSString *VLCMediaListItemDeleted = @"VLCMediaListItemDeleted";
@end
/* 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];
id self = user_data;
......@@ -67,19 +67,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
[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
- (id)init
{
......@@ -87,9 +74,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{
// Create a new libvlc media list instance
libvlc_exception_t p_e;
libvlc_exception_init(&p_e);
p_mlist = libvlc_media_list_new([VLCLibrary sharedInstance], &p_e);
quit_on_exception(&p_e);
libvlc_exception_init( &p_e );
p_mlist = libvlc_media_list_new( [VLCLibrary sharedInstance], &p_e );
quit_on_exception( &p_e );
// Initialize internals to defaults
cachedMedia = [[NSMutableArray alloc] init];
......@@ -119,7 +106,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (void)dealloc
{
// Release allocated memory
libvlc_media_list_release(p_mlist);
delegate = nil;
libvlc_media_list_release( p_mlist );
[cachedMedia release];
[flatAspect release];
[hierarchicalAspect release];
......@@ -129,7 +118,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
- (NSString *)description
{
NSMutableString *content = [NSMutableString string];
NSMutableString * content = [NSMutableString string];
int i;
for( i = 0; i < [self count]; i++)
{
......@@ -138,16 +127,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
return [NSString stringWithFormat:@"<%@ %p> {\n%@}", [self className], self, content];
}
- (void)setDelegate:(id)value
{
delegate = value;
}
- (id)delegate
{
return delegate;
}
- (void)lock
{
libvlc_media_list_lock( p_mlist );
......@@ -192,11 +171,6 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
return [cachedMedia objectAtIndex:index];
}
- (int)count
{
return [cachedMedia count];
}
- (int)indexOfMedia:(VLCMedia *)media
{
libvlc_exception_t p_e;
......@@ -207,6 +181,24 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
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
{
libvlc_exception_t p_e;
......@@ -222,8 +214,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{
if( hierarchicalAspect )
return hierarchicalAspect;
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 );
return hierarchicalAspect;
}
......@@ -232,8 +225,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{
if( hierarchicalNodeAspect )
return hierarchicalNodeAspect;
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 );
return hierarchicalNodeAspect;
}
......@@ -242,8 +236,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{
if( flatAspect )
return flatAspect;
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 );
return flatAspect;
}
......@@ -261,14 +256,15 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
if( self = [super init] )
{
p_mlist = p_new_mlist;
libvlc_media_list_retain(p_mlist);
libvlc_media_list_lock(p_mlist);
cachedMedia = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count(p_mlist, NULL)];
int i, count = libvlc_media_list_count(p_mlist, NULL);
libvlc_media_list_retain( p_mlist );
libvlc_media_list_lock( p_mlist );
cachedMedia = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count( p_mlist, NULL )];
int i, count = libvlc_media_list_count( p_mlist, NULL );
for( i = 0; i < count; i++ )
{
libvlc_media_descriptor_t * p_md = libvlc_media_list_item_at_index(p_mlist, i, NULL);
[cachedMedia addObject:[VLCMedia mediaWithLibVLCMediaDescriptor: p_md]];
libvlc_media_descriptor_t * p_md = libvlc_media_list_item_at_index( p_mlist, i, NULL );
[cachedMedia addObject:[VLCMedia mediaWithLibVLCMediaDescriptor:p_md]];
libvlc_media_descriptor_release(p_md);
}
[self initInternalMediaList];
......@@ -288,9 +284,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
{
// Add event callbacks
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_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