]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/playlist.m
Add a function to get the Title and fallback to the name if the title is empty.
[vlc] / modules / gui / macosx / playlist.m
index 89216a831ee1ffba68141bb5384d1fb75c189863..d777d4ae864edec3715a16ff20e41e0e32b23f9d 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * playlist.m: MacOS X interface module
  *****************************************************************************
-* Copyright (C) 2002-2008 the VideoLAN team
+* Copyright (C) 2002-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -82,7 +82,7 @@
 
         case NSEnterCharacter:
         case NSCarriageReturnCharacter:
-            [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] playItem:self];
+            [(VLCPlaylist *)[[VLCMain sharedInstance] playlist] playItem:self];
             break;
 
         default:
 
     if( o_value == nil )
     {
-        /* Why is there a warning if that happens all the time and seems
+        /* FIXME: Why is there a warning if that happens all the time and seems
          * 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];
     if( [[o_tc identifier] isEqualToString:@"name"] )
     {
         /* sanity check to prevent the NSString class from crashing */
-        char *psz_title =  input_item_GetTitle( p_item->p_input );
-        if( !EMPTY_STR( psz_title ) )
+        char *psz_title =  input_item_GetTitleFbName( p_item->p_input );
+        if( psz_title )
         {
             o_value = [NSString stringWithUTF8String: psz_title];
+            free( psz_title );
         }
-        else
-        {
-            char *psz_name = input_item_GetName( p_item->p_input );
-            if( psz_name )
-                o_value = [NSString stringWithUTF8String: psz_name];
-            free( psz_name );
-        }
-        free( psz_title );
     }
     else if( [[o_tc identifier] isEqualToString:@"artist"] )
     {
     [o_save_accessory_text setStringValue: _NS("File Format:")];
     [[o_save_accessory_popup itemAtIndex:0] setTitle: _NS("Extended M3U")];
     [[o_save_accessory_popup itemAtIndex:1] setTitle: _NS("XML Shareable Playlist Format (XSPF)")];
+    [[o_save_accessory_popup itemAtIndex:2] setTitle: _NS("HTML Playlist")];
 }
 
 - (void)playlistUpdated
     // TODO Find a way to keep the dict size to a minimum
     //[o_outline_dict removeAllObjects];
     [o_outline_view reloadData];
-    [[[[VLCMain sharedInstance] getWizard] getPlaylistWizard] reloadOutlineView];
-    [[[[VLCMain sharedInstance] getBookmarks] getDataTable] reloadData];
+    [[[[VLCMain sharedInstance] wizard] playlistWizard] reloadOutlineView];
+    [[[[VLCMain sharedInstance] bookmarks] dataTable] reloadData];
 
     playlist_t *p_playlist = pl_Hold( VLCIntf );
 
     bool loop = var_GetBool( p_playlist, "loop" );
     bool repeat = var_GetBool( p_playlist, "repeat" );
     if( repeat )
-        [[[VLCMain sharedInstance] getControls] repeatOne];
+        [[[VLCMain sharedInstance] controls] repeatOne];
     else if( loop )
-        [[[VLCMain sharedInstance] getControls] repeatAll];
+        [[[VLCMain sharedInstance] controls] repeatAll];
     else
-        [[[VLCMain sharedInstance] getControls] repeatOff];
+        [[[VLCMain sharedInstance] controls] repeatOff];
 
-    [[[VLCMain sharedInstance] getControls] shuffle];
+    [[[VLCMain sharedInstance] controls] shuffle];
 
     pl_Release( VLCIntf );
 }
         if( psz_uri )
         {
             o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
-        
+
             /* perform some checks whether it is a file and if it is local at all... */
             NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
             if( prefix_range.location != NSNotFound )
                 [o_mrl deleteCharactersInRange: prefix_range];
-            
+
             if( [o_mrl characterAtIndex:0] == '/' )
             {
                 [o_mi_revealInFinder setEnabled: YES];
         if( [[VLCMain sharedInstance] isPlaylistCollapsed] == NO )
         {
             /* update our info-panel to reflect the new item, if we aren't collapsed */
-            [[[VLCMain sharedInstance] getInfo] updatePanelWithItem:p_item->p_input];
+            [[[VLCMain sharedInstance] info] updatePanelWithItem:p_item->p_input];
         }
     }
 }
     NSSavePanel *o_save_panel = [NSSavePanel savePanel];
     NSString * o_name = [NSString stringWithFormat: @"%@", _NS("Untitled")];
 
-    //[o_save_panel setAllowedFileTypes: [NSArray arrayWithObjects: @"m3u", @"xpf", nil] ];
     [o_save_panel setTitle: _NS("Save Playlist")];
     [o_save_panel setPrompt: _NS("Save")];
     [o_save_panel setAccessoryView: o_save_accessory_view];
     {
         NSString *o_filename = [o_save_panel filename];
 
-        if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
+        if( [o_save_accessory_popup indexOfSelectedItem] == 0 )
+        {
+            NSString * o_real_filename;
+            NSRange range;
+            range.location = [o_filename length] - [@".m3u" length];
+            range.length = [@".m3u" length];
+
+            if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
+                                             range: range] != NSOrderedSame )
+            {
+                o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
+            }
+            else
+            {
+                o_real_filename = o_filename;
+            }
+            playlist_Export( p_playlist,
+                [o_real_filename fileSystemRepresentation],
+                p_playlist->p_local_category, "export-m3u" );
+        }
+        else if( [o_save_accessory_popup indexOfSelectedItem] == 1 )
         {
             NSString * o_real_filename;
             NSRange range;
         {
             NSString * o_real_filename;
             NSRange range;
-            range.location = [o_filename length] - [@".m3u" length];
-            range.length = [@".m3u" length];
+            range.location = [o_filename length] - [@".html" length];
+            range.length = [@".html" length];
 
-            if( [o_filename compare:@".m3u" options: NSCaseInsensitiveSearch
+            if( [o_filename compare:@".html" options: NSCaseInsensitiveSearch
                                              range: range] != NSOrderedSame )
             {
-                o_real_filename = [NSString stringWithFormat: @"%@.m3u", o_filename];
+                o_real_filename = [NSString stringWithFormat: @"%@.html", o_filename];
             }
             else
             {
             }
             playlist_Export( p_playlist,
                 [o_real_filename fileSystemRepresentation],
-                p_playlist->p_local_category, "export-m3u" );
+                p_playlist->p_local_category, "export-html" );
         }
     }
     pl_Release( VLCIntf );
 
 - (IBAction)addNode:(id)sender
 {
-    /* we have to create a new thread here because otherwise we would block the
-     * interface since the interaction-stuff and this code would run in the same
-     * thread */
-    [NSThread detachNewThreadSelector: @selector(addNodeThreadedly)
-        toTarget: self withObject:nil];
-    [self playlistUpdated];
-}
-
-- (void)addNodeThreadedly
-{
-    NSAutoreleasePool * ourPool = [[NSAutoreleasePool alloc] init];
-
-    /* simply adds a new node to the end of the playlist */
     playlist_t * p_playlist = pl_Hold( VLCIntf );
     vlc_thread_set_priority( p_playlist, VLC_THREAD_PRIORITY_LOW );
 
-    int ret_v;
-    char *psz_name = NULL;
-    ret_v = intf_UserStringInput( p_playlist, _("New Node"),
-        _("Please enter a name for the new node."), &psz_name );
-
     PL_LOCK;
-    if( ret_v != DIALOG_CANCELLED && psz_name )
-    {
-        playlist_NodeCreate( p_playlist, psz_name,
+    playlist_NodeCreate( p_playlist, _("Empty Folder"),
                                       p_playlist->p_local_category, 0, NULL );
-    }
-    else if(! config_GetInt( p_playlist, "interact" ) )
-    {
-        /* in case that the interaction is disabled, just give it a bogus name */
-        playlist_NodeCreate( p_playlist, _("Empty Folder"),
-                                      p_playlist->p_local_category, 0, NULL );
-    }
     PL_UNLOCK;
 
-    free( psz_name );
     pl_Release( VLCIntf );
-    [ourPool release];
-}
 
+    [self playlistUpdated];
+}
 @end
 
 @implementation VLCPlaylist (NSOutlineViewDataSource)