Commit 5c1e88e0 authored by Vibhoothi's avatar Vibhoothi Committed by Felix Paul Kühne

macosx: Remove sidebar from VLCMainWindow.m

This is part of first steps in making the Library view
parent 88b2a5a4
......@@ -65,7 +65,6 @@
CGFloat f_lastSplitViewHeight;
CGFloat f_lastLeftSplitViewWidth;
NSMutableArray *o_sidebaritems;
/* this is only true, when we have NO video playing inside the main window */
......@@ -164,9 +163,7 @@ static const float f_min_window_height = 307.;
[playlist setPlaylistHeaderView:_outlineView.headerView];
[self setNextResponder:playlist];
// (Re)load sidebar for the first time and select first item
[self reloadSidebar];
[_sidebarView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
/*
......@@ -207,7 +204,6 @@ static const float f_min_window_height = 307.;
if (![defaults objectForKey:@"VLCFirstRun"]) {
[defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
[_sidebarView expandItem:nil expandChildren:YES];
NSAlert *albumArtAlert = [[NSAlert alloc] init];
[albumArtAlert setMessageText:_NS("Check for album art and metadata?")];
......@@ -220,7 +216,6 @@ static const float f_min_window_height = 307.;
}
[_playlistScrollView setBorderType:NSNoBorder];
[_sidebarScrollView setBorderType:NSNoBorder];
[defaultCenter addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
[defaultCenter addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
......@@ -244,116 +239,12 @@ static const float f_min_window_height = 307.;
if (var_InheritBool(pl_Get(getIntf()), "fullscreen"))
[self.controlsBar setFullscreenState:YES];
/* restore split view */
f_lastLeftSplitViewWidth = 200;
[[[VLCMain sharedInstance] mainMenu] updateSidebarMenuItem: ![_splitView isSubviewCollapsed:_splitViewLeft]];
}
#pragma mark -
#pragma mark appearance management
- (void)reloadSidebar
{
BOOL isAReload = NO;
if (o_sidebaritems)
isAReload = YES;
o_sidebaritems = [[NSMutableArray alloc] init];
SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
[playlistItem setIcon: imageFromRes(@"sidebar-playlist")];
SideBarItem *medialibraryItem = [SideBarItem itemWithTitle:_NS("Media Library") identifier:@"medialibrary"];
[medialibraryItem setIcon: imageFromRes(@"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"];
SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
/* SD subnodes, inspired by the Qt intf */
char **ppsz_longnames = NULL;
int *p_categories = NULL;
char **ppsz_names = vlc_sd_GetNames(pl_Get(getIntf()), &ppsz_longnames, &p_categories);
if (!ppsz_names)
msg_Err(getIntf(), "no sd item found"); //TODO
char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
int *p_category = p_categories;
NSMutableArray *internetItems = [[NSMutableArray alloc] init];
NSMutableArray *devicesItems = [[NSMutableArray alloc] init];
NSMutableArray *lanItems = [[NSMutableArray alloc] init];
NSMutableArray *mycompItems = [[NSMutableArray alloc] init];
NSString *o_identifier;
for (; ppsz_name && *ppsz_name; ppsz_name++, ppsz_longname++, p_category++) {
o_identifier = toNSStr(*ppsz_name);
switch (*p_category) {
case SD_CAT_INTERNET:
[internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
[[internetItems lastObject] setSdtype: SD_CAT_INTERNET];
break;
case SD_CAT_DEVICES:
[devicesItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
[[devicesItems lastObject] setIcon: imageFromRes(@"sidebar-local")];
[[devicesItems lastObject] setSdtype: SD_CAT_DEVICES];
break;
case SD_CAT_LAN:
[lanItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
[[lanItems lastObject] setIcon: imageFromRes(@"sidebar-local")];
[[lanItems lastObject] setSdtype: SD_CAT_LAN];
break;
case SD_CAT_MYCOMPUTER:
[mycompItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
if (!strncmp(*ppsz_name, "video_dir", 9))
[[mycompItems lastObject] setIcon: imageFromRes(@"sidebar-movie")];
else if (!strncmp(*ppsz_name, "audio_dir", 9))
[[mycompItems lastObject] setIcon: imageFromRes(@"sidebar-music")];
else if (!strncmp(*ppsz_name, "picture_dir", 11))
[[mycompItems lastObject] setIcon: imageFromRes(@"sidebar-pictures")];
else
[[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
[[mycompItems lastObject] setSdtype: SD_CAT_MYCOMPUTER];
break;
default:
msg_Warn(getIntf(), "unknown SD type found, skipping (%s)", *ppsz_name);
break;
}
free(*ppsz_name);
free(*ppsz_longname);
}
[mycompItem setChildren: [NSArray arrayWithArray: mycompItems]];
[devicesItem setChildren: [NSArray arrayWithArray: devicesItems]];
[lanItem setChildren: [NSArray arrayWithArray: lanItems]];
[internetItem setChildren: [NSArray arrayWithArray: internetItems]];
free(ppsz_names);
free(ppsz_longnames);
free(p_categories);
[libraryItem setChildren: [NSArray arrayWithObjects:playlistItem, medialibraryItem, nil]];
[o_sidebaritems addObject: libraryItem];
if ([mycompItem hasChildren])
[o_sidebaritems addObject: mycompItem];
if ([devicesItem hasChildren])
[o_sidebaritems addObject: devicesItem];
if ([lanItem hasChildren])
[o_sidebaritems addObject: lanItem];
if ([internetItem hasChildren])
[o_sidebaritems addObject: internetItem];
[_sidebarView reloadData];
[_sidebarView setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
[_sidebarView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
[_sidebarView setAutosaveName:@"mainwindow-sidebar"];
[_sidebarView setDataSource:self];
[_sidebarView setDelegate:self];
[_sidebarView setAutosaveExpandedItems:YES];
[_sidebarView expandItem:libraryItem expandChildren:YES];
if (isAReload) {
[_sidebarView expandItem:nil expandChildren:YES];
}
}
// Show split view and hide the video view
- (void)makeSplitViewVisible
{
......@@ -652,7 +543,6 @@ static const float f_min_window_height = 307.;
else
[self showDropZone];
PL_UNLOCK;
[_sidebarView setNeedsDisplay:YES];
[self _updatePlaylistTitle];
}
......@@ -794,7 +684,6 @@ static const float f_min_window_height = 307.;
else
[_splitView setPosition:[_splitView minPossiblePositionOfDividerAtIndex:0] ofDividerAtIndex:0];
[[[VLCMain sharedInstance] mainMenu] updateSidebarMenuItem: ![_splitView isSubviewCollapsed:_splitViewLeft]];
}
#pragma mark -
......@@ -846,29 +735,6 @@ static const float f_min_window_height = 307.;
[_searchField selectText:sender];
}
#pragma mark -
#pragma mark Side Bar Data handling
/* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
- (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
{
//Works the same way as the NSOutlineView data source: `nil` means a parent item
if (item==nil)
return [o_sidebaritems count];
else
return [[item children] count];
}
- (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
{
//Works the same way as the NSOutlineView data source: `nil` means a parent item
if (item==nil)
return [o_sidebaritems objectAtIndex:index];
else
return [[item children] objectAtIndex:index];
}
- (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
{
return [item title];
......@@ -966,75 +832,6 @@ static const float f_min_window_height = 307.;
}
}
#pragma mark -
#pragma mark Side Bar Delegate Methods
/* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
- (BOOL)sourceList:(PXSourceList*)aSourceList isGroupAlwaysExpanded:(id)group
{
if ([[group identifier] isEqualToString:@"library"])
return YES;
return NO;
}
- (void)sourceListSelectionDidChange:(NSNotification *)notification
{
playlist_t * p_playlist = pl_Get(getIntf());
NSIndexSet *selectedIndexes = [_sidebarView selectedRowIndexes];
id item = [_sidebarView itemAtRow:[selectedIndexes firstIndex]];
//Set the label text to represent the new selection
if ([item sdtype] > -1 && [[item identifier] length] > 0) {
BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
if (!sd_loaded)
playlist_ServicesDiscoveryAdd(p_playlist, [[item identifier] UTF8String]);
}
[_categoryLabel setStringValue:[item title]];
if ([[item identifier] isEqualToString:@"playlist"]) {
PL_LOCK;
[[[[VLCMain sharedInstance] playlist] model] changeRootItem:p_playlist->p_playing];
PL_UNLOCK;
[self _updatePlaylistTitle];
} else if ([[item identifier] isEqualToString:@"medialibrary"]) {
if (p_playlist->p_media_library) {
PL_LOCK;
[[[[VLCMain sharedInstance] playlist] model] changeRootItem:p_playlist->p_media_library];
PL_UNLOCK;
[self _updatePlaylistTitle];
}
} else {
PL_LOCK;
const char *title = [[item title] UTF8String];
playlist_item_t *pl_item = playlist_ChildSearchName(&p_playlist->root, title);
if (pl_item)
[[[[VLCMain sharedInstance] playlist] model] changeRootItem:pl_item];
else
msg_Err(getIntf(), "Could not find playlist entry with name %s", title);
PL_UNLOCK;
}
PL_LOCK;
if ([[[[VLCMain sharedInstance] playlist] model] currentRootType] != ROOT_TYPE_PLAYLIST ||
[[[[VLCMain sharedInstance] playlist] model] hasChildren])
[self hideDropZone];
else
[self showDropZone];
PL_UNLOCK;
[[NSNotificationCenter defaultCenter] postNotificationName: VLCMediaKeySupportSettingChangedNotification
object: nil
userInfo: nil];
}
- (NSDragOperation)sourceList:(PXSourceList *)aSourceList validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
{
if ([[item identifier] isEqualToString:@"playlist"] || [[item identifier] isEqualToString:@"medialibrary"]) {
......@@ -1090,25 +887,6 @@ static const float f_min_window_height = 307.;
return [item identifier];
}
- (id)sourceList:(PXSourceList *)aSourceList itemForPersistentObject:(id)object
{
/* the following code assumes for sakes of simplicity that only the top level
* items are allowed to have children */
NSArray * array = [NSArray arrayWithArray: o_sidebaritems]; // read-only arrays are noticebly faster
NSUInteger count = [array count];
if (count < 1)
return nil;
for (NSUInteger x = 0; x < count; x++) {
id item = [array objectAtIndex:x]; // save one objc selector call
if ([[item identifier] isEqualToString:object])
return item;
}
return nil;
}
@end
@interface VLCDetachedVideoWindow ()
......
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