diff options
Diffstat (limited to 'backends/taskbar/macosx/macosx-taskbar.mm')
-rw-r--r-- | backends/taskbar/macosx/macosx-taskbar.mm | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/backends/taskbar/macosx/macosx-taskbar.mm b/backends/taskbar/macosx/macosx-taskbar.mm index ae087dfb85..c842eb8090 100644 --- a/backends/taskbar/macosx/macosx-taskbar.mm +++ b/backends/taskbar/macosx/macosx-taskbar.mm @@ -29,9 +29,6 @@ // NSDockTile was introduced with Mac OS X 10.5. // Try provide backward compatibility by avoiding NSDockTile symbols. -// TODO: Implement recent list, maybe as a custom menu on dock tile when app is not running -// See Dock Tile plug-in at https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/customizing_docktile/CreatingaDockTilePlug-in/CreatingaDockTilePlug-in.html - #include "backends/taskbar/macosx/macosx-taskbar.h" #include "common/config-manager.h" #include "common/file.h" @@ -39,6 +36,9 @@ #include <AppKit/NSApplication.h> #include <AppKit/NSImage.h> #include <Foundation/NSString.h> +#include <Foundation/NSDictionary.h> +#include <Foundation/NSArray.h> +#include <Foundation/NSUserDefaults.h> #include <AppKit/NSImageView.h> #include <AppKit/NSColor.h> #include <AppKit/NSBezierPath.h> @@ -120,7 +120,7 @@ void MacOSXTaskbarManager::setOverlayIcon(const Common::String &name, const Comm initOverlayIconView(); CFStringRef imageFile = CFStringCreateWithCString(0, path.c_str(), kCFStringEncodingASCII); - NSImage* image = [[NSImage alloc] initWithContentsOfFile:(NSString *)imageFile]; + NSImage *image = [[NSImage alloc] initWithContentsOfFile:(NSString *)imageFile]; [_overlayIconView setImage:image]; [image release]; CFRelease(imageFile); @@ -234,5 +234,64 @@ return (path); \ return ""; } +void MacOSXTaskbarManager::addRecent(const Common::String &name, const Common::String &description) { + //warning("[MacOSXTaskbarManager::addRecent] Adding recent list entry: %s (%s)", name.c_str(), description.c_str()); + + if (_dockTile == nil) + return; + + // Store the game, description and icon in user preferences. + // The NSDockTilePlugin will retrieve them there to list them in the dock tile menu. + + CFStringRef gameName = CFStringCreateWithCString(0, name.c_str(), kCFStringEncodingASCII); + CFStringRef desc = CFStringCreateWithCString(0, description.c_str(), kCFStringEncodingASCII); + + // First build the dictionary for this game. + NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; + [dict setObject:(NSString *)gameName forKey:@"game"]; + [dict setObject:(NSString *)desc forKey:@"description"]; + + // Icon + Common::String iconPath = getIconPath(name); + if (!iconPath.empty()) { + CFStringRef icon = CFStringCreateWithCString(0, iconPath.c_str(), kCFStringEncodingASCII); + [dict setObject:(NSString *)icon forKey:@"icon"]; + CFRelease(icon); + } + + // Retrieve the current list of recent items and update it. + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSArray *oldArray = [defaults arrayForKey:@"recentGames"]; + if (oldArray == nil) { + [defaults setObject:[NSArray arrayWithObject:dict] forKey:@"recentGames"]; + } else { + NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:oldArray]; + // Insert the new game at the start + [newArray insertObject:dict atIndex:0]; + // If the game was already present in the array, remove it + for (unsigned int i = 1 ; i < [newArray count] ; ++i) { + NSDictionary *oldDict = [newArray objectAtIndex:i]; + if (oldDict == nil) + continue; + NSString *oldGame = [oldDict valueForKey:@"game"]; + if (oldGame != nil && [oldGame isEqualToString:(NSString*)gameName]) { + [newArray removeObjectAtIndex:i]; + break; + } + } + // And make sure we limit the size of the array to 5 games + if ([newArray count] > 5) + [newArray removeLastObject]; + [defaults setObject:newArray forKey:@"recentGames"]; + [newArray release]; + } + + // Finally release the dictionary + [dict release]; + CFRelease(gameName); + CFRelease(desc); +} + + #endif |