/* * QEMU Cocoa Control Controller * * Copyright (c) 2005 - 2007 Mike Kronenberg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #import "../host-cocoa/CGSPrivate.h" #import "cocoaControlController.h" #import "cocoaControlDiskImage.h" #import "cocoaControlNewPCAssistant.h" @implementation cocoaControlController -(id)init { // NSLog(@"cocoaControlController: init"); /* preferences */ [[NSUserDefaults standardUserDefaults] registerDefaults:[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects: [NSString stringWithString:@"Quartz"], /* enable Quartz by default */ [NSNumber numberWithBool:TRUE], /* enable search for updates */ [NSNumber numberWithBool:FALSE], /* disable log to console */ [@"~/Documents/QEMU" stringByExpandingTildeInPath], /* standart path */ nil ] forKeys:[NSArray arrayWithObjects:@"display", @"enableCheckForUpdates", @"enableLogToConsole", @"dataPath", nil]]]; userDefaults = [NSUserDefaults standardUserDefaults]; /* compatibility with old prefferences */ if ([userDefaults objectForKey:@"enableOpenGL"]) { if (![userDefaults boolForKey:@"enableOpenGL"]) { [userDefaults setObject:@"QuickDraw" forKey:@"display"]; } [userDefaults removeObjectForKey:@"enableOpenGL"]; } if ((self = [super init])) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkATaskStatus:) name:NSTaskDidTerminateNotification object:nil]; /* check for update */ if ([userDefaults boolForKey:@"enableCheckForUpdates"]) { [self getLatestVersion]; } /* start qserver for distributed object */ qdoserver = [[cocoaControlDOServer alloc] init]; [qdoserver setSender:self]; return self; } return nil; } -(id)pcs { return pcs; } - (id)pcsTasks { return pcsTasks; } /* NSApp Delegate */ - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { // NSLog(@"cocoaControlController: openFile"); [ self startPC:filename]; return true; } -(void)awakeFromNib { // NSLog(@"cocoaControlController: awakeFromNib"); [NSApp setDelegate:self]; [mainWindow setDelegate:self]; /* other Nibs */ editPC = [[cocoaControlEditPC alloc] init]; if (![NSBundle loadNibNamed:@"cocoaControlEditPC" owner:editPC]) { printf("cocoaControlEditPC.nib not loaded!\n"); } [[editPC editPCPanel] center]; preferences = [[cocoaControlPreferences alloc] init]; if (![NSBundle loadNibNamed:@"cocoaControlPreferences" owner:preferences]) { printf("cocoaControlPreferences.nib not loaded!\n"); } /* div vars */ if (![userDefaults objectForKey:@"dataPath"]) { /* here we take care of older userDefaults without @"dataPath" */ [userDefaults setObject:[NSString stringWithFormat:@"%@/Documents/QEMU", NSHomeDirectory()] forKey:@"dataPath"]; } cpuTypes = [[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"i386-softmmu",@"x86_64-softmmu",@"ppc-softmmu",@"sparc-softmmu",@"mips-softmmu",@"arm-softmmu",nil] forKeys:[NSArray arrayWithObjects:@"x86",@"x86-64",@"PowerPC",@"SPARC",@"MIPS",@"ARM",nil]] retain]; /* create PC directory */ NSFileManager *fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath: [NSString stringWithFormat:@"%@/", [userDefaults objectForKey:@"dataPath"]]] == NO) [fileManager createDirectoryAtPath: [NSString stringWithFormat:@"%@/", [userDefaults objectForKey:@"dataPath"]] attributes: nil]; /* initialise pcs */ [self loadConfigurations]; /* change status to "shutdown" after corrupt termination of QEMU */ int i; for (i=0; i < [pcs count]; i++) if ([[[[pcs objectAtIndex:i] objectForKey:@"PC Data"] objectForKey:@"state"] isEqual:@"running"] ) { [[[pcs objectAtIndex:i] objectForKey:@"PC Data"] setObject:@"shutdown" forKey:@"state"]; [self savePCConfiguration:[pcs objectAtIndex:i]]; } /* Creating Toolbar */ NSToolbar *controlWindowToolbar = [[[NSToolbar alloc] initWithIdentifier: @"controlWindowToolbarIdentifier"] autorelease]; [controlWindowToolbar setAllowsUserCustomization: YES]; //allow customisation [controlWindowToolbar setAutosavesConfiguration: YES]; //autosave changes [controlWindowToolbar setDisplayMode: NSToolbarDisplayModeIconOnly]; //what is shown [controlWindowToolbar setSizeMode:NSToolbarSizeModeSmall]; //default Toolbar Size [controlWindowToolbar setDelegate: self]; // We are the delegate [mainWindow setToolbar: controlWindowToolbar]; // Attach the toolbar to the document window /* format Cell to imageCell */ id cell; NSTableColumn *theColumn; theColumn = [table tableColumnWithIdentifier:@"image"]; cell = [NSImageCell new]; [theColumn setDataCell:cell]; /* set infos for microIcons */ [table setQControl:self]; /* handle Table DoubleClick */ [table setTarget:self]; [table setDoubleAction:@selector(tableDoubleClick:)]; /* Timer for Updates */ timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector( updateThumbnails ) userInfo:nil repeats:YES]; /* Dictionary for Tasks */ pcsTasks = [[NSMutableDictionary alloc] init]; pcsPIDs = [[NSMutableDictionary alloc] init]; /* Dictionary for Windows Numbers */ pcsWindows = [[NSMutableArray alloc] init]; /* loading initial Thumbnails */ [self updateThumbnails]; /* register table for drag'n drop */ [table registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]]; } - (void) applicationWillBecomeActive:(NSNotification *)aNotification { // NSLog(@"applicationWillBecomeActive: applicationWillBecomeActive"); NSEnumerator *enumerator = [pcsPIDs keyEnumerator]; id key; NSMutableDictionary *pcsWindowsNumbers = [[NSMutableDictionary alloc] init]; while ((key = [enumerator nextObject])) { [pcsWindowsNumbers setObject: [[[pcsPIDs objectForKey:key] objectForKey:@"PC Data"] objectForKey:@"name"] forKey: [NSString stringWithFormat:@"%d",[qdoserver guestWindowNumber:[[[pcsPIDs objectForKey:key] objectForKey:@"PC Data"] objectForKey:@"name"]]] ]; } int wcount; NSCountWindows(&wcount); int wlist[wcount]; NSWindowList(wcount, wlist); [pcsWindows removeAllObjects]; int i; for (i=0; i