diff options
author | Thierry Crozat | 2016-03-19 15:18:23 +0000 |
---|---|---|
committer | Thierry Crozat | 2016-03-25 15:37:04 +0000 |
commit | 2671918c92d68733e651fa870ee0e1de167ed128 (patch) | |
tree | 7af02b04557e4da03eb3ced186f90e8c1e0deafa /backends/taskbar | |
parent | 0fb6f31d4e53b6ac194775b13e6d0f553891dccd (diff) | |
download | scummvm-rg350-2671918c92d68733e651fa870ee0e1de167ed128.tar.gz scummvm-rg350-2671918c92d68733e651fa870ee0e1de167ed128.tar.bz2 scummvm-rg350-2671918c92d68733e651fa870ee0e1de167ed128.zip |
OS X: Implement saving recent games list to user preferences
Diffstat (limited to 'backends/taskbar')
-rw-r--r-- | backends/taskbar/macosx/macosx-taskbar.h | 1 | ||||
-rw-r--r-- | backends/taskbar/macosx/macosx-taskbar.mm | 78 |
2 files changed, 76 insertions, 3 deletions
diff --git a/backends/taskbar/macosx/macosx-taskbar.h b/backends/taskbar/macosx/macosx-taskbar.h index 5d5b9d02cd..55bb97a691 100644 --- a/backends/taskbar/macosx/macosx-taskbar.h +++ b/backends/taskbar/macosx/macosx-taskbar.h @@ -37,6 +37,7 @@ public: virtual void setProgressValue(int completed, int total); virtual void setProgressState(TaskbarProgressState state); virtual void setCount(int count); + virtual void addRecent(const Common::String &name, const Common::String &description); virtual void notifyError(); virtual void clearError(); diff --git a/backends/taskbar/macosx/macosx-taskbar.mm b/backends/taskbar/macosx/macosx-taskbar.mm index ae087dfb85..1b19ea0c56 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" @@ -234,5 +231,80 @@ return (path); \ return ""; } +void MacOSXTaskbarManager::addRecent(const Common::String &name, const Common::String &description) { + // 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 + + //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 (int i = 1 ; i < [newArray count] ; ++i) { + NSDictionary* oldDict = newArray[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); + + + // The command to use would be "open " + path + " --args " + game. + // NSString *cmdString = [NSString stringWithFormat:@"open %@ --args %@", bundlePath, gameName]; + // We could use [[NSBundle mainBundle] bundlePath] to get the path here and then store it in the user preferences. + // Or we can let the NSDockTilePlugin find the path with: + // NSString *scummVMPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"org.scummvm.scummvm"]; + // We can then also use NSWorkspace to launch the app. + // if (scummVMPath == nil) + // return; + // NSURL* url = [NSURL fileURLWithPath:scummVMPath]; + // [NSWorkspace launchApplicationAtURL:url options: configuration: error:] to start the application with some arguments + +} + + #endif |