[vlc-commits] macosx/library: add basic SD representation
Felix Paul Kühne
git at videolan.org
Mon Apr 29 19:26:50 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Apr 22 14:11:24 2019 +0200| [c50c777dadcbbee0068f37ef6eb249d2ed871c21] | committer: Felix Paul Kühne
macosx/library: add basic SD representation
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c50c777dadcbbee0068f37ef6eb249d2ed871c21
---
modules/gui/macosx/UI/VLCLibraryWindow.xib | 79 +++++++++++++--
modules/gui/macosx/library/VLCLibraryDataSource.h | 2 +-
modules/gui/macosx/library/VLCLibraryDataSource.m | 118 ++++++++++++++++++++++
modules/gui/macosx/library/VLCLibraryWindow.h | 4 +-
modules/gui/macosx/library/VLCLibraryWindow.m | 14 ++-
5 files changed, 205 insertions(+), 12 deletions(-)
diff --git a/modules/gui/macosx/UI/VLCLibraryWindow.xib b/modules/gui/macosx/UI/VLCLibraryWindow.xib
index 005b6cd1ec..4308834f0f 100644
--- a/modules/gui/macosx/UI/VLCLibraryWindow.xib
+++ b/modules/gui/macosx/UI/VLCLibraryWindow.xib
@@ -69,12 +69,75 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
+ <scrollView borderType="groove" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="StN-Jd-vFI">
+ <rect key="frame" x="0.0" y="0.0" width="242" height="291"/>
+ <clipView key="contentView" id="bCd-C3-hHf">
+ <rect key="frame" x="2" y="2" width="238" height="287"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" id="jpB-GR-lUa">
+ <rect key="frame" x="0.0" y="0.0" width="238" height="287"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <size key="intercellSpacing" width="3" height="2"/>
+ <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
+ <color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
+ <tableColumns>
+ <tableColumn width="235" minWidth="40" maxWidth="1000" id="J5a-b7-jfY">
+ <tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
+ <font key="font" metaFont="smallSystem"/>
+ <color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
+ </tableHeaderCell>
+ <textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" title="Text Cell" id="ecA-vR-33j">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
+ <prototypeCellViews>
+ <tableCellView id="SJC-NO-4mY">
+ <rect key="frame" x="1" y="1" width="235" height="17"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xoJ-y7-ayy">
+ <rect key="frame" x="0.0" y="0.0" width="235" height="17"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="qc9-Zy-xBC">
+ <font key="font" metaFont="system"/>
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ </subviews>
+ <connections>
+ <outlet property="textField" destination="xoJ-y7-ayy" id="Vbb-iK-ddd"/>
+ </connections>
+ </tableCellView>
+ </prototypeCellViews>
+ </tableColumn>
+ </tableColumns>
+ </tableView>
+ </subviews>
+ </clipView>
+ <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="iwL-84-2YW">
+ <rect key="frame" x="2" y="117" width="236" height="16"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </scroller>
+ <scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="H17-SV-gee">
+ <rect key="frame" x="224" y="17" width="15" height="102"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </scroller>
+ </scrollView>
</subviews>
<constraints>
+ <constraint firstAttribute="bottom" secondItem="StN-Jd-vFI" secondAttribute="bottom" id="EVe-lP-xOg"/>
<constraint firstItem="nXS-11-7iK" firstAttribute="leading" secondItem="iSp-bV-w6B" secondAttribute="leading" id="SPv-yC-58y"/>
<constraint firstItem="nXS-11-7iK" firstAttribute="top" secondItem="iSp-bV-w6B" secondAttribute="top" id="Sje-VZ-Kcw"/>
<constraint firstAttribute="trailing" secondItem="nXS-11-7iK" secondAttribute="trailing" id="Tuh-vj-qaU"/>
+ <constraint firstAttribute="trailing" secondItem="StN-Jd-vFI" secondAttribute="trailing" id="aBt-Lo-Cvu"/>
+ <constraint firstItem="StN-Jd-vFI" firstAttribute="leading" secondItem="iSp-bV-w6B" secondAttribute="leading" id="bGP-Wn-WoI"/>
<constraint firstAttribute="bottom" secondItem="nXS-11-7iK" secondAttribute="bottom" id="piy-A4-FaO"/>
+ <constraint firstItem="StN-Jd-vFI" firstAttribute="top" secondItem="iSp-bV-w6B" secondAttribute="top" id="y5h-3Q-xb5"/>
</constraints>
</customView>
<customView id="dus-WQ-AmE">
@@ -107,26 +170,22 @@
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
- <tableCellView id="gVL-bx-hRL">
+ <tableCellView id="3Pj-5C-4K4">
<rect key="frame" x="1" y="1" width="234" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
- <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="hYg-bX-voP">
+ <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dY4-Im-HRr">
<rect key="frame" x="0.0" y="0.0" width="234" height="17"/>
- <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="vBe-8X-jwD">
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="vlq-wz-y8v">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
- <constraints>
- <constraint firstItem="hYg-bX-voP" firstAttribute="centerX" secondItem="gVL-bx-hRL" secondAttribute="centerX" id="VEv-n0-OZf"/>
- <constraint firstItem="hYg-bX-voP" firstAttribute="centerY" secondItem="gVL-bx-hRL" secondAttribute="centerY" id="aXu-4w-Vvk"/>
- <constraint firstItem="hYg-bX-voP" firstAttribute="leading" secondItem="gVL-bx-hRL" secondAttribute="leading" constant="2" id="xcX-Wj-7dq"/>
- </constraints>
<connections>
- <outlet property="textField" destination="hYg-bX-voP" id="i9z-OF-vvT"/>
+ <outlet property="textField" destination="dY4-Im-HRr" id="KWv-rt-UK7"/>
</connections>
</tableCellView>
</prototypeCellViews>
@@ -300,6 +359,8 @@
</view>
<connections>
<outlet property="libraryCollectionView" destination="B8x-e8-7zp" id="djF-Lw-nXT"/>
+ <outlet property="mediaSourceScrollView" destination="StN-Jd-vFI" id="i2e-GX-VfP"/>
+ <outlet property="mediaSourceTableView" destination="jpB-GR-lUa" id="NQ0-0c-wdU"/>
<outlet property="playlistTableView" destination="Fr1-af-8gb" id="yaB-Ab-jrx"/>
<outlet property="segmentedTitleControl" destination="W1M-0o-qYG" id="Gw1-T6-78k"/>
<outlet property="videoView" destination="12s-0J-Uvj" id="zTg-s0-qZ5"/>
diff --git a/modules/gui/macosx/library/VLCLibraryDataSource.h b/modules/gui/macosx/library/VLCLibraryDataSource.h
index abb4daed9e..94d80c4cd6 100644
--- a/modules/gui/macosx/library/VLCLibraryDataSource.h
+++ b/modules/gui/macosx/library/VLCLibraryDataSource.h
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@class VLCLibraryModel;
- at interface VLCLibraryDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate>
+ at interface VLCLibraryDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate, NSTableViewDataSource, NSTableViewDelegate>
@property (readwrite, assign) VLCLibraryModel *libraryModel;
diff --git a/modules/gui/macosx/library/VLCLibraryDataSource.m b/modules/gui/macosx/library/VLCLibraryDataSource.m
index 443d7dbdbf..b64a974ae4 100644
--- a/modules/gui/macosx/library/VLCLibraryDataSource.m
+++ b/modules/gui/macosx/library/VLCLibraryDataSource.m
@@ -22,16 +22,72 @@
#import "VLCLibraryDataSource.h"
+#import "main/VLCMain.h"
+
#import "library/VLCLibraryCollectionViewItem.h"
#import "library/VLCLibraryModel.h"
#import "library/VLCLibraryDataTypes.h"
+#import "library/VLCInputItem.h"
+
+#import "media-source/VLCMediaSourceProvider.h"
+#import "media-source/VLCMediaSource.h"
+#import "playlist/VLCPlaylistTableCellView.h"
#import "extensions/NSString+Helpers.h"
#import "views/VLCImageView.h"
+static NSString *VLCMediaSourceCellIdentifier = @"VLCMediaSourceCellIdentifier";
+
+ at interface VLCLibraryDataSource ()
+{
+ NSArray *_mediaDiscovery;
+}
+ at end
+
@implementation VLCLibraryDataSource
+- (instancetype)init
+{
+ self = [super init];
+ if (self) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self lazyLoadMediaSources];
+ });
+ }
+ return self;
+}
+
+- (void)lazyLoadMediaSources
+{
+ NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
+ NSArray *mediaDiscoveryForDevices = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_DEVICES];
+ if (mediaDiscoveryForDevices.count > 0) {
+ [mutableArray addObject:_NS("Devices")];
+ [mutableArray addObjectsFromArray:mediaDiscoveryForDevices];
+ }
+
+ NSArray *mediaDiscoveryForLAN = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_LAN];
+ if (mediaDiscoveryForLAN.count > 0) {
+ [mutableArray addObject:_NS("Local Network")];
+ [mutableArray addObjectsFromArray:mediaDiscoveryForLAN];
+ }
+
+ NSArray *mediaDiscoveryForInternet = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_INTERNET];
+ if (mediaDiscoveryForInternet.count > 0) {
+ [mutableArray addObject:_NS("Internet")];
+ [mutableArray addObjectsFromArray:mediaDiscoveryForInternet];
+ }
+
+ NSArray *mediaDiscoveryForMyComputer = [VLCMediaSourceProvider listOfMediaSourcesForCategory:SD_CAT_MYCOMPUTER];
+ if (mediaDiscoveryForMyComputer.count > 0) {
+ [mutableArray addObject:_NS("My Computer")];
+ [mutableArray addObjectsFromArray:mediaDiscoveryForMyComputer];
+ }
+
+ _mediaDiscovery = [mutableArray copy];
+}
+
- (NSInteger)collectionView:(NSCollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
@@ -92,4 +148,66 @@
NSLog(@"library selection changed: %@", indexPaths);
}
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
+{
+ return _mediaDiscovery.count;
+}
+
+- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
+{
+ VLCPlaylistTableCellView *cellView = [tableView makeViewWithIdentifier:VLCMediaSourceCellIdentifier owner:self];
+
+ if (cellView == nil) {
+ /* the following code saves us an instance of NSViewController which we don't need */
+ NSNib *nib = [[NSNib alloc] initWithNibNamed:@"VLCPlaylistTableCellView" bundle:nil];
+ NSArray *topLevelObjects;
+ if (![nib instantiateWithOwner:self topLevelObjects:&topLevelObjects]) {
+ msg_Err(getIntf(), "Failed to load nib file to show playlist items");
+ return nil;
+ }
+
+ for (id topLevelObject in topLevelObjects) {
+ if ([topLevelObject isKindOfClass:[VLCPlaylistTableCellView class]]) {
+ cellView = topLevelObject;
+ break;
+ }
+ }
+ cellView.identifier = VLCMediaSourceCellIdentifier;
+ }
+
+ if ([self tableView:tableView isGroupRow:row]) {
+ NSString *labelString = _mediaDiscovery[row];
+ cellView.mediaTitleTextField.hidden = NO;
+ cellView.secondaryMediaTitleTextField.hidden = YES;
+ cellView.artistTextField.hidden = YES;
+ cellView.mediaTitleTextField.stringValue = labelString;
+ cellView.durationTextField.stringValue = @"";
+ } else {
+ VLCMediaSource *mediaSource = _mediaDiscovery[row];
+
+ VLCInputItem *inputItem = mediaSource.rootNode.inputItem;
+ if (inputItem) {
+ cellView.mediaTitleTextField.hidden = YES;
+ cellView.secondaryMediaTitleTextField.hidden = NO;
+ cellView.artistTextField.hidden = NO;
+ cellView.secondaryMediaTitleTextField.stringValue = mediaSource.mediaSourceDescription;
+ cellView.artistTextField.stringValue = inputItem.name;
+ cellView.durationTextField.stringValue = [NSString stringWithTimeFromTicks:inputItem.duration];
+ } else {
+ cellView.mediaTitleTextField.hidden = NO;
+ cellView.secondaryMediaTitleTextField.hidden = YES;
+ cellView.artistTextField.hidden = YES;
+ cellView.mediaTitleTextField.stringValue = mediaSource.mediaSourceDescription;
+ cellView.durationTextField.stringValue = @"";
+ }
+ }
+
+ return cellView;
+}
+
+- (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row
+{
+ return [_mediaDiscovery[row] isKindOfClass:[NSString class]];
+}
+
@end
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.h b/modules/gui/macosx/library/VLCLibraryWindow.h
index e1497fcbd7..2f17befa2a 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.h
+++ b/modules/gui/macosx/library/VLCLibraryWindow.h
@@ -36,7 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface VLCLibraryWindow : VLCVideoWindowCommon
@property (readwrite, weak) IBOutlet NSSegmentedControl *segmentedTitleControl;
- at property (readwrite, weak) IBOutlet NSCollectionView *libraryCollectionView;
+ at property (readwrite, weak) IBOutlet VLCLibraryCollectionView *libraryCollectionView;
+ at property (readwrite, weak) IBOutlet NSTableView *mediaSourceTableView;
+ at property (readwrite, weak) IBOutlet NSScrollView *mediaSourceScrollView;
@property (readwrite, weak) IBOutlet NSTableView *playlistTableView;
@property (readonly) BOOL nativeFullscreenMode;
diff --git a/modules/gui/macosx/library/VLCLibraryWindow.m b/modules/gui/macosx/library/VLCLibraryWindow.m
index 394d29b882..5386214921 100644
--- a/modules/gui/macosx/library/VLCLibraryWindow.m
+++ b/modules/gui/macosx/library/VLCLibraryWindow.m
@@ -101,6 +101,10 @@ static const float f_playlist_row_height = 72.;
_libraryCollectionView.delegate = _libraryDataSource;
[_libraryCollectionView registerClass:[VLCLibraryCollectionViewItem class] forItemWithIdentifier:VLCLibraryCellIdentifier];
+ _mediaSourceTableView.dataSource = _libraryDataSource;
+ _mediaSourceTableView.delegate = _libraryDataSource;
+ _mediaSourceTableView.rowHeight = f_playlist_row_height;
+
[self segmentedControlAction:nil];
}
@@ -114,17 +118,25 @@ static const float f_playlist_row_height = 72.;
switch (_segmentedTitleControl.selectedSegment) {
case 0:
_libraryDataSource.libraryModel.libraryMode = VLCLibraryModeAudio;
+ _mediaSourceScrollView.hidden = YES;
+ _libraryCollectionView.hidden = NO;
+ [_libraryCollectionView reloadData];
break;
case 1:
_libraryDataSource.libraryModel.libraryMode = VLCLibraryModeVideo;
+ _mediaSourceScrollView.hidden = YES;
+ _libraryCollectionView.hidden = NO;
+ [_libraryCollectionView reloadData];
break;
default:
_libraryDataSource.libraryModel.libraryMode = VLCLibraryModeNetwork;
+ _mediaSourceScrollView.hidden = NO;
+ _libraryCollectionView.hidden = YES;
+ [_mediaSourceTableView reloadData];
break;
}
- [_libraryCollectionView reloadData];
}
- (void)playlistDoubleClickAction:(id)sender
More information about the vlc-commits
mailing list