Commit be61e161 authored by Felix Paul Kühne's avatar Felix Paul Kühne Committed by David Fuhrmann

macosx: reload sidebar if the user un-/installs an SD using the addon manager

(cherry picked from commit 708f5f01f54a3e91d67d514d8387db7eeac64dba)
Signed-off-by: default avatarDavid Fuhrmann <dfuhrmann@videolan.org>
parent 8f7e58d2
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#import "AddonManager.h" #import "AddonManager.h"
#import "intf.h" #import "intf.h"
#import "MainWindow.h"
#import "AddonListDataSource.h" #import "AddonListDataSource.h"
@interface VLCAddonManager () @interface VLCAddonManager ()
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
addons_manager_t *_manager; addons_manager_t *_manager;
NSMutableArray *_addons; NSMutableArray *_addons;
NSArray *_displayedAddons; NSArray *_displayedAddons;
BOOL _shouldRefreshSideBarOnAddonChange;
} }
- (void)addAddon:(NSValue *)o_value; - (void)addAddon:(NSValue *)o_value;
...@@ -161,7 +163,7 @@ static VLCAddonManager *_o_sharedInstance = nil; ...@@ -161,7 +163,7 @@ static VLCAddonManager *_o_sharedInstance = nil;
return; return;
VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow]; VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow];
[self _installAddonWithID:[currentAddon uuid]]; [self _installAddonWithID:[currentAddon uuid] type:[currentAddon type]];
[_installButton setEnabled:NO]; [_installButton setEnabled:NO];
} }
...@@ -173,7 +175,7 @@ static VLCAddonManager *_o_sharedInstance = nil; ...@@ -173,7 +175,7 @@ static VLCAddonManager *_o_sharedInstance = nil;
return; return;
VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow]; VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow];
[self _removeAddonWithID:[currentAddon uuid]]; [self _removeAddonWithID:[currentAddon uuid] type:[currentAddon type]];
[_installButton setEnabled:NO]; [_installButton setEnabled:NO];
} }
...@@ -248,6 +250,10 @@ static VLCAddonManager *_o_sharedInstance = nil; ...@@ -248,6 +250,10 @@ static VLCAddonManager *_o_sharedInstance = nil;
- (void)addonChanged:(NSValue *)o_value - (void)addonChanged:(NSValue *)o_value
{ {
[self _refactorDataModel]; [self _refactorDataModel];
if (_shouldRefreshSideBarOnAddonChange) {
[[VLCMainWindow sharedInstance] performSelector:@selector(reloadSidebar) withObject:nil afterDelay:0.5];
_shouldRefreshSideBarOnAddonChange = NO;
}
} }
#pragma mark - helpers #pragma mark - helpers
...@@ -309,19 +315,25 @@ static VLCAddonManager *_o_sharedInstance = nil; ...@@ -309,19 +315,25 @@ static VLCAddonManager *_o_sharedInstance = nil;
[self performSelectorOnMainThread:@selector(_refactorDataModel) withObject:nil waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(_refactorDataModel) withObject:nil waitUntilDone:NO];
} }
- (void)_installAddonWithID:(NSData *)o_data - (void)_installAddonWithID:(NSData *)o_data type:(addon_type_t)type
{ {
addon_uuid_t uuid; addon_uuid_t uuid;
[o_data getBytes:uuid length:sizeof(uuid)]; [o_data getBytes:uuid length:sizeof(uuid)];
if (type == ADDON_SERVICE_DISCOVERY)
_shouldRefreshSideBarOnAddonChange = YES;
addons_manager_Install(_manager, uuid); addons_manager_Install(_manager, uuid);
} }
- (void)_removeAddonWithID:(NSData *)o_data - (void)_removeAddonWithID:(NSData *)o_data type:(addon_type_t)type
{ {
addon_uuid_t uuid; addon_uuid_t uuid;
[o_data getBytes:uuid length:sizeof(uuid)]; [o_data getBytes:uuid length:sizeof(uuid)];
if (type == ADDON_SERVICE_DISCOVERY)
_shouldRefreshSideBarOnAddonChange = YES;
addons_manager_Remove(_manager, uuid); addons_manager_Remove(_manager, uuid);
} }
......
...@@ -122,6 +122,8 @@ typedef enum { ...@@ -122,6 +122,8 @@ typedef enum {
- (void)windowResizedOrMoved:(NSNotification *)notification; - (void)windowResizedOrMoved:(NSNotification *)notification;
- (void)reloadSidebar;
- (void)toggleLeftSubSplitView; - (void)toggleLeftSubSplitView;
- (void)showDropZone; - (void)showDropZone;
- (void)hideDropZone; - (void)hideDropZone;
......
...@@ -219,7 +219,109 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -219,7 +219,109 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_search_fld setFrame: frame]; [o_search_fld setFrame: frame];
} }
/* create the sidebar */ /* reload the sidebar */
[self reloadSidebar];
o_fspanel = [[VLCFSPanel alloc] initWithContentRect:NSMakeRect(110.,267.,549.,87.)
styleMask:NSTexturedBackgroundWindowMask
backing:NSBackingStoreBuffered
defer:YES];
/* make sure we display the desired default appearance when VLC launches for the first time */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:@"VLCFirstRun"]) {
[defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
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_fspanel center];
NSAlert *albumArtAlert = [NSAlert alertWithMessageText:_NS("Check for album art and metadata?") defaultButton:_NS("Enable Metadata Retrieval") alternateButton:_NS("No, Thanks") otherButton:nil informativeTextWithFormat:@"%@",_NS("VLC can check online for album art and metadata to enrich your playback experience, e.g. by providing track information when playing Audio CDs. To provide this functionality, VLC will send information about your contents to trusted services in an anonymized form.")];
NSInteger returnValue = [albumArtAlert runModal];
config_PutInt(VLCIntf, "metadata-network-access", returnValue == NSAlertDefaultReturn);
}
// select playlist item by default
[o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
if (b_dark_interface) {
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
[self setBackgroundColor: [NSColor clearColor]];
[self setOpaque: NO];
[self display];
[self setHasShadow:NO];
[self setHasShadow:YES];
NSRect winrect = [self frame];
CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
[o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
winrect.size.width, f_titleBarHeight)];
[[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: o_split_view];
if (winrect.size.height > 100) {
[self setFrame: winrect display:YES animate:YES];
previousSavedFrame = winrect;
}
winrect = [o_split_view frame];
winrect.size.height = winrect.size.height - f_titleBarHeight;
[o_split_view setFrame: winrect];
[o_video_view setFrame: winrect];
o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_split_view frame]];
[[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_split_view];
[o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
} else {
[o_video_view setFrame: [o_split_view frame]];
[o_playlist_table setBorderType: NSNoBorder];
[o_sidebar_scrollview setBorderType: NSNoBorder];
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(mainSplitViewDidResizeSubviews:) name: NSSplitViewDidResizeSubviewsNotification object:o_split_view];
if (b_splitviewShouldBeHidden) {
[self hideSplitView: YES];
f_lastSplitViewHeight = 300;
}
/* sanity check for the window size */
NSRect frame = [self frame];
NSSize screenSize = [[self screen] frame].size;
if (screenSize.width <= frame.size.width || screenSize.height <= frame.size.height) {
nativeVideoSize = screenSize;
[self resizeWindow];
}
/* update fs button to reflect state for next startup */
if (var_InheritBool(pl_Get(VLCIntf), "fullscreen"))
[o_controls_bar setFullscreenState:YES];
/* restore split view */
f_lastLeftSplitViewWidth = 200;
/* trick NSSplitView implementation, which pretends to know better than us */
if (!config_GetInt(VLCIntf, "macosx-show-sidebar"))
[self performSelector:@selector(toggleLeftSubSplitView) withObject:nil afterDelay:0.05];
}
#pragma mark -
#pragma mark appearance management
- (void)reloadSidebar
{
BOOL isAReload = NO;
if (o_sidebaritems) {
[o_sidebaritems release];
isAReload = YES;
}
o_sidebaritems = [[NSMutableArray alloc] init]; o_sidebaritems = [[NSMutableArray alloc] init];
SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"]; SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"]; SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
...@@ -323,98 +425,13 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -323,98 +425,13 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_sidebar_view expandItem: libraryItem expandChildren: YES]; [o_sidebar_view expandItem: libraryItem expandChildren: YES];
o_fspanel = [[VLCFSPanel alloc] initWithContentRect:NSMakeRect(110.,267.,549.,87.) if (isAReload) {
styleMask:NSTexturedBackgroundWindowMask
backing:NSBackingStoreBuffered
defer:YES];
/* make sure we display the desired default appearance when VLC launches for the first time */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:@"VLCFirstRun"]) {
[defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
NSUInteger i_sidebaritem_count = [o_sidebaritems count]; NSUInteger i_sidebaritem_count = [o_sidebaritems count];
for (NSUInteger x = 0; x < i_sidebaritem_count; x++) for (NSUInteger x = 0; x < i_sidebaritem_count; x++)
[o_sidebar_view expandItem: [o_sidebaritems objectAtIndex:x] expandChildren: YES]; [o_sidebar_view expandItem: [o_sidebaritems objectAtIndex:x] expandChildren: YES];
[o_fspanel center];
NSAlert *albumArtAlert = [NSAlert alertWithMessageText:_NS("Check for album art and metadata?") defaultButton:_NS("Enable Metadata Retrieval") alternateButton:_NS("No, Thanks") otherButton:nil informativeTextWithFormat:@"%@",_NS("VLC can check online for album art and metadata to enrich your playback experience, e.g. by providing track information when playing Audio CDs. To provide this functionality, VLC will send information about your contents to trusted services in an anonymized form.")];
NSInteger returnValue = [albumArtAlert runModal];
config_PutInt(VLCIntf, "metadata-network-access", returnValue == NSAlertDefaultReturn);
}
// select playlist item by default
[o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
if (b_dark_interface) {
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
[self setBackgroundColor: [NSColor clearColor]];
[self setOpaque: NO];
[self display];
[self setHasShadow:NO];
[self setHasShadow:YES];
NSRect winrect = [self frame];
CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
[o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
winrect.size.width, f_titleBarHeight)];
[[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: o_split_view];
if (winrect.size.height > 100) {
[self setFrame: winrect display:YES animate:YES];
previousSavedFrame = winrect;
} }
winrect = [o_split_view frame];
winrect.size.height = winrect.size.height - f_titleBarHeight;
[o_split_view setFrame: winrect];
[o_video_view setFrame: winrect];
o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_split_view frame]];
[[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_split_view];
[o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
} else {
[o_video_view setFrame: [o_split_view frame]];
[o_playlist_table setBorderType: NSNoBorder];
[o_sidebar_scrollview setBorderType: NSNoBorder];
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(mainSplitViewDidResizeSubviews:) name: NSSplitViewDidResizeSubviewsNotification object:o_split_view];
if (b_splitviewShouldBeHidden) {
[self hideSplitView: YES];
f_lastSplitViewHeight = 300;
}
/* sanity check for the window size */
NSRect frame = [self frame];
NSSize screenSize = [[self screen] frame].size;
if (screenSize.width <= frame.size.width || screenSize.height <= frame.size.height) {
nativeVideoSize = screenSize;
[self resizeWindow];
}
/* update fs button to reflect state for next startup */
if (var_InheritBool(pl_Get(VLCIntf), "fullscreen"))
[o_controls_bar setFullscreenState:YES];
/* restore split view */
f_lastLeftSplitViewWidth = 200;
/* trick NSSplitView implementation, which pretends to know better than us */
if (!config_GetInt(VLCIntf, "macosx-show-sidebar"))
[self performSelector:@selector(toggleLeftSubSplitView) withObject:nil afterDelay:0.05];
} }
#pragma mark -
#pragma mark appearance management
- (VLCMainWindowControlsBar *)controlsBar; - (VLCMainWindowControlsBar *)controlsBar;
{ {
return (VLCMainWindowControlsBar *)o_controls_bar; return (VLCMainWindowControlsBar *)o_controls_bar;
......
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