Skip to content

Commit

Permalink
Some updates, better preferences, mini controls.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruaridh Thomson committed Apr 4, 2011
1 parent f5ea476 commit 308db82
Show file tree
Hide file tree
Showing 22 changed files with 4,700 additions and 997 deletions.
Binary file added .DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

// Status menu stuff
NSStatusItem *statusItem;
NSStatusItem *playItem;
NSStatusItem *fwrdItem;
NSStatusItem *backItem;

IBOutlet NSView *statusView;
IBOutlet NSMenu *statusMenu;
Expand All @@ -51,6 +54,7 @@
KeyCombo sbGlobalHotkey;

IBOutlet NSButton *showDockIcon;
IBOutlet NSButton *showMenubarIcon;
IBOutlet NSButton *openAtLogin;
IBOutlet NSButton *showWelcomeWindow;
IBOutlet NSButton *openSpotifyOnLaunch;
Expand All @@ -61,6 +65,29 @@
IBOutlet NSButton *skipForwardButton;
IBOutlet NSButton *skipBackButton;

// Preferences Stuff
IBOutlet NSWindow *prefWindow;

NSView *currentView;
IBOutlet NSView *prefContentView;

IBOutlet NSView *generalView;
IBOutlet NSView *shortcutsView;
IBOutlet NSView *advancedView;
IBOutlet NSView *helpView;
IBOutlet NSView *aboutView;
IBOutlet NSView *simbleView;

IBOutlet NSToolbar *prefToolbar;
IBOutlet NSToolbarItem *generalToolbarItem;
IBOutlet NSToolbarItem *shortcutsToolbarItem;
IBOutlet NSToolbarItem *advancedToolbarItem;
IBOutlet NSToolbarItem *helpToolbarItem;
IBOutlet NSToolbarItem *aboutToolbarItem;
IBOutlet NSToolbarItem *simblToolbarItem;

IBOutlet NSPopUpButton *menubarIconStyle;

}

- (int)numberOfProcesses;
Expand All @@ -86,6 +113,12 @@
- (IBAction)openSpotifyPreferences:(id)sender;
- (IBAction)resetKeybinds:(id)sender;
- (IBAction)toggleOpenAtLogin:(id)sender;
- (IBAction)toggleMiniControls:(id)sender;
- (IBAction)switchMenubarIconStyle:(id)sender;

- (IBAction)openAboutWindow:(id)sender;
- (IBAction)switchPreferenceView:(id)sender;
- (void)loadView:(NSView *)theView;

- (IBAction)sendPlayPause:(id)sender;
- (IBAction)sendSkipForward:(id)sender;
Expand All @@ -95,7 +128,10 @@
- (IBAction)syncroniseUserDefaults:(id)sender;
- (IBAction)openURLLifeUpNorth:(id)sender;
- (IBAction)sendLUNemail:(id)sender;
- (IBAction)openUrlSimbl:(id)sender;
- (IBAction)openUrlLunPlugin:(id)sender;

- (void)setStatusItem;
- (void)addAppAsLoginItem;
- (void)deleteAppFromLoginItem;
- (IBAction)setApplicationIsAgent:(id)sender;
Expand Down
149 changes: 129 additions & 20 deletions AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,18 @@ - (id) init
queue = [[NSOperationQueue alloc] init];

spotifyChecker = [NSTimer scheduledTimerWithTimeInterval:10.0 target: self selector: @selector(checkIsSpotifyActive) userInfo:nil repeats:YES];

return self;
//[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showMenubarIcon"];

return self;
}

- (void)awakeFromNib
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"runAsUIAgent"]) {
// Create an NSStatusItem.
float width = 25.0;
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];
[statusItem setMenu:statusMenu];
[statusItem setImage:[NSImage imageNamed:@"statusOn.png"]];
[statusItem setAlternateImage:[NSImage imageNamed:@"statusHighlight.png"]];
[statusItem setHighlightMode:YES];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"showMenubarIcon"]) {
[self setStatusItem];
}

// Shortcut Recorders

[playPauseRecorder setCanCaptureGlobalHotKeys:YES];
[skipForwardRecorder setCanCaptureGlobalHotKeys:YES];
[skipBackRecorder setCanCaptureGlobalHotKeys:YES];
Expand Down Expand Up @@ -89,6 +83,12 @@ - (void)awakeFromNib
[[NSWorkspace sharedWorkspace] launchApplication:@"Spotify"];
}

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"showMiniControls"]) {
[self toggleMiniControls:nil];
}

// Setup the preferences window.
[self loadView:generalView];
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
Expand All @@ -115,11 +115,14 @@ - (NSOperationQueue *)operationQueue
- (void)checkIsSpotifyActive
{
if (![self isSpotifyActive]) {
[statusItem setImage:[NSImage imageNamed:@"statusOffGrey.png"]];
if ([[menubarIconStyle selectedItem] tag] == 1) {
[statusItem setImage:[NSImage imageNamed:@"statusOff.png"]];
} else {
[statusItem setImage:[NSImage imageNamed:@"statusOffGrey.png"]];
}
} else {
[statusItem setImage:[NSImage imageNamed:@"statusOn.png"]];
}

}

- (BOOL)isSpotifyActive
Expand All @@ -131,18 +134,62 @@ - (BOOL)isSpotifyActive
} else {
return YES;
}

}

#pragma mark -
#pragma mark IBActions

- (IBAction)switchMenubarIconStyle:(id)sender
{
[self checkIsSpotifyActive];
}

- (IBAction)switchPreferenceView:(id)sender
{
[prefToolbar setSelectedItemIdentifier:[sender itemIdentifier]];

if ([sender tag] == 0) {
[self loadView: generalView];
} else if ([sender tag] == 1) {
[self loadView: shortcutsView];
} else if ([sender tag] == 2) {
[self loadView: advancedView];
} else if ([sender tag] == 3) {
[self loadView: helpView];
} else if ([sender tag] == 4) {
[self loadView: aboutView];
} else if ([sender tag] == 5) {
[self loadView: simbleView];
}
}

- (void)loadView:(NSView *)theView
{
NSView *tempView = [[NSView alloc] initWithFrame: [[prefWindow contentView] frame]];
[prefWindow setContentView: tempView];
[tempView release];

NSRect newFrame = [prefWindow frame];
newFrame.size.height = [theView frame].size.height + ([prefWindow frame].size.height - [[prefWindow contentView] frame].size.height); // Compensates for toolbar
newFrame.size.width = [theView frame].size.width;
newFrame.origin.y += ([[prefWindow contentView] frame].size.height - [theView frame].size.height); // Origin moves by difference in two views
newFrame.origin.x += ([[prefWindow contentView] frame].size.width - newFrame.size.width)/2; // Origin moves by difference in two views, halved to keep center alignment

[prefWindow setFrame: newFrame display: YES animate: YES];
[prefWindow setContentView: theView];
}

- (IBAction)openAboutWindow:(id)sender
{
[self loadView:aboutView];
[self openPreferences:self];
}

- (IBAction)openPreferences:(id)sender
{
//[preferencesWindow makeKeyAndOrderFront:NULL];
[NSApp activateIgnoringOtherApps:YES];
[preferencesWindow makeKeyAndOrderFront:self];

[prefWindow makeKeyAndOrderFront:self];
}

- (IBAction)openSpotifyPreferences:(id)sender
Expand Down Expand Up @@ -172,7 +219,46 @@ - (IBAction)toggleOpenAtLogin:(id)sender
} else {
[self deleteAppFromLoginItem];
}
}

- (IBAction)toggleMiniControls:(id)sender
{
float width = 25.0;

if ( !playItem ) {
fwrdItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];
playItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];
backItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];

[playItem setImage:[NSImage imageNamed:@"mini-play-up"]];
[playItem setAlternateImage:[NSImage imageNamed:@"mini-play-down"]];
[playItem setHighlightMode:NO];
[playItem setTarget:self];
[playItem setAction:@selector(sendPlayPauseThreaded)];

[fwrdItem setImage:[NSImage imageNamed:@"mini-fwrd-up"]];
[fwrdItem setAlternateImage:[NSImage imageNamed:@"mini-fwrd-down"]];
[fwrdItem setHighlightMode:NO];
[fwrdItem setTarget:self];
[fwrdItem setAction:@selector(sendSkipForwardThreaded)];

[backItem setImage:[NSImage imageNamed:@"mini-back-up"]];
[backItem setAlternateImage:[NSImage imageNamed:@"mini-back-down"]];
[backItem setHighlightMode:NO];
[backItem setTarget:self];
[backItem setAction:@selector(sendSkipBackThreaded)];

} else {
[playItem release];
playItem = nil;

[fwrdItem release];
fwrdItem = nil;

[backItem release];
backItem = nil;
}

}

- (IBAction)checkForProcesses:(id)sender
Expand Down Expand Up @@ -246,7 +332,15 @@ - (IBAction)sendLUNemail:(id)sender
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"mailto:[email protected]"]];
}

- (IBAction)openUrlSimbl:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.culater.net/software/SIMBL/SIMBL.php"]];
}

- (IBAction)openUrlLunPlugin:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://lifeupnorth.co.uk/lun/#5"]];
}

#pragma mark -
#pragma mark KeyEvents
Expand Down Expand Up @@ -756,15 +850,30 @@ -(void) deleteAppFromLoginItem
#pragma mark -
#pragma mark Preferences

- (void)setStatusItem
{
// Create an NSStatusItem.
float width = 25.0;
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];
[statusItem setMenu:statusMenu];
[statusItem setImage:[NSImage imageNamed:@"statusOffGrey.png"]];
[statusItem setAlternateImage:[NSImage imageNamed:@"statusHighlight.png"]];
[statusItem setHighlightMode:YES];

}

- (IBAction)setApplicationIsAgent:(id)sender
{
if (![showDockIcon state]) {
NSLog(@"Show Dock Icon");
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"runAsUIAgent"]) {
//NSLog(@"Show Dock Icon");
[self setShouldBeUIElement:NO];

[showMenubarIcon setEnabled:YES];
} else {
NSLog(@"Hide Dock Icon");
//NSLog(@"Hide Dock Icon");
[self setShouldBeUIElement:YES];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showMenubarIcon"];
[showMenubarIcon setEnabled:NO];
[showMenubarIcon setState:1];
}
}

Expand Down
6 changes: 3 additions & 3 deletions English.lproj/Credits.rtf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
\
\pard\pardeftab720\qc

\f2\b \cf2 SGHotKeyLib
\f2\b \cf2 SDGlobalShortcuts
\b0 \cf0 \
by Second Gear\
by S. Degutis\
\pard\pardeftab720\qc
{\field{\*\fldinst{HYPERLINK "http://github.com/secondgear/SGHotKeysLib"}}{\fldrslt \cf0 http://github.com/secondgear/SGHotKeysLib/}}
{\field{\*\fldinst{HYPERLINK "http://github.com/sdegutis/SDGlobalShortcuts"}}{\fldrslt \cf0 http://github.com/sdegutis/SDGlobalShortcuts/}}
\f0 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\qc\pardirnatural
\cf0 \
Expand Down
Loading

0 comments on commit 308db82

Please sign in to comment.