]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/playlist.m
macosx: fixed playlist/video toggling and some memory leaks
[vlc] / modules / gui / macosx / playlist.m
index c5abc22d27659941544362d3d7248acad81f833d..e6846c6b3c434c25693be15a2cabc0a3fff7176a 100644 (file)
@@ -47,7 +47,6 @@
 #import "playlist.h"
 #import "controls.h"
 #import "misc.h"
-#import "sidebarview.h"
 
 #include <vlc_keys.h>
 #import <vlc_services_discovery.h>
     if( o_value == nil )
     {
         /* FIXME: Why is there a warning if that happens all the time and seems
-         * to be normal? Add an assert and fix it. 
+         * to be normal? Add an assert and fix it.
          * msg_Warn( VLCIntf, "playlist item misses pointer value, adding one" ); */
         o_value = [[NSValue valueWithPointer: p_return] retain];
     }
         }
         return @"error" ;
     }
+
     p_item = (playlist_item_t *)[item pointerValue];
     if( !p_item || !p_item->p_input )
     {
         }
         return @"error";
     }
+
     attempted_reload = NO;
 
     if( [[o_tc identifier] isEqualToString:@"name"] )
     {
         if( input_item_HasErrorWhenReading( p_item->p_input ) )
         {
-            o_value = [NSImage imageWithWarningIcon];
+            o_value = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertCautionIcon)];
+            [o_value setSize: NSMakeSize(16,16)];
         }
     }
     return o_value;
     char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
     if( !ppsz_services )
         return;
-    
+
     for( i = 0; ppsz_services[i]; i++ )
     {
         bool  b_enabled;
     [o_mi_sort_author setTitle: _NS("Sort Node by Author")];
     [o_mi_services setTitle: _NS("Services discovery")];
     [o_mm_mi_services setTitle: _NS("Services discovery")];
-    [o_status_field setStringValue: _NS("No items in the playlist")];
-    [o_status_field_embed setStringValue: _NS("No items in the playlist")];
 
     [o_search_field setToolTip: _NS("Search in Playlist")];
     [o_search_field_other setToolTip: _NS("Search in Playlist")];
-    [o_mi_addNode setTitle: _NS("Add Folder to Playlist")];
 
     [o_save_accessory_text setStringValue: _NS("File Format:")];
     [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
     // TODO Find a way to keep the dict size to a minimum
     //[o_outline_dict removeAllObjects];
     [o_outline_view reloadData];
-    [o_sidebar updateSidebar:[self playingItem]];
     [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
     [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
 
-    playlist_t *p_playlist = pl_Get( VLCIntf );
-
-    PL_LOCK;
-    if( playlist_CurrentSize( p_playlist ) >= 2 )
-    {
-        [o_status_field setStringValue: [NSString stringWithFormat:
-                    _NS("%i items"),
-                playlist_CurrentSize( p_playlist )]];
-        [o_status_field_embed setStringValue: [NSString stringWithFormat:
-                                               _NS("%i items"),
-                                               playlist_CurrentSize( p_playlist )]];        
-    }
-    else
-    {
-        if( playlist_IsEmpty( p_playlist ) )
-        {
-            [o_status_field setStringValue: _NS("No items in the playlist")];
-            [o_status_field_embed setStringValue: _NS("No items in the playlist")];
-        }
-        else
-        {
-            [o_status_field setStringValue: _NS("1 item")];
-            [o_status_field_embed setStringValue: _NS("1 item")];
-        }
-    }
-    PL_UNLOCK;
-
     [self outlineViewSelectionDidChange: nil];
 }
 
-- (void)playModeUpdated
-{
-    playlist_t *p_playlist = pl_Get( VLCIntf );
-
-    bool loop = var_GetBool( p_playlist, "loop" );
-    bool repeat = var_GetBool( p_playlist, "repeat" );
-    if( repeat )
-        [[[VLCMain sharedInstance] controls] repeatOne];
-    else if( loop )
-        [[[VLCMain sharedInstance] controls] repeatAll];
-    else
-        [[[VLCMain sharedInstance] controls] repeatOff];
-
-    [[[VLCMain sharedInstance] controls] shuffle];
-}
-
 - (void)outlineViewSelectionDidChange:(NSNotification *)notification
 {
     // FIXME: unsafe
             free( psz_uri );
         }
 
-        if( [[VLCMain sharedInstance] isPlaylistCollapsed] == NO )
-        {
-            /* update our info-panel to reflect the new item, if we aren't collapsed */
-            [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
-        }
+        /* update our info-panel to reflect the new item */
+        [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
     }
 }
 
     PL_UNLOCK;
 }
 
-- (void)playSidebarItem:(id)item
-{
-    intf_thread_t * p_intf = VLCIntf;
-    playlist_t * p_playlist = pl_Get( p_intf );
-    
-    playlist_item_t *p_item;
-    playlist_item_t *p_node = NULL;
-    
-    p_item = [item pointerValue];
-    
-    if( p_item )
-    {
-        if( p_item->i_children == -1 )
-        {
-            p_node = p_item->p_parent;
-            
-        }
-        else
-        {
-            p_node = p_item;
-            if( p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1 )
-            {
-                p_item = p_node->pp_children[0];
-            }
-            else
-            {
-                p_item = NULL;
-            }
-        }
-        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked, p_node, p_item );
-    }
-}
-
 - (IBAction)revealItemInFinder:(id)sender
 {
     playlist_item_t * p_item = [[o_outline_view itemAtRow:[o_outline_view selectedRow]] pointerValue];
 
     if(! p_item || !p_item->p_input )
         return;
-    
+
     char *psz_uri = decode_URI( input_item_GetURI( p_item->p_input ) );
     if( psz_uri )
         o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
     NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
     if( prefix_range.location != NSNotFound )
         [o_mrl deleteCharactersInRange: prefix_range];
-    
+
     if( [o_mrl characterAtIndex:0] == '/' )
         [[NSWorkspace sharedWorkspace] selectFile: o_mrl inFileViewerRootedAtPath: o_mrl];
-}    
+}
 
 /* When called retrieves the selected outlineview row and plays that node or item */
 - (IBAction)preparseItem:(id)sender
     NSMutableArray *o_to_preparse;
     intf_thread_t * p_intf = VLCIntf;
     playlist_t * p_playlist = pl_Get( p_intf );
+
     o_to_preparse = [NSMutableArray arrayWithArray:[[o_outline_view selectedRowEnumerator] allObjects]];
     i_count = [o_to_preparse count];
 
         PL_LOCK;
         playlist_item_t *p_item = [o_item pointerValue];
 #ifndef NDEBUG
-        msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count, 
+        msg_Dbg( p_intf, "deleting item %i (of %i) with id \"%i\", pointerValue \"%p\" and %i children", i+1, i_count,
                 p_item->p_input->i_id, [o_item pointerValue], p_item->i_children +1 );
 #endif
         [o_to_delete removeObject: o_number];
                         checkItemExistence: NO locked:YES] == YES )
                 // if current item is in selected node and is playing then stop playlist
                 playlist_Control(p_playlist, PLAYLIST_STOP, pl_Locked );
-    
+
             playlist_NodeDelete( p_playlist, p_item, true, false );
         }
         else
         o_uri = o_temp;
     }
 
-    p_input = input_item_New( p_playlist, [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
+    p_input = input_item_New( [o_uri fileSystemRepresentation], o_name ? [o_name UTF8String] : NULL );
     if( !p_input )
         return NULL;
 
 
         /* Add the item */
         /* FIXME: playlist_AddInput() can fail */
-        
+
         playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
              i_position == -1 ? PLAYLIST_END : i_position + i_item, true,
          pl_Locked );
 - (id)playingItem
 {
     playlist_t *p_playlist = pl_Get( VLCIntf );
-    
+
     id o_playing_item;
 
     PL_LOCK;
-    o_playing_item = [o_outline_dict objectForKey:
-                      [NSString stringWithFormat:@"%p",  playlist_CurrentPlayingItem( p_playlist )]];
+    o_playing_item = [o_outline_dict objectForKey: [NSString stringWithFormat:@"%p",  playlist_CurrentPlayingItem( p_playlist )]];
     PL_UNLOCK;
 
     return o_playing_item;
 }
-
-- (IBAction)addNode:(id)sender
-{
-    playlist_t * p_playlist = pl_Get( VLCIntf );
-
-    PL_LOCK;
-    playlist_NodeCreate( p_playlist, _("Empty Folder"),
-                                      p_playlist->p_local_category, PLAYLIST_END, 0, NULL );
-    PL_UNLOCK;
-
-    [self playlistUpdated];
-}
 @end
 
 @implementation VLCPlaylist (NSOutlineViewDataSource)
 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item
 {
     id o_value = [super outlineView: outlineView child: index ofItem: item];
-    playlist_t *p_playlist = pl_Get( VLCIntf );
-
-    PL_LOCK;
-    if( playlist_CurrentSize( p_playlist )  >= 2 )
-    {
-        [o_status_field setStringValue: [NSString stringWithFormat:
-                    _NS("%i items"),
-             playlist_CurrentSize( p_playlist )]];
-        [o_status_field_embed setStringValue: [NSString stringWithFormat:
-                                               _NS("%i items"),
-                                               playlist_CurrentSize( p_playlist )]];
-    }
-    else
-    {
-        if( playlist_IsEmpty( p_playlist ) )
-        {
-            [o_status_field setStringValue: _NS("No items in the playlist")];
-            [o_status_field_embed setStringValue: _NS("No items in the playlist")];
-        }
-        else
-        {
-            [o_status_field setStringValue: _NS("1 item")];
-            [o_status_field_embed setStringValue: _NS("1 item")];
-        }
-    }
-    PL_UNLOCK;
 
     [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",
                                                     [o_value pointerValue]]];
     /* We refuse to drop an item in anything else than a child of the General
        Node. We still accept items that would be root nodes of the outlineview
        however, to allow drop in an empty playlist. */
-    if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] || 
+    if( !( ([self isItem: [item pointerValue] inNode: p_playlist->p_local_category checkItemExistence: NO] ||
         ( var_CreateGetBool( p_playlist, "media-library" ) && [self isItem: [item pointerValue] inNode: p_playlist->p_ml_category checkItemExistence: NO] ) ) || item == nil ) )
     {
         return NSDragOperationNone;