]> git.sesse.net Git - vlc/blobdiff - projects/macosx/framework/Sources/VLCMediaList.m
macosx/framework: Remove a bunch of exception.
[vlc] / projects / macosx / framework / Sources / VLCMediaList.m
index 8d1cc96a23716f3c9d2d201ee683c816b73f3978..03364e7b03033ae98624dd3826a313810de22200 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * VLCMediaList.m: VLC.framework VLCMediaList implementation
+ * VLCMediaList.m: VLCKit.framework VLCMediaList implementation
  *****************************************************************************
  * Copyright (C) 2007 Pierre d'Herbemont
  * Copyright (C) 2007 the VideoLAN team
@@ -52,8 +52,8 @@ static void HandleMediaListItemAdded(const libvlc_event_t * event, void * user_d
 {
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     id self = user_data;
-    [[VLCEventManager sharedManager] callOnMainThreadObject:self 
-                                                 withMethod:@selector(mediaListItemAdded:) 
+    [[VLCEventManager sharedManager] callOnMainThreadObject:self
+                                                 withMethod:@selector(mediaListItemAdded:)
                                        withArgumentAsObject:[NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           [VLCMedia mediaWithLibVLCMediaDescriptor:event->u.media_list_item_added.item], @"media",
                                                           [NSNumber numberWithInt:event->u.media_list_item_added.index], @"index",
@@ -65,8 +65,8 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
 {
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     id self = user_data;
-    [[VLCEventManager sharedManager] callOnMainThreadObject:self 
-                                                 withMethod:@selector(mediaListItemRemoved:) 
+    [[VLCEventManager sharedManager] callOnMainThreadObject:self
+                                                 withMethod:@selector(mediaListItemRemoved:)
                                        withArgumentAsObject:[NSNumber numberWithInt:event->u.media_list_item_deleted.index]];
     [pool release];
 }
@@ -77,11 +77,8 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
     if (self = [super init])
     {
         // 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 );
-        catch_exception( &p_e );
-        
+        p_mlist = libvlc_media_list_new([VLCLibrary sharedInstance]);
+
         // Initialize internals to defaults
         cachedMedia = [[NSMutableArray alloc] init];
         delegate = flatAspect = hierarchicalAspect = hierarchicalNodeAspect = nil;
@@ -99,9 +96,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
             /* 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_event_manager(p_mlist, NULL);
-            libvlc_event_detach(p_em, libvlc_MediaListItemDeleted, HandleMediaListItemDeleted, self, NULL);
-            libvlc_event_detach(p_em, libvlc_MediaListItemAdded,   HandleMediaListItemAdded,   self, NULL);
+            libvlc_event_manager_t * p_em = libvlc_media_list_event_manager(p_mlist);
+            libvlc_event_detach(p_em, libvlc_MediaListItemDeleted, HandleMediaListItemDeleted, self);
+            libvlc_event_detach(p_em, libvlc_MediaListItemAdded,   HandleMediaListItemAdded,   self);
         }
         [super release];
     }
@@ -111,7 +108,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
 {
     // Release allocated memory
     delegate = nil;
-    
+
     libvlc_media_list_release( p_mlist );
     [cachedMedia release];
     [flatAspect release];
@@ -141,14 +138,14 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
     libvlc_media_list_unlock( p_mlist );
 }
 
-- (int)addMedia:(VLCMedia *)media
+- (NSInteger)addMedia:(VLCMedia *)media
 {
     int index = [self count];
     [self insertMedia:media atIndex:index];
     return index;
 }
 
-- (void)insertMedia:(VLCMedia *)media atIndex: (int)index
+- (void)insertMedia:(VLCMedia *)media atIndex: (NSInteger)index
 {
     [media retain];
 
@@ -159,7 +156,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
     catch_exception( &p_e );
 }
 
-- (void)removeMediaAtIndex:(int)index
+- (void)removeMediaAtIndex:(NSInteger)index
 {
     [[self mediaAtIndex:index] release];
 
@@ -170,47 +167,48 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
     catch_exception( &p_e );
 }
 
-- (VLCMedia *)mediaAtIndex:(int)index
+- (VLCMedia *)mediaAtIndex:(NSInteger)index
 {
     return [cachedMedia objectAtIndex:index];
 }
 
-- (int)indexOfMedia:(VLCMedia *)media
+- (NSInteger)indexOfMedia:(VLCMedia *)media
 {
-    libvlc_exception_t p_e;
-    libvlc_exception_init( &p_e );
-    int result = libvlc_media_list_index_of_item( p_mlist, [media libVLCMediaDescriptor], &p_e );
-    catch_exception( &p_e );
-    
+    NSInteger result = libvlc_media_list_index_of_item(p_mlist, [media libVLCMediaDescriptor]);
     return result;
 }
 
 /* KVC Compliance: For the @"media" key */
-- (int)countOfMedia
+- (NSInteger)countOfMedia
 {
     return [self count];
 }
 
-- (id)objectInMediaAtIndex:(int)i
+- (id)objectInMediaAtIndex:(NSUInteger)i
 {
     return [self mediaAtIndex:i];
 }
 
-- (int)count
+- (NSInteger)count
 {
     return [cachedMedia count];
 }
 
+- (void)insertObject:(id)object inMediaAtIndex:(NSUInteger)i
+{
+    [self insertMedia:object atIndex:i];
+}
+
+- (void)removeObjectFromMediaAtIndex:(NSUInteger)i
+{
+    [self removeMediaAtIndex:i];
+}
+
 @synthesize delegate;
 
 - (BOOL)isReadOnly
 {
-    libvlc_exception_t p_e;
-    libvlc_exception_init( &p_e );
-    BOOL isReadOnly = libvlc_media_list_is_readonly( p_mlist );
-    catch_exception( &p_e );
-    
-    return isReadOnly;
+    return libvlc_media_list_is_readonly( p_mlist );
 }
 
 /* Media list aspect */
@@ -218,8 +216,8 @@ 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 );
+
+    libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_view(p_mlist);
     hierarchicalAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView:p_mlv andMediaList:self] retain];
     libvlc_media_list_view_release( p_mlv );
     return hierarchicalAspect;
@@ -229,8 +227,8 @@ 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 );
+
+    libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_node_view(p_mlist);
     hierarchicalNodeAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView:p_mlv andMediaList:self] retain];
     libvlc_media_list_view_release( p_mlv );
     return hierarchicalNodeAspect;
@@ -240,8 +238,8 @@ 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 );
+
+    libvlc_media_list_view_t * p_mlv = libvlc_media_list_flat_view(p_mlist, NULL);
     flatAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView:p_mlv andMediaList:self] retain];
     libvlc_media_list_view_release( p_mlv );
     return flatAspect;
@@ -262,9 +260,9 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
         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 )];
+        cachedMedia = [[NSMutableArray alloc] initWithCapacity:libvlc_media_list_count(p_mlist)];
 
-        int i, count = libvlc_media_list_count( p_mlist, NULL );
+        NSUInteger i, count = libvlc_media_list_count(p_mlist);
         for( i = 0; i < count; i++ )
         {
             libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_mlist, i, NULL );
@@ -287,27 +285,22 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
 - (void)initInternalMediaList
 {
     // Add event callbacks
-    libvlc_exception_t p_e;
-    libvlc_exception_init( &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 );
-    
-    catch_exception( &p_e );
+    libvlc_event_manager_t * p_em = libvlc_media_list_event_manager(p_mlist);
+    libvlc_event_attach( p_em, libvlc_MediaListItemAdded,   HandleMediaListItemAdded,   self);
+    libvlc_event_attach( p_em, libvlc_MediaListItemDeleted, HandleMediaListItemDeleted, self);
 }
 
 - (void)mediaListItemAdded:(NSArray *)arrayOfArgs
 {
     /* We hope to receive index in a nide range, that could change one day */
-    int start = [[[arrayOfArgs objectAtIndex: 0] objectForKey:@"index"] intValue];
-    int end = [[[arrayOfArgs objectAtIndex: [arrayOfArgs count]-1] objectForKey:@"index"] intValue];
+    NSInteger start = [[[arrayOfArgs objectAtIndex: 0] objectForKey:@"index"] intValue];
+    NSInteger end = [[[arrayOfArgs objectAtIndex: [arrayOfArgs count]-1] objectForKey:@"index"] intValue];
     NSRange range = NSMakeRange(start, end-start);
 
     [self willChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndexesInRange:range] forKey:@"media"];
     for( NSDictionary * args in arrayOfArgs )
     {
-        int index = [[args objectForKey:@"index"] intValue];
+        NSInteger index = [[args objectForKey:@"index"] intValue];
         VLCMedia * media = [args objectForKey:@"media"];
         /* Sanity check */
         if( index && index > [cachedMedia count] )
@@ -333,7 +326,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
     [self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"];
 
     // Post the notification
-    [[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaListItemDeleted 
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCMediaListItemDeleted
                                                         object:self
                                                       userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           index, @"index",