Commit 18e545d8 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: implemented the sidebar completely to support switching between the...

macosx: implemented the sidebar completely to support switching between the playlist's top-level nodes (fixes #4944)
(cherry picked from commit 59a028786195c9a61c62b65e66c7c6d65a04c93b)
parent d814ffb8
......@@ -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
......@@ -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;
......
......@@ -16,6 +16,7 @@
@implementation SideBarItem
@synthesize title;
@synthesize untranslatedTitle;
@synthesize identifier;
@synthesize icon;
@synthesize badgeValue;
......
......@@ -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 */
......
/*****************************************************************************
* 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
......@@ -49,8 +50,11 @@
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;
......
/*****************************************************************************
* 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
......@@ -107,6 +108,9 @@
- (id)init
{
playlist_t * p_playlist = pl_Get( VLCIntf );
p_current_root_item = p_playlist->p_local_category;
self = [super init];
if ( self != nil )
{
......@@ -114,6 +118,7 @@
}
return self;
}
- (void)awakeFromNib
{
playlist_t * p_playlist = pl_Get( VLCIntf );
......@@ -142,6 +147,18 @@
[[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)
......@@ -175,7 +192,6 @@
@end
@implementation VLCPlaylistCommon (NSOutlineViewDataSource)
/* return the number of children for Obj-C pointer item */ /* DONE */
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
......@@ -186,7 +202,9 @@
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];
......@@ -208,7 +226,7 @@
if( item == nil )
{
/* root object */
p_item = p_playlist->p_root_category;
p_item = p_current_root_item;
}
else
{
......@@ -240,9 +258,9 @@
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
......@@ -415,7 +433,7 @@
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 )
......@@ -453,6 +471,7 @@
}
free( ppsz_services );
free( ppsz_name );
#endif
}
- (void)searchfieldChanged:(NSNotification *)o_notification
......@@ -974,7 +993,7 @@
else
/*If no item is selected, sort the whole playlist*/
{
p_item = p_playlist->p_root_category;
p_item = [self currentPlaylistRoot];
}
PL_LOCK;
......@@ -1079,6 +1098,11 @@
{
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++ )
......@@ -1097,7 +1121,7 @@
/* 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 );
......@@ -1224,11 +1248,11 @@
/*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 )
{
......@@ -1344,7 +1368,7 @@
}
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];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment