Browse Source

macosx: Move shuffle and repeat button functionality from VLCControlsBarCommon to VLCMainWindowControlsBar

Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
pull/144/head
Claudio Cambra 4 years ago
committed by Jean-Baptiste Kempf
parent
commit
3eb2682c6d
  1. 2
      modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h
  2. 86
      modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m
  3. 3
      modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.h
  4. 98
      modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m

2
modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.h

@ -45,8 +45,6 @@
@property (readwrite, strong) IBOutlet NSButton *playButton;
@property (readwrite, strong) IBOutlet NSButton *backwardButton;
@property (readwrite, strong) IBOutlet NSButton *forwardButton;
@property (readwrite, strong) IBOutlet NSButton *repeatButton;
@property (readwrite, strong) IBOutlet NSButton *shuffleButton;
@property (readwrite, strong) IBOutlet VLCSlider *timeSlider;
@property (readwrite, strong) IBOutlet VLCVolumeSlider *volumeSlider;

86
modules/gui/macosx/windows/mainwindow/VLCControlsBarCommon.m

@ -24,7 +24,6 @@
#import "VLCControlsBarCommon.h"
#import "extensions/NSString+Helpers.h"
#import "extensions/NSColor+VLCAdditions.h"
#import "main/VLCMain.h"
#import "playlist/VLCPlaylistController.h"
#import "playlist/VLCPlayerController.h"
@ -51,11 +50,6 @@
NSImage *_pressedPauseImage;
NSImage *_playImage;
NSImage *_pressedPlayImage;
NSImage *_repeatOffImage;
NSImage *_repeatAllImage;
NSImage *_repeatOneImage;
NSImage *_shuffleOffImage;
NSImage *_shuffleOnImage;
NSTimeInterval last_fwd_event;
NSTimeInterval last_bwd_event;
@ -100,14 +94,6 @@
selector:@selector(fullscreenStateUpdated:)
name:VLCPlayerFullscreenChanged
object:nil];
[notificationCenter addObserver:self
selector:@selector(shuffleStateUpdated:)
name:VLCPlaybackOrderChanged
object:nil];
[notificationCenter addObserver:self
selector:@selector(repeatStateUpdated:)
name:VLCPlaybackRepeatChanged
object:nil];
_nativeFullscreenMode = var_InheritBool(getIntf(), "macosx-nativefullscreenmode");
@ -191,23 +177,11 @@
[self.forwardButton setAction:@selector(fwd:)];
[self.backwardButton setAction:@selector(bwd:)];
self.repeatButton.action = @selector(repeatAction:);
self.shuffleButton.action = @selector(shuffleAction:);
[self playerStateUpdated:nil];
[self repeatStateUpdated:nil];
[self shuffleStateUpdated:nil];
[_artworkImageView setCropsImagesToRoundedCorners:YES];
[_artworkImageView setImage:[NSImage imageNamed:@"noart"]];
[_artworkImageView setContentGravity:VLCImageViewContentGravityResize];
_repeatAllImage = [NSImage imageNamed:@"repeatAll"];
_repeatOffImage = [NSImage imageNamed:@"repeatOff"];
_repeatOneImage = [NSImage imageNamed:@"repeatOne"];
_shuffleOffImage = [NSImage imageNamed:@"shuffleOff"];
_shuffleOnImage = [NSImage imageNamed:@"shuffleOn"];
}
- (void)dealloc
@ -344,32 +318,6 @@
[_playerController toggleFullscreen];
}
- (IBAction)shuffleAction:(id)sender
{
if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL) {
_playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;
} else {
_playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
}
}
- (IBAction)repeatAction:(id)sender
{
enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat;
switch (currentRepeatState) {
case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
_playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
break;
case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
_playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
break;
default:
_playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
break;
}
}
#pragma mark -
#pragma mark Updaters
@ -451,40 +399,6 @@
}
}
- (void)repeatStateUpdated:(NSNotification *)aNotification
{
enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat;
switch (currentRepeatState) {
case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
self.repeatButton.image = _repeatOneImage;
break;
case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
self.repeatButton.image = _repeatAllImage;
break;
case VLC_PLAYLIST_PLAYBACK_REPEAT_NONE:
default:
self.repeatButton.image = _repeatOffImage;
break;
}
if (@available(macOS 11.0, *)) {
self.repeatButton.contentTintColor = currentRepeatState == VLC_PLAYLIST_PLAYBACK_REPEAT_NONE ?
nil : [NSColor VLCAccentColor];
}
}
- (void)shuffleStateUpdated:(NSNotification *)aNotification
{
self.shuffleButton.image = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ?
_shuffleOffImage : _shuffleOnImage;
if (@available(macOS 11.0, *)) {
self.shuffleButton.contentTintColor = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ?
nil : [NSColor VLCAccentColor];
}
}
- (void)updatePlaybackControls:(NSNotification *)aNotification
{
bool b_seekable = _playerController.seekable;

3
modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.h

@ -40,6 +40,9 @@
@property (readwrite, strong) IBOutlet NSButton *prevButton;
@property (readwrite, strong) IBOutlet NSButton *nextButton;
@property (readwrite, strong) IBOutlet NSButton *repeatButton;
@property (readwrite, strong) IBOutlet NSButton *shuffleButton;
@property (readwrite, strong) IBOutlet NSLayoutConstraint *artistNameTextFieldWidthConstraint;
@property (readwrite, strong) IBOutlet NSTextField *songArtistSeparatorTextField;

98
modules/gui/macosx/windows/mainwindow/VLCMainWindowControlsBar.m

@ -24,6 +24,7 @@
#import "VLCMainWindowControlsBar.h"
#import "VLCControlsBarCommon.h"
#import "extensions/NSColor+VLCAdditions.h"
#import "extensions/NSString+Helpers.h"
#import "library/VLCInputItem.h"
@ -46,6 +47,12 @@
@interface VLCMainWindowControlsBar()
{
NSImage *_repeatOffImage;
NSImage *_repeatAllImage;
NSImage *_repeatOneImage;
NSImage *_shuffleOffImage;
NSImage *_shuffleOnImage;
VLCPlaylistController *_playlistController;
VLCPlayerController *_playerController;
}
@ -60,8 +67,35 @@
_playerController = _playlistController.playerController;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(updatePlaybackControls:) name:VLCPlaylistCurrentItemChanged object:nil];
[notificationCenter addObserver:self selector:@selector(playbackStateChanged:) name:VLCPlayerStateChanged object:nil];
[notificationCenter addObserver:self
selector:@selector(updatePlaybackControls:)
name:VLCPlaylistCurrentItemChanged
object:nil];
[notificationCenter addObserver:self
selector:@selector(playbackStateChanged:)
name:VLCPlayerStateChanged
object:nil];
[notificationCenter addObserver:self
selector:@selector(shuffleStateUpdated:)
name:VLCPlaybackOrderChanged
object:nil];
[notificationCenter addObserver:self
selector:@selector(repeatStateUpdated:)
name:VLCPlaybackRepeatChanged
object:nil];
_repeatAllImage = [NSImage imageNamed:@"repeatAll"];
_repeatOffImage = [NSImage imageNamed:@"repeatOff"];
_repeatOneImage = [NSImage imageNamed:@"repeatOne"];
_shuffleOffImage = [NSImage imageNamed:@"shuffleOff"];
_shuffleOnImage = [NSImage imageNamed:@"shuffleOn"];
self.repeatButton.action = @selector(repeatAction:);
self.shuffleButton.action = @selector(shuffleAction:);
[self repeatStateUpdated:nil];
[self shuffleStateUpdated:nil];
[self.stopButton setToolTip: _NS("Stop")];
self.stopButton.accessibilityLabel = self.stopButton.toolTip;
@ -122,6 +156,32 @@
[[VLCMain sharedInstance].libraryWindow reopenVideoView];
}
- (IBAction)shuffleAction:(id)sender
{
if (_playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL) {
_playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;
} else {
_playlistController.playbackOrder = VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
}
}
- (IBAction)repeatAction:(id)sender
{
enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat;
switch (currentRepeatState) {
case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
_playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
break;
case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
_playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
break;
default:
_playlistController.playbackRepeat = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
break;
}
}
#pragma mark -
#pragma mark Extra updaters
@ -146,6 +206,40 @@
}
}
- (void)repeatStateUpdated:(NSNotification *)aNotification
{
enum vlc_playlist_playback_repeat currentRepeatState = _playlistController.playbackRepeat;
switch (currentRepeatState) {
case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
self.repeatButton.image = _repeatOneImage;
break;
case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
self.repeatButton.image = _repeatAllImage;
break;
case VLC_PLAYLIST_PLAYBACK_REPEAT_NONE:
default:
self.repeatButton.image = _repeatOffImage;
break;
}
if (@available(macOS 11.0, *)) {
self.repeatButton.contentTintColor = currentRepeatState == VLC_PLAYLIST_PLAYBACK_REPEAT_NONE ?
nil : [NSColor VLCAccentColor];
}
}
- (void)shuffleStateUpdated:(NSNotification *)aNotification
{
self.shuffleButton.image = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ?
_shuffleOffImage : _shuffleOnImage;
if (@available(macOS 11.0, *)) {
self.shuffleButton.contentTintColor = _playlistController.playbackOrder == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL ?
nil : [NSColor VLCAccentColor];
}
}
- (void)updatePlaybackControls:(NSNotification *)aNotification
{
bool b_seekable = _playerController.seekable;

Loading…
Cancel
Save