]> git.sesse.net Git - vlc/commitdiff
* playlist.* support for DnD from Finder
authorBenjamin Pracht <bigben@videolan.org>
Thu, 5 May 2005 19:34:56 +0000 (19:34 +0000)
committerBenjamin Pracht <bigben@videolan.org>
Thu, 5 May 2005 19:34:56 +0000 (19:34 +0000)
* BUGS: remove OSX playlist (anyone sees some more issue here readd it with a description...)

BUGS
modules/gui/macosx/playlist.h
modules/gui/macosx/playlist.m

diff --git a/BUGS b/BUGS
index b745ed293ad36a019ee2f83180ad29e46ed01ac2..082fe77b7e6ffa0b282f7eead868a99c45adf4f1 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -7,12 +7,12 @@ Feel free to work on these :)
 Regressions from previous versions
 ----------------------------------
 *** OS X preferences
-*** OS X playlist
 *** OS X resampler 
 *   CDDAX 
 
-** Playlist : previous item sometimes doesn't get any item, or an item
+** Playlist : the "previous item" action sometimes doesn't get any item, or an item
 at the other edge of the playlist, when at the beginning of a node
+
 * Sort by Author unimplemented
 
 *** wxWindows : Play button state
index f69b3fe548857db8af9d0b9249174e8884a1df91..0da71a09350e457b4152cbc38b37d5b8181d0047 100644 (file)
@@ -97,6 +97,7 @@
 - (IBAction)sortNodeByAuthor:(id)sender;
 
 - (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue;
+- (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position inView:(int)i_view enqueue:(BOOL)b_enqueue;
 
 - (playlist_item_t *)selectedPlaylistItem;
 
index 76716b61b70b0765ca7ebdb9c5b2dc3c3b1d05e9..0214c731bc8dc02e1b771d70f9d33b3c2a8a6008 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * playlist.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2002-2005 VideoLAN
+* Copyright (C) 2002-2005 VideoLAN
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -543,111 +543,165 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
     [self playlistUpdated];
 }
 
-- (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
+- (playlist_item_t *)createItem:(NSDictionary *)o_one_item
 {
-    int i_item;
     intf_thread_t * p_intf = VLCIntf;
     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
 
     if( p_playlist == NULL )
     {
-        return;
+        return NULL;
     }
-
-    for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
+    playlist_item_t *p_item;
+    int i;
+    BOOL b_rem = FALSE, b_dir = FALSE;
+    NSString *o_uri, *o_name;
+    NSArray *o_options;
+    NSURL *o_true_file;
+
+    /* Get the item */
+    o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
+    o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
+    o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
+
+    /* Find the name for a disc entry ( i know, can you believe the trouble?) */
+    if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
     {
-        /* One item */
-        NSDictionary *o_one_item;
-        playlist_item_t *p_item;
-        int i;
-        BOOL b_rem = FALSE, b_dir = FALSE;
-        NSString *o_uri, *o_name;
-        NSArray *o_options;
-        NSURL *o_true_file;
-
-        /* Get the item */
-        o_one_item = [o_array objectAtIndex: i_item];
-        o_uri = (NSString *)[o_one_item objectForKey: @"ITEM_URL"];
-        o_name = (NSString *)[o_one_item objectForKey: @"ITEM_NAME"];
-        o_options = (NSArray *)[o_one_item objectForKey: @"ITEM_OPTIONS"];
+        int i_count, i_index;
+        struct statfs *mounts = NULL;
 
-        /* Find the name for a disc entry ( i know, can you believe the trouble?) */
-        if( ( !o_name || [o_name isEqualToString:@""] ) && [o_uri rangeOfString: @"/dev/"].location != NSNotFound )
+        i_count = getmntinfo (&mounts, MNT_NOWAIT);
+        /* getmntinfo returns a pointer to static data. Do not free. */
+        for( i_index = 0 ; i_index < i_count; i_index++ )
         {
-            int i_count, i_index;
-            struct statfs *mounts = NULL;
-            
-            i_count = getmntinfo (&mounts, MNT_NOWAIT);
-            /* getmntinfo returns a pointer to static data. Do not free. */
-            for( i_index = 0 ; i_index < i_count; i_index++ )
+            NSMutableString *o_temp, *o_temp2;
+            o_temp = [NSMutableString stringWithString: o_uri];
+            o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
+            [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
+            [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
+            [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
+
+            if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
             {
-                NSMutableString *o_temp, *o_temp2;
-                o_temp = [NSMutableString stringWithString: o_uri];
-                o_temp2 = [NSMutableString stringWithCString: mounts[i_index].f_mntfromname];
-                [o_temp replaceOccurrencesOfString: @"/dev/rdisk" withString: @"/dev/disk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
-                [o_temp2 replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
-                [o_temp2 replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp2 length]) ];
-
-                if( strstr( [o_temp fileSystemRepresentation], [o_temp2 fileSystemRepresentation] ) != NULL )
-                {
-                    o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
-                }
+                o_name = [[NSFileManager defaultManager] displayNameAtPath: [NSString stringWithCString:mounts[i_index].f_mntonname]];
             }
         }
-        /* If no name, then make a guess */
-        if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
+    }
+    /* If no name, then make a guess */
+    if( !o_name) o_name = [[NSFileManager defaultManager] displayNameAtPath: o_uri];
 
-        if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
-            [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
-                    isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem   )
+    if( [[NSFileManager defaultManager] fileExistsAtPath:o_uri isDirectory:&b_dir] && b_dir &&
+        [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath: o_uri isRemovable: &b_rem
+                isWritable:NULL isUnmountable:NULL description:NULL type:NULL] && b_rem   )
+    {
+        /* All of this is to make sure CD's play when you D&D them on VLC */
+        /* Converts mountpoint to a /dev file */
+        struct statfs *buf;
+        char *psz_dev;
+        NSMutableString *o_temp;
+
+        buf = (struct statfs *) malloc (sizeof(struct statfs));
+        statfs( [o_uri fileSystemRepresentation], buf );
+        psz_dev = strdup(buf->f_mntfromname);
+        o_temp = [NSMutableString stringWithCString: psz_dev ];
+        [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
+        [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
+        [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
+        o_uri = o_temp;
+    }
+
+    p_item = playlist_ItemNew( p_intf, [o_uri fileSystemRepresentation], [o_name UTF8String] );
+    if( !p_item )
+       return NULL;
+
+    if( o_options )
+    {
+        for( i = 0; i < (int)[o_options count]; i++ )
         {
-            /* All of this is to make sure CD's play when you D&D them on VLC */
-            /* Converts mountpoint to a /dev file */
-            struct statfs *buf;
-            char *psz_dev;
-            NSMutableString *o_temp;
-
-            buf = (struct statfs *) malloc (sizeof(struct statfs));
-            statfs( [o_uri fileSystemRepresentation], buf );
-            psz_dev = strdup(buf->f_mntfromname);
-            o_temp = [NSMutableString stringWithCString: psz_dev ];
-            [o_temp replaceOccurrencesOfString: @"/dev/disk" withString: @"/dev/rdisk" options:NULL range:NSMakeRange(0, [o_temp length]) ];
-            [o_temp replaceOccurrencesOfString: @"s0" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
-            [o_temp replaceOccurrencesOfString: @"s1" withString: @"" options:NULL range:NSMakeRange(0, [o_temp length]) ];
-            o_uri = o_temp;
+            playlist_ItemAddOption( p_item, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
         }
-        
-        p_item = playlist_ItemNew( p_intf, [o_uri fileSystemRepresentation], [o_name UTF8String] );
-        if( !p_item )
-            continue;
+    }
 
-        if( o_options )
+    /* Recent documents menu */
+    o_true_file = [NSURL fileURLWithPath: o_uri];
+    if( o_true_file != nil )
+    {
+        [[NSDocumentController sharedDocumentController]
+            noteNewRecentDocumentURL: o_true_file];
+    }
+
+    vlc_object_release( p_playlist );
+    return p_item;
+}
+
+- (void)appendArray:(NSArray*)o_array atPos:(int)i_position enqueue:(BOOL)b_enqueue
+{
+    int i_item;
+    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
+                                            FIND_ANYWHERE );
+    if( p_playlist == NULL )
+    {
+        return;
+    }
+
+    for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
+    {
+        playlist_item_t *p_item;
+        NSDictionary *o_one_item;
+
+        /* Get the item */
+        o_one_item = [o_array objectAtIndex: i_item];
+        p_item = [self createItem: o_one_item];
+        if( !p_item )
         {
-            for( i = 0; i < (int)[o_options count]; i++ )
-            {
-                playlist_ItemAddOption( p_item, strdup( [[o_options objectAtIndex:i] UTF8String] ) );
-            }
+            continue;
         }
 
         /* Add the item */
         playlist_AddItem( p_playlist, p_item, PLAYLIST_APPEND, i_position == -1 ? PLAYLIST_END : i_position + i_item );
 
-        /* Recent documents menu */
-        o_true_file = [NSURL fileURLWithPath: o_uri];
-        if( o_true_file != nil )
+        if( i_item == 0 && !b_enqueue )
+        {
+            playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
+        }
+    }
+    vlc_object_release( p_playlist );
+}
+
+- (void)appendNodeArray:(NSArray*)o_array inNode:(playlist_item_t *)p_node atPos:(int)i_position inView:(int)i_view enqueue:(BOOL)b_enqueue
+{
+    int i_item;
+    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
+                                            FIND_ANYWHERE );
+    if( p_playlist == NULL )
+    {
+        return;
+    }
+
+    for( i_item = 0; i_item < (int)[o_array count]; i_item++ )
+    {
+        playlist_item_t *p_item;
+        NSDictionary *o_one_item;
+
+        /* Get the item */
+        o_one_item = [o_array objectAtIndex: i_item];
+        p_item = [self createItem: o_one_item];
+        if( !p_item )
         {
-            [[NSDocumentController sharedDocumentController]
-                noteNewRecentDocumentURL: o_true_file];
+            continue;
         }
 
+        /* Add the item */
+        playlist_NodeAddItem( p_playlist, p_item, i_view, p_node, PLAYLIST_APPEND, i_position + i_item );
+
         if( i_item == 0 && !b_enqueue )
         {
             playlist_Control( p_playlist, PLAYLIST_ITEMPLAY, p_item );
         }
     }
-
     vlc_object_release( p_playlist );
+
 }
 
 - (IBAction)handlePopUp:(id)sender
@@ -1076,7 +1130,7 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
     {
         return( @"error" );
     }
-    
+
     p_item = (playlist_item_t *)[item pointerValue];
 
     if( p_item == NULL )
@@ -1132,14 +1186,92 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
 /* Required for drag & drop and reordering */
 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
 {
+/*    unsigned int i;
+
+    for( i = 0 ; i < [items count] ; i++ )
+    {
+        if( [outlineView levelForItem: [items objectAtIndex: i]] == 0 )
+        {
+            return NO;
+        }
+    }*/
     return NO;
 }
 
 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
 {
+    NSPasteboard *o_pasteboard = [info draggingPasteboard];
+
+    if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
+    {
+        return NSDragOperationGeneric;
+    }
     return NSDragOperationNone;
 }
 
+- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
+{
+    playlist_t * p_playlist =  vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
+                                                       FIND_ANYWHERE );
+    NSPasteboard *o_pasteboard = [info draggingPasteboard];
+
+    if( !p_playlist ) return NO;
+
+    if( [[o_pasteboard types] containsObject: NSFilenamesPboardType] )
+    {
+        int i;
+        playlist_item_t *p_node = [item pointerValue];
+
+        NSArray *o_array = [NSArray array];
+        NSArray *o_values = [[o_pasteboard propertyListForType:
+                                        NSFilenamesPboardType]
+                                sortedArrayUsingSelector:
+                                        @selector(caseInsensitiveCompare:)];
+
+        for( i = 0; i < (int)[o_values count]; i++)
+        {
+            NSDictionary *o_dic;
+            o_dic = [NSDictionary dictionaryWithObject:[o_values
+                        objectAtIndex:i] forKey:@"ITEM_URL"];
+            o_array = [o_array arrayByAddingObject: o_dic];
+        }
+
+        if ( item == nil )
+        {
+            [self appendArray: o_array atPos: index enqueue: YES];
+        }
+        else if( p_node->i_children == -1 )
+        {
+            int i_counter;
+            playlist_item_t *p_real_node = NULL;
+
+            for( i_counter = 0 ; i_counter < p_node->i_parents ; i_counter++ )
+            {
+                if( p_node->pp_parents[i_counter]->i_view == i_current_view )
+                {
+                    p_real_node = p_node->pp_parents[i_counter]->p_parent;
+                    break;
+                }
+                if( i_counter == p_node->i_parents )
+                {
+                    return NO;
+                }
+            }
+            [self appendNodeArray: o_array inNode: p_real_node
+                atPos: index inView: i_current_view enqueue: YES];
+        }
+        else
+        {
+            [self appendNodeArray: o_array inNode: p_node
+                atPos: index inView: i_current_view enqueue: YES];
+        }
+        vlc_object_release( p_playlist );
+        return YES;
+    }
+    vlc_object_release( p_playlist );
+    return NO;
+}
+
 /* Delegate method of NSWindow */
 /*- (void)windowWillClose:(NSNotification *)aNotification
 {