From c8f679027448bddfebcb7555a617f9b6662e5032 Mon Sep 17 00:00:00 2001 From: Kyle Neideck Date: Sun, 13 Nov 2016 00:06:58 +1100 Subject: [PATCH] Add a link to the about panel and refactor its code. Link to the project website (GitHub) in the About Background Music window, and move its code into its own class. Also, update the copyright notices in the UI and README. --- BGMApp/BGMApp.xcodeproj/project.pbxproj | 6 + BGMApp/BGMApp/Base.lproj/MainMenu.xib | 48 +++--- BGMApp/BGMApp/Info.plist | 2 +- BGMApp/BGMApp/Preferences/BGMAboutPanel.h | 43 ++++++ BGMApp/BGMApp/Preferences/BGMAboutPanel.m | 138 ++++++++++++++++++ .../BGMApp/Preferences/BGMPreferencesMenu.mm | 62 +------- README.md | 3 +- 7 files changed, 226 insertions(+), 76 deletions(-) create mode 100644 BGMApp/BGMApp/Preferences/BGMAboutPanel.h create mode 100644 BGMApp/BGMApp/Preferences/BGMAboutPanel.m diff --git a/BGMApp/BGMApp.xcodeproj/project.pbxproj b/BGMApp/BGMApp.xcodeproj/project.pbxproj index 76f43b2..a66937f 100644 --- a/BGMApp/BGMApp.xcodeproj/project.pbxproj +++ b/BGMApp/BGMApp.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 2795973B1C982E4E00A002FB /* BGMXPCListener.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2795973A1C982E4E00A002FB /* BGMXPCListener.mm */; }; 279F48771DD6D73A00768A85 /* BGMHermes.m in Sources */ = {isa = PBXBuildFile; fileRef = 279F48761DD6D73900768A85 /* BGMHermes.m */; }; 27C457E61CF2BC2600A6C9A6 /* BGMAutoPauseMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C457E51CF2BC2600A6C9A6 /* BGMAutoPauseMenuItem.m */; }; + 27D1D6BB1DD7226C0049E707 /* BGMAboutPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D1D6BA1DD7226C0049E707 /* BGMAboutPanel.m */; }; 27D643BE1C9FB84C00737F6E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 27D643BB1C9FB84C00737F6E /* Info.plist */; }; 27D643C01C9FB99200737F6E /* BGMXPCHelperService.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D643BA1C9FB84C00737F6E /* BGMXPCHelperService.m */; }; 27D643C11C9FB99200737F6E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D643BC1C9FB84C00737F6E /* main.m */; }; @@ -219,6 +220,8 @@ 279F48781DD6D94000768A85 /* Hermes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Hermes.h; path = "Music Players/Hermes.h"; sourceTree = ""; }; 27C457E41CF2BC2600A6C9A6 /* BGMAutoPauseMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BGMAutoPauseMenuItem.h; sourceTree = ""; }; 27C457E51CF2BC2600A6C9A6 /* BGMAutoPauseMenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BGMAutoPauseMenuItem.m; sourceTree = ""; }; + 27D1D6B91DD7226C0049E707 /* BGMAboutPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BGMAboutPanel.h; path = Preferences/BGMAboutPanel.h; sourceTree = ""; }; + 27D1D6BA1DD7226C0049E707 /* BGMAboutPanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BGMAboutPanel.m; path = Preferences/BGMAboutPanel.m; sourceTree = ""; }; 27D643B41C9FABBD00737F6E /* BGM_Types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BGM_Types.h; path = ../SharedSource/BGM_Types.h; sourceTree = ""; }; 27D643B51C9FABBD00737F6E /* BGMXPCProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BGMXPCProtocols.h; path = ../SharedSource/BGMXPCProtocols.h; sourceTree = ""; }; 27D643B91C9FB84C00737F6E /* BGMXPCHelperService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BGMXPCHelperService.h; path = BGMXPCHelper/BGMXPCHelperService.h; sourceTree = SOURCE_ROOT; }; @@ -280,6 +283,8 @@ children = ( 1C0BD0A61BF1B029004F4CF5 /* BGMPreferencesMenu.h */, 1C0BD0A71BF1B029004F4CF5 /* BGMPreferencesMenu.mm */, + 27D1D6B91DD7226C0049E707 /* BGMAboutPanel.h */, + 27D1D6BA1DD7226C0049E707 /* BGMAboutPanel.m */, 1C0BD0A31BF1A8E6004F4CF5 /* BGMAutoPauseMusicPrefs.h */, 1C0BD0A41BF1A8E6004F4CF5 /* BGMAutoPauseMusicPrefs.mm */, 1CE7064A1BF1EC0600BFC06D /* BGMOutputDevicePrefs.h */, @@ -758,6 +763,7 @@ 1CB8B33F1BBA75EF000E2DD1 /* main.m in Sources */, 1CB8B33D1BBA75EF000E2DD1 /* AppDelegate.mm in Sources */, 271677BA1C6CBDFA0080B0A2 /* CACFNumber.cpp in Sources */, + 27D1D6BB1DD7226C0049E707 /* BGMAboutPanel.m in Sources */, 27379B8A1C7C562D0084A24C /* BGMVLC.m in Sources */, 1C2336DF1BEAE10C004C1C4E /* BGMSpotify.m in Sources */, 1CED616C1C316E1A002CAFCF /* BGMAudioDeviceManager.mm in Sources */, diff --git a/BGMApp/BGMApp/Base.lproj/MainMenu.xib b/BGMApp/BGMApp/Base.lproj/MainMenu.xib index cc31e40..f7389e8 100644 --- a/BGMApp/BGMApp/Base.lproj/MainMenu.xib +++ b/BGMApp/BGMApp/Base.lproj/MainMenu.xib @@ -1,8 +1,9 @@ - + - + + @@ -88,14 +89,14 @@ - + - + - + @@ -104,7 +105,7 @@ - + @@ -113,7 +114,7 @@ - + @@ -122,20 +123,29 @@ - + - + - + + + + + + + + + + - + @@ -143,7 +153,7 @@ - + @@ -151,17 +161,17 @@ - + - - + + - + - + @@ -173,13 +183,13 @@ - + - + diff --git a/BGMApp/BGMApp/Info.plist b/BGMApp/BGMApp/Info.plist index d86ff96..d3e340c 100644 --- a/BGMApp/BGMApp/Info.plist +++ b/BGMApp/BGMApp/Info.plist @@ -29,7 +29,7 @@ LSUIElement NSHumanReadableCopyright - Copyright © 2016 Kyle Neideck + Copyright © 2016 Background Music contributors NSMainNibFile MainMenu NSPrincipalClass diff --git a/BGMApp/BGMApp/Preferences/BGMAboutPanel.h b/BGMApp/BGMApp/Preferences/BGMAboutPanel.h new file mode 100644 index 0000000..d7d8b21 --- /dev/null +++ b/BGMApp/BGMApp/Preferences/BGMAboutPanel.h @@ -0,0 +1,43 @@ +// This file is part of Background Music. +// +// Background Music 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. +// +// Background Music 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 Background Music. If not, see . + +// +// BGMAboutPanel.h +// BGMApp +// +// Copyright © 2016 Kyle Neideck +// +// This class manages the "About Background Music" window. +// + +// System Includes +#import + + +NS_ASSUME_NONNULL_BEGIN + +@interface BGMAboutPanel : NSObject + +- (instancetype)initWithPanel:(NSPanel*)inAboutPanel licenseView:(NSTextView*)inLicenseView; +- (void) show; + +@end + + +@interface BGMLinkField : NSTextField +@end + +NS_ASSUME_NONNULL_END + diff --git a/BGMApp/BGMApp/Preferences/BGMAboutPanel.m b/BGMApp/BGMApp/Preferences/BGMAboutPanel.m new file mode 100644 index 0000000..9befc76 --- /dev/null +++ b/BGMApp/BGMApp/Preferences/BGMAboutPanel.m @@ -0,0 +1,138 @@ +// This file is part of Background Music. +// +// Background Music 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. +// +// Background Music 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 Background Music. If not, see . + +// +// BGMAboutPanel.m +// BGMApp +// +// Copyright © 2016 Kyle Neideck +// + +// Self Include +#import "BGMAboutPanel.h" + +// PublicUtility Includes +#undef CoreAudio_ThreadStampMessages +#define CoreAudio_ThreadStampMessages 0 // Requires C++ +#include "CADebugMacros.h" + + +NS_ASSUME_NONNULL_BEGIN + +static NSInteger const kVersionLabelTag = 1; +static NSInteger const kCopyrightLabelTag = 2; +static NSInteger const kProjectWebsiteLabelTag = 3; + +@implementation BGMAboutPanel { + NSPanel* aboutPanel; + + NSTextField* versionLabel; + NSTextField* copyrightLabel; + NSTextField* websiteLabel; + + NSString* projectURL; + + NSTextView* licenseView; +} + +- (instancetype)initWithPanel:(NSPanel*)inAboutPanel licenseView:(NSTextView*)inLicenseView { + if ((self = [super init])) { + aboutPanel = inAboutPanel; + + versionLabel = [[aboutPanel contentView] viewWithTag:kVersionLabelTag]; + copyrightLabel = [[aboutPanel contentView] viewWithTag:kCopyrightLabelTag]; + websiteLabel = [[aboutPanel contentView] viewWithTag:kProjectWebsiteLabelTag]; + + projectURL = websiteLabel.stringValue; + + licenseView = inLicenseView; + + [self initAboutPanel]; + } + + return self; +} + +- (void) initAboutPanel { + // Set up the About Background Music window + + NSBundle* bundle = [NSBundle mainBundle]; + + if (bundle == nil) { + NSLog(@"Background Music: BGMAboutPanel::initAboutPanel: Could not find main bundle"); + } else { + // Version number label + NSString* __nullable version = + [[bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + + if (version) { + versionLabel.stringValue = [NSString stringWithFormat:@"Version %@", version]; + } + + // Copyright notice label + NSString* __nullable copyrightNotice = + [[bundle infoDictionary] objectForKey:@"NSHumanReadableCopyright"]; + + if (copyrightNotice) { + copyrightLabel.stringValue = (NSString*)copyrightNotice; + } + + // Project website link label + websiteLabel.selectable = YES; + websiteLabel.allowsEditingTextAttributes = YES; + websiteLabel.attributedStringValue = + [[NSAttributedString alloc] initWithString:projectURL + attributes:@{ NSLinkAttributeName: projectURL, + NSFontAttributeName: websiteLabel.font }]; + + // Load the text of the license into the text view + NSString* __nullable licensePath = [bundle pathForResource:@"LICENSE" ofType:nil]; + + NSError* err; + NSString* __nullable licenseStr = (!licensePath ? nil : + [NSString stringWithContentsOfFile:(NSString*)licensePath + encoding:NSASCIIStringEncoding + error:&err]); + + if (err || !licenseStr || [licenseStr isEqualToString:@""]) { + NSLog(@"Error loading license file: %@", err); + licenseStr = @"Error: could not open license file."; + } + + licenseView.string = licenseStr; + } +} + +- (void) show { + DebugMsg("BGMAboutPanel::showAboutPanel: Opening \"About Background Music\" panel"); + [NSApp activateIgnoringOtherApps:YES]; + [aboutPanel setIsVisible:YES]; + [aboutPanel makeKeyAndOrderFront:self]; +} + +@end + +@implementation BGMLinkField + +- (void) resetCursorRects { + // Change the mouse cursor when hovering over the link. (It does change by default, but only after + // you've clicked it once.) + [self addCursorRect:self.bounds cursor:[NSCursor pointingHandCursor]]; +} + +@end + +NS_ASSUME_NONNULL_END + diff --git a/BGMApp/BGMApp/Preferences/BGMPreferencesMenu.mm b/BGMApp/BGMApp/Preferences/BGMPreferencesMenu.mm index 1c3e1aa..e5f287b 100644 --- a/BGMApp/BGMApp/Preferences/BGMPreferencesMenu.mm +++ b/BGMApp/BGMApp/Preferences/BGMPreferencesMenu.mm @@ -26,6 +26,7 @@ // Local Includes #import "BGMAutoPauseMusicPrefs.h" #import "BGMOutputDevicePrefs.h" +#import "BGMAboutPanel.h" NS_ASSUME_NONNULL_BEGIN @@ -34,19 +35,13 @@ NS_ASSUME_NONNULL_BEGIN static NSInteger const kPreferencesMenuItemTag = 1; static NSInteger const kAboutPanelMenuItemTag = 3; -static NSInteger const kAboutPanelVersionLabelTag = 1; -static NSInteger const kAboutPanelCopyrightLabelTag = 2; - @implementation BGMPreferencesMenu { // Menu sections BGMAutoPauseMusicPrefs* autoPauseMusicPrefs; BGMOutputDevicePrefs* outputDevicePrefs; - // About Background Music window - NSPanel* aboutPanel; - NSTextField* aboutPanelVersionLabel; - NSTextField* aboutPanelCopyrightLabel; - NSTextView* aboutPanelLicenseView; + // The About Background Music window + BGMAboutPanel* aboutPanel; } - (id) initWithBGMMenu:(NSMenu*)inBGMMenu @@ -55,12 +50,6 @@ static NSInteger const kAboutPanelCopyrightLabelTag = 2; aboutPanel:(NSPanel*)inAboutPanel aboutPanelLicenseView:(NSTextView*)inAboutPanelLicenseView { if ((self = [super init])) { - aboutPanel = inAboutPanel; - - aboutPanelVersionLabel = [[aboutPanel contentView] viewWithTag:kAboutPanelVersionLabelTag]; - aboutPanelCopyrightLabel = [[aboutPanel contentView] viewWithTag:kAboutPanelCopyrightLabelTag]; - aboutPanelLicenseView = inAboutPanelLicenseView; - NSMenu* prefsMenu = [[inBGMMenu itemWithTag:kPreferencesMenuItemTag] submenu]; [prefsMenu setDelegate:self]; @@ -70,54 +59,17 @@ static NSInteger const kAboutPanelCopyrightLabelTag = 2; outputDevicePrefs = [[BGMOutputDevicePrefs alloc] initWithAudioDevices:inAudioDevices]; + aboutPanel = [[BGMAboutPanel alloc] initWithPanel:inAboutPanel licenseView:inAboutPanelLicenseView]; + // Set up the "About Background Music" menu item NSMenuItem* aboutMenuItem = [prefsMenu itemWithTag:kAboutPanelMenuItemTag]; - [aboutMenuItem setTarget:self]; - [aboutMenuItem setAction:@selector(showAboutPanel)]; - - [self initAboutPanel]; + [aboutMenuItem setTarget:aboutPanel]; + [aboutMenuItem setAction:@selector(show)]; } return self; } -- (void) initAboutPanel { - // Set up the About Background Music window - - NSBundle* bundle = [NSBundle mainBundle]; - - if (bundle == nil) { - LogWarning("Background Music: BGMPreferencesMenu::initAboutPanel: Could not find main bundle"); - } else { - // Version number label - NSString* version = [[bundle infoDictionary] objectForKey:@"CFBundleShortVersionString"]; - [aboutPanelVersionLabel setStringValue:[NSString stringWithFormat:@"Version %@", version]]; - - // Copyright notice label - NSString* copyrightNotice = [[bundle infoDictionary] objectForKey:@"NSHumanReadableCopyright"]; - [aboutPanelCopyrightLabel setStringValue:copyrightNotice]; - - // Load the text of the license into the text view - NSString* licensePath = [bundle pathForResource:@"LICENSE" ofType:nil]; - NSError* err; - NSString* licenseStr = [NSString stringWithContentsOfFile:licensePath encoding:NSASCIIStringEncoding error:&err]; - - if (err != nil || [licenseStr isEqualToString:@""]) { - NSLog(@"Error loading license file: %@", err); - licenseStr = @"Error: could not open license file."; - } - - [aboutPanelLicenseView setString:licenseStr]; - } -} - -- (void) showAboutPanel { - DebugMsg("BGMPreferencesMenu::showAboutPanel: Opening \"About Background Music\" panel"); - [NSApp activateIgnoringOtherApps:YES]; - [aboutPanel setIsVisible:YES]; - [aboutPanel makeKeyAndOrderFront:self]; -} - #pragma mark NSMenuDelegate - (void) menuNeedsUpdate:(NSMenu*)menu { diff --git a/README.md b/README.md index 5be0600..b518ecb 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,8 @@ change the default device and then change it back again. Failing that, you might ## License -GPLv2 or later +Copyright © 2016 [Background Music contributors](https://github.com/kyleneideck/BackgroundMusic/graphs/contributors). +Licensed under [GPLv2](https://www.gnu.org/licenses/gpl-2.0.html), or any later version. ----