Commit 5b6707ba authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/media-source: split data source to designated class

parent b22cc22b
......@@ -157,6 +157,7 @@
7DFBDCBB226CED6300B700A5 /* VLCMediaSourceProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCBA226CED6300B700A5 /* VLCMediaSourceProvider.m */; };
7DFBDCBE226CED7200B700A5 /* VLCMediaSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCBD226CED7200B700A5 /* VLCMediaSource.m */; };
7DFBDCC1226DC16200B700A5 /* VLCInputItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCC0226DC16200B700A5 /* VLCInputItem.m */; };
7DFBDCC4226E445500B700A5 /* VLCMediaSourceDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFBDCC3226E445500B700A5 /* VLCMediaSourceDataSource.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
......@@ -530,6 +531,8 @@
7DFBDCBD226CED7200B700A5 /* VLCMediaSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMediaSource.m; sourceTree = "<group>"; };
7DFBDCBF226DC16200B700A5 /* VLCInputItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCInputItem.h; sourceTree = "<group>"; };
7DFBDCC0226DC16200B700A5 /* VLCInputItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCInputItem.m; sourceTree = "<group>"; };
7DFBDCC2226E445500B700A5 /* VLCMediaSourceDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCMediaSourceDataSource.h; sourceTree = "<group>"; };
7DFBDCC3226E445500B700A5 /* VLCMediaSourceDataSource.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCMediaSourceDataSource.m; sourceTree = "<group>"; };
8E49720006417F6800370C9F /* VLCInformationWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCInformationWindowController.h; sourceTree = "<group>"; };
8E49720106417F6800370C9F /* VLCInformationWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCInformationWindowController.m; sourceTree = "<group>"; };
8E55FB7F0459B0FD00FB3317 /* VLCOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCOutput.h; sourceTree = "<group>"; };
......@@ -1318,6 +1321,8 @@
7DFBDCBA226CED6300B700A5 /* VLCMediaSourceProvider.m */,
7DFBDCBC226CED7200B700A5 /* VLCMediaSource.h */,
7DFBDCBD226CED7200B700A5 /* VLCMediaSource.m */,
7DFBDCC2226E445500B700A5 /* VLCMediaSourceDataSource.h */,
7DFBDCC3226E445500B700A5 /* VLCMediaSourceDataSource.m */,
);
path = "media-source";
sourceTree = "<group>";
......@@ -1642,6 +1647,7 @@
1C3113D71E508C6900D4DD76 /* VLCPopupPanelController.m in Sources */,
7D445D8B22032B9200263D34 /* VLCPlaylistTableView.m in Sources */,
1C3113D91E508C6900D4DD76 /* VLCSimplePrefsController.m in Sources */,
7DFBDCC4226E445500B700A5 /* VLCMediaSourceDataSource.m in Sources */,
6B2EFC601F2819F700F3C0EA /* VLCVolumeSlider.m in Sources */,
7D2E0EDB20CD204D0033A221 /* VLCWindow.m in Sources */,
6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */,
......
......@@ -69,6 +69,12 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/main/VLCMain.h \
gui/macosx/main/VLCMain.m \
gui/macosx/main/macosx.m \
gui/macosx/media-source/VLCMediaSource.h \
gui/macosx/media-source/VLCMediaSource.m \
gui/macosx/media-source/VLCMediaSourceDataSource.h \
gui/macosx/media-source/VLCMediaSourceDataSource.m \
gui/macosx/media-source/VLCMediaSourceProvider.h \
gui/macosx/media-source/VLCMediaSourceProvider.m \
gui/macosx/menus/VLCMainMenu.h \
gui/macosx/menus/VLCMainMenu.m \
gui/macosx/menus/VLCStatusBarIcon.h \
......@@ -139,10 +145,6 @@ libmacosx_plugin_la_SOURCES = \
gui/macosx/preferences/prefs.m \
gui/macosx/preferences/prefs_widgets.h \
gui/macosx/preferences/prefs_widgets.m \
gui/macosx/media-source/VLCMediaSource.h \
gui/macosx/media-source/VLCMediaSource.m \
gui/macosx/media-source/VLCMediaSourceProvider.h \
gui/macosx/media-source/VLCMediaSourceProvider.m \
gui/macosx/views/VLCBottomBarView.h \
gui/macosx/views/VLCBottomBarView.m \
gui/macosx/views/VLCDefaultValueSlider.h \
......
......@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@class VLCLibraryModel;
@interface VLCLibraryDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate, NSTableViewDataSource, NSTableViewDelegate>
@interface VLCLibraryDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate>
@property (readwrite, assign) VLCLibraryModel *libraryModel;
......
......@@ -22,72 +22,15 @@
#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";
@interface VLCLibraryDataSource ()
{
NSArray *_mediaDiscovery;
}
@end
#import "extensions/NSString+Helpers.h"
@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
{
......@@ -148,66 +91,4 @@ static NSString *VLCMediaSourceCellIdentifier = @"VLCMediaSourceCellIdentifier";
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
......@@ -34,6 +34,8 @@
#import "library/VLCLibraryModel.h"
#import "library/VLCLibraryMenuController.h"
#import "media-source/VLCMediaSourceDataSource.h"
#import "windows/mainwindow/VLCControlsBarCommon.h"
#import "windows/video/VLCFSPanelController.h"
#import "windows/video/VLCVoutView.h"
......@@ -46,6 +48,7 @@ static const float f_playlist_row_height = 72.;
{
VLCPlaylistDataSource *_playlistDataSource;
VLCLibraryDataSource *_libraryDataSource;
VLCMediaSourceDataSource *_mediaSourceDataSource;
NSRect _windowFrameBeforePlayback;
......@@ -101,8 +104,9 @@ static const float f_playlist_row_height = 72.;
_libraryCollectionView.delegate = _libraryDataSource;
[_libraryCollectionView registerClass:[VLCLibraryCollectionViewItem class] forItemWithIdentifier:VLCLibraryCellIdentifier];
_mediaSourceTableView.dataSource = _libraryDataSource;
_mediaSourceTableView.delegate = _libraryDataSource;
_mediaSourceDataSource = [[VLCMediaSourceDataSource alloc] init];
_mediaSourceTableView.dataSource = _mediaSourceDataSource;
_mediaSourceTableView.delegate = _mediaSourceDataSource;
_mediaSourceTableView.rowHeight = f_playlist_row_height;
[self segmentedControlAction:nil];
......
/*****************************************************************************
* VLCMediaSourceDataSource.h: MacOS X interface module
*****************************************************************************
* Copyright (C) 2019 VLC authors and VideoLAN
*
* Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@interface VLCMediaSourceDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate>
@end
NS_ASSUME_NONNULL_END
/*****************************************************************************
* VLCMediaSourceDataSource.m: MacOS X interface module
*****************************************************************************
* Copyright (C) 2019 VLC authors and VideoLAN
*
* Authors: Felix Paul Kühne <fkuehne # videolan -dot- org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "VLCMediaSourceDataSource.h"
#import "media-source/VLCMediaSourceProvider.h"
#import "media-source/VLCMediaSource.h"
#import "playlist/VLCPlaylistTableCellView.h"
#import "main/VLCMain.h"
#import "library/VLCInputItem.h"
#import "extensions/NSString+Helpers.h"
static NSString *VLCMediaSourceCellIdentifier = @"VLCMediaSourceCellIdentifier";
@interface VLCMediaSourceDataSource ()
{
NSArray *_mediaDiscovery;
}
@end
@implementation VLCMediaSourceDataSource
- (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)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
......@@ -487,6 +487,12 @@ modules/gui/macosx/main/VLCMain+OldPrefs.m
modules/gui/macosx/main/VLCMain.h
modules/gui/macosx/main/VLCMain.m
modules/gui/macosx/main/macosx.m
modules/gui/macosx/media-source/VLCMediaSource.h
modules/gui/macosx/media-source/VLCMediaSource.m
modules/gui/macosx/media-source/VLCMediaSourceDataSource.h
modules/gui/macosx/media-source/VLCMediaSourceDataSource.m
modules/gui/macosx/media-source/VLCMediaSourceProvider.h
modules/gui/macosx/media-source/VLCMediaSourceProvider.m
modules/gui/macosx/menus/VLCMainMenu.h
modules/gui/macosx/menus/VLCMainMenu.m
modules/gui/macosx/menus/VLCStatusBarIcon.h
......@@ -555,10 +561,6 @@ modules/gui/macosx/preferences/prefs.h
modules/gui/macosx/preferences/prefs.m
modules/gui/macosx/preferences/prefs_widgets.h
modules/gui/macosx/preferences/prefs_widgets.m
modules/gui/macosx/media-source/VLCMediaSource.h
modules/gui/macosx/media-source/VLCMediaSource.m
modules/gui/macosx/media-source/VLCMediaSourceProvider.h
modules/gui/macosx/media-source/VLCMediaSourceProvider.m
modules/gui/macosx/views/VLCBottomBarView.h
modules/gui/macosx/views/VLCBottomBarView.m
modules/gui/macosx/views/VLCDefaultValueSlider.h
......
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