]> git.sesse.net Git - vlc/commitdiff
macosx: implemented the sidebar completely to support switching between the playlist...
authorFelix Paul Kühne <fkuehne@videolan.org>
Sun, 12 Feb 2012 19:41:03 +0000 (20:41 +0100)
committerFelix Paul Kühne <fkuehne@videolan.org>
Sun, 12 Feb 2012 19:41:17 +0000 (20:41 +0100)
modules/gui/macosx/MainWindow.m
modules/gui/macosx/SideBarItem.h
modules/gui/macosx/SideBarItem.m
modules/gui/macosx/intf.m
modules/gui/macosx/playlist.h
modules/gui/macosx/playlist.m

index e8c45d75f0c2820b9bc558e78fc63305a6eec9d3..3e7d083eae3fdbcf6874876e9cd0e3d0d5616a1f 100644 (file)
@@ -32,6 +32,7 @@
 #import "MainMenu.h"
 #import "open.h"
 #import "controls.h" // TODO: remove me
+#import "playlist.h"
 #import "SideBarItem.h"
 #import <vlc_playlist.h>
 #import <vlc_aout_intf.h>
@@ -307,6 +308,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
     SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
     [playlistItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
+    SideBarItem *medialibraryItem = [SideBarItem itemWithTitle:_NS("Media Library") identifier:@"medialibrary"];
+    [medialibraryItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
     SideBarItem *mycompItem = [SideBarItem itemWithTitle:_NS("MY COMPUTER") identifier:@"mycomputer"];
     SideBarItem *devicesItem = [SideBarItem itemWithTitle:_NS("DEVICES") identifier:@"devices"];
     SideBarItem *lanItem = [SideBarItem itemWithTitle:_NS("LOCAL NETWORK") identifier:@"localnetwork"];
@@ -333,10 +336,12 @@ static VLCMainWindow *_o_sharedInstance = nil;
                 {
                     [internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
                     if (!strncmp( *ppsz_name, "podcast", 7 ))
-                        [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
+                        [internetItems removeLastObject]; // we don't support podcasts at this point (see #6017)
+//                        [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
                     else
                         [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
                     [[internetItems lastObject] setSdtype: SD_CAT_INTERNET];
+                    [[internetItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
                 }
                 break;
             case SD_CAT_DEVICES:
@@ -344,6 +349,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
                     [devicesItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
                     [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
                     [[devicesItems lastObject] setSdtype: SD_CAT_DEVICES];
+                    [[devicesItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
                 }
                 break;
             case SD_CAT_LAN:
@@ -351,6 +357,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
                     [lanItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
                     [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
                     [[lanItems lastObject] setSdtype: SD_CAT_LAN];
+                    [[lanItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
                 }
                 break;
             case SD_CAT_MYCOMPUTER:
@@ -364,6 +371,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
                         [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
                     else
                         [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
+                    [[mycompItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
                     [[mycompItems lastObject] setSdtype: SD_CAT_MYCOMPUTER];
                 }
                 break;
@@ -387,7 +395,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
     free( ppsz_longnames );
     free( p_categories );
 
-    [libraryItem setChildren: [NSArray arrayWithObject: playlistItem]];
+    [libraryItem setChildren: [NSArray arrayWithObjects: playlistItem, medialibraryItem, nil]];
     [o_sidebaritems addObject: libraryItem];
     if ([mycompItem hasChildren])
         [o_sidebaritems addObject: mycompItem];
@@ -399,10 +407,10 @@ static VLCMainWindow *_o_sharedInstance = nil;
         [o_sidebaritems addObject: internetItem];
 
     [o_sidebar_view reloadData];
-    [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:YES];
     NSUInteger i_sidebaritem_count = [o_sidebaritems count];
     for (NSUInteger x = 0; x < i_sidebaritem_count; x++)
         [o_sidebar_view expandItem: [o_sidebaritems objectAtIndex: x] expandChildren: YES];
+    [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
 
     if( b_dark_interface )
     {
@@ -1104,7 +1112,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [o_fspanel setSeekable: b_seekable];
 
     PL_LOCK;
-    if (p_playlist->items.i_size >= 1)
+    if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
         [self hideDropZone];
     else
         [self showDropZone];
@@ -1897,7 +1905,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasBadge:(id)item
 {
-    if ([[item identifier] isEqualToString: @"playlist"])
+    if ([[item identifier] isEqualToString: @"playlist"] || [[item identifier] isEqualToString: @"medialibrary"])
         return YES;
 
        return [item hasBadge];
@@ -1906,12 +1914,21 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (NSInteger)sourceList:(PXSourceList*)aSourceList badgeValueForItem:(id)item
 {
-    if ([[item identifier] isEqualToString: @"playlist"]) {
-        playlist_t * p_playlist = pl_Get( VLCIntf );
-        NSInteger i_playlist_size;
+    playlist_t * p_playlist = pl_Get( VLCIntf );
+    NSInteger i_playlist_size;
 
+    if ([[item identifier] isEqualToString: @"playlist"])
+    {
+        PL_LOCK;
+        i_playlist_size = p_playlist->p_local_category->i_children;
+        PL_UNLOCK;
+
+        return i_playlist_size;
+    }
+    if ([[item identifier] isEqualToString: @"medialibrary"])
+    {
         PL_LOCK;
-        i_playlist_size = p_playlist->items.i_size;
+        i_playlist_size = p_playlist->p_ml_category->i_children;
         PL_UNLOCK;
 
         return i_playlist_size;
@@ -1979,26 +1996,45 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (void)sourceListSelectionDidChange:(NSNotification *)notification
 {
+    playlist_t * p_playlist = pl_Get( VLCIntf );
        NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
+    id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
 
        //Set the label text to represent the new selection
-    if([selectedIndexes count]==1) {
-        id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
-        if ([item sdtype] > -1)
+    if ([item sdtype] > -1)
+    {
+        BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded( p_playlist, [[item identifier] UTF8String] );
+        if (!sd_loaded)
         {
-            playlist_t * p_playlist = pl_Get( VLCIntf );
-            BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded( p_playlist, [[item identifier] UTF8String] );
-            if (!sd_loaded)
-            {
-                playlist_ServicesDiscoveryAdd( p_playlist, [[item identifier] UTF8String] );
-            }
+            playlist_ServicesDiscoveryAdd( p_playlist, [[item identifier] UTF8String] );
         }
+    }
 
-               [o_chosen_category_lbl setStringValue:[item title]];
-       }
-       else {
-               [o_chosen_category_lbl setStringValue:@"(none)"];
-       }
+    [o_chosen_category_lbl setStringValue:[item title]];
+
+    if ([[item identifier] isEqualToString:@"playlist"])
+    {
+        [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_local_category];
+    }
+    else if([[item identifier] isEqualToString:@"medialibrary"])
+    {
+        [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_ml_category];
+    }
+    else
+    {
+        playlist_item_t * pl_item;
+        PL_LOCK;
+        pl_item = playlist_ChildSearchName( p_playlist->p_root, [[item untranslatedTitle] UTF8String] );
+        PL_UNLOCK;
+        [[[VLCMain sharedInstance] playlist] setPlaylistRoot: pl_item];
+    }
+
+    PL_LOCK;
+    if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
+        [self hideDropZone];
+    else
+        [self showDropZone];
+    PL_UNLOCK;
 }
 
 @end
index acb403bd6ec8982fab783c02d621f82e30eb5ab0..c0df2c9fde9f19626da8fe61df631e27c9f454a0 100644 (file)
@@ -30,6 +30,7 @@
 @interface SideBarItem : NSObject {
        NSString *title;
        NSString *identifier;
+    NSString *untranslatedTitle;
        NSImage *icon;
        NSInteger badgeValue;
     NSInteger sdtype;
@@ -39,6 +40,7 @@
 
 @property (nonatomic, copy) NSString *title;
 @property (nonatomic, copy) NSString *identifier;
+@property (nonatomic, copy) NSString *untranslatedTitle;
 @property (nonatomic, retain) NSImage *icon;
 @property NSInteger badgeValue;
 @property NSInteger sdtype;
index 859031f31c87f9d8acf5faa40cbc72e7286545cc..180c2c3384ff1432ba2f98ce0a92228a124db87c 100644 (file)
@@ -16,6 +16,7 @@
 @implementation SideBarItem
 
 @synthesize title;
+@synthesize untranslatedTitle;
 @synthesize identifier;
 @synthesize icon;
 @synthesize badgeValue;
index d319b45c7ea558913ffb645374af36ae791fc3ac..88148db2195ba0c2824e09f5a26aea1b31dfdbff 100644 (file)
@@ -705,7 +705,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     if (notification == nil)
         [[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillTerminateNotification object: nil];
 
-    playlist_t * p_playlist = pl_Get( p_intf );;
+    playlist_t * p_playlist = pl_Get( p_intf );
     int returnedValue = 0;
 
     /* Save some interface state in configuration, at module quit */
index 6f30ba1be7e912adfb18032c76a8c1ab5723043f..00d405b8a5b7dbd3e84ad229b84bf07dec9a2968 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
  * playlist.h: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2002-2006 VLC authors and VideoLAN
+ * Copyright (C) 2002-2012 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Derk-Jan Hartman <hartman at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
     IBOutlet VLCPlaylistView* o_outline_view_other;
 
     NSMutableDictionary *o_outline_dict;
+    playlist_item_t * p_current_root_item;
 }
 
+- (void)setPlaylistRoot: (playlist_item_t *)root_item;
+- (playlist_item_t *)currentPlaylistRoot;
 - (void)initStrings;
 - (playlist_item_t *)selectedPlaylistItem;
 - (NSOutlineView *)outlineView;
index d322ae026d06d49102d59ea0071666b7695a01ac..ff88139a4c40f3a708b41c1726c982d742254b9b 100644 (file)
@@ -1,12 +1,13 @@
 /*****************************************************************************
  * playlist.m: MacOS X interface module
  *****************************************************************************
-* Copyright (C) 2002-2009 VLC authors and VideoLAN
+* Copyright (C) 2002-2012 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Derk-Jan Hartman <hartman at videola/n dot org>
  *          Benjamin Pracht <bigben at videolab dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 - (id)init
 {
+    playlist_t * p_playlist = pl_Get( VLCIntf );
+    p_current_root_item = p_playlist->p_local_category;
+
     self = [super init];
     if ( self != nil )
     {
     }
     return self;
 }
+
 - (void)awakeFromNib
 {
     playlist_t * p_playlist = pl_Get( VLCIntf );
     [[o_tc_duration_other headerCell] setStringValue:_NS("Duration")];
 }
 
+- (void)setPlaylistRoot: (playlist_item_t *)root_item
+{
+    p_current_root_item = root_item;
+    [o_outline_view reloadData];
+    [o_outline_view_other reloadData];
+}
+
+- (playlist_item_t *)currentPlaylistRoot
+{
+    return p_current_root_item;
+}
+
 - (void)swapPlaylists:(id)newList
 {
        if(newList != o_outline_view)
 @end
 
 @implementation VLCPlaylistCommon (NSOutlineViewDataSource)
-
 /* return the number of children for Obj-C pointer item */ /* DONE */
 - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
 {
 
     PL_LOCK;
     if( !item )
-        p_item = p_playlist->p_root_category;
+    {
+        p_item = p_current_root_item;
+    }
     else
         p_item = (playlist_item_t *)[item pointerValue];
 
     if( item == nil )
     {
         /* root object */
-        p_item = p_playlist->p_root_category;
+        p_item = p_current_root_item;
     }
     else
     {
     if( item == nil )
     {
         /* root object */
-        if( p_playlist->p_root_category )
+        if( p_current_root_item )
         {
-            i_return = p_playlist->p_root_category->i_children;
+            i_return = p_current_root_item->i_children;
         }
     }
     else
     o_descendingSortingImage = [[NSOutlineView class] _defaultTableHeaderReverseSortImage];
 
     o_tc_sortColumn = nil;
-
+#if 0
     char ** ppsz_name;
     char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
     if( !ppsz_services )
     }
     free( ppsz_services );
     free( ppsz_name );
+#endif
 }
 
 - (void)searchfieldChanged:(NSNotification *)o_notification
     else
     /*If no item is selected, sort the whole playlist*/
     {
-        p_item = p_playlist->p_root_category;
+        p_item = [self currentPlaylistRoot];
     }
 
     PL_LOCK;
 {
     playlist_t * p_playlist = pl_Get( VLCIntf );
     NSUInteger count = [o_array count];
+    BOOL b_usingPlaylist;
+    if ([self currentPlaylistRoot] == p_playlist->p_ml_category)
+        b_usingPlaylist = NO;
+    else
+        b_usingPlaylist = YES;
 
     PL_LOCK;
     for( NSUInteger i_item = 0; i_item < count; i_item++ )
         /* 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,
+        playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT, i_position == -1 ? PLAYLIST_END : i_position + i_item, b_usingPlaylist,
          pl_Locked );
 
         vlc_gc_decref( p_input );
 
         /*First, only search after the selected item:*
          *(b_selected_item_met = NO)                 */
-    o_result = [self subSearchItem:p_playlist->p_root_category];
+    o_result = [self subSearchItem:[self currentPlaylistRoot]];
     if( o_result == NULL )
     {
         /* If the first search failed, search again from the beginning */
-        o_result = [self subSearchItem:p_playlist->p_root_category];
+        o_result = [self subSearchItem:[self currentPlaylistRoot]];
     }
     if( o_result != NULL )
     {
     }
 
     PL_LOCK;
-    playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_category, i_mode, i_type );
+    playlist_RecursiveNodeSort( p_playlist, [self currentPlaylistRoot], i_mode, i_type );
     PL_UNLOCK;
 
     [self playlistUpdated];