[vlc-commits] [Git][videolan/vlc][master] 15 commits: macosx: Make representedItem in VLCLibraryMenuController a weak property...
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sun Jan 8 10:45:03 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
0b163e87 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Make representedItem in VLCLibraryMenuController a weak property rather than a setter and a private member
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
dad5ac29 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add representedInputItem to VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
37055e1c by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Hide or show specific menu items for input items in VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
d8b4c6c8 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add support for playing input item in VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
1dd7a0fe by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add support for revealing input item in finder in VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
a94e5508 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add support for moving input item to trash in VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
2379d0b8 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add path property to VLCInputItem
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
c293bd9f by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add menu controller to VLCMediaSourceCollectionViewItem
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
61d1019f by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Differentiate between local and remote inputItems in VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
b6ff85a8 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add mediaSourceInputItemAtRow method to VLCMediaSourceDataSource
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
54b7fc5b by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add and use new mediaSourceInputNodeAtRow internal method in VLCmediaSourceDataSource to eliminate duplication
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
45f3d56c by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Make library/input item properties strong as this led to null item objects when menu controller used in table views
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
60186f48 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Add support for VLCMediaSourceDataSource in VLCLibraryTableView
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
e7646b43 by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Make the media source table view in VLCLibraryWindow XIB use VLCLibraryTableView as its customclass
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
49a0bccf by Claudio Cambra at 2023-01-08T10:29:36+00:00
macosx: Ensure correct menu items are shown and hidden depending on represented item for VLCLibraryMenuController
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
9 changed files:
- modules/gui/macosx/UI/VLCLibraryWindow.xib
- modules/gui/macosx/library/VLCInputItem.h
- modules/gui/macosx/library/VLCInputItem.m
- modules/gui/macosx/library/VLCLibraryMenuController.h
- modules/gui/macosx/library/VLCLibraryMenuController.m
- modules/gui/macosx/library/VLCLibraryTableView.m
- modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m
- modules/gui/macosx/media-source/VLCMediaSourceDataSource.h
- modules/gui/macosx/media-source/VLCMediaSourceDataSource.m
Changes:
=====================================
modules/gui/macosx/UI/VLCLibraryWindow.xib
=====================================
@@ -955,7 +955,7 @@
<rect key="frame" x="0.0" y="0.0" width="528" height="371"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
- <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" viewBased="YES" id="vpJ-Oz-Ebz">
+ <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" viewBased="YES" id="vpJ-Oz-Ebz" customClass="VLCLibraryTableView">
<rect key="frame" x="0.0" y="0.0" width="528" height="371"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
=====================================
modules/gui/macosx/library/VLCInputItem.h
=====================================
@@ -43,6 +43,7 @@ extern NSString *VLCInputItemPreparsingSucceeded;
@property (readonly) struct input_item_t *vlcInputItem;
@property (readonly) NSString *MRL;
@property (readonly) NSString *decodedMRL;
+ at property (readonly) NSString *path;
@property (readwrite) NSString *name;
@property (readwrite) NSString *title;
@property (readwrite) NSString *artist;
=====================================
modules/gui/macosx/library/VLCInputItem.m
=====================================
@@ -450,6 +450,25 @@ static const struct input_preparser_callbacks_t preparseCallbacks = {
return nil;
}
+- (NSString*)path
+{
+ if (_vlcInputItem || (_vlcInputItem && _vlcInputItem->b_net)) {
+ char *psz_url = input_item_GetURI(_vlcInputItem);
+ if (!psz_url) {
+ return @"";
+ }
+
+ char *psz_path = vlc_uri2path(psz_url);
+ NSString *path = toNSStr(psz_path);
+ free(psz_url);
+ free(psz_path);
+
+ return path;
+ }
+
+ return @"";
+}
+
- (vlc_tick_t)duration
{
if (_vlcInputItem) {
=====================================
modules/gui/macosx/library/VLCLibraryMenuController.h
=====================================
@@ -24,14 +24,16 @@
NS_ASSUME_NONNULL_BEGIN
+ at class VLCInputItem;
@protocol VLCMediaLibraryItemProtocol;
@interface VLCLibraryMenuController : NSObject
@property (readonly) NSMenu *libraryMenu;
+ at property (readwrite, strong, nonatomic) id<VLCMediaLibraryItemProtocol> representedItem;
+ at property (readwrite, strong, nonatomic) VLCInputItem *representedInputItem;
- (void)popupMenuWithEvent:(NSEvent *)theEvent forView:(NSView *)theView;
-- (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)item;
@end
=====================================
modules/gui/macosx/library/VLCLibraryMenuController.m
=====================================
@@ -22,20 +22,28 @@
#import "VLCLibraryMenuController.h"
-#import "main/VLCMain.h"
+#import "extensions/NSMenu+VLCAdditions.h"
+#import "extensions/NSString+Helpers.h"
+
+#import "library/VLCInputItem.h"
#import "library/VLCLibraryController.h"
#import "library/VLCLibraryDataTypes.h"
#import "library/VLCLibraryInformationPanel.h"
-#import "extensions/NSString+Helpers.h"
-#import "extensions/NSMenu+VLCAdditions.h"
+#import "main/VLCMain.h"
+
+#import "playlist/VLCPlaylistController.h"
+
+#import <vlc_input.h>
+#import <vlc_url.h>
@interface VLCLibraryMenuController ()
{
VLCLibraryInformationPanel *_informationPanel;
- id<VLCMediaLibraryItemProtocol> _representedItem;
NSHashTable<NSMenuItem*> *_mediaItemRequiringMenuItems;
+ NSHashTable<NSMenuItem*> *_inputItemRequiringMenuItems;
+ NSHashTable<NSMenuItem*> *_localInputItemRequiringMenuItems;
}
@end
@@ -79,21 +87,35 @@
[_mediaItemRequiringMenuItems addObject:revealItem];
[_mediaItemRequiringMenuItems addObject:deleteItem];
[_mediaItemRequiringMenuItems addObject:informationItem];
+
+ _inputItemRequiringMenuItems = [NSHashTable weakObjectsHashTable];
+ [_inputItemRequiringMenuItems addObject:playItem];
+ [_inputItemRequiringMenuItems addObject:appendItem];
+
+ _localInputItemRequiringMenuItems = [NSHashTable weakObjectsHashTable];
+ [_localInputItemRequiringMenuItems addObject:revealItem];
+ [_localInputItemRequiringMenuItems addObject:deleteItem];
}
-- (void)setMediaItemRequiringMenuItemsHidden:(BOOL)hidden
+- (void)menuItems:(NSHashTable<NSMenuItem*>*)menuItems
+ setHidden:(BOOL)hidden
{
- for (NSMenuItem *menuItem in _mediaItemRequiringMenuItems) {
+ for (NSMenuItem *menuItem in menuItems) {
menuItem.hidden = hidden;
}
}
-- (void)updateLibraryMenuItems
+- (void)updateMenuItems
{
- if (_representedItem) {
- [self setMediaItemRequiringMenuItemsHidden:NO];
- } else {
- [self setMediaItemRequiringMenuItemsHidden:YES];
+ if (_representedItem != nil) {
+ [self menuItems:_inputItemRequiringMenuItems setHidden:YES];
+ [self menuItems:_localInputItemRequiringMenuItems setHidden:YES];
+ [self menuItems:_mediaItemRequiringMenuItems setHidden:NO];
+ } else if (_representedInputItem != nil) {
+ [self menuItems:_mediaItemRequiringMenuItems setHidden:YES];
+ [self menuItems:_inputItemRequiringMenuItems setHidden:NO];
+
+ [self menuItems:_localInputItemRequiringMenuItems setHidden:_representedInputItem.isStream];
}
}
@@ -105,16 +127,27 @@
#pragma mark - actions
- (void)addToPlaylist:(BOOL)playImmediately
{
- if(_representedItem == nil) {
- return;
+ if (_representedItem != nil) {
+ [self addMediaLibraryItemToPlaylist:_representedItem
+ playImmediately:playImmediately];
+ } else if (_representedInputItem != nil) {
+ [self addInputItemToPlaylist:_representedInputItem
+ playImmediately:playImmediately];
}
+}
+
+- (void)addMediaLibraryItemToPlaylist:(id<VLCMediaLibraryItemProtocol>)mediaLibraryItem
+ playImmediately:(BOOL)playImmediately
+{
+ NSParameterAssert(mediaLibraryItem);
// We want to add all the tracks to the playlist but only play the first one immediately,
// otherwise we will skip straight to the last track of the last album from the artist
__block BOOL beginPlayImmediately = playImmediately;
- [_representedItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* mediaItem) {
- [[[VLCMain sharedInstance] libraryController] appendItemToPlaylist:mediaItem playImmediately:beginPlayImmediately];
+ [mediaLibraryItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* childMediaItem) {
+ [VLCMain.sharedInstance.libraryController appendItemToPlaylist:childMediaItem
+ playImmediately:beginPlayImmediately];
if(beginPlayImmediately) {
beginPlayImmediately = NO;
@@ -122,6 +155,16 @@
}];
}
+- (void)addInputItemToPlaylist:(VLCInputItem*)inputItem
+ playImmediately:(BOOL)playImmediately
+{
+ NSParameterAssert(inputItem);
+ [VLCMain.sharedInstance.playlistController addInputItem:_representedInputItem.vlcInputItem
+ atPosition:-1
+ startPlayback:playImmediately];
+
+}
+
- (void)play:(id)sender
{
[self addToPlaylist:YES];
@@ -151,31 +194,76 @@
- (void)revealInFinder:(id)sender
{
- if(_representedItem == nil) {
- return;
+ if (_representedItem != nil) {
+ [self revealMediaLibraryItemInFinder:_representedItem];
+ } else if (_representedInputItem != nil && (!_representedInputItem.isStream)) {
+ [self revealInputItemInFinder:_representedInputItem];
}
+}
- VLCMediaLibraryMediaItem *firstMediaItem = _representedItem.firstMediaItem;
+- (void)revealMediaLibraryItemInFinder:(id<VLCMediaLibraryItemProtocol>)mediaLibraryItem
+{
+ NSParameterAssert(mediaLibraryItem);
+ VLCMediaLibraryMediaItem *firstMediaItem = mediaLibraryItem.firstMediaItem;
if(firstMediaItem) {
- [[[VLCMain sharedInstance] libraryController] showItemInFinder:firstMediaItem];
+ [VLCMain.sharedInstance.libraryController showItemInFinder:firstMediaItem];
}
}
-- (void)moveToTrash:(id)sender
+- (void)revealInputItemInFinder:(VLCInputItem*)inputItem
{
- if(_representedItem == nil) {
+ NSParameterAssert(inputItem);
+ NSAssert(!inputItem.isStream, @"Cannot reveal a stream input item in Finder");
+
+ NSString *path = inputItem.path;
+
+ if (!path || path.length == 0) {
return;
}
+ [NSWorkspace.sharedWorkspace selectFile:path inFileViewerRootedAtPath:path];
+}
+
+- (void)moveToTrash:(id)sender
+{
+ if (_representedItem != nil) {
+ [self moveMediaLibraryItemToTrash:_representedItem];
+ } else if (_representedInputItem != nil && (!_representedInputItem.isStream)) {
+ [self moveInputItemToTrash:_representedInputItem];
+ }
+}
+
+- (void)moveMediaLibraryItemToTrash:(id<VLCMediaLibraryItemProtocol>)mediaLibraryItem
+{
+ NSParameterAssert(mediaLibraryItem);
+
NSFileManager *fileManager = [NSFileManager defaultManager];
- [_representedItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* mediaItem) {
- for (VLCMediaLibraryFile *fileToTrash in mediaItem.files) {
- [fileManager trashItemAtURL:fileToTrash.fileURL resultingItemURL:nil error:nil];
+ [mediaLibraryItem iterateMediaItemsWithBlock:^(VLCMediaLibraryMediaItem* childMediaItem) {
+ for (VLCMediaLibraryFile *fileToTrash in childMediaItem.files) {
+ [fileManager trashItemAtURL:fileToTrash.fileURL
+ resultingItemURL:nil
+ error:nil];
}
}];
}
+- (void)moveInputItemToTrash:(VLCInputItem*)inputItem
+{
+ NSParameterAssert(inputItem);
+ NSAssert(!inputItem.isStream, @"Cannot move a stream input item to trash");
+
+ NSString *path = inputItem.path;
+
+ if (!path || path.length == 0) {
+ return;
+ }
+
+ [NSFileManager.defaultManager trashItemAtURL:[NSURL URLWithString:path]
+ resultingItemURL:nil
+ error:nil];
+}
+
- (void)showInformation:(id)sender
{
if (!_informationPanel) {
@@ -190,7 +278,15 @@
- (void)setRepresentedItem:(id<VLCMediaLibraryItemProtocol>)item
{
_representedItem = item;
- [self updateLibraryMenuItems];
+ _representedInputItem = nil;
+ [self updateMenuItems];
+}
+
+- (void)setRepresentedInputItem:(VLCInputItem *)representedInputItem
+{
+ _representedInputItem = representedInputItem;
+ _representedItem = nil;
+ [self updateMenuItems];
}
@end
=====================================
modules/gui/macosx/library/VLCLibraryTableView.m
=====================================
@@ -21,8 +21,9 @@
*****************************************************************************/
#import "VLCLibraryTableView.h"
-#import <library/VLCLibraryDataTypes.h>
+#import "library/VLCLibraryDataTypes.h"
#import "library/VLCLibraryMenuController.h"
+#import "media-source/VLCMediaSourceDataSource.h"
@interface VLCLibraryTableView ()
{
@@ -47,7 +48,8 @@
{
[super setDataSource:dataSource];
- if([self.dataSource conformsToProtocol:@protocol(VLCLibraryTableViewDataSource)]) {
+ if([self.dataSource conformsToProtocol:@protocol(VLCLibraryTableViewDataSource)] ||
+ self.dataSource.class == VLCMediaSourceDataSource.class) {
_vlcDataSourceConforming = YES;
[self setupMenu];
} else {
@@ -65,7 +67,17 @@
return;
}
- [_menuController setRepresentedItem:[(id<VLCLibraryTableViewDataSource>)self.dataSource libraryItemAtRow:self.clickedRow forTableView:self]];
+ if([self.dataSource conformsToProtocol:@protocol(VLCLibraryTableViewDataSource)]) {
+ id<VLCLibraryTableViewDataSource> vlcLibraryDataSource = (id<VLCLibraryTableViewDataSource>)self.dataSource;
+ id<VLCMediaLibraryItemProtocol> mediaLibraryItem = [vlcLibraryDataSource libraryItemAtRow:self.clickedRow
+ forTableView:self];
+ [_menuController setRepresentedItem:mediaLibraryItem];
+ } else if (self.dataSource.class == VLCMediaSourceDataSource.class) {
+ VLCMediaSourceDataSource *mediaSourceDataSource = (VLCMediaSourceDataSource*)self.dataSource;
+ NSAssert(mediaSourceDataSource != nil, @"This should be a valid pointer");
+ VLCInputItem *mediaSourceInputItem = [mediaSourceDataSource mediaSourceInputItemAtRow:self.clickedRow];
+ [_menuController setRepresentedInputItem:mediaSourceInputItem];
+ }
}
@end
=====================================
modules/gui/macosx/media-source/VLCMediaSourceCollectionViewItem.m
=====================================
@@ -23,17 +23,28 @@
#import "VLCMediaSourceCollectionViewItem.h"
#import "main/VLCMain.h"
-#import "views/VLCImageView.h"
-#import "views/VLCTrackingView.h"
+
#import "extensions/NSString+Helpers.h"
#import "extensions/NSFont+VLCAdditions.h"
#import "extensions/NSColor+VLCAdditions.h"
#import "extensions/NSView+VLCAdditions.h"
+
#import "library/VLCInputItem.h"
+#import "library/VLCLibraryMenuController.h"
+
#import "playlist/VLCPlaylistController.h"
+#import "views/VLCImageView.h"
+#import "views/VLCTrackingView.h"
+
NSString *VLCMediaSourceCellIdentifier = @"VLCLibraryCellIdentifier";
+ at interface VLCMediaSourceCollectionViewItem()
+{
+ VLCLibraryMenuController *_menuController;
+}
+ at end
+
@implementation VLCMediaSourceCollectionViewItem
- (instancetype)initWithNibName:(NSNibName)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
@@ -185,4 +196,30 @@ NSString *VLCMediaSourceCellIdentifier = @"VLCLibraryCellIdentifier";
[[[VLCMain sharedInstance] playlistController] addInputItem:_representedInputItem.vlcInputItem atPosition:-1 startPlayback:NO];
}
+-(void)mouseDown:(NSEvent *)theEvent
+{
+ if (theEvent.modifierFlags & NSControlKeyMask) {
+ if (!_menuController) {
+ _menuController = [[VLCLibraryMenuController alloc] init];
+ }
+
+ [_menuController setRepresentedInputItem:_representedInputItem];
+ [_menuController popupMenuWithEvent:theEvent forView:self.view];
+ }
+
+ [super mouseDown:theEvent];
+}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+ if (!_menuController) {
+ _menuController = [[VLCLibraryMenuController alloc] init];
+ }
+
+ [_menuController setRepresentedInputItem:_representedInputItem];
+ [_menuController popupMenuWithEvent:theEvent forView:self.view];
+
+ [super rightMouseDown:theEvent];
+}
+
@end
=====================================
modules/gui/macosx/media-source/VLCMediaSourceDataSource.h
=====================================
@@ -24,6 +24,7 @@
NS_ASSUME_NONNULL_BEGIN
+ at class VLCInputItem;
@class VLCInputNode;
@class VLCMediaSource;
@@ -37,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (readwrite) BOOL gridViewMode;
- (void)setupViews;
+- (VLCInputItem*)mediaSourceInputItemAtRow:(NSInteger)tableViewRow;
@end
=====================================
modules/gui/macosx/media-source/VLCMediaSourceDataSource.m
=====================================
@@ -120,12 +120,7 @@
cellView.identifier = @"VLCMediaSourceTableViewCellIdentifier";
}
- VLCInputNode *rootNode = _nodeToDisplay;
- NSArray *nodeChildren = rootNode.children;
- VLCInputNode *childNode = nodeChildren[row];
- VLCInputItem *childRootInput = childNode.inputItem;
- cellView.representedInputItem = childRootInput;
-
+ cellView.representedInputItem = [self mediaSourceInputItemAtRow:row];
return cellView;
}
@@ -135,10 +130,8 @@
if (selectedIndex < 0) {
return;
}
- VLCInputNode *rootNode = self.nodeToDisplay;
- NSArray *nodeChildren = rootNode.children;
- VLCInputNode *childNode = nodeChildren[selectedIndex];
+ VLCInputNode *childNode = [self mediaSourceInputNodeAtRow:selectedIndex];
[self performActionForNode:childNode allowPlayback:NO];
}
@@ -149,11 +142,35 @@
return;
}
- VLCInputNode *rootNode = self.nodeToDisplay;
+ VLCInputNode *childNode = [self mediaSourceInputNodeAtRow:selectedIndex];
+ [self performActionForNode:childNode allowPlayback:YES];
+}
+
+- (VLCInputNode*)mediaSourceInputNodeAtRow:(NSInteger)tableViewRow
+{
+ if (_nodeToDisplay == nil) {
+ return nil;
+ }
+
+ VLCInputNode *rootNode = _nodeToDisplay;
NSArray *nodeChildren = rootNode.children;
- VLCInputNode *childNode = nodeChildren[selectedIndex];
- [self performActionForNode:childNode allowPlayback:YES];
+ if (nodeChildren == nil || nodeChildren.count == 0) {
+ return nil;
+ }
+
+ return nodeChildren[tableViewRow];
+}
+
+- (VLCInputItem*)mediaSourceInputItemAtRow:(NSInteger)tableViewRow
+{
+ VLCInputNode *childNode = [self mediaSourceInputNodeAtRow:tableViewRow];
+
+ if (childNode == nil) {
+ return nil;
+ }
+
+ return childNode.inputItem;
}
#pragma mark - generic actions
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d78b14ed18177355e35459e6dd5ff5931f19097...49a0bccff70aabc7b2a06ca20388c8c7f01df31b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d78b14ed18177355e35459e6dd5ff5931f19097...49a0bccff70aabc7b2a06ca20388c8c7f01df31b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list