ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

dockplugin.m

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include <Cocoa/Cocoa.h>
00024 
00025 @interface ScummVMDockTilePlugIn : NSObject <NSDockTilePlugIn> {
00026     NSMenu *recentGamesMenu;
00027 }
00028 @end
00029 
00030 @interface StartGameMenuItem : NSMenuItem {
00031     NSString *game;
00032 }
00033 - (IBAction) startGame;
00034 - (NSMenuItem*)initWithGame:(NSString *)gameId description:(NSString*)desc icon:(NSString*)iconFile;
00035 @end
00036 
00037 @implementation ScummVMDockTilePlugIn
00038 
00039 - (id)init {
00040     self = [super init];
00041     if (self) {
00042         recentGamesMenu = nil;
00043     }
00044     return self;
00045 }
00046 
00047 - (void)dealloc {
00048     [recentGamesMenu release];
00049     [super dealloc];
00050 }
00051 
00052 
00053 - (void)setDockTile:(NSDockTile *)dockTile {
00054 }
00055 
00056 - (NSMenu*)dockMenu {
00057     // Get the list or recent games
00058     CFPreferencesAppSynchronize(CFSTR("org.residualvm.residaulvm"));
00059     NSArray *array = CFPreferencesCopyAppValue(CFSTR("recentGames"), CFSTR("org.residualvm.residualvm"));
00060     if (array == nil)
00061         return nil;
00062 
00063     // Create the menu
00064     if (recentGamesMenu == nil)
00065         recentGamesMenu = [[NSMenu alloc] init];
00066     else
00067         [recentGamesMenu removeAllItems];
00068 
00069     NSEnumerator *enumerator = [array objectEnumerator];
00070     NSDictionary *recentGame;
00071     while (recentGame = [enumerator nextObject]) {
00072         NSString *gameId = [recentGame valueForKey:@"game"];
00073         NSString *desc = [recentGame valueForKey:@"description"];
00074         NSString *iconFile = [recentGame valueForKey:@"icon"];
00075 
00076         StartGameMenuItem *menuItem = [[StartGameMenuItem alloc] initWithGame:gameId description:desc icon:iconFile];
00077         [recentGamesMenu addItem:menuItem];
00078         [menuItem release];
00079     }
00080 
00081     return recentGamesMenu;
00082 }
00083 
00084 @end
00085 
00086 @implementation StartGameMenuItem
00087 
00088 - (NSMenuItem*)initWithGame:(NSString *)gameId description:(NSString*)desc icon:(NSString*)iconFile {
00089     self = [super initWithTitle:(desc == nil ? gameId : desc) action:@selector(startGame) keyEquivalent:@""];
00090     [self setTarget:self];
00091 
00092     if (iconFile != nil) {
00093         NSImage *image = [[NSImage alloc] initWithContentsOfFile:iconFile];
00094         [self setImage:image];
00095         [image release];
00096     }
00097 
00098     game = gameId;
00099     [game retain];
00100 
00101     return self;
00102 }
00103 
00104 - (void)dealloc {
00105     [game release];
00106     [super dealloc];
00107 }
00108 
00109 - (IBAction) startGame {
00110     NSLog(@"Starting Game %@...", game);
00111 
00112     NSString *scummVMPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"org.residualvm.residualvm"];
00113     if (scummVMPath == nil) {
00114         NSLog(@"Cannot find ResidualVM.app!");
00115         return;
00116     }
00117     // Start ScummVM.app with the game ID as argument
00118     NSURL *url = [NSURL fileURLWithPath:scummVMPath];
00119     NSMutableDictionary *args = [[NSMutableDictionary alloc] init];
00120     [args setObject:[NSArray arrayWithObject:game] forKey:NSWorkspaceLaunchConfigurationArguments];
00121     [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url options:NSWorkspaceLaunchDefault configuration:args error:nil];
00122     [args release];
00123 }
00124 
00125 @end


Generated on Sat Feb 16 2019 05:00:49 for ResidualVM by doxygen 1.7.1
curved edge   curved edge