Commit 157acdbe authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: simplify and style fixes for status bar menu

parent d276418d
/***************************************************************************** /*****************************************************************************
* VLCStatusBarIcon.h: Mac OS X module for vlc * VLCStatusBarIcon.h: Mac OS X module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2016 VLC authors and VideoLAN * Copyright (C) 2016 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Goran Dokic <vlc at 8hz dot com> * Authors: Goran Dokic <vlc at 8hz dot com>
...@@ -21,37 +21,25 @@ ...@@ -21,37 +21,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#import <cocoa/cocoa.h> #import <Cocoa/Cocoa.h>
@interface VLCStatusBarIcon : NSObject <NSMenuDelegate> @interface VLCStatusBarIcon : NSObject <NSMenuDelegate>
{
NSMenuItem *_vlcStatusBarMenuItem;
NSString *_nameToDisplay;
NSString *_timeToDisplay;
NSString *_durationToDisplay;
NSString *_urlToDisplay;
NSImage *_menuImagePlay;
NSImage *_menuImagePause;
NSImage *_menuImageStop;
}
@property NSStatusItem *statusItem; @property NSStatusItem *statusItem;
@property NSTimer *dataRefreshUpdateTimer; @property NSTimer *dataRefreshUpdateTimer;
@property (readwrite, strong) IBOutlet NSMenu *vlcStatusBarIconMenu; @property (readwrite, strong) IBOutlet NSMenu *vlcStatusBarIconMenu;
// get data from VLC and update the little status menu // get data from VLC and update the little status menu
- (void) updateMenuItemRandom; - (void)updateMenuItemRandom;
- (void) updateMenuItemPlayPause; - (void)updateMenuItemPlayPause;
- (void) setDataUpdateTimer:(float) interval; - (void)setDataUpdateTimer:(float)interval;
- (IBAction) updateMenuItemContent:(id)sender; - (IBAction)updateMenuItemContent:(id)sender;
- (IBAction) restoreMainWindow:(id)sender; - (IBAction)restoreMainWindow:(id)sender;
- (IBAction) statusBarIconTogglePlayPause:(id)sender; - (IBAction)statusBarIconTogglePlayPause:(id)sender;
- (IBAction) statusBarIconStop:(id)sender; - (IBAction)statusBarIconStop:(id)sender;
- (IBAction) statusBarIconNext:(id)sender; - (IBAction)statusBarIconNext:(id)sender;
- (IBAction) statusBarIconPrevious:(id)sender; - (IBAction)statusBarIconPrevious:(id)sender;
- (IBAction) statusBarIconToggleRandom:(id)sender; - (IBAction)statusBarIconToggleRandom:(id)sender;
@end @end
/***************************************************************************** /*****************************************************************************
* VLCStatusBarIcon.m: Mac OS X module for vlc * VLCStatusBarIcon.m: Mac OS X module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2016 VLC authors and VideoLAN * Copyright (C) 2016 VLC authors and VideoLAN
* $Id$ * $Id$
* *
* Authors: Goran Dokic <vlc at 8hz dot com> * Authors: Goran Dokic <vlc at 8hz dot com>
...@@ -42,57 +42,36 @@ ...@@ -42,57 +42,36 @@
#define NSInitialToolTipDelayIn_ms 20 #define NSInitialToolTipDelayIn_ms 20
// #define showURLInToolTip 1 // #define showURLInToolTip 1
@interface VLCStatusBarIcon ()
{
NSMenuItem *_vlcStatusBarMenuItem;
NSString *_nameToDisplay;
NSString *_timeToDisplay;
NSString *_durationToDisplay;
NSString *_urlToDisplay;
NSImage *_menuImagePlay;
NSImage *_menuImagePause;
NSImage *_menuImageStop;
}
@end
#pragma mark - #pragma mark -
#pragma mark Implementation #pragma mark Implementation
//-- @implementation VLCStatusBarIcon
@implementation VLCStatusBarIcon {
//
}
#pragma mark - #pragma mark -
#pragma mark Init #pragma mark Init
//-- - (void)dealloc
//
//
+(id)alloc
{
return [super alloc];
}
//--
//
//
- (id) init
{ {
self = [super init]; // cleanup
if (self) [self.dataRefreshUpdateTimer invalidate];
{ self.dataRefreshUpdateTimer = nil;
// Do some init if needed
}
return self;
} }
//-- - (void)awakeFromNib
// Cleanup on isle 6
//
- (void) dealloc
{
if (self)
{
// cleanup
[self.dataRefreshUpdateTimer invalidate];
}
// [super dealloc];
}
// fire it up
//
//
- (void) awakeFromNib
{ {
[super awakeFromNib]; [super awakeFromNib];
...@@ -162,11 +141,8 @@ ...@@ -162,11 +141,8 @@
// override class method. Called every time before menu is drawn. // override class method. Called every time before menu is drawn.
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{ {
SEL action = menuItem.action;
// disable the URL/Path options menu if there is no meaningful data // disable the URL/Path options menu if there is no meaningful data
if ((action == @selector(updateMenuItemContent:)) && (!_urlToDisplay)) if ((menuItem.action == @selector(updateMenuItemContent:)) && (!_urlToDisplay)) {
{
return NO; return NO;
} }
return YES; return YES;
...@@ -176,7 +152,7 @@ ...@@ -176,7 +152,7 @@
//--- //---
// callback for tooltip update timer // callback for tooltip update timer
// //
- (void) dataRefreshTimeHandler:(NSTimer *)timer - (void)dataRefreshTimeHandler:(NSTimer *)timer
{ {
[self gatherDataToDisplay]; [self gatherDataToDisplay];
[self updateToolTipText]; [self updateToolTipText];
...@@ -190,7 +166,7 @@ ...@@ -190,7 +166,7 @@
//--- //---
// enables menu icon/status item, sets proporties like image, attach menu // enables menu icon/status item, sets proporties like image, attach menu
// //
- (void) enableMenuIcon - (void)enableMenuIcon
{ {
_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; _statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[_statusItem setHighlightMode:YES]; [_statusItem setHighlightMode:YES];
...@@ -212,7 +188,7 @@ ...@@ -212,7 +188,7 @@
//--- //---
// Make sure data is fresh, before displaying // Make sure data is fresh, before displaying
// //
- (void) gatherDataToDisplay - (void)gatherDataToDisplay
{ {
mtime_t pos; mtime_t pos;
...@@ -223,14 +199,12 @@ ...@@ -223,14 +199,12 @@
// If status is 'stopped' there is no useful data // If status is 'stopped' there is no useful data
// Otherwise could have used 'if (_nameToDisplay == nil)' // Otherwise could have used 'if (_nameToDisplay == nil)'
if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) {
{
_urlToDisplay = nil; _urlToDisplay = nil;
} else { } else {
input_thread_t * p_input; input_thread_t * p_input;
p_input = pl_CurrentInput(getIntf()); p_input = pl_CurrentInput(getIntf());
if (p_input) if (p_input) {
{
pos = var_GetInteger(p_input, "time") / CLOCK_FREQ; pos = var_GetInteger(p_input, "time") / CLOCK_FREQ;
vlc_object_release(p_input); // must release or get segfault on quit vlc_object_release(p_input); // must release or get segfault on quit
} }
...@@ -251,21 +225,20 @@ ...@@ -251,21 +225,20 @@
//--- //---
// Call for periodic updates of tooltip text // Call for periodic updates of tooltip text
// //
- (void) updateToolTipText - (void)updateToolTipText
{ {
NSString *toolTipText = nil; NSString *toolTipText = nil;
// craft the multiline string, for the tooltip, depending on play status // craft the multiline string, for the tooltip, depending on play status
if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) {
{ // nothing playing
// nothing playing toolTipText = @"VLC media player\nNothing playing";
toolTipText = @"VLC media player\nNothing playing";
} else { } else {
#ifdef showURLInToolTip #ifdef showURLInToolTip
toolTipText = [NSString stringWithFormat:@"VLC media player\nName: %@\nDuration: %@\nTime: %@\nURL/Path: %@", _nameToDisplay, _durationToDisplay, _timeToDisplay, _urlToDisplay]; toolTipText = [NSString stringWithFormat:@"VLC media player\nName: %@\nDuration: %@\nTime: %@\nURL/Path: %@", _nameToDisplay, _durationToDisplay, _timeToDisplay, _urlToDisplay];
#else #else
toolTipText = [NSString stringWithFormat:@"VLC media player\nName: %@\nDuration: %@\nTime: %@", _nameToDisplay, _durationToDisplay, _timeToDisplay]; toolTipText = [NSString stringWithFormat:@"VLC media player\nName: %@\nDuration: %@\nTime: %@", _nameToDisplay, _durationToDisplay, _timeToDisplay];
#endif #endif
} }
...@@ -277,24 +250,22 @@ ...@@ -277,24 +250,22 @@
//--- //---
// Call for updating of dynamic menu item // Call for updating of dynamic menu item
// //
- (void) updateDynamicMenuItemText - (void)updateDynamicMenuItemText
{ {
NSString *menuString = nil; NSString *menuString = nil;
// create string for dynamic menu bit (sync?) // create string for dynamic menu bit (sync?)
if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) {
{ // put back our disabled menu item text.
// put back our disabled menu item text. menuString = @"URL/Path Options";
menuString = @"URL/Path Options";
} else { } else {
if ([_urlToDisplay hasPrefix:@"file://"]) if ([_urlToDisplay hasPrefix:@"file://"]) {
{ // offer to show 'file://' in finder
// offer to show 'file://' in finder menuString = [NSString stringWithFormat:@"Select File In Finder"];
menuString = [NSString stringWithFormat:@"Select File In Finder"]; } else {
} else { // offer to copy URL to clipboard
// offer to copy URL to clipboard menuString = [NSString stringWithFormat:@"Copy URL to clipboard"];
menuString = [NSString stringWithFormat:@"Copy URL to clipboard"]; }
}
} }
[_vlcStatusBarMenuItem setTitle:menuString]; [_vlcStatusBarMenuItem setTitle:menuString];
...@@ -304,20 +275,20 @@ ...@@ -304,20 +275,20 @@
//--- //---
// set timer for tooltips updates and flee // set timer for tooltips updates and flee
// //
- (void) setDataUpdateTimer:(float) interval - (void)setDataUpdateTimer:(float)interval
{ {
self.dataRefreshUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:interval self.dataRefreshUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:interval
target:self target:self
selector:@selector(dataRefreshTimeHandler:) selector:@selector(dataRefreshTimeHandler:)
userInfo:nil userInfo:nil
repeats:YES]; repeats:YES];
} }
//--- //---
// //
// //
- (void) updateMenuItemRandom - (void)updateMenuItemRandom
{ {
// get current random status // get current random status
bool b_value; bool b_value;
...@@ -326,8 +297,7 @@ ...@@ -326,8 +297,7 @@
// get menuitem 'Random' // get menuitem 'Random'
NSMenuItem* menuItemToChange = [_vlcStatusBarIconMenu itemWithTag:randomMenuItemTag]; NSMenuItem* menuItemToChange = [_vlcStatusBarIconMenu itemWithTag:randomMenuItemTag];
if (b_value) if (b_value) {
{
[menuItemToChange setState:NSOnState]; [menuItemToChange setState:NSOnState];
} else { } else {
[menuItemToChange setState:NSOffState]; [menuItemToChange setState:NSOffState];
...@@ -338,12 +308,11 @@ ...@@ -338,12 +308,11 @@
//--- //---
// //
// //
- (void) updateMenuItemPlayPause - (void)updateMenuItemPlayPause
{ {
NSMenuItem* menuItemToChange = [_vlcStatusBarIconMenu itemWithTag:playPauseMenuItemTag]; NSMenuItem* menuItemToChange = [_vlcStatusBarIconMenu itemWithTag:playPauseMenuItemTag];
if ([self vlcPlayingStatus] == PLAYLIST_RUNNING) if ([self vlcPlayingStatus] == PLAYLIST_RUNNING) {
{
[menuItemToChange setTitle:@"Pause"]; [menuItemToChange setTitle:@"Pause"];
[menuItemToChange setImage:_menuImagePause]; [menuItemToChange setImage:_menuImagePause];
} else { } else {
...@@ -359,7 +328,7 @@ ...@@ -359,7 +328,7 @@
//--- //---
// Returns VLC playlist status // Returns VLC playlist status
// Check for: constants PLAYLIST_RUNNING, PLAYLIST_STOPPED, PLAYLIST_PAUSED. // Check for: constants PLAYLIST_RUNNING, PLAYLIST_STOPPED, PLAYLIST_PAUSED.
- (int) vlcPlayingStatus - (int)vlcPlayingStatus
{ {
int res; int res;
// get the playlist 'playing' status // get the playlist 'playing' status
...@@ -376,7 +345,7 @@ ...@@ -376,7 +345,7 @@
//--- //---
// Returns true if playing, false in all other cases. // Returns true if playing, false in all other cases.
// //
- (BOOL) isVLCPlaying - (BOOL)isVLCPlaying
{ {
bool vlcPlaying = false; bool vlcPlaying = false;
...@@ -384,15 +353,8 @@ ...@@ -384,15 +353,8 @@
playlist_t *p_playlist = pl_Get(getIntf()); playlist_t *p_playlist = pl_Get(getIntf());
PL_LOCK; PL_LOCK;
switch( playlist_Status( p_playlist ) ) if (playlist_Status( p_playlist ) == PLAYLIST_RUNNING) {
{ vlcPlaying = true;
case PLAYLIST_RUNNING:
vlcPlaying = true;
break;
case PLAYLIST_STOPPED:
case PLAYLIST_PAUSED:
default:
break;
} }
PL_UNLOCK; PL_UNLOCK;
...@@ -411,19 +373,16 @@ ...@@ -411,19 +373,16 @@
// Here we offer to copy the url to the clipboard or // Here we offer to copy the url to the clipboard or
// select/show a local file in the finder..(useful imo ;-) // select/show a local file in the finder..(useful imo ;-)
if ([self vlcPlayingStatus] == PLAYLIST_STOPPED) if ([self vlcPlayingStatus] != PLAYLIST_STOPPED) {
{ if ([_urlToDisplay hasPrefix:@"file://"]) {
// Don't do anything, as the 'URL/path' is emtpy
} else {
if ([_urlToDisplay hasPrefix:@"file://"])
{
// show local file in finder // show local file in finder
NSString *path=[_urlToDisplay substringFromIndex:7]; NSString *path=[_urlToDisplay substringFromIndex:7];
[[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:path]; [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:path];
} else { } else {
// copy remote URL to clipboard // copy remote URL to clipboard
[[NSPasteboard generalPasteboard] clearContents]; NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[[NSPasteboard generalPasteboard] setString:_urlToDisplay forType:NSStringPboardType]; [pasteboard clearContents];
[pasteboard setString:_urlToDisplay forType:NSStringPboardType];
} }
} }
} }
......
...@@ -96,8 +96,7 @@ int OpenIntf (vlc_object_t *p_this) ...@@ -96,8 +96,7 @@ int OpenIntf (vlc_object_t *p_this)
[NSBundle loadNibNamed:@"MainMenu" owner:[[VLCMain sharedInstance] mainMenu]]; [NSBundle loadNibNamed:@"MainMenu" owner:[[VLCMain sharedInstance] mainMenu]];
// if statusbar enabled in preferences // if statusbar enabled in preferences
if (config_GetInt(p_intf, "macosx-statusicon")) if (config_GetInt(p_intf, "macosx-statusicon")) {
{
[NSBundle loadNibNamed:@"VLCStatusBarIconMainMenu" owner:[[VLCMain sharedInstance] statusBarIcon]]; [NSBundle loadNibNamed:@"VLCStatusBarIconMainMenu" owner:[[VLCMain sharedInstance] statusBarIcon]];
} }
[[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:nil]; [[[VLCMain sharedInstance] mainWindow] makeKeyAndOrderFront:nil];
......
...@@ -489,7 +489,6 @@ static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_nam ...@@ -489,7 +489,6 @@ static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_nam
if (p_item->value.psz && !strcmp(p_item->value.psz, values[i])) if (p_item->value.psz && !strcmp(p_item->value.psz, values[i]))
[object selectItem: [object lastItem]]; [object selectItem: [object lastItem]];
} else { } else {
[[object menu] addItem: [NSMenuItem separatorItem]]; [[object menu] addItem: [NSMenuItem separatorItem]];
} }
......
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