浏览代码

MacOSX/Framework/VLCMediaList.m: Implement -description: and fix -flatAspect and -hierarchicalAspect when used with bindings.

Pierre d'Herbemont 17 年之前
父节点
当前提交
1cad3630d1
共有 2 个文件被更改,包括 24 次插入5 次删除
  1. 2 0
      Headers/Public/VLCMediaList.h
  2. 22 5
      Sources/VLCMediaList.m

+ 2 - 0
Headers/Public/VLCMediaList.h

@@ -44,6 +44,8 @@ extern NSString * VLCMediaListItemDeleted;
     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;
 }
 
 /* Properties */

+ 22 - 5
Sources/VLCMediaList.m

@@ -93,7 +93,7 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
         
         // Initialize internals to defaults
         cachedMedia = [[NSMutableArray alloc] init];
-        delegate = nil;
+        delegate = flatAspect = hierarchicalAspect = nil;
         [self initInternalMediaList];
     }
     return self;
@@ -121,9 +121,24 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
     // Release allocated memory
     libvlc_media_list_release(p_mlist);
     [cachedMedia release];
+    [flatAspect release];
+    [hierarchicalAspect release];
     [super dealloc];
 }
 
+- (NSString *)description
+{
+    NSMutableString *content = [NSMutableString string];
+    int i;
+    [self lock];
+    for( i = 0; i < [self count]; i++)
+    {
+        [content appendFormat:@"%@\n", [self mediaAtIndex: i]];
+    }
+    [self unlock];
+    return [NSString stringWithFormat:@"<%@ %p> {\n%@}", [self className], self, content];
+}
+
 - (void)setDelegate:(id)value
 {
     delegate = value;
@@ -196,18 +211,20 @@ static void HandleMediaListItemDeleted( const libvlc_event_t * event, void * use
 /* Media list aspect */
 - (VLCMediaListAspect *)hierarchicalAspect
 {
-    VLCMediaListAspect * hierarchicalAspect;
+    if( hierarchicalAspect )
+        return hierarchicalAspect;
     libvlc_media_list_view_t * p_mlv = libvlc_media_list_hierarchical_view( p_mlist, NULL );
-    hierarchicalAspect = [VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv];
+    hierarchicalAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv] retain];
     libvlc_media_list_view_release( p_mlv );
     return hierarchicalAspect;
 }
 
 - (VLCMediaListAspect *)flatAspect
 {
-    VLCMediaListAspect * flatAspect;
+    if( flatAspect )
+        return flatAspect;
     libvlc_media_list_view_t * p_mlv = libvlc_media_list_flat_view( p_mlist, NULL );
-    flatAspect = [VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv];
+    flatAspect = [[VLCMediaListAspect mediaListAspectWithLibVLCMediaListView: p_mlv] retain];
     libvlc_media_list_view_release( p_mlv );
     return flatAspect;
 }