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 @@
#import "AddonManager.h"
#import "intf.h"
#import "MainWindow.h"
#import "AddonListDataSource.h"
@interface VLCAddonManager ()
......@@ -32,6 +33,7 @@
addons_manager_t *_manager;
NSMutableArray *_addons;
NSArray *_displayedAddons;
BOOL _shouldRefreshSideBarOnAddonChange;
}
- (void)addAddon:(NSValue *)o_value;
......@@ -161,7 +163,7 @@ static VLCAddonManager *_o_sharedInstance = nil;
return;
VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow];
[self _installAddonWithID:[currentAddon uuid]];
[self _installAddonWithID:[currentAddon uuid] type:[currentAddon type]];
[_installButton setEnabled:NO];
}
......@@ -173,7 +175,7 @@ static VLCAddonManager *_o_sharedInstance = nil;
return;
VLCAddon *currentAddon = [_displayedAddons objectAtIndex:selectedRow];
[self _removeAddonWithID:[currentAddon uuid]];
[self _removeAddonWithID:[currentAddon uuid] type:[currentAddon type]];
[_installButton setEnabled:NO];
}
......@@ -248,6 +250,10 @@ static VLCAddonManager *_o_sharedInstance = nil;
- (void)addonChanged:(NSValue *)o_value
{
[self _refactorDataModel];
if (_shouldRefreshSideBarOnAddonChange) {
[[VLCMainWindow sharedInstance] performSelector:@selector(reloadSidebar) withObject:nil afterDelay:0.5];
_shouldRefreshSideBarOnAddonChange = NO;
}
}
#pragma mark - helpers
......@@ -309,19 +315,25 @@ static VLCAddonManager *_o_sharedInstance = nil;
[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;
[o_data getBytes:uuid length:sizeof(uuid)];
if (type == ADDON_SERVICE_DISCOVERY)
_shouldRefreshSideBarOnAddonChange = YES;
addons_manager_Install(_manager, uuid);
}
- (void)_removeAddonWithID:(NSData *)o_data
- (void)_removeAddonWithID:(NSData *)o_data type:(addon_type_t)type
{
addon_uuid_t uuid;
[o_data getBytes:uuid length:sizeof(uuid)];
if (type == ADDON_SERVICE_DISCOVERY)
_shouldRefreshSideBarOnAddonChange = YES;
addons_manager_Remove(_manager, uuid);
}
......
......@@ -122,6 +122,8 @@ typedef enum {
- (void)windowResizedOrMoved:(NSNotification *)notification;
- (void)reloadSidebar;
- (void)toggleLeftSubSplitView;
- (void)showDropZone;
- (void)hideDropZone;
......
......@@ -219,109 +219,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_search_fld setFrame: frame];
}
/* create the sidebar */
o_sidebaritems = [[NSMutableArray alloc] init];
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"];
SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
/* SD subnodes, inspired by the Qt4 intf */
char **ppsz_longnames = NULL;
int *p_categories = NULL;
char **ppsz_names = vlc_sd_GetNames(pl_Get(VLCIntf), &ppsz_longnames, &p_categories);
if (!ppsz_names)
msg_Err(VLCIntf, "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 = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
switch (*p_category) {
case SD_CAT_INTERNET:
[internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
if (!strncmp(*ppsz_name, "podcast", 7))
[[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:
[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:
[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:
[mycompItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
if (!strncmp(*ppsz_name, "video_dir", 9))
[[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
else if (!strncmp(*ppsz_name, "audio_dir", 9))
[[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
else if (!strncmp(*ppsz_name, "picture_dir", 11))
[[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;
default:
msg_Warn(VLCIntf, "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]];
[mycompItems release];
[devicesItems release];
[lanItems release];
[internetItems release];
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];
[o_sidebar_view reloadData];
[o_sidebar_view setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
[o_sidebar_view registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
[o_sidebar_view setAutosaveName:@"mainwindow-sidebar"];
[(PXSourceList *)o_sidebar_view setDataSource:self];
[o_sidebar_view setDelegate:self];
[o_sidebar_view setAutosaveExpandedItems:YES];
[o_sidebar_view expandItem: libraryItem expandChildren: YES];
/* reload the sidebar */
[self reloadSidebar];
o_fspanel = [[VLCFSPanel alloc] initWithContentRect:NSMakeRect(110.,267.,549.,87.)
styleMask:NSTexturedBackgroundWindowMask
......@@ -415,6 +314,124 @@ static VLCMainWindow *_o_sharedInstance = nil;
#pragma mark -
#pragma mark appearance management
- (void)reloadSidebar
{
BOOL isAReload = NO;
if (o_sidebaritems) {
[o_sidebaritems release];
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: [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"];
SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
/* SD subnodes, inspired by the Qt4 intf */
char **ppsz_longnames = NULL;
int *p_categories = NULL;
char **ppsz_names = vlc_sd_GetNames(pl_Get(VLCIntf), &ppsz_longnames, &p_categories);
if (!ppsz_names)
msg_Err(VLCIntf, "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 = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
switch (*p_category) {
case SD_CAT_INTERNET:
[internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
if (!strncmp(*ppsz_name, "podcast", 7))
[[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:
[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:
[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:
[mycompItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
if (!strncmp(*ppsz_name, "video_dir", 9))
[[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
else if (!strncmp(*ppsz_name, "audio_dir", 9))
[[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
else if (!strncmp(*ppsz_name, "picture_dir", 11))
[[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;
default:
msg_Warn(VLCIntf, "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]];
[mycompItems release];
[devicesItems release];
[lanItems release];
[internetItems release];
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];
[o_sidebar_view reloadData];
[o_sidebar_view setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
[o_sidebar_view registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
[o_sidebar_view setAutosaveName:@"mainwindow-sidebar"];
[(PXSourceList *)o_sidebar_view setDataSource:self];
[o_sidebar_view setDelegate:self];
[o_sidebar_view setAutosaveExpandedItems:YES];
[o_sidebar_view expandItem: libraryItem expandChildren: YES];
if (isAReload) {
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];
}
}
- (VLCMainWindowControlsBar *)controlsBar;
{
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