diff options
author | Thierry Crozat | 2016-03-20 21:27:47 +0000 |
---|---|---|
committer | Thierry Crozat | 2016-03-25 15:37:13 +0000 |
commit | d519dd8ec3ee7258ed3657821990553a84960e2a (patch) | |
tree | 7bf099f9fef3e2621e3a27f035f766c7f6a4fc04 /dists | |
parent | 2671918c92d68733e651fa870ee0e1de167ed128 (diff) | |
download | scummvm-rg350-d519dd8ec3ee7258ed3657821990553a84960e2a.tar.gz scummvm-rg350-d519dd8ec3ee7258ed3657821990553a84960e2a.tar.bz2 scummvm-rg350-d519dd8ec3ee7258ed3657821990553a84960e2a.zip |
OS X: Implement a Dock Tile Plugin to display recent games menu in dock
This allows to start a recently played game directly from the dock. The
ScummVM.app application should have been permanently added to the
dock and the menu is only present when ScummVM is not running. The
list of recently played game is written by the taskbar code in ScummVM.
The Dock Tile Plugin only reads that list to populate the menu.
Diffstat (limited to 'dists')
-rw-r--r-- | dists/macosx/Info.plist | 2 | ||||
-rw-r--r-- | dists/macosx/Info.plist.in | 2 | ||||
-rw-r--r-- | dists/macosx/dockplugin/Info.plist | 26 | ||||
-rw-r--r-- | dists/macosx/dockplugin/Info.plist.in | 26 | ||||
-rw-r--r-- | dists/macosx/dockplugin/dockplugin.m | 125 |
5 files changed, 181 insertions, 0 deletions
diff --git a/dists/macosx/Info.plist b/dists/macosx/Info.plist index 7f6170294a..4013838e68 100644 --- a/dists/macosx/Info.plist +++ b/dists/macosx/Info.plist @@ -54,6 +54,8 @@ <string>NSApplication</string> <key>SUFeedURL</key> <string>http://www.scummvm.org/appcasts/macosx/release.xml</string> + <key>NSDockTilePlugIn</key> + <string>scummvm.docktileplugin</string> <key>SUPublicDSAKeyFile</key> <string>dsa_pub.pem</string> </dict> diff --git a/dists/macosx/Info.plist.in b/dists/macosx/Info.plist.in index 55be27d77b..7ba49f2dca 100644 --- a/dists/macosx/Info.plist.in +++ b/dists/macosx/Info.plist.in @@ -54,6 +54,8 @@ <string>NSApplication</string> <key>SUFeedURL</key> <string>http://www.scummvm.org/appcasts/macosx/release.xml</string> + <key>NSDockTilePlugIn</key> + <string>scummvm.docktileplugin</string> <key>SUPublicDSAKeyFile</key> <string>dsa_pub.pem</string> </dict> diff --git a/dists/macosx/dockplugin/Info.plist b/dists/macosx/dockplugin/Info.plist new file mode 100644 index 0000000000..c66f96a6b9 --- /dev/null +++ b/dists/macosx/dockplugin/Info.plist @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>ScummVMDockTilePlugin</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleIdentifier</key> + <string>org.scummvm.scummvm.DockTilePlugin</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>1.9.0git</string> + <key>CFBundleVersion</key> + <string>1.9.0git</string> + <key>NSHumanReadableCopyright</key> + <string>Copyright 2001-2016 The ScummVM Team</string> + <key>NSPrincipalClass</key> + <string>ScummVMDockTilePlugIn</string> +</dict> +</plist> diff --git a/dists/macosx/dockplugin/Info.plist.in b/dists/macosx/dockplugin/Info.plist.in new file mode 100644 index 0000000000..851fc70f11 --- /dev/null +++ b/dists/macosx/dockplugin/Info.plist.in @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>ScummVMDockTilePlugin</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleIdentifier</key> + <string>org.scummvm.scummvm.DockTilePlugin</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>@VERSION@</string> + <key>CFBundleVersion</key> + <string>@VERSION@</string> + <key>NSHumanReadableCopyright</key> + <string>Copyright 2001-2016 The ScummVM Team</string> + <key>NSPrincipalClass</key> + <string>ScummVMDockTilePlugIn</string> +</dict> +</plist> diff --git a/dists/macosx/dockplugin/dockplugin.m b/dists/macosx/dockplugin/dockplugin.m new file mode 100644 index 0000000000..9bf0b9b033 --- /dev/null +++ b/dists/macosx/dockplugin/dockplugin.m @@ -0,0 +1,125 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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. + * + */ + +#include <Cocoa/Cocoa.h> + +@interface ScummVMDockTilePlugIn : NSObject <NSDockTilePlugIn> { + NSMenu* recentGamesMenu; +} +@end + +@interface StartGameMenuItem : NSMenuItem { + NSString* game; +} +- (IBAction) startGame; +- (NSMenuItem*)initWithGame:(NSString *)gameId description:(NSString*)desc icon:(NSString*)iconFile; +@end + +@implementation ScummVMDockTilePlugIn + +- (id)init { + self = [super init]; + if (self) { + recentGamesMenu = nil; + } + return self; +} + +- (void)dealloc { + [recentGamesMenu release]; + [super dealloc]; +} + + +- (void)setDockTile:(NSDockTile *)dockTile { +} + +- (NSMenu*)dockMenu { + // Get the list or recent games + CFPreferencesAppSynchronize(CFSTR("org.scummvm.scummvm")); + NSArray* array = CFPreferencesCopyAppValue(CFSTR("recentGames"), CFSTR("org.scummvm.scummvm")); + if (array == nil) + return nil; + + // Create the menu + if (recentGamesMenu == nil) + recentGamesMenu = [[NSMenu alloc] init]; + else + [recentGamesMenu removeAllItems]; + + NSEnumerator *enumerator = [array objectEnumerator]; + NSDictionary* recentGame; + while (recentGame = [enumerator nextObject]) { + NSString* gameId = [recentGame valueForKey:@"game"]; + NSString* desc = [recentGame valueForKey:@"description"]; + NSString* iconFile = [recentGame valueForKey:@"icon"]; + + StartGameMenuItem* menuItem = [[StartGameMenuItem alloc] initWithGame:gameId description:desc icon:iconFile]; + [recentGamesMenu addItem:menuItem]; + [menuItem release]; + } + + return recentGamesMenu; +} + +@end + +@implementation StartGameMenuItem + +- (NSMenuItem*)initWithGame:(NSString *)gameId description:(NSString*)desc icon:(NSString*)iconFile { + self = [super initWithTitle:(desc == nil ? gameId : desc) action:@selector(startGame) keyEquivalent:@""]; + [self setTarget:self]; + + if (iconFile != nil) { + NSImage* image = [[NSImage alloc] initWithContentsOfFile:iconFile]; + [self setImage:image]; + [image release]; + } + + game = gameId; + [game retain]; + + return self; +} + +- (void)dealloc { + [game release]; + [super dealloc]; +} + +- (IBAction) startGame { + NSLog(@"Starting Game %@...", game); + + NSString *scummVMPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"org.scummvm.scummvm"]; + if (scummVMPath == nil) { + NSLog(@"Cannot find ScummVM.app!"); + return; + } + // Start ScummVM.app with the game ID as argument + NSURL* url = [NSURL fileURLWithPath:scummVMPath]; + NSMutableDictionary* args = [[NSMutableDictionary alloc] init]; + [args setObject:[NSArray arrayWithObject:game] forKey:NSWorkspaceLaunchConfigurationArguments]; + [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url options:NSWorkspaceLaunchDefault configuration:args error:nil]; + [args release]; +} + +@end |