[vlc-commits] macosx/library: allow playback of media

Felix Paul Kühne git at videolan.org
Mon Apr 29 19:26:57 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sat Apr 27 17:15:56 2019 +0200| [41ca75a09e4672a8de4d632d3c2739b0dd11ffe2] | committer: Felix Paul Kühne

macosx/library: allow playback of media

This can be done through preliminary buttons or the right-click menu

This commit also moves logic from the view to the controller (where it belongs).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=41ca75a09e4672a8de4d632d3c2739b0dd11ffe2
---

 .../gui/macosx/UI/VLCLibraryCollectionViewItem.xib | 26 +++++++++++++++++++
 .../macosx/library/VLCLibraryCollectionViewItem.h  |  5 ++++
 .../macosx/library/VLCLibraryCollectionViewItem.m  | 29 ++++++++++++++++++++++
 modules/gui/macosx/library/VLCLibraryController.h  |  3 +++
 modules/gui/macosx/library/VLCLibraryController.m  | 26 +++++++++++++++++++
 .../gui/macosx/library/VLCLibraryMenuController.m  | 26 ++++++++-----------
 6 files changed, 99 insertions(+), 16 deletions(-)

diff --git a/modules/gui/macosx/UI/VLCLibraryCollectionViewItem.xib b/modules/gui/macosx/UI/VLCLibraryCollectionViewItem.xib
index 25e6093550..1315f68822 100644
--- a/modules/gui/macosx/UI/VLCLibraryCollectionViewItem.xib
+++ b/modules/gui/macosx/UI/VLCLibraryCollectionViewItem.xib
@@ -7,9 +7,11 @@
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="VLCLibraryCollectionViewItem">
             <connections>
+                <outlet property="addToPlaylistButton" destination="Ubz-8I-W2F" id="k0q-b1-PZi"/>
                 <outlet property="durationTextField" destination="VAn-gF-QiZ" id="U8T-Cs-HaL"/>
                 <outlet property="mediaImageView" destination="2aB-sB-hfY" id="Sv0-G1-KNm"/>
                 <outlet property="mediaTitleTextField" destination="OBS-Eh-1mT" id="h1n-PU-IAx"/>
+                <outlet property="playInstantlyButton" destination="S3I-5Z-qgS" id="JlC-bE-i5Y"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
             </connections>
         </customObject>
@@ -42,15 +44,39 @@
                         <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                     </textFieldCell>
                 </textField>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ubz-8I-W2F">
+                    <rect key="frame" x="417" y="224" width="49" height="32"/>
+                    <buttonCell key="cell" type="push" title="+" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6ko-MM-ds0">
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                    <connections>
+                        <action selector="addToPlaylist:" target="-2" id="2C9-Rn-VAb"/>
+                    </connections>
+                </button>
+                <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="S3I-5Z-qgS">
+                    <rect key="frame" x="368" y="224" width="49" height="32"/>
+                    <buttonCell key="cell" type="push" title="P" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="IHP-p1-d0R">
+                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                    <connections>
+                        <action selector="playInstantly:" target="-2" id="E2B-oj-rx3"/>
+                    </connections>
+                </button>
             </subviews>
             <constraints>
                 <constraint firstItem="VAn-gF-QiZ" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="OBS-Eh-1mT" secondAttribute="trailing" constant="20" id="2di-oZ-tsC"/>
+                <constraint firstItem="Ubz-8I-W2F" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="8Qf-Un-Gdl"/>
                 <constraint firstAttribute="bottom" secondItem="2aB-sB-hfY" secondAttribute="bottom" id="C2H-Jc-A9V"/>
+                <constraint firstItem="Ubz-8I-W2F" firstAttribute="leading" secondItem="S3I-5Z-qgS" secondAttribute="trailing" constant="12" id="DZe-x4-j0v"/>
                 <constraint firstItem="A5y-ue-y7t" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="NpD-8l-D5s"/>
                 <constraint firstAttribute="trailing" secondItem="VAn-gF-QiZ" secondAttribute="trailing" constant="20" id="Ol6-wf-2dJ"/>
                 <constraint firstItem="2aB-sB-hfY" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="YP6-lv-ECe"/>
+                <constraint firstAttribute="trailing" secondItem="Ubz-8I-W2F" secondAttribute="trailing" constant="20" id="ZVz-SL-rxZ"/>
                 <constraint firstAttribute="bottom" secondItem="A5y-ue-y7t" secondAttribute="bottom" id="cnQ-bx-Fmn"/>
                 <constraint firstAttribute="bottom" secondItem="OBS-Eh-1mT" secondAttribute="bottom" constant="20" id="dy4-gP-Sdi"/>
+                <constraint firstItem="Ubz-8I-W2F" firstAttribute="centerY" secondItem="S3I-5Z-qgS" secondAttribute="centerY" id="fTo-dl-S2N"/>
                 <constraint firstAttribute="trailing" secondItem="2aB-sB-hfY" secondAttribute="trailing" id="oZw-Ab-83p"/>
                 <constraint firstAttribute="trailing" secondItem="A5y-ue-y7t" secondAttribute="trailing" id="rKQ-WW-oC6"/>
                 <constraint firstItem="2aB-sB-hfY" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="t9g-tX-AQX"/>
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.h b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
index 59274905a8..bf79d58055 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.h
@@ -33,6 +33,11 @@ extern NSString *VLCLibraryCellIdentifier;
 @property (readwrite, assign) IBOutlet NSTextField *mediaTitleTextField;
 @property (readwrite, assign) IBOutlet NSTextField *durationTextField;
 @property (readwrite, assign) IBOutlet VLCImageView *mediaImageView;
+ at property (readwrite, assign) IBOutlet NSButton *playInstantlyButton;
+ at property (readwrite, assign) IBOutlet NSButton *addToPlaylistButton;
+
+- (IBAction)playInstantly:(id)sender;
+- (IBAction)addToPlaylist:(id)sender;
 
 @end
 
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
index 82255b6e6d..1b100678ca 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
@@ -22,8 +22,37 @@
 
 #import "VLCLibraryCollectionViewItem.h"
 
+#import "main/VLCMain.h"
+#import "library/VLCLibraryController.h"
+
 NSString *VLCLibraryCellIdentifier = @"VLCLibraryCellIdentifier";
 
+ at interface VLCLibraryCollectionViewItem()
+{
+    VLCLibraryController *_libraryController;
+}
+ at end
+
 @implementation VLCLibraryCollectionViewItem
 
+- (IBAction)playInstantly:(id)sender
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    NSIndexPath *indexPath = [[self collectionView] indexPathForItem:self];
+    [_libraryController appendItemAtIndexPathToPlaylist:indexPath playImmediately:YES];
+}
+
+- (IBAction)addToPlaylist:(id)sender
+{
+    if (!_libraryController) {
+        _libraryController = [[VLCMain sharedInstance] libraryController];
+    }
+
+    NSIndexPath *indexPath = [[self collectionView] indexPathForItem:self];
+    [_libraryController appendItemAtIndexPathToPlaylist:indexPath playImmediately:NO];
+}
+
 @end
diff --git a/modules/gui/macosx/library/VLCLibraryController.h b/modules/gui/macosx/library/VLCLibraryController.h
index b5725e712c..ad2b45adfc 100644
--- a/modules/gui/macosx/library/VLCLibraryController.h
+++ b/modules/gui/macosx/library/VLCLibraryController.h
@@ -30,6 +30,9 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (readonly) VLCLibraryModel *libraryModel;
 
+- (void)appendItemAtIndexPathToPlaylist:(NSIndexPath *)indexPath playImmediately:(BOOL)playImmediately;
+- (void)showItemAtIndexPathInFinder:(NSIndexPath *)indexPath;
+
 @end
 
 NS_ASSUME_NONNULL_END
diff --git a/modules/gui/macosx/library/VLCLibraryController.m b/modules/gui/macosx/library/VLCLibraryController.m
index 837ef837f7..891c64257b 100644
--- a/modules/gui/macosx/library/VLCLibraryController.m
+++ b/modules/gui/macosx/library/VLCLibraryController.m
@@ -23,8 +23,10 @@
 #import "VLCLibraryController.h"
 
 #import "main/VLCMain.h"
+#import "playlist/VLCPlaylistController.h"
 #import "playlist/VLCPlayerController.h"
 #import "library/VLCLibraryModel.h"
+#import "library/VLCLibraryDataTypes.h"
 
 #import <vlc_media_library.h>
 
@@ -86,4 +88,28 @@
     }
 }
 
+- (void)appendItemAtIndexPathToPlaylist:(NSIndexPath *)indexPath playImmediately:(BOOL)playImmediately
+{
+    VLCMediaLibraryMediaItem *mediaItem = [self.libraryModel mediaItemAtIndexPath:indexPath];
+    input_item_t *p_inputItem = vlc_ml_get_input_item(_p_libraryInstance, mediaItem.libraryID);
+    [[[VLCMain sharedInstance] playlistController] addInputItem:p_inputItem atPosition:-1 startPlayback:playImmediately];
+    input_item_Release(p_inputItem);
+}
+
+- (void)showItemAtIndexPathInFinder:(NSIndexPath *)indexPath
+{
+    VLCMediaLibraryMediaItem *mediaItem = [self.libraryModel mediaItemAtIndexPath:indexPath];
+    if (mediaItem == nil) {
+        return;
+    }
+    VLCMediaLibraryFile *firstFile = mediaItem.files.firstObject;
+
+    if (firstFile) {
+        NSURL *URL = [NSURL URLWithString:firstFile.MRL];
+        if (URL) {
+            [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[URL]];
+        }
+    }
+}
+
 @end
diff --git a/modules/gui/macosx/library/VLCLibraryMenuController.m b/modules/gui/macosx/library/VLCLibraryMenuController.m
index 2d67aac5e7..3a944bbde4 100644
--- a/modules/gui/macosx/library/VLCLibraryMenuController.m
+++ b/modules/gui/macosx/library/VLCLibraryMenuController.m
@@ -24,8 +24,6 @@
 
 #import "main/VLCMain.h"
 #import "library/VLCLibraryController.h"
-#import "library/VLCLibraryModel.h"
-#import "library/VLCLibraryDataTypes.h"
 
 #import "extensions/NSString+Helpers.h"
 
@@ -45,10 +43,12 @@
         _libraryMenu = [[NSMenu alloc] initWithTitle:@""];
         [_libraryMenu addItemWithTitle:_NS("Play") action:@selector(play:) keyEquivalent:@""];
         [[_libraryMenu itemAtIndex:0] setTarget:self];
-        [_libraryMenu addItemWithTitle:_NS("Add Media...") action:@selector(addMedia:) keyEquivalent:@""];
+        [_libraryMenu addItemWithTitle:_NS("Append to Playlist") action:@selector(appendToPlaylist:) keyEquivalent:@""];
         [[_libraryMenu itemAtIndex:1] setTarget:self];
-        [_libraryMenu addItemWithTitle:_NS("Reveal in Finder") action:@selector(revealInFinder:) keyEquivalent:@""];
+        [_libraryMenu addItemWithTitle:_NS("Add Media...") action:@selector(addMedia:) keyEquivalent:@""];
         [[_libraryMenu itemAtIndex:2] setTarget:self];
+        [_libraryMenu addItemWithTitle:_NS("Reveal in Finder") action:@selector(revealInFinder:) keyEquivalent:@""];
+        [[_libraryMenu itemAtIndex:3] setTarget:self];
     }
     return self;
 }
@@ -64,7 +64,12 @@
 
 - (void)play:(id)sender
 {
+    [[[VLCMain sharedInstance] libraryController] appendItemAtIndexPathToPlaylist:_actionIndexPath playImmediately:YES];
+}
 
+- (void)appendToPlaylist:(id)sender
+{
+    [[[VLCMain sharedInstance] libraryController] appendItemAtIndexPathToPlaylist:_actionIndexPath playImmediately:NO];
 }
 
 - (void)addMedia:(id)sender
@@ -74,18 +79,7 @@
 
 - (void)revealInFinder:(id)sender
 {
-    VLCMediaLibraryMediaItem *mediaItem = [[[[VLCMain sharedInstance] libraryController] libraryModel] mediaItemAtIndexPath:_actionIndexPath];
-    if (mediaItem == nil) {
-        return;
-    }
-    VLCMediaLibraryFile *firstFile = mediaItem.files.firstObject;
-
-    if (firstFile) {
-        NSURL *URL = [NSURL URLWithString:firstFile.MRL];
-        if (URL) {
-            [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[URL]];
-        }
-    }
+    [[[VLCMain sharedInstance] libraryController] showItemAtIndexPathInFinder:_actionIndexPath];
 }
 
 @end



More information about the vlc-commits mailing list