| 1 | /* |
|---|
| 2 | * QEMU Cocoa Control PC Editor Window |
|---|
| 3 | * |
|---|
| 4 | * Copyright (c) 2005 - 2007 Mike Kronenberg |
|---|
| 5 | * |
|---|
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 7 | * of this software and associated documentation files (the "Software"), to deal |
|---|
| 8 | * in the Software without restriction, including without limitation the rights |
|---|
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 10 | * copies of the Software, and to permit persons to whom the Software is |
|---|
| 11 | * furnished to do so, subject to the following conditions: |
|---|
| 12 | * |
|---|
| 13 | * The above copyright notice and this permission notice shall be included in |
|---|
| 14 | * all copies or substantial portions of the Software. |
|---|
| 15 | * |
|---|
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|---|
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 22 | * THE SOFTWARE. |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | #import "cocoaControlEditPC.h" |
|---|
| 26 | |
|---|
| 27 | //#import "AppleHelp.h" |
|---|
| 28 | #import "Carbon/Carbon.h" |
|---|
| 29 | |
|---|
| 30 | #import "cocoaControlController.h" |
|---|
| 31 | #import "cocoaControlDiskImage.h" |
|---|
| 32 | |
|---|
| 33 | @implementation cocoaControlEditPC |
|---|
| 34 | - (id) init |
|---|
| 35 | { |
|---|
| 36 | // NSLog(@"cocoaControlEditPC: init"); |
|---|
| 37 | |
|---|
| 38 | if ((self = [super init])) { |
|---|
| 39 | userDefaults = [NSUserDefaults standardUserDefaults]; |
|---|
| 40 | return self; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | return nil; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | - (void) dealloc |
|---|
| 47 | { |
|---|
| 48 | // NSLog(@"cocoaControlEditPC: dealloc"); |
|---|
| 49 | |
|---|
| 50 | [super dealloc]; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | - (NSPanel *) editPCPanel |
|---|
| 54 | { |
|---|
| 55 | // NSLog(@"cocoaControlEditPC: editPCPanel"); |
|---|
| 56 | |
|---|
| 57 | return editPCPanel; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | - (void) viewGeneral:(id)sender |
|---|
| 61 | { |
|---|
| 62 | // NSLog(@"cocoaControlEditPC: viewGeneral"); |
|---|
| 63 | |
|---|
| 64 | if ([viewHardware superview]) { |
|---|
| 65 | [viewHardware retain]; |
|---|
| 66 | [viewHardware removeFromSuperview]; |
|---|
| 67 | } |
|---|
| 68 | if ([viewAdvanced superview]) { |
|---|
| 69 | [viewAdvanced retain]; |
|---|
| 70 | [viewAdvanced removeFromSuperview]; |
|---|
| 71 | } |
|---|
| 72 | if ([viewNetwork superview]) { |
|---|
| 73 | [viewNetwork retain]; |
|---|
| 74 | [viewNetwork removeFromSuperview]; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | [editPCPanel setTitle:[NSString stringWithFormat: NSLocalizedStringFromTable(@"editPCviewGeneral:title", @"Localizable", @"cocoaControlEditPC"), [[thisPC objectForKey:@"PC Data"] objectForKey:@"name"]]]; |
|---|
| 78 | [editPCPanel setFrame:NSMakeRect( |
|---|
| 79 | [editPCPanel frame].origin.x, |
|---|
| 80 | [editPCPanel frame].origin.y + [editPCPanel frame].size.height - [viewGeneral bounds].size.height - 140, |
|---|
| 81 | [editPCPanel frame].size.width, |
|---|
| 82 | [viewGeneral bounds].size.height + 140 |
|---|
| 83 | ) display:YES animate:YES]; |
|---|
| 84 | |
|---|
| 85 | [[editPCPanel contentView] addSubview:viewGeneral]; |
|---|
| 86 | [viewGeneral setFrameOrigin:NSMakePoint(0,60)]; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | - (void) viewHardware:(id)sender |
|---|
| 90 | { |
|---|
| 91 | // NSLog(@"cocoaControlEditPC: viewHardware"); |
|---|
| 92 | |
|---|
| 93 | if ([viewGeneral superview]) { |
|---|
| 94 | [viewGeneral retain]; |
|---|
| 95 | [viewGeneral removeFromSuperview]; |
|---|
| 96 | } |
|---|
| 97 | if ([viewAdvanced superview]) { |
|---|
| 98 | [viewAdvanced retain]; |
|---|
| 99 | [viewAdvanced removeFromSuperview]; |
|---|
| 100 | } |
|---|
| 101 | if ([viewNetwork superview]) { |
|---|
| 102 | [viewNetwork retain]; |
|---|
| 103 | [viewNetwork removeFromSuperview]; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | [editPCPanel setTitle:[NSString stringWithFormat: NSLocalizedStringFromTable(@"viewHardware:title", @"Localizable", @"cocoaControlEditPC"), [[thisPC objectForKey:@"PC Data"] objectForKey:@"name"]]]; |
|---|
| 107 | [editPCPanel setFrame:NSMakeRect( |
|---|
| 108 | [editPCPanel frame].origin.x, |
|---|
| 109 | [editPCPanel frame].origin.y + [editPCPanel frame].size.height - [viewHardware bounds].size.height - 140, |
|---|
| 110 | [editPCPanel frame].size.width, |
|---|
| 111 | [viewHardware bounds].size.height + 140 |
|---|
| 112 | ) display:YES animate:YES]; |
|---|
| 113 | |
|---|
| 114 | [[editPCPanel contentView] addSubview:viewHardware]; |
|---|
| 115 | [viewHardware setFrameOrigin:NSMakePoint(0,60)]; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | - (void) viewAdvanced:(id)sender |
|---|
| 119 | { |
|---|
| 120 | // NSLog(@"cocoaControlEditPC: viewAdvanced"); |
|---|
| 121 | |
|---|
| 122 | if ([viewHardware superview]) { |
|---|
| 123 | [viewHardware retain]; |
|---|
| 124 | [viewHardware removeFromSuperview]; |
|---|
| 125 | } |
|---|
| 126 | if ([viewGeneral superview]) { |
|---|
| 127 | [viewGeneral retain]; |
|---|
| 128 | [viewGeneral removeFromSuperview]; |
|---|
| 129 | } |
|---|
| 130 | if ([viewNetwork superview]) { |
|---|
| 131 | [viewNetwork retain]; |
|---|
| 132 | [viewNetwork removeFromSuperview]; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | [editPCPanel setTitle:[NSString stringWithFormat: NSLocalizedStringFromTable(@"viewAdvanced:title", @"Localizable", @"cocoaControlEditPC"), [[thisPC objectForKey:@"PC Data"] objectForKey:@"name"]]]; |
|---|
| 136 | [editPCPanel setFrame:NSMakeRect( |
|---|
| 137 | [editPCPanel frame].origin.x, |
|---|
| 138 | [editPCPanel frame].origin.y + [editPCPanel frame].size.height - [viewAdvanced bounds].size.height - 140, |
|---|
| 139 | [editPCPanel frame].size.width, |
|---|
| 140 | [viewAdvanced bounds].size.height + 140 |
|---|
| 141 | ) display:YES animate:YES]; |
|---|
| 142 | |
|---|
| 143 | [[editPCPanel contentView] addSubview:viewAdvanced]; |
|---|
| 144 | [viewAdvanced setFrameOrigin:NSMakePoint(0,60)]; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | - (void) viewNetwork:(id)sender |
|---|
| 148 | { |
|---|
| 149 | if ([viewHardware superview]) { |
|---|
| 150 | [viewHardware retain]; |
|---|
| 151 | [viewHardware removeFromSuperview]; |
|---|
| 152 | } |
|---|
| 153 | if ([viewGeneral superview]) { |
|---|
| 154 | [viewGeneral retain]; |
|---|
| 155 | [viewGeneral removeFromSuperview]; |
|---|
| 156 | } |
|---|
| 157 | if ([viewAdvanced superview]) { |
|---|
| 158 | [viewAdvanced retain]; |
|---|
| 159 | [viewAdvanced removeFromSuperview]; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | [editPCPanel setTitle:[NSString stringWithFormat: NSLocalizedStringFromTable(@"viewNetwork:title", @"Localizable", @"cocoaControlEditPC"), [[thisPC objectForKey:@"PC Data"] objectForKey:@"name"]]]; |
|---|
| 163 | [editPCPanel setFrame:NSMakeRect( |
|---|
| 164 | [editPCPanel frame].origin.x, |
|---|
| 165 | [editPCPanel frame].origin.y + [editPCPanel frame].size.height - [viewNetwork bounds].size.height - 140, |
|---|
| 166 | [editPCPanel frame].size.width, |
|---|
| 167 | [viewNetwork bounds].size.height + 140 |
|---|
| 168 | ) display:YES animate:YES]; |
|---|
| 169 | |
|---|
| 170 | [[editPCPanel contentView] addSubview:viewNetwork]; |
|---|
| 171 | [viewNetwork setFrameOrigin:NSMakePoint(0,60)]; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | - (void) setOption:(id)option argument:(id)argument |
|---|
| 175 | { |
|---|
| 176 | // NSLog(@"cocoaControlEditPC: setOption:%@ argument:%@", option, argument); |
|---|
| 177 | |
|---|
| 178 | /* -smp */ |
|---|
| 179 | if ([option isEqual:@"-smp"]) { |
|---|
| 180 | [popUpButtonSMP selectItemAtIndex:(int)ceil(log2([argument doubleValue]))]; |
|---|
| 181 | |
|---|
| 182 | /* -m */ |
|---|
| 183 | } else if ([option isEqual:@"-m"]) { |
|---|
| 184 | [textFieldRAM setStringValue:[NSString stringWithString:argument]]; |
|---|
| 185 | |
|---|
| 186 | /* -std-vga */ |
|---|
| 187 | } else if ([option isEqual:@"-std-vga"]) { |
|---|
| 188 | [popUpButtonVGA selectItemAtIndex:1]; |
|---|
| 189 | |
|---|
| 190 | /* -soundhw */ |
|---|
| 191 | } else if ([option isEqual:@"-soundhw"]) { |
|---|
| 192 | if ([argument rangeOfString:@"adlib" options:NSCaseInsensitiveSearch].location != NSNotFound) { |
|---|
| 193 | [buttonEnableAdlib setState:NSOnState]; |
|---|
| 194 | } |
|---|
| 195 | if ([argument rangeOfString:@"sb16" options:NSCaseInsensitiveSearch].location != NSNotFound) { |
|---|
| 196 | [buttonEnableSB16 setState:NSOnState]; |
|---|
| 197 | } |
|---|
| 198 | if ([argument rangeOfString:@"es1370" options:NSCaseInsensitiveSearch].location != NSNotFound) { |
|---|
| 199 | [buttonEnableES1370 setState:NSOnState]; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | /* -usbdevice */ |
|---|
| 204 | } else if ([option isEqual:@"-usbdevice"]) { |
|---|
| 205 | if ([argument isEqual:@"tablet"]) { |
|---|
| 206 | [buttonEnableUSBTablet setState:NSOnState]; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | /* -localtime */ |
|---|
| 210 | } else if ([option isEqual:@"-localtime"]) { |
|---|
| 211 | [buttonLocaltime setState:NSOnState]; |
|---|
| 212 | |
|---|
| 213 | /* -net */ |
|---|
| 214 | } else if ([option isEqual:@"-net"]) { |
|---|
| 215 | if ([argument isEqual:@"nic"]) { |
|---|
| 216 | [buttonNetNicNe2000 setState:NSOnState]; |
|---|
| 217 | } else if ([argument isEqual:@"nic,model=rtl8139"]) { |
|---|
| 218 | [buttonNetNicRtl8139 setState:NSOnState]; |
|---|
| 219 | } else if ([argument isEqual:@"nic,model=pcnet"]) { |
|---|
| 220 | [buttonNetNicPcnet setState:NSOnState]; |
|---|
| 221 | } |
|---|
| 222 | if ([argument isEqual:@"user"]) { |
|---|
| 223 | [buttonNetUser setState:NSOnState]; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | /* -smb */ |
|---|
| 227 | } else if ([option isEqual:@"-smb"]) { |
|---|
| 228 | if ([argument isEqual:@"~/Desktop/Q Shared Files/"]) { |
|---|
| 229 | [popUpButtonSmbFilesharing selectItemAtIndex:1]; |
|---|
| 230 | } else { |
|---|
| 231 | [popUpButtonSmbFilesharing insertItemWithTitle:[NSString stringWithString:argument] atIndex:2]; |
|---|
| 232 | [popUpButtonSmbFilesharing selectItemAtIndex:2]; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | /* -fda */ |
|---|
| 236 | } else if ([option isEqual:@"-fda"]) { |
|---|
| 237 | [popUpButtonFda insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 238 | [popUpButtonFda selectItemAtIndex:1]; |
|---|
| 239 | |
|---|
| 240 | /* -hda */ |
|---|
| 241 | } else if ([option isEqual:@"-hda"]) { |
|---|
| 242 | if ([popUpButtonHda indexOfItemWithTitle:argument] > -1) { |
|---|
| 243 | [popUpButtonHda selectItemWithTitle:argument]; |
|---|
| 244 | } else { |
|---|
| 245 | int intResult; |
|---|
| 246 | NSString *stringValue; |
|---|
| 247 | NSScanner *scanner = [NSScanner scannerWithString: argument]; |
|---|
| 248 | |
|---|
| 249 | if ([scanner scanString:@"createNew" intoString:&stringValue]) { |
|---|
| 250 | [scanner scanInt:&intResult]; |
|---|
| 251 | customImagePopUpButtonTemp = popUpButtonHda; |
|---|
| 252 | [self setCustomDIType:@"qcow2" size:intResult]; |
|---|
| 253 | } else { |
|---|
| 254 | [popUpButtonHda insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 255 | [popUpButtonHda selectItemAtIndex:1]; |
|---|
| 256 | } |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | /* -hdb */ |
|---|
| 260 | } else if ([option isEqual:@"-hdb"]) { |
|---|
| 261 | if ([popUpButtonHdb indexOfItemWithTitle:argument] > -1) { |
|---|
| 262 | [popUpButtonHdb selectItemWithTitle:argument]; |
|---|
| 263 | } else { |
|---|
| 264 | [popUpButtonHdb insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 265 | [popUpButtonHdb selectItemAtIndex:1]; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | /* -hdc */ |
|---|
| 269 | } else if ([option isEqual:@"-hdc"]) { |
|---|
| 270 | if ([popUpButtonHdc indexOfItemWithTitle:argument] > -1) { |
|---|
| 271 | [popUpButtonHdc selectItemWithTitle:argument]; |
|---|
| 272 | } else { |
|---|
| 273 | [popUpButtonHdc insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 274 | [popUpButtonHdc selectItemAtIndex:1]; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | /* -hdd */ |
|---|
| 278 | } else if ([option isEqual:@"-hdd"]) { |
|---|
| 279 | if ([popUpButtonHdd indexOfItemWithTitle:argument] > -1) { |
|---|
| 280 | [popUpButtonHdd selectItemWithTitle:argument]; |
|---|
| 281 | } else { |
|---|
| 282 | [popUpButtonHdd insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 283 | [popUpButtonHdd selectItemAtIndex:1]; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /* -cdrom */ |
|---|
| 287 | } else if ([option isEqual:@"-cdrom"]) { |
|---|
| 288 | if ([argument isEqual:@"/dev/cdrom"]) { |
|---|
| 289 | [popUpButtonCdrom selectItemAtIndex:1]; |
|---|
| 290 | } else { |
|---|
| 291 | [popUpButtonCdrom insertItemWithTitle:[NSString stringWithString:argument] atIndex:2]; |
|---|
| 292 | [popUpButtonCdrom selectItemAtIndex:2]; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | /* -boot */ |
|---|
| 296 | } else if ([option isEqual:@"-boot"]) { |
|---|
| 297 | switch ([argument characterAtIndex:0]) { |
|---|
| 298 | case 'a': |
|---|
| 299 | [popUpButtonBoot selectItemAtIndex:0]; |
|---|
| 300 | break; |
|---|
| 301 | case 'd': |
|---|
| 302 | [popUpButtonBoot selectItemAtIndex:2]; |
|---|
| 303 | break; |
|---|
| 304 | default: |
|---|
| 305 | [popUpButtonBoot selectItemAtIndex:1]; |
|---|
| 306 | break; |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | /* -win2k-hack */ |
|---|
| 310 | } else if ([option isEqual:@"-win2k-hack"]) { |
|---|
| 311 | [buttonWin2kHack setState:NSOnState]; |
|---|
| 312 | |
|---|
| 313 | /* -kernel */ |
|---|
| 314 | } else if ([option isEqual:@"-kernel"]) { |
|---|
| 315 | [popUpButtonKernel insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 316 | [popUpButtonKernel selectItemAtIndex:1]; |
|---|
| 317 | |
|---|
| 318 | /* -append */ |
|---|
| 319 | } else if ([option isEqual:@"-append"]) { |
|---|
| 320 | [textFieldAppend setStringValue:[NSString stringWithString:argument]]; |
|---|
| 321 | |
|---|
| 322 | /* -initrd */ |
|---|
| 323 | } else if ([option isEqual:@"-initrd"]) { |
|---|
| 324 | [popUpButtonInitrd insertItemWithTitle:[NSString stringWithString:argument] atIndex:1]; |
|---|
| 325 | [popUpButtonInitrd selectItemAtIndex:1]; |
|---|
| 326 | |
|---|
| 327 | /* -redir */ |
|---|
| 328 | } else if ([option isEqual:@"-redir"]) { |
|---|
| 329 | // we do not have to do anything about it here, because the information is already saved in the configuration.plist |
|---|
| 330 | /* -M */ |
|---|
| 331 | } else if ([option isEqual:@"-M"]) { |
|---|
| 332 | |
|---|
| 333 | /* free Arguments */ |
|---|
| 334 | } else { |
|---|
| 335 | [textFieldArguments setStringValue:[[textFieldArguments stringValue] stringByAppendingString:[NSString stringWithFormat:@" %@ %@", option, argument]]]; |
|---|
| 336 | } |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | - (void) prepareEditPCPanel:(NSMutableDictionary *)aPC newPC:(BOOL)newPC sender:(id)sender |
|---|
| 340 | { |
|---|
| 341 | // NSLog(@"cocoaControlEditPC: prepareEditPCPanel"); |
|---|
| 342 | |
|---|
| 343 | thisPC = aPC; |
|---|
| 344 | qSender = sender; |
|---|
| 345 | [thisPC retain]; |
|---|
| 346 | |
|---|
| 347 | /* prepare panel */ |
|---|
| 348 | [self viewGeneral:self]; |
|---|
| 349 | [[editPCPanel toolbar] setSelectedItemIdentifier:@"general"]; |
|---|
| 350 | |
|---|
| 351 | /* Name */ |
|---|
| 352 | [textFieldName setTextColor:[NSColor blackColor]]; |
|---|
| 353 | [textFieldName setStringValue: [[thisPC objectForKey:@"PC Data"] objectForKey:@"name"]]; |
|---|
| 354 | |
|---|
| 355 | /* WMStopWhenInactive */ |
|---|
| 356 | if ([[thisPC objectForKey:@"Temporary"] objectForKey:@"WMStopWhenInactive"]) { |
|---|
| 357 | [buttonWMStopWhenInactive setState:NSOnState]; |
|---|
| 358 | } else { |
|---|
| 359 | [buttonWMStopWhenInactive setState:NSOffState]; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | /* Q Windows Drivers */ |
|---|
| 363 | if ([[thisPC objectForKey:@"Temporary"] objectForKey:@"QWinDrivers"]) { |
|---|
| 364 | [buttonQWinDrivers setState:NSOnState]; |
|---|
| 365 | } else { |
|---|
| 366 | [buttonQWinDrivers setState:NSOffState]; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | /* Platform */ |
|---|
| 370 | if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"x86"]) { |
|---|
| 371 | [popUpButtonCPU selectItemAtIndex:0]; |
|---|
| 372 | } else if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"x86-64"]) { |
|---|
| 373 | [popUpButtonCPU selectItemAtIndex:1]; |
|---|
| 374 | } else if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"PowerPC"] && [[[thisPC objectForKey:@"Temporary"] objectForKey:@"-M"] isEqual:@"prep"]) { |
|---|
| 375 | [popUpButtonCPU selectItemAtIndex:3]; |
|---|
| 376 | } else if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"PowerPC"]) { |
|---|
| 377 | [popUpButtonCPU selectItemAtIndex:2]; |
|---|
| 378 | } else if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"SPARC"]) { |
|---|
| 379 | [popUpButtonCPU selectItemAtIndex:4]; |
|---|
| 380 | } else if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"MIPS"]) { |
|---|
| 381 | [popUpButtonCPU selectItemAtIndex:5]; |
|---|
| 382 | } else if ([[[thisPC objectForKey:@"PC Data"] objectForKey:@"architecture"] isEqual:@"ARM"]) { |
|---|
| 383 | [popUpButtonCPU selectItemAtIndex:6]; |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | /* SMP */ |
|---|
| 387 | [popUpButtonSMP selectItemAtIndex:0]; |
|---|
| 388 | |
|---|
| 389 | /* reset Textfields */ |
|---|
| 390 | [textFieldAppend setStringValue:@""]; |
|---|
| 391 | |
|---|
| 392 | /* reset Buttons */ |
|---|
| 393 | [popUpButtonVGA selectItemAtIndex:0]; |
|---|
| 394 | [buttonEnableAdlib setState:NSOffState]; |
|---|
| 395 | [buttonEnableSB16 setState:NSOffState]; |
|---|
| 396 | [buttonEnableES1370 setState:NSOffState]; |
|---|
| 397 | [buttonEnableUSBTablet setState:NSOffState]; |
|---|
| 398 | [buttonLocaltime setState:NSOffState]; |
|---|
| 399 | [buttonNetNicNe2000 setState:NSOffState]; |
|---|
| 400 | [buttonNetNicRtl8139 setState:NSOffState]; |
|---|
| 401 | [buttonNetNicPcnet setState:NSOffState]; |
|---|
| 402 | [buttonNetUser setState:NSOffState]; |
|---|
| 403 | [buttonWin2kHack setState:NSOffState]; |
|---|
| 404 | [popUpButtonBoot selectItemAtIndex:1]; |
|---|
| 405 | |
|---|
| 406 | /* cleanup -smb */ |
|---|
| 407 | while(![[popUpButtonSmbFilesharing itemAtIndex:2] isSeparatorItem]) |
|---|
| 408 | [popUpButtonSmbFilesharing removeItemAtIndex:2]; |
|---|
| 409 | [popUpButtonSmbFilesharing selectItemAtIndex:0]; |
|---|
| 410 | |
|---|
| 411 | /* cleanup -fda */ |
|---|
| 412 | while(![[popUpButtonFda itemAtIndex:1] isSeparatorItem]) |
|---|
| 413 | [popUpButtonFda removeItemAtIndex:1]; |
|---|
| 414 | [popUpButtonFda selectItemAtIndex:0]; |
|---|
| 415 | |
|---|
| 416 | NSString *diskImageFile; |
|---|
| 417 | NSDirectoryEnumerator *directoryEnumerator; |
|---|
| 418 | |
|---|
| 419 | /* cleanup -hda and add Harddisks located in Package to Menu */ |
|---|
| 420 | while(![[popUpButtonHda itemAtIndex:1] isSeparatorItem]) |
|---|
| 421 | [popUpButtonHda removeItemAtIndex:1]; |
|---|
| 422 | if ([popUpButtonHda numberOfItems] > 8) { |
|---|
| 423 | while(![[popUpButtonHda itemAtIndex:2] isSeparatorItem]) |
|---|
| 424 | [popUpButtonHda removeItemAtIndex:2]; |
|---|
| 425 | } else { |
|---|
| 426 | [[popUpButtonHda menu] insertItem:[NSMenuItem separatorItem] atIndex:2]; |
|---|
| 427 | } |
|---|
| 428 | directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"]]; |
|---|
| 429 | while ((diskImageFile = [directoryEnumerator nextObject])) { |
|---|
| 430 | if ([FILE_TYPES containsObject:[diskImageFile pathExtension]]) |
|---|
| 431 | [popUpButtonHda insertItemWithTitle:[diskImageFile lastPathComponent] atIndex:2]; |
|---|
| 432 | } |
|---|
| 433 | if([[popUpButtonHda itemAtIndex:2] isSeparatorItem]) |
|---|
| 434 | [popUpButtonHda removeItemAtIndex:2]; |
|---|
| 435 | [popUpButtonHda selectItemAtIndex:0]; |
|---|
| 436 | |
|---|
| 437 | /* cleanup -hdb and add Harddisks located in Package to Menu */ |
|---|
| 438 | while(![[popUpButtonHdb itemAtIndex:1] isSeparatorItem]) |
|---|
| 439 | [popUpButtonHdb removeItemAtIndex:1]; |
|---|
| 440 | if ([popUpButtonHdb numberOfItems] > 8) { |
|---|
| 441 | while(![[popUpButtonHdb itemAtIndex:2] isSeparatorItem]) |
|---|
| 442 | [popUpButtonHdb removeItemAtIndex:2]; |
|---|
| 443 | } else { |
|---|
| 444 | [[popUpButtonHdb menu] insertItem:[NSMenuItem separatorItem] atIndex:2]; |
|---|
| 445 | } |
|---|
| 446 | directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"]]; |
|---|
| 447 | while ((diskImageFile = [directoryEnumerator nextObject])) { |
|---|
| 448 | if ([FILE_TYPES containsObject:[diskImageFile pathExtension]]) |
|---|
| 449 | [popUpButtonHdb insertItemWithTitle:[diskImageFile lastPathComponent] atIndex:2]; |
|---|
| 450 | } |
|---|
| 451 | if([[popUpButtonHdb itemAtIndex:2] isSeparatorItem]) |
|---|
| 452 | [popUpButtonHdb removeItemAtIndex:2]; |
|---|
| 453 | [popUpButtonHdb selectItemAtIndex:0]; |
|---|
| 454 | |
|---|
| 455 | /* cleanup -hdc and add Harddisks located in Package to Menu */ |
|---|
| 456 | while(![[popUpButtonHdc itemAtIndex:1] isSeparatorItem]) |
|---|
| 457 | [popUpButtonHdc removeItemAtIndex:1]; |
|---|
| 458 | if ([popUpButtonHdc numberOfItems] > 8) { |
|---|
| 459 | while(![[popUpButtonHdc itemAtIndex:2] isSeparatorItem]) |
|---|
| 460 | [popUpButtonHdc removeItemAtIndex:2]; |
|---|
| 461 | } else { |
|---|
| 462 | [[popUpButtonHdc menu] insertItem:[NSMenuItem separatorItem] atIndex:2]; |
|---|
| 463 | } |
|---|
| 464 | directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"]]; |
|---|
| 465 | while ((diskImageFile = [directoryEnumerator nextObject])) { |
|---|
| 466 | if ([FILE_TYPES containsObject:[diskImageFile pathExtension]]) |
|---|
| 467 | [popUpButtonHdc insertItemWithTitle:[diskImageFile lastPathComponent] atIndex:2]; |
|---|
| 468 | } |
|---|
| 469 | if([[popUpButtonHdc itemAtIndex:2] isSeparatorItem]) |
|---|
| 470 | [popUpButtonHdc removeItemAtIndex:2]; |
|---|
| 471 | [popUpButtonHdc selectItemAtIndex:0]; |
|---|
| 472 | |
|---|
| 473 | /* cleanup -hdd and add Harddisks located in Package to Menu */ |
|---|
| 474 | while(![[popUpButtonHdd itemAtIndex:1] isSeparatorItem]) |
|---|
| 475 | [popUpButtonHdd removeItemAtIndex:1]; |
|---|
| 476 | if ([popUpButtonHdd numberOfItems] > 8) { |
|---|
| 477 | while(![[popUpButtonHdd itemAtIndex:2] isSeparatorItem]) |
|---|
| 478 | [popUpButtonHdd removeItemAtIndex:2]; |
|---|
| 479 | } else { |
|---|
| 480 | [[popUpButtonHdd menu] insertItem:[NSMenuItem separatorItem] atIndex:2]; |
|---|
| 481 | } |
|---|
| 482 | directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"]]; |
|---|
| 483 | while ((diskImageFile = [directoryEnumerator nextObject])) { |
|---|
| 484 | if ([FILE_TYPES containsObject:[diskImageFile pathExtension]]) |
|---|
| 485 | [popUpButtonHdd insertItemWithTitle:[diskImageFile lastPathComponent] atIndex:2]; |
|---|
| 486 | } |
|---|
| 487 | if([[popUpButtonHdd itemAtIndex:2] isSeparatorItem]) |
|---|
| 488 | [popUpButtonHdd removeItemAtIndex:2]; |
|---|
| 489 | [popUpButtonHdd selectItemAtIndex:0]; |
|---|
| 490 | |
|---|
| 491 | /* cleanup -cdrom */ |
|---|
| 492 | while(![[popUpButtonCdrom itemAtIndex:2] isSeparatorItem]) |
|---|
| 493 | [popUpButtonCdrom removeItemAtIndex:2]; |
|---|
| 494 | [popUpButtonCdrom selectItemAtIndex:0]; |
|---|
| 495 | |
|---|
| 496 | /* cleanup -kernel */ |
|---|
| 497 | while(![[popUpButtonKernel itemAtIndex:1] isSeparatorItem]) |
|---|
| 498 | [popUpButtonKernel removeItemAtIndex:1]; |
|---|
| 499 | [popUpButtonKernel selectItemAtIndex:0]; |
|---|
| 500 | |
|---|
| 501 | /* cleanup -initrd */ |
|---|
| 502 | while(![[popUpButtonInitrd itemAtIndex:1] isSeparatorItem]) |
|---|
| 503 | [popUpButtonInitrd removeItemAtIndex:1]; |
|---|
| 504 | [popUpButtonInitrd selectItemAtIndex:0]; |
|---|
| 505 | |
|---|
| 506 | /* cleanup free qemu Arguments */ |
|---|
| 507 | [textFieldArguments setStringValue:@""]; |
|---|
| 508 | |
|---|
| 509 | /* init firewall configuration */ |
|---|
| 510 | [self initFirewallSettings]; |
|---|
| 511 | |
|---|
| 512 | /* Arguments of thisPC */ |
|---|
| 513 | NSArray *array = [[thisPC objectForKey:@"Arguments"] componentsSeparatedByString:@" "]; |
|---|
| 514 | NSMutableString *option = [[NSMutableString alloc] initWithString:@""]; |
|---|
| 515 | NSMutableString *argument = [[NSMutableString alloc] init]; |
|---|
| 516 | int i; |
|---|
| 517 | for (i = 0; i < [array count]; i++) { |
|---|
| 518 | if ([[array objectAtIndex:i] cString][0] != '-') { //Teil eines Arguments |
|---|
| 519 | [argument appendFormat:[NSString stringWithFormat:@" %@", [array objectAtIndex:i]]]; |
|---|
| 520 | } else { |
|---|
| 521 | if ([option length] > 0) { |
|---|
| 522 | if ([argument isEqual:@""]) { |
|---|
| 523 | [self setOption:option argument:@""]; |
|---|
| 524 | } else { |
|---|
| 525 | [self setOption:option argument:[argument substringFromIndex:1]]; |
|---|
| 526 | } |
|---|
| 527 | } |
|---|
| 528 | [option setString:[array objectAtIndex:i]]; |
|---|
| 529 | [argument setString:@""]; |
|---|
| 530 | } |
|---|
| 531 | } |
|---|
| 532 | if ([argument isEqual:@""]) { |
|---|
| 533 | [self setOption:option argument:@""]; |
|---|
| 534 | } else { |
|---|
| 535 | [self setOption:option argument:[argument substringFromIndex:1]]; |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | if (newPC) { |
|---|
| 539 | [buttonOk setTitle: NSLocalizedStringFromTable(@"prepareEditPCPanel:newPC", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 540 | } else { |
|---|
| 541 | [buttonOk setTitle: NSLocalizedStringFromTable(@"prepareEditPCPanel:updatePC", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | //Do not allow editing while PC is running |
|---|
| 545 | if (![[[thisPC objectForKey:@"PC Data"] objectForKey:@"state"] isEqual:@"shutdown"]) { |
|---|
| 546 | [buttonOk setEnabled:FALSE]; |
|---|
| 547 | } else { |
|---|
| 548 | [buttonOk setEnabled:TRUE]; |
|---|
| 549 | } |
|---|
| 550 | } |
|---|
| 551 | |
|---|
| 552 | -(void) awakeFromNib |
|---|
| 553 | { |
|---|
| 554 | // NSLog(@"cocoaControlEditPC: awakeFromNib"); |
|---|
| 555 | |
|---|
| 556 | NSToolbar *editPCPanelToolbar = [[[NSToolbar alloc] initWithIdentifier: @"editPCPanelToolbarIdentifier"] autorelease]; |
|---|
| 557 | [editPCPanelToolbar setAllowsUserCustomization: NO]; //allow customisation |
|---|
| 558 | [editPCPanelToolbar setAutosavesConfiguration: NO]; //autosave changes |
|---|
| 559 | [editPCPanelToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel]; //what is shown |
|---|
| 560 | [editPCPanelToolbar setSizeMode:NSToolbarSizeModeRegular]; //default Toolbar Size |
|---|
| 561 | [editPCPanelToolbar setDelegate: self]; // We are the delegate |
|---|
| 562 | [editPCPanel setToolbar: editPCPanelToolbar]; // Attach the toolbar to the document window |
|---|
| 563 | [firewallPortTable setDelegate:self]; |
|---|
| 564 | [firewallPortTable setDataSource:self]; |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | /* Toolbar Delegates*/ |
|---|
| 568 | - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted |
|---|
| 569 | { |
|---|
| 570 | NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdent] autorelease]; |
|---|
| 571 | |
|---|
| 572 | if ([itemIdent isEqual: @"general"]) { |
|---|
| 573 | [toolbarItem setLabel: NSLocalizedStringFromTable(@"toolbar:label:general", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 574 | [toolbarItem setPaletteLabel: NSLocalizedStringFromTable(@"toolbar:paletteLabel:general", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 575 | [toolbarItem setToolTip: NSLocalizedStringFromTable(@"toolbar:toolTip:general", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 576 | [toolbarItem setImage: [NSImage imageNamed: @"cocoa_tb_general.png"]]; |
|---|
| 577 | [toolbarItem setTarget: self]; |
|---|
| 578 | [toolbarItem setAction: @selector( viewGeneral: )]; |
|---|
| 579 | } else if ([itemIdent isEqual: @"hardware"]) { |
|---|
| 580 | [toolbarItem setLabel: NSLocalizedStringFromTable(@"toolbar:label:hardware", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 581 | [toolbarItem setPaletteLabel: NSLocalizedStringFromTable(@"toolbar:paletteLabel:hardware", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 582 | [toolbarItem setToolTip: NSLocalizedStringFromTable(@"toolbar:toolTip:hardware", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 583 | [toolbarItem setImage: [NSImage imageNamed: @"cocoa_tb_hardware.png"]]; |
|---|
| 584 | [toolbarItem setTarget: self]; |
|---|
| 585 | [toolbarItem setAction: @selector( viewHardware: )]; |
|---|
| 586 | } else if ([itemIdent isEqual: @"advanced"]) { |
|---|
| 587 | [toolbarItem setLabel: NSLocalizedStringFromTable(@"toolbar:label:advanced", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 588 | [toolbarItem setPaletteLabel: NSLocalizedStringFromTable(@"toolbar:paletteLabel:advanced", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 589 | [toolbarItem setToolTip: NSLocalizedStringFromTable(@"toolbar:toolTip:advanced", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 590 | [toolbarItem setImage: [NSImage imageNamed: @"cocoa_tb_advanced.png"]]; |
|---|
| 591 | [toolbarItem setTarget: self]; |
|---|
| 592 | [toolbarItem setAction: @selector( viewAdvanced: )]; |
|---|
| 593 | } else if ([itemIdent isEqual: @"network"]) { |
|---|
| 594 | [toolbarItem setLabel: NSLocalizedStringFromTable(@"toolbar:label:network", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 595 | [toolbarItem setPaletteLabel: NSLocalizedStringFromTable(@"toolbar:paletteLabel:network", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 596 | [toolbarItem setToolTip: NSLocalizedStringFromTable(@"toolbar:toolTip:network", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 597 | [toolbarItem setImage: [NSImage imageNamed: @"cocoa_tb_network.tiff"]]; |
|---|
| 598 | [toolbarItem setTarget: self]; |
|---|
| 599 | [toolbarItem setAction: @selector( viewNetwork: )]; |
|---|
| 600 | } else { |
|---|
| 601 | toolbarItem = nil; |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | return toolbarItem; |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar |
|---|
| 608 | { |
|---|
| 609 | return [NSArray arrayWithObjects: |
|---|
| 610 | @"general", |
|---|
| 611 | @"hardware", |
|---|
| 612 | @"network", |
|---|
| 613 | @"advanced", |
|---|
| 614 | nil]; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | - (NSArray *) toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar |
|---|
| 618 | { |
|---|
| 619 | return [NSArray arrayWithObjects: |
|---|
| 620 | @"general", |
|---|
| 621 | @"hardware", |
|---|
| 622 | @"network", |
|---|
| 623 | @"advanced", |
|---|
| 624 | nil]; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | - (NSArray *) toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar |
|---|
| 628 | { |
|---|
| 629 | return [NSArray arrayWithObjects: |
|---|
| 630 | @"general", |
|---|
| 631 | @"hardware", |
|---|
| 632 | @"network", |
|---|
| 633 | @"advanced", |
|---|
| 634 | nil]; |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | - (void) genericFolderSelectPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo |
|---|
| 638 | { |
|---|
| 639 | // NSLog(@"cocoaControlEditPC: genericFolderSelectPanelDidEnd"); |
|---|
| 640 | |
|---|
| 641 | /* hide Save Sheet */ |
|---|
| 642 | [ sheet orderOut:self ]; |
|---|
| 643 | |
|---|
| 644 | /* smbFilesharing */ |
|---|
| 645 | if ([[contextInfo menu] isEqual:[popUpButtonSmbFilesharing menu]]) { |
|---|
| 646 | if ( returnCode == NSOKButton ) { |
|---|
| 647 | if (![[popUpButtonSmbFilesharing itemAtIndex:2] isSeparatorItem]) |
|---|
| 648 | [popUpButtonSmbFilesharing removeItemAtIndex:2]; |
|---|
| 649 | [popUpButtonSmbFilesharing insertItemWithTitle:[sheet filename] atIndex:2]; |
|---|
| 650 | [popUpButtonSmbFilesharing selectItemAtIndex:2]; |
|---|
| 651 | } else { |
|---|
| 652 | [popUpButtonSmbFilesharing selectItemAtIndex:0]; |
|---|
| 653 | } |
|---|
| 654 | } |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | - (IBAction) genericFolderSelectPanel:(id)sender |
|---|
| 658 | { |
|---|
| 659 | // NSLog(@"cocoaControlEditPC: genericFolderSelectPanel"); |
|---|
| 660 | |
|---|
| 661 | NSOpenPanel *openPanel = [[NSOpenPanel alloc] init]; |
|---|
| 662 | [openPanel setCanChooseDirectories:YES]; |
|---|
| 663 | [openPanel setCanCreateDirectories:YES]; |
|---|
| 664 | [openPanel setCanChooseFiles:NO]; |
|---|
| 665 | [openPanel beginSheetForDirectory:nil |
|---|
| 666 | file:nil |
|---|
| 667 | types:nil |
|---|
| 668 | modalForWindow:editPCPanel |
|---|
| 669 | modalDelegate:self |
|---|
| 670 | didEndSelector:@selector(genericFolderSelectPanelDidEnd:returnCode:contextInfo:) |
|---|
| 671 | contextInfo:sender]; |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | - (void) genericImageSelectPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(id)contextInfo |
|---|
| 675 | { |
|---|
| 676 | // NSLog(@"cocoaControlEditPC: genericImageSelectPanelDidEnd"); |
|---|
| 677 | |
|---|
| 678 | /* hide Save Sheet */ |
|---|
| 679 | [ sheet orderOut:self ]; |
|---|
| 680 | |
|---|
| 681 | /* -fda */ |
|---|
| 682 | if ([[contextInfo menu] isEqual:[popUpButtonFda menu]]) { |
|---|
| 683 | if(returnCode == NSOKButton) { |
|---|
| 684 | if (![[popUpButtonFda itemAtIndex:1] isSeparatorItem]) |
|---|
| 685 | [popUpButtonFda removeItemAtIndex:1]; |
|---|
| 686 | [popUpButtonFda insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 687 | [popUpButtonFda selectItemAtIndex:1]; |
|---|
| 688 | } else { |
|---|
| 689 | [popUpButtonFda selectItemAtIndex:0]; |
|---|
| 690 | } |
|---|
| 691 | /* -hda */ |
|---|
| 692 | } else if ([[contextInfo menu] isEqual:[popUpButtonHda menu]]) { |
|---|
| 693 | if (returnCode == NSOKButton) { |
|---|
| 694 | if (![[popUpButtonHda itemAtIndex:1] isSeparatorItem]) |
|---|
| 695 | [popUpButtonHda removeItemAtIndex:1]; |
|---|
| 696 | [popUpButtonHda insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 697 | [popUpButtonHda selectItemAtIndex:1]; |
|---|
| 698 | } else { |
|---|
| 699 | [popUpButtonHda selectItemAtIndex:0]; |
|---|
| 700 | } |
|---|
| 701 | /* -hdb */ |
|---|
| 702 | } else if ([[contextInfo menu] isEqual:[popUpButtonHdb menu]]) { |
|---|
| 703 | if (returnCode == NSOKButton) { |
|---|
| 704 | if (![[popUpButtonHdb itemAtIndex:1] isSeparatorItem]) |
|---|
| 705 | [popUpButtonHdb removeItemAtIndex:1]; |
|---|
| 706 | [popUpButtonHdb insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 707 | [popUpButtonHdb selectItemAtIndex:1]; |
|---|
| 708 | } else { |
|---|
| 709 | [popUpButtonHdb selectItemAtIndex:0]; |
|---|
| 710 | } |
|---|
| 711 | /* -hdc */ |
|---|
| 712 | } else if ([[contextInfo menu] isEqual:[popUpButtonHdc menu]]) { |
|---|
| 713 | if (returnCode == NSOKButton) { |
|---|
| 714 | if (![[popUpButtonHdc itemAtIndex:1] isSeparatorItem]) |
|---|
| 715 | [popUpButtonHdc removeItemAtIndex:1]; |
|---|
| 716 | [popUpButtonHdc insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 717 | [popUpButtonHdc selectItemAtIndex:1]; |
|---|
| 718 | } else { |
|---|
| 719 | [popUpButtonHdc selectItemAtIndex:0]; |
|---|
| 720 | } |
|---|
| 721 | /* -hdd */ |
|---|
| 722 | } else if ([[contextInfo menu] isEqual:[popUpButtonHdd menu]]) { |
|---|
| 723 | if (returnCode == NSOKButton) { |
|---|
| 724 | if (![[popUpButtonHdd itemAtIndex:1] isSeparatorItem]) |
|---|
| 725 | [popUpButtonHdd removeItemAtIndex:1]; |
|---|
| 726 | [popUpButtonHdd insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 727 | [popUpButtonHdd selectItemAtIndex:1]; |
|---|
| 728 | } else { |
|---|
| 729 | [popUpButtonHdd selectItemAtIndex:0]; |
|---|
| 730 | } |
|---|
| 731 | /* -cdrom */ |
|---|
| 732 | } else if ([[contextInfo menu] isEqual:[popUpButtonCdrom menu]]) { |
|---|
| 733 | if (returnCode == NSOKButton) { |
|---|
| 734 | if (![[popUpButtonCdrom itemAtIndex:2] isSeparatorItem]) |
|---|
| 735 | [popUpButtonCdrom removeItemAtIndex:2]; |
|---|
| 736 | [popUpButtonCdrom insertItemWithTitle:[sheet filename] atIndex:2]; |
|---|
| 737 | [popUpButtonCdrom selectItemAtIndex:2]; |
|---|
| 738 | } else { |
|---|
| 739 | [popUpButtonCdrom selectItemAtIndex:0]; |
|---|
| 740 | } |
|---|
| 741 | /* -kernel */ |
|---|
| 742 | } else if ([[contextInfo menu] isEqual:[popUpButtonKernel menu]]) { |
|---|
| 743 | if(returnCode == NSOKButton) { |
|---|
| 744 | if (![[popUpButtonKernel itemAtIndex:1] isSeparatorItem]) |
|---|
| 745 | [popUpButtonKernel removeItemAtIndex:1]; |
|---|
| 746 | [popUpButtonKernel insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 747 | [popUpButtonKernel selectItemAtIndex:1]; |
|---|
| 748 | } else { |
|---|
| 749 | [popUpButtonKernel selectItemAtIndex:0]; |
|---|
| 750 | } |
|---|
| 751 | /* -initrd */ |
|---|
| 752 | } else if ([[contextInfo menu] isEqual:[popUpButtonInitrd menu]]) { |
|---|
| 753 | if(returnCode == NSOKButton) { |
|---|
| 754 | if (![[popUpButtonInitrd itemAtIndex:1] isSeparatorItem]) |
|---|
| 755 | [popUpButtonInitrd removeItemAtIndex:1]; |
|---|
| 756 | [popUpButtonInitrd insertItemWithTitle:[sheet filename] atIndex:1]; |
|---|
| 757 | [popUpButtonInitrd selectItemAtIndex:1]; |
|---|
| 758 | } else { |
|---|
| 759 | [popUpButtonInitrd selectItemAtIndex:0]; |
|---|
| 760 | } |
|---|
| 761 | } |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | - (IBAction) genericImageSelectPanel:(id)sender |
|---|
| 765 | { |
|---|
| 766 | // NSLog(@"cocoaControlEditPC: genericImageSelectPanel"); |
|---|
| 767 | |
|---|
| 768 | NSOpenPanel *openPanel = [[NSOpenPanel alloc] init]; |
|---|
| 769 | [openPanel beginSheetForDirectory:nil |
|---|
| 770 | file:nil |
|---|
| 771 | types:FILE_TYPES |
|---|
| 772 | modalForWindow:editPCPanel |
|---|
| 773 | modalDelegate:self |
|---|
| 774 | didEndSelector:@selector(genericImageSelectPanelDidEnd:returnCode:contextInfo:) |
|---|
| 775 | contextInfo:sender]; |
|---|
| 776 | } |
|---|
| 777 | |
|---|
| 778 | /* dIWindow */ |
|---|
| 779 | - (IBAction) menuItemNewImage:(id)sender |
|---|
| 780 | { |
|---|
| 781 | // NSLog(@"cocoaControlEditPC: menuItemNewImage"); |
|---|
| 782 | |
|---|
| 783 | cocoaControlDiskImage *dI = [[cocoaControlDiskImage alloc] init]; |
|---|
| 784 | [NSBundle loadNibNamed:@"cocoaControlDiskImage" owner:dI]; |
|---|
| 785 | [dI setQSender:self]; |
|---|
| 786 | |
|---|
| 787 | [NSApp beginSheet:[dI dIWindow] |
|---|
| 788 | modalForWindow:editPCPanel |
|---|
| 789 | modalDelegate:dI |
|---|
| 790 | didEndSelector:@selector(dIPanelDidEnd:returnCode:contextInfo:) |
|---|
| 791 | contextInfo:nil]; |
|---|
| 792 | |
|---|
| 793 | if ([[popUpButtonHda menu]isEqual:[sender menu]]) { |
|---|
| 794 | customImagePopUpButtonTemp = popUpButtonHda; |
|---|
| 795 | } else if ([[popUpButtonHdb menu]isEqual:[sender menu]]) { |
|---|
| 796 | customImagePopUpButtonTemp = popUpButtonHdb; |
|---|
| 797 | } else if ([[popUpButtonHdc menu]isEqual:[sender menu]]) { |
|---|
| 798 | customImagePopUpButtonTemp = popUpButtonHdc; |
|---|
| 799 | } else if ([[popUpButtonHdd menu]isEqual:[sender menu]]) { |
|---|
| 800 | customImagePopUpButtonTemp = popUpButtonHdd; |
|---|
| 801 | } |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | - (void) setCustomDIType:(NSString *)string size:(int)size |
|---|
| 805 | { |
|---|
| 806 | // NSLog(@"cocoaControlEditPC: setCustomDIType"); |
|---|
| 807 | |
|---|
| 808 | if (![[customImagePopUpButtonTemp itemAtIndex:1] isSeparatorItem]) |
|---|
| 809 | [customImagePopUpButtonTemp removeItemAtIndex:1]; |
|---|
| 810 | [customImagePopUpButtonTemp insertItemWithTitle:[NSString stringWithFormat:@"%@: %dMB %@", NSLocalizedStringFromTable(@"setCustomDIType:title", @"Localizable", @"cocoaControlEditPC"), size, string] atIndex:1]; |
|---|
| 811 | [customImagePopUpButtonTemp selectItemAtIndex:1]; |
|---|
| 812 | |
|---|
| 813 | if ([customImagePopUpButtonTemp isEqual:popUpButtonHda]) { |
|---|
| 814 | customImageSizeHda = size; |
|---|
| 815 | if (customImageTypeHda) |
|---|
| 816 | [customImageTypeHda release]; |
|---|
| 817 | customImageTypeHda = [[NSString alloc] initWithString:string]; |
|---|
| 818 | } else if ([customImagePopUpButtonTemp isEqual:popUpButtonHdb]) { |
|---|
| 819 | customImageSizeHdb = size; |
|---|
| 820 | if (customImageTypeHdb) |
|---|
| 821 | [customImageTypeHdb release]; |
|---|
| 822 | customImageTypeHdb = [[NSString alloc] initWithString:string]; |
|---|
| 823 | } else if ([customImagePopUpButtonTemp isEqual:popUpButtonHdc]) { |
|---|
| 824 | customImageSizeHdc = size; |
|---|
| 825 | if (customImageTypeHdc) |
|---|
| 826 | [customImageTypeHdc release]; |
|---|
| 827 | customImageTypeHdc = [[NSString alloc] initWithString:string]; |
|---|
| 828 | } else if ([customImagePopUpButtonTemp isEqual:popUpButtonHdd]) { |
|---|
| 829 | customImageSizeHdd = size; |
|---|
| 830 | if (customImageTypeHdd) |
|---|
| 831 | [customImageTypeHdd release]; |
|---|
| 832 | customImageTypeHdd = [[NSString alloc] initWithString:string]; |
|---|
| 833 | } |
|---|
| 834 | } |
|---|
| 835 | |
|---|
| 836 | - (IBAction) closeEditPCPanel:(id)sender |
|---|
| 837 | { |
|---|
| 838 | // NSLog(@"cocoaControlEditPC: closeEditPCPanel"); |
|---|
| 839 | |
|---|
| 840 | [NSApp stopModal]; |
|---|
| 841 | [editPCPanel close]; |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | - (IBAction) editPCEditPCPanel:(id)sender; |
|---|
| 846 | { |
|---|
| 847 | // NSLog(@"cocoaControlEditPC: editPCEditPCPanel"); |
|---|
| 848 | |
|---|
| 849 | /* Check data */ |
|---|
| 850 | [textFieldName setTextColor:[NSColor blackColor]]; |
|---|
| 851 | [textFieldRAM setTextColor:[NSColor blackColor]]; |
|---|
| 852 | |
|---|
| 853 | /* no empty PC Name */ |
|---|
| 854 | if ([[textFieldName stringValue] isEqual:@""]) { |
|---|
| 855 | [textFieldName setStringValue: NSLocalizedStringFromTable(@"editPCEditPCPanel:name", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 856 | [textFieldName setTextColor:[NSColor redColor]]; |
|---|
| 857 | return; |
|---|
| 858 | } |
|---|
| 859 | |
|---|
| 860 | /* no ":", ".", "/" in Names */ |
|---|
| 861 | int i,ii; |
|---|
| 862 | unichar tChar; |
|---|
| 863 | BOOL checkOK = 1; |
|---|
| 864 | NSString *tForbidden = [NSString stringWithString:@":./"]; |
|---|
| 865 | NSString *tName = [NSString stringWithString:[textFieldName stringValue]]; |
|---|
| 866 | for (i = 0; i < [tName length]; i++) { |
|---|
| 867 | tChar = [tName characterAtIndex:i]; |
|---|
| 868 | for (ii=0; ii < [tForbidden length]; ii++) { |
|---|
| 869 | if (tChar == [tForbidden characterAtIndex:ii]) |
|---|
| 870 | checkOK = 0; |
|---|
| 871 | } |
|---|
| 872 | } |
|---|
| 873 | if (!checkOK) { |
|---|
| 874 | [textFieldName setStringValue: NSLocalizedStringFromTable(@"editPCEditPCPanel:charName", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 875 | [textFieldName setTextColor:[NSColor redColor]]; |
|---|
| 876 | return; |
|---|
| 877 | } |
|---|
| 878 | |
|---|
| 879 | /* no double PC Name */ |
|---|
| 880 | if ( [[buttonOk title] isEqualTo: NSLocalizedStringFromTable(@"prepareEditPCPanel:newPC", @"Localizable", @"cocoaControlEditPC")]) { |
|---|
| 881 | if ( ![qSender checkPC:thisPC name:[textFieldName stringValue] create:YES] ) { |
|---|
| 882 | [textFieldName setStringValue: NSLocalizedStringFromTable(@"prepareEditPCPanel:otherName", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 883 | [textFieldName setTextColor:[NSColor redColor]]; |
|---|
| 884 | return; |
|---|
| 885 | } |
|---|
| 886 | } else { |
|---|
| 887 | if ( ![qSender checkPC:thisPC name:[textFieldName stringValue] create:NO] ) { |
|---|
| 888 | [textFieldName setStringValue: NSLocalizedStringFromTable(@"prepareEditPCPanel:otherName", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 889 | [textFieldName setTextColor:[NSColor redColor]]; |
|---|
| 890 | return; |
|---|
| 891 | } |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | /* no 0 mb RAM */ |
|---|
| 895 | if ( [textFieldRAM intValue] < 1 ) { |
|---|
| 896 | [textFieldRAM setStringValue:@"0"]; |
|---|
| 897 | [textFieldRAM setTextColor:[NSColor redColor]]; |
|---|
| 898 | return; |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | /* prepare Files */ |
|---|
| 902 | NSFileManager *fileManager = [NSFileManager defaultManager]; |
|---|
| 903 | /* creating files if PC is new */ |
|---|
| 904 | if ([[buttonOk title] isEqualTo: NSLocalizedStringFromTable(@"prepareEditPCPanel:newPC", @"Localizable", @"cocoaControlEditPC")]) { |
|---|
| 905 | if ([fileManager fileExistsAtPath: [NSString stringWithFormat:@"%@/%@.qvm", [userDefaults objectForKey:@"dataPath"], [textFieldName stringValue]]] == NO) |
|---|
| 906 | [fileManager createDirectoryAtPath: [NSString stringWithFormat:@"%@/%@.qvm", [userDefaults objectForKey:@"dataPath"], [textFieldName stringValue]] attributes: nil]; |
|---|
| 907 | /* moving files if PC was renamed */ |
|---|
| 908 | } else { |
|---|
| 909 | if ([fileManager fileExistsAtPath:[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"]]) |
|---|
| 910 | [fileManager movePath:[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"] toPath:[NSString stringWithFormat:@"%@/%@.qvm", [[[thisPC objectForKey:@"Temporary"] objectForKey:@"-cocoapath"] stringByDeletingLastPathComponent], [textFieldName stringValue]] handler:nil]; |
|---|
| 911 | } |
|---|
| 912 | [[thisPC objectForKey:@"Temporary"] setObject:[NSString stringWithFormat:@"%@/%@.qvm", [userDefaults objectForKey:@"dataPath"], [textFieldName stringValue]] forKey:@"-cocoapath"]; |
|---|
| 913 | |
|---|
| 914 | /* cleanup Dics */ |
|---|
| 915 | [[thisPC objectForKey:@"Arguments"] setString:@""]; |
|---|
| 916 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"-cocoaquickdraw"]; |
|---|
| 917 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"QWinDrivers"]; |
|---|
| 918 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"WMStopWhenInactive"]; |
|---|
| 919 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"-m"]; |
|---|
| 920 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"-M"]; |
|---|
| 921 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"-soundhw"]; |
|---|
| 922 | [[thisPC objectForKey:@"Temporary"] removeObjectForKey:@"-smp"]; |
|---|
| 923 | |
|---|
| 924 | /* setting Settings :) */ |
|---|
| 925 | [[thisPC objectForKey:@"PC Data"] setObject:[textFieldName stringValue] forKey:@"name"]; |
|---|
| 926 | |
|---|
| 927 | /* WMStopWhenInactive */ |
|---|
| 928 | if ([buttonWMStopWhenInactive state] == NSOnState) |
|---|
| 929 | [[thisPC objectForKey:@"Temporary"] setObject:[NSNumber numberWithBool:true] forKey:@"WMStopWhenInactive"]; |
|---|
| 930 | |
|---|
| 931 | /* Q Windows Drivers */ |
|---|
| 932 | if ([buttonQWinDrivers state] == NSOnState) |
|---|
| 933 | [[thisPC objectForKey:@"Temporary"] setObject:[NSNumber numberWithBool:true] forKey:@"QWinDrivers"]; |
|---|
| 934 | |
|---|
| 935 | /* platform */ |
|---|
| 936 | switch ([popUpButtonCPU indexOfSelectedItem]) { |
|---|
| 937 | case 0: |
|---|
| 938 | [[thisPC objectForKey:@"PC Data"] setObject:@"x86" forKey:@"architecture"]; |
|---|
| 939 | break; |
|---|
| 940 | case 1: |
|---|
| 941 | [[thisPC objectForKey:@"PC Data"] setObject:@"x86-64" forKey:@"architecture"]; |
|---|
| 942 | break; |
|---|
| 943 | case 2: |
|---|
| 944 | [[thisPC objectForKey:@"PC Data"] setObject:@"PowerPC" forKey:@"architecture"]; |
|---|
| 945 | break; |
|---|
| 946 | case 3: |
|---|
| 947 | [[thisPC objectForKey:@"PC Data"] setObject:@"PowerPC" forKey:@"architecture"]; |
|---|
| 948 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -M prep"]]; |
|---|
| 949 | break; |
|---|
| 950 | case 4: |
|---|
| 951 | [[thisPC objectForKey:@"PC Data"] setObject:@"SPARC" forKey:@"architecture"]; |
|---|
| 952 | break; |
|---|
| 953 | case 5: |
|---|
| 954 | [[thisPC objectForKey:@"PC Data"] setObject:@"MIPS" forKey:@"architecture"]; |
|---|
| 955 | break; |
|---|
| 956 | case 6: |
|---|
| 957 | [[thisPC objectForKey:@"PC Data"] setObject:@"ARM" forKey:@"architecture"]; |
|---|
| 958 | break; |
|---|
| 959 | } |
|---|
| 960 | |
|---|
| 961 | /* -smp */ |
|---|
| 962 | if([popUpButtonSMP indexOfSelectedItem] > 0) |
|---|
| 963 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -smp %D", (int)ceil(pow(2.0, (double)[popUpButtonSMP indexOfSelectedItem]))]]; |
|---|
| 964 | |
|---|
| 965 | /* -m */ |
|---|
| 966 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -m %D", [textFieldRAM intValue]]]; |
|---|
| 967 | |
|---|
| 968 | /* VGA */ |
|---|
| 969 | if ([popUpButtonVGA indexOfSelectedItem] == 1) { |
|---|
| 970 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -std-vga"]]; |
|---|
| 971 | } |
|---|
| 972 | |
|---|
| 973 | /* -soundhw */ |
|---|
| 974 | NSMutableArray *soundhw = [NSMutableArray arrayWithCapacity:4]; |
|---|
| 975 | if ([buttonEnableAdlib state] == NSOnState) |
|---|
| 976 | [soundhw addObject:@"adlib"]; |
|---|
| 977 | if ([buttonEnableSB16 state] == NSOnState) |
|---|
| 978 | [soundhw addObject:@"sb16"]; |
|---|
| 979 | if ([buttonEnableES1370 state] == NSOnState) |
|---|
| 980 | [soundhw addObject:@"es1370"]; |
|---|
| 981 | if ([soundhw count] > 0) |
|---|
| 982 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -soundhw %@", [soundhw componentsJoinedByString:@","]]]; |
|---|
| 983 | |
|---|
| 984 | /* -localtime */ |
|---|
| 985 | if ([buttonLocaltime state] == NSOnState) |
|---|
| 986 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -localtime"]]; |
|---|
| 987 | |
|---|
| 988 | /* -usbdevice */ |
|---|
| 989 | if ([buttonEnableUSBTablet state] == NSOnState) { |
|---|
| 990 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -usbdevice tablet"]]; |
|---|
| 991 | } |
|---|
| 992 | |
|---|
| 993 | /* -net */ |
|---|
| 994 | if ([buttonNetNicNe2000 state] == NSOnState) { |
|---|
| 995 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -net nic"]]; |
|---|
| 996 | } |
|---|
| 997 | if ([buttonNetNicRtl8139 state] == NSOnState) { |
|---|
| 998 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -net nic,model=rtl8139"]]; |
|---|
| 999 | } |
|---|
| 1000 | if ([buttonNetNicPcnet state] == NSOnState) { |
|---|
| 1001 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -net nic,model=pcnet"]]; |
|---|
| 1002 | } |
|---|
| 1003 | if ([buttonNetUser state] == NSOnState) { |
|---|
| 1004 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -net user"]]; |
|---|
| 1005 | } |
|---|
| 1006 | |
|---|
| 1007 | /* -smb */ |
|---|
| 1008 | if ([popUpButtonSmbFilesharing indexOfSelectedItem] == 1) { |
|---|
| 1009 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -smb ~/Desktop/Q Shared Files/"]]; |
|---|
| 1010 | } else if ([popUpButtonSmbFilesharing indexOfSelectedItem] == 2) { |
|---|
| 1011 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -smb %@", [popUpButtonSmbFilesharing titleOfSelectedItem]]]; |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | /* -fda */ |
|---|
| 1015 | if ([popUpButtonFda indexOfSelectedItem] == 1) { |
|---|
| 1016 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -fda %@", [popUpButtonFda titleOfSelectedItem]]]; |
|---|
| 1017 | } |
|---|
| 1018 | |
|---|
| 1019 | /* -hda */ |
|---|
| 1020 | if ([popUpButtonHda indexOfSelectedItem] > 0) { |
|---|
| 1021 | if ([popUpButtonHda indexOfSelectedItem] == [popUpButtonHda indexOfItemWithTag:200]) { |
|---|
| 1022 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hda %@", [self createDI:@"qcow2" withSize:10]]]; |
|---|
| 1023 | } else if ([popUpButtonHda indexOfSelectedItem] == [popUpButtonHda indexOfItemWithTag:201]) { |
|---|
| 1024 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hda %@", [self createDI:@"qcow2" withSize:100]]]; |
|---|
| 1025 | } else if ([popUpButtonHda indexOfSelectedItem] == [popUpButtonHda indexOfItemWithTag:202]) { |
|---|
| 1026 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hda %@", [self createDI:@"qcow2" withSize:4000]]]; |
|---|
| 1027 | } else if ([popUpButtonHda indexOfSelectedItem] == [popUpButtonHda indexOfItemWithTag:203]) { |
|---|
| 1028 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hda %@", [self createDI:@"raw" withSize:4000]]]; |
|---|
| 1029 | } else if ([[popUpButtonHda titleOfSelectedItem] rangeOfString: NSLocalizedStringFromTable(@"setCustomDIType:title", @"Localizable", @"cocoaControlEditPC")].location != NSNotFound) { |
|---|
| 1030 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hda %@", [self createDI:customImageTypeHda withSize:customImageSizeHda]]]; |
|---|
| 1031 | } else { |
|---|
| 1032 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hda %@", [popUpButtonHda titleOfSelectedItem]]]; |
|---|
| 1033 | } |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | /* -hdb */ |
|---|
| 1037 | if ([popUpButtonHdb indexOfSelectedItem] > 0) { |
|---|
| 1038 | if ([popUpButtonHdb indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:200]) { |
|---|
| 1039 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdb %@", [self createDI:@"qcow2" withSize:10]]]; |
|---|
| 1040 | } else if ([popUpButtonHdb indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:201]) { |
|---|
| 1041 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdb %@", [self createDI:@"qcow2" withSize:100]]]; |
|---|
| 1042 | } else if ([popUpButtonHdb indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:202]) { |
|---|
| 1043 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdb %@", [self createDI:@"qcow2" withSize:4000]]]; |
|---|
| 1044 | } else if ([popUpButtonHdb indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:203]) { |
|---|
| 1045 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdb %@", [self createDI:@"raw" withSize:4000]]]; |
|---|
| 1046 | } else if ([[popUpButtonHdb titleOfSelectedItem] rangeOfString:@"Custom Image:"].location != NSNotFound) { |
|---|
| 1047 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdb %@", [self createDI:customImageTypeHdb withSize:customImageSizeHdb]]]; |
|---|
| 1048 | } else { |
|---|
| 1049 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdb %@", [popUpButtonHdb titleOfSelectedItem]]]; |
|---|
| 1050 | } |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | /* -hdc */ |
|---|
| 1054 | if ([popUpButtonHdc indexOfSelectedItem] > 0) { |
|---|
| 1055 | if ([popUpButtonHdc indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:200]) { |
|---|
| 1056 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdc %@", [self createDI:@"qcow2" withSize:10]]]; |
|---|
| 1057 | } else if ([popUpButtonHdc indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:201]) { |
|---|
| 1058 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdc %@", [self createDI:@"qcow2" withSize:100]]]; |
|---|
| 1059 | } else if ([popUpButtonHdc indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:202]) { |
|---|
| 1060 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdc %@", [self createDI:@"qcow2" withSize:4000]]]; |
|---|
| 1061 | } else if ([popUpButtonHdc indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:203]) { |
|---|
| 1062 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdc %@", [self createDI:@"raw" withSize:4000]]]; |
|---|
| 1063 | } else if ([[popUpButtonHdc titleOfSelectedItem] rangeOfString:@"Custom Image:"].location != NSNotFound) { |
|---|
| 1064 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdc %@", [self createDI:customImageTypeHdc withSize:customImageSizeHdc]]]; |
|---|
| 1065 | } else { |
|---|
| 1066 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdc %@", [popUpButtonHdc titleOfSelectedItem]]]; |
|---|
| 1067 | } |
|---|
| 1068 | } |
|---|
| 1069 | |
|---|
| 1070 | /* -hdd */ |
|---|
| 1071 | if ([popUpButtonHdd indexOfSelectedItem] > 0) { |
|---|
| 1072 | if ([popUpButtonHdd indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:200]) { |
|---|
| 1073 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdd %@", [self createDI:@"qcow2" withSize:10]]]; |
|---|
| 1074 | } else if ([popUpButtonHdd indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:201]) { |
|---|
| 1075 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdd %@", [self createDI:@"qcow2" withSize:100]]]; |
|---|
| 1076 | } else if ([popUpButtonHdd indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:202]) { |
|---|
| 1077 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdd %@", [self createDI:@"qcow2" withSize:4000]]]; |
|---|
| 1078 | } else if ([popUpButtonHdd indexOfSelectedItem] == [popUpButtonHdb indexOfItemWithTag:203]) { |
|---|
| 1079 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdd %@", [self createDI:@"raw" withSize:4000]]]; |
|---|
| 1080 | } else if ([[popUpButtonHdd titleOfSelectedItem] rangeOfString:@"Custom Image:"].location != NSNotFound) { |
|---|
| 1081 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdd %@", [self createDI:customImageTypeHdd withSize:customImageSizeHdd]]]; |
|---|
| 1082 | } else { |
|---|
| 1083 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -hdd %@", [popUpButtonHdd titleOfSelectedItem]]]; |
|---|
| 1084 | } |
|---|
| 1085 | } |
|---|
| 1086 | |
|---|
| 1087 | /* -cdrom */ |
|---|
| 1088 | if ([popUpButtonCdrom indexOfSelectedItem] == 1) { |
|---|
| 1089 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -cdrom /dev/cdrom"]]; |
|---|
| 1090 | } else if ([popUpButtonCdrom indexOfSelectedItem] == 2) { |
|---|
| 1091 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -cdrom %@", [popUpButtonCdrom titleOfSelectedItem]]]; |
|---|
| 1092 | } |
|---|
| 1093 | |
|---|
| 1094 | /* -boot */ |
|---|
| 1095 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -boot %C", [@"acd" characterAtIndex:[popUpButtonBoot indexOfSelectedItem]]]]; |
|---|
| 1096 | |
|---|
| 1097 | /* -win2k-hack */ |
|---|
| 1098 | if ([buttonWin2kHack state] == NSOnState) |
|---|
| 1099 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -win2k-hack"]]; |
|---|
| 1100 | |
|---|
| 1101 | /* -kernel */ |
|---|
| 1102 | if ([popUpButtonKernel indexOfSelectedItem] == 1) { |
|---|
| 1103 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -kernel %@", [popUpButtonKernel titleOfSelectedItem]]]; |
|---|
| 1104 | } |
|---|
| 1105 | |
|---|
| 1106 | /* -append */ |
|---|
| 1107 | if (![[textFieldAppend stringValue] isEqual:@""]) |
|---|
| 1108 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -append %@", [textFieldAppend stringValue]]]; |
|---|
| 1109 | |
|---|
| 1110 | /* -initrd */ |
|---|
| 1111 | if ([popUpButtonInitrd indexOfSelectedItem] == 1) { |
|---|
| 1112 | [[thisPC objectForKey:@"Arguments"] appendFormat:[NSString stringWithFormat:@" -initrd %@", [popUpButtonInitrd titleOfSelectedItem]]]; |
|---|
| 1113 | } |
|---|
| 1114 | |
|---|
| 1115 | /* -redir */ |
|---|
| 1116 | // first save to configuration.plist, then add to arguments |
|---|
| 1117 | [self saveFirewallPortList]; |
|---|
| 1118 | [[thisPC objectForKey:@"Arguments"] appendFormat:@"%@",[self constructFirewallArguments]]; |
|---|
| 1119 | |
|---|
| 1120 | |
|---|
| 1121 | /* qemu arguments */ |
|---|
| 1122 | if ([[textFieldArguments stringValue] length] > 0) |
|---|
| 1123 | [[thisPC objectForKey:@"Arguments"] appendFormat:@" %@",[textFieldArguments stringValue]]; |
|---|
| 1124 | |
|---|
| 1125 | /* save PC */ |
|---|
| 1126 | [qSender savePCConfiguration:thisPC]; |
|---|
| 1127 | [qSender loadConfigurations]; |
|---|
| 1128 | |
|---|
| 1129 | /* cleanup */ |
|---|
| 1130 | [thisPC release]; |
|---|
| 1131 | |
|---|
| 1132 | /* hide sheet */ |
|---|
| 1133 | [NSApp stopModal]; |
|---|
| 1134 | [editPCPanel close]; |
|---|
| 1135 | } |
|---|
| 1136 | |
|---|
| 1137 | - (IBAction) showHelp:(id)sender |
|---|
| 1138 | { |
|---|
| 1139 | // NSLog(@"cocoaControlEditPC: showHelp"); |
|---|
| 1140 | |
|---|
| 1141 | AHGotoPage (CFSTR("Q Help"), CFSTR("html/editPC.html"), nil); |
|---|
| 1142 | } |
|---|
| 1143 | |
|---|
| 1144 | - (NSString *) createDI:(NSString *)type withSize:(int)size |
|---|
| 1145 | { |
|---|
| 1146 | // NSLog(@"cocoaControlEditPC: createDI"); |
|---|
| 1147 | |
|---|
| 1148 | /* search a free Name */ |
|---|
| 1149 | int i = 1; |
|---|
| 1150 | NSString *name; |
|---|
| 1151 | NSString *path = [NSString stringWithFormat:@"%@/%@.qvm", [userDefaults objectForKey:@"dataPath"], [textFieldName stringValue]]; |
|---|
| 1152 | NSFileManager *fileManager = [NSFileManager defaultManager]; |
|---|
| 1153 | |
|---|
| 1154 | while ([fileManager fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", path, [NSString stringWithFormat:@"Harddisk_%d.%@", i, type]]]) |
|---|
| 1155 | i++; |
|---|
| 1156 | name = [NSString stringWithFormat:@"Harddisk_%d.%@", i, type]; |
|---|
| 1157 | |
|---|
| 1158 | /* create diskImage */ |
|---|
| 1159 | NSArray *arguments = [NSArray arrayWithObjects:@"create",@"-f", type, [NSString stringWithFormat:@"%@/%@", path, name], [NSString stringWithFormat:@"%dM", size], nil]; |
|---|
| 1160 | NSTask *task; |
|---|
| 1161 | task = [[NSTask alloc] init]; |
|---|
| 1162 | [task setLaunchPath: [NSString stringWithFormat:@"%@/MacOS/qemu-img", [[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]]]; |
|---|
| 1163 | [task setArguments: arguments]; |
|---|
| 1164 | [task launch]; |
|---|
| 1165 | [task waitUntilExit]; |
|---|
| 1166 | [task release]; |
|---|
| 1167 | |
|---|
| 1168 | return name; |
|---|
| 1169 | } |
|---|
| 1170 | |
|---|
| 1171 | /* Network Methods */ |
|---|
| 1172 | /* Firewall Port Tableview Delegates */ |
|---|
| 1173 | |
|---|
| 1174 | - (int)numberOfRowsInTableView:(NSTableView *)tableView |
|---|
| 1175 | { |
|---|
| 1176 | return [firewallPortList count]; |
|---|
| 1177 | } |
|---|
| 1178 | |
|---|
| 1179 | - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row |
|---|
| 1180 | { |
|---|
| 1181 | id thisPort; |
|---|
| 1182 | thisPort = [firewallPortList objectAtIndex:row]; |
|---|
| 1183 | |
|---|
| 1184 | if ([[tableColumn identifier] isEqualToString:@"status"]) { |
|---|
| 1185 | return [thisPort objectForKey:@"Enabled"]; |
|---|
| 1186 | } else if ([[tableColumn identifier] isEqualToString:@"name"]) { |
|---|
| 1187 | return [thisPort objectForKey:@"Name"]; |
|---|
| 1188 | } else { |
|---|
| 1189 | return @""; |
|---|
| 1190 | } |
|---|
| 1191 | return nil; |
|---|
| 1192 | } |
|---|
| 1193 | |
|---|
| 1194 | // for setting the checkbox status to the configuration file |
|---|
| 1195 | - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)theValue forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex |
|---|
| 1196 | { |
|---|
| 1197 | if([[aTableColumn identifier] isEqualToString:@"status"]) { |
|---|
| 1198 | // set the new "enabled" status in firewallPortList |
|---|
| 1199 | [[firewallPortList objectAtIndex:rowIndex] setObject:theValue forKey:@"Enabled"]; |
|---|
| 1200 | // calls table reloadData automatically |
|---|
| 1201 | } |
|---|
| 1202 | } |
|---|
| 1203 | |
|---|
| 1204 | - (void)initFirewallSettings |
|---|
| 1205 | { |
|---|
| 1206 | //NSLog(@"cocoaControlEditPC: initFirewallSettings"); |
|---|
| 1207 | firewallPortTableEnabled = YES; |
|---|
| 1208 | if(firewallPortList == nil) { |
|---|
| 1209 | firewallPortList = [[[NSMutableArray alloc] init] retain]; |
|---|
| 1210 | } else { |
|---|
| 1211 | [firewallPortList removeAllObjects]; |
|---|
| 1212 | } |
|---|
| 1213 | // load defaults into array |
|---|
| 1214 | NSArray * firewallDefaults = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-defaults" ofType:@"plist"]]; |
|---|
| 1215 | NSMutableArray * tempArray = [NSMutableArray arrayWithCapacity:5]; |
|---|
| 1216 | [firewallPortList addObjectsFromArray:firewallDefaults]; |
|---|
| 1217 | // load customs from thisPC |
|---|
| 1218 | if([[thisPC objectForKey:@"Network"] objectForKey:@"Redirect"]) { |
|---|
| 1219 | // enumerate through entries and check for defaults |
|---|
| 1220 | int i; |
|---|
| 1221 | int ii; |
|---|
| 1222 | int found = 0; |
|---|
| 1223 | for(i=0; i<[[[thisPC objectForKey:@"Network"] objectForKey:@"Redirect"] count]; i++) { |
|---|
| 1224 | for(ii=0; ii<[firewallPortList count]; ii++) { |
|---|
| 1225 | if([[[[[thisPC objectForKey:@"Network"] objectForKey:@"Redirect"] objectAtIndex:i] objectForKey:@"Name"] isEqualTo:[[firewallDefaults objectAtIndex:ii] objectForKey:@"Name"]]) { |
|---|
| 1226 | // found equal entry in customs, set enabled status in firewallPortList |
|---|
| 1227 | [[firewallPortList objectAtIndex:ii] setObject:[NSNumber numberWithBool:YES] forKey:@"Enabled"]; |
|---|
| 1228 | found = 1; |
|---|
| 1229 | } |
|---|
| 1230 | } |
|---|
| 1231 | // check if previously found |
|---|
| 1232 | if(found == 0) { |
|---|
| 1233 | // not found, add entry to firewallPortList |
|---|
| 1234 | [tempArray addObject:[[[thisPC objectForKey:@"Network"] objectForKey:@"Redirect"] objectAtIndex:i]]; |
|---|
| 1235 | } |
|---|
| 1236 | found = 0; |
|---|
| 1237 | } |
|---|
| 1238 | if([tempArray count] > 0) [firewallPortList addObjectsFromArray:tempArray]; |
|---|
| 1239 | } |
|---|
| 1240 | |
|---|
| 1241 | // load additionals into additional selector |
|---|
| 1242 | NSArray * firewallAdditionalServices = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-additionals" ofType:@"plist"]]; |
|---|
| 1243 | |
|---|
| 1244 | int i; |
|---|
| 1245 | [popUpButtonFirewallAdditionalPorts removeAllItems]; |
|---|
| 1246 | for(i=0; i<[firewallAdditionalServices count]; i++) { |
|---|
| 1247 | [popUpButtonFirewallAdditionalPorts addItemWithTitle:[[firewallAdditionalServices objectAtIndex:i] valueForKey:@"Name"]]; |
|---|
| 1248 | } |
|---|
| 1249 | [[popUpButtonFirewallAdditionalPorts menu] addItem:[NSMenuItem separatorItem]]; |
|---|
| 1250 | [popUpButtonFirewallAdditionalPorts addItemWithTitle: NSLocalizedStringFromTable(@"initFirewallSettings:popUpButtonFirewallAdittionalPortsCustom", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1251 | [popUpButtonFirewallAdditionalPorts selectItemAtIndex:0]; |
|---|
| 1252 | |
|---|
| 1253 | [firewallPortTable reloadData]; |
|---|
| 1254 | [firewallPortTable selectRow:0 byExtendingSelection:NO]; |
|---|
| 1255 | } |
|---|
| 1256 | |
|---|
| 1257 | - (IBAction) startShowNewPort:(id)sender |
|---|
| 1258 | { |
|---|
| 1259 | //NSLog(@"cocoaControlEditPC: startShowNewPort"); |
|---|
| 1260 | |
|---|
| 1261 | [self startEditPort:YES]; |
|---|
| 1262 | } |
|---|
| 1263 | - (IBAction) startShowEditPort:(id)sender |
|---|
| 1264 | { |
|---|
| 1265 | //NSLog(@"cocoaControlEditPC: startShowEditPort"); |
|---|
| 1266 | |
|---|
| 1267 | int restrictedPort = 0; |
|---|
| 1268 | NSArray * additionalPorts = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-additionals" ofType:@"plist"]]; |
|---|
| 1269 | if([firewallPortTable selectedRow] >= 0) { |
|---|
| 1270 | int i; |
|---|
| 1271 | for(i=0; i<=[additionalPorts count]-1; i++) { |
|---|
| 1272 | if([[[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] objectForKey:@"Name"] isEqualTo:[[additionalPorts objectAtIndex:i] objectForKey:@"Name"]]) { |
|---|
| 1273 | restrictedPort = 1; |
|---|
| 1274 | } |
|---|
| 1275 | } |
|---|
| 1276 | if([firewallPortTable selectedRow] >= 0 && [firewallPortTable selectedRow] < [[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-defaults" ofType:@"plist"]] count]) { |
|---|
| 1277 | restrictedPort = 1; |
|---|
| 1278 | } |
|---|
| 1279 | if(restrictedPort == 1) { |
|---|
| 1280 | NSString * redirectedPorts; |
|---|
| 1281 | if(![[[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"TCP-Ports-Host"] isEqualToString:@""] && ![[[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"UDP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1282 | // tcp and udp |
|---|
| 1283 | redirectedPorts = [NSString stringWithFormat: NSLocalizedStringFromTable(@"startShowEditPort:restrictedPorts1", @"Localizable", @"cocoaControlEditPC"), [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"TCP-Ports-Host"], [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"UDP-Ports-Host"], [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"TCP-Ports-Guest"], [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"UDP-Ports-Guest"]]; |
|---|
| 1284 | } else if (![[[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"TCP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1285 | // tcp only |
|---|
| 1286 | redirectedPorts = [NSString stringWithFormat: NSLocalizedStringFromTable(@"startShowEditPort:restrictedPorts2", @"Localizable", @"cocoaControlEditPC"), [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"TCP-Ports-Host"], [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"TCP-Ports-Guest"]]; |
|---|
| 1287 | } else { |
|---|
| 1288 | // udp only |
|---|
| 1289 | redirectedPorts = [NSString stringWithFormat: NSLocalizedStringFromTable(@"startShowEditPort:restrictedPorts3", @"Localizable", @"cocoaControlEditPC"), [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"UDP-Ports-Host"], [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"UDP-Ports-Guest"]]; |
|---|
| 1290 | } |
|---|
| 1291 | |
|---|
| 1292 | NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedStringFromTable(@"startShowEditPort:AlertSheet:messageText", @"Localizable", @"cocoaControlEditPC") |
|---|
| 1293 | defaultButton: NSLocalizedStringFromTable(@"startShowEditPort:AlertSheet:defaultButton", @"Localizable", @"cocoaControlEditPC") |
|---|
| 1294 | alternateButton:nil |
|---|
| 1295 | otherButton:nil |
|---|
| 1296 | informativeTextWithFormat:[NSString stringWithFormat: NSLocalizedStringFromTable(@"startShowEditPort:AlertSheet:informativeText", @"Localizable", @"cocoaControlEditPC"), [[firewallPortList objectAtIndex:[firewallPortTable selectedRow]] valueForKey:@"Name"], redirectedPorts]]; |
|---|
| 1297 | |
|---|
| 1298 | [alert runModal]; |
|---|
| 1299 | } else { |
|---|
| 1300 | [self startEditPort:NO]; |
|---|
| 1301 | } |
|---|
| 1302 | } |
|---|
| 1303 | } |
|---|
| 1304 | |
|---|
| 1305 | - (void) startEditPort:(BOOL)newPort |
|---|
| 1306 | { |
|---|
| 1307 | //NSLog(@"cocoaControlEditPC: startEditPort"); |
|---|
| 1308 | |
|---|
| 1309 | /*[firewallPortPanel setFrame:NSMakeRect( |
|---|
| 1310 | [firewallPortPanel frame].origin.x, |
|---|
| 1311 | [firewallPortPanel frame].origin.y - 263, |
|---|
| 1312 | [firewallPortPanel frame].size.width, |
|---|
| 1313 | [firewallPortPanel frame].size.height + 263 |
|---|
| 1314 | ) display:YES animate:YES]; |
|---|
| 1315 | */ |
|---|
| 1316 | |
|---|
| 1317 | [NSApp beginSheet:firewallPortEditPanel |
|---|
| 1318 | modalForWindow:editPCPanel |
|---|
| 1319 | modalDelegate:self |
|---|
| 1320 | didEndSelector:nil |
|---|
| 1321 | contextInfo:nil]; |
|---|
| 1322 | |
|---|
| 1323 | if(newPort) { |
|---|
| 1324 | // called to create a new port |
|---|
| 1325 | [textFieldFirewallPortName setStringValue:@""]; |
|---|
| 1326 | [popUpButtonFirewallServiceType selectItemAtIndex:0]; |
|---|
| 1327 | [textFieldFirewallPortHostPorts setStringValue:@""]; |
|---|
| 1328 | [textFieldFirewallPortGuestPorts setStringValue:@""]; |
|---|
| 1329 | |
|---|
| 1330 | [popUpButtonFirewallAdditionalPorts selectItemAtIndex:0]; |
|---|
| 1331 | [self setAdditionalPort:self]; |
|---|
| 1332 | [buttonFirewallSavePort setTarget:self]; |
|---|
| 1333 | [buttonFirewallSavePort setAction:@selector(saveNewPort:)]; |
|---|
| 1334 | } else { |
|---|
| 1335 | // called to edit a port |
|---|
| 1336 | [buttonFirewallSavePort setTarget:self]; |
|---|
| 1337 | [buttonFirewallSavePort setAction:@selector(saveEditPort:)]; |
|---|
| 1338 | [popUpButtonFirewallAdditionalPorts selectItemWithTitle: NSLocalizedStringFromTable(@"startEditPort:popUpButtonFirewallAdittionalPortsCustom", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1339 | // load port info from list |
|---|
| 1340 | int selectedPort = [firewallPortTable selectedRow]; |
|---|
| 1341 | |
|---|
| 1342 | [textFieldFirewallPortName setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"Name"]]; |
|---|
| 1343 | if(![[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"TCP-Ports-Host"] isEqualToString:@""] && ![[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"UDP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1344 | [popUpButtonFirewallServiceType selectItemAtIndex:2]; |
|---|
| 1345 | [textFieldFirewallPortHostPorts setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"TCP-Ports-Host"]]; |
|---|
| 1346 | [textFieldFirewallPortGuestPorts setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"TCP-Ports-Guest"]]; |
|---|
| 1347 | } else if(![[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"TCP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1348 | [popUpButtonFirewallServiceType selectItemAtIndex:0]; |
|---|
| 1349 | [textFieldFirewallPortHostPorts setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"TCP-Ports-Host"]]; |
|---|
| 1350 | [textFieldFirewallPortGuestPorts setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"TCP-Ports-Guest"]]; |
|---|
| 1351 | } else if(![[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"UDP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1352 | [popUpButtonFirewallServiceType selectItemAtIndex:1]; |
|---|
| 1353 | [textFieldFirewallPortHostPorts setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"UDP-Ports-Host"]]; |
|---|
| 1354 | [textFieldFirewallPortGuestPorts setStringValue:[[firewallPortList objectAtIndex:selectedPort] valueForKey:@"UDP-Ports-Guest"]]; |
|---|
| 1355 | } |
|---|
| 1356 | } |
|---|
| 1357 | } |
|---|
| 1358 | |
|---|
| 1359 | - (IBAction) deletePort:(id)sender |
|---|
| 1360 | { |
|---|
| 1361 | //NSLog(@"cocoaControlEditPC: deletePort"); |
|---|
| 1362 | |
|---|
| 1363 | // check if port is a default port |
|---|
| 1364 | if([firewallPortTable selectedRow] >= 0 && [firewallPortTable selectedRow] < [[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-defaults" ofType:@"plist"]] count]) { |
|---|
| 1365 | NSAlert *alert = [NSAlert alertWithMessageText: NSLocalizedStringFromTable(@"deletePort:AlertSheet:messageText", @"Localizable", @"cocoaControlEditPC") |
|---|
| 1366 | defaultButton: NSLocalizedStringFromTable(@"deletePort:AlertSheet:defaultButton", @"Localizable", @"cocoaControlEditPC") |
|---|
| 1367 | alternateButton:nil |
|---|
| 1368 | otherButton:nil |
|---|
| 1369 | informativeTextWithFormat: NSLocalizedStringFromTable(@"deletePort:AlertSheet:informativeText", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1370 | |
|---|
| 1371 | [alert runModal]; |
|---|
| 1372 | } else { |
|---|
| 1373 | // delete |
|---|
| 1374 | [firewallPortList removeObjectAtIndex:[firewallPortTable selectedRow]]; |
|---|
| 1375 | [firewallPortTable reloadData]; |
|---|
| 1376 | } |
|---|
| 1377 | } |
|---|
| 1378 | |
|---|
| 1379 | - (IBAction) setAdditionalPort:(id)sender |
|---|
| 1380 | { |
|---|
| 1381 | //NSLog(@"cocoaControlEditPC: setAdditionalPort"); |
|---|
| 1382 | |
|---|
| 1383 | // load data from fw-additionals.plist |
|---|
| 1384 | if ([popUpButtonFirewallAdditionalPorts indexOfSelectedItem] <= ([popUpButtonFirewallAdditionalPorts numberOfItems] - 3)) { |
|---|
| 1385 | // only sets from fw-additionals are loaded here.. |
|---|
| 1386 | NSArray * additionalPorts = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-additionals" ofType:@"plist"]]; |
|---|
| 1387 | |
|---|
| 1388 | [textFieldFirewallPortName setStringValue:[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"Name"]]; |
|---|
| 1389 | if(![[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"TCP-Ports-Host"] isEqualToString:@""] && ![[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"UDP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1390 | // tcp and udp |
|---|
| 1391 | // add both type's ports, if set is saved we load it directly from fw-additionals because of possible duplicates |
|---|
| 1392 | [popUpButtonFirewallServiceType selectItemAtIndex:2]; |
|---|
| 1393 | [textFieldFirewallPortHostPorts setStringValue:[NSString stringWithFormat:@"%@,%@", [[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"TCP-Ports-Host"], [[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"UDP-Ports-Host"]]]; |
|---|
| 1394 | [textFieldFirewallPortGuestPorts setStringValue:[NSString stringWithFormat:@"%@,%@", [[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"TCP-Ports-Guest"], [[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"UDP-Ports-Guest"]]]; |
|---|
| 1395 | } else if(![[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"TCP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1396 | // tcp only |
|---|
| 1397 | [popUpButtonFirewallServiceType selectItemAtIndex:0]; |
|---|
| 1398 | [textFieldFirewallPortHostPorts setStringValue:[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"TCP-Ports-Host"]]; |
|---|
| 1399 | [textFieldFirewallPortGuestPorts setStringValue:[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"TCP-Ports-Guest"]]; |
|---|
| 1400 | } else if(![[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"UDP-Ports-Host"] isEqualToString:@""]) { |
|---|
| 1401 | // udp only |
|---|
| 1402 | [popUpButtonFirewallServiceType selectItemAtIndex:1]; |
|---|
| 1403 | [textFieldFirewallPortHostPorts setStringValue:[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"UDP-Ports-Host"]]; |
|---|
| 1404 | [textFieldFirewallPortGuestPorts setStringValue:[[additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]] valueForKey:@"UDP-Ports-Guest"]]; |
|---|
| 1405 | } |
|---|
| 1406 | // lock elements |
|---|
| 1407 | [textFieldFirewallPortName setEnabled:NO]; |
|---|
| 1408 | [textFieldFirewallPortHostPorts setEnabled:NO]; |
|---|
| 1409 | [textFieldFirewallPortGuestPorts setEnabled:NO]; |
|---|
| 1410 | [popUpButtonFirewallServiceType setEnabled:NO]; |
|---|
| 1411 | } else { |
|---|
| 1412 | // custom port chosen |
|---|
| 1413 | [textFieldFirewallPortName setStringValue:@""]; |
|---|
| 1414 | [textFieldFirewallPortHostPorts setStringValue:@""]; |
|---|
| 1415 | [textFieldFirewallPortGuestPorts setStringValue:@""]; |
|---|
| 1416 | [popUpButtonFirewallServiceType selectItemAtIndex:0]; |
|---|
| 1417 | |
|---|
| 1418 | [textFieldFirewallPortName setEnabled:YES]; |
|---|
| 1419 | [textFieldFirewallPortHostPorts setEnabled:YES]; |
|---|
| 1420 | [textFieldFirewallPortGuestPorts setEnabled:YES]; |
|---|
| 1421 | [popUpButtonFirewallServiceType setEnabled:YES]; |
|---|
| 1422 | } |
|---|
| 1423 | } |
|---|
| 1424 | |
|---|
| 1425 | - (IBAction) saveNewPort:(id)sender |
|---|
| 1426 | { |
|---|
| 1427 | //NSLog(@"cocoaControlEditPC: saveNewPort"); |
|---|
| 1428 | |
|---|
| 1429 | if([self checkPort:YES] == YES) { |
|---|
| 1430 | NSMutableDictionary * portDict; |
|---|
| 1431 | if ([popUpButtonFirewallAdditionalPorts indexOfSelectedItem] <= ([popUpButtonFirewallAdditionalPorts numberOfItems] - 3)) { |
|---|
| 1432 | // this is a set from fw-additionals, load it directly from the file |
|---|
| 1433 | NSArray * additionalPorts = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-additionals" ofType:@"plist"]]; |
|---|
| 1434 | portDict = [additionalPorts objectAtIndex:[popUpButtonFirewallAdditionalPorts indexOfSelectedItem]]; |
|---|
| 1435 | } else { |
|---|
| 1436 | // this is a custom port, take entries from textFields |
|---|
| 1437 | portDict = [NSMutableDictionary dictionaryWithCapacity:5]; |
|---|
| 1438 | [portDict setObject:[textFieldFirewallPortName stringValue] forKey:@"Name"]; |
|---|
| 1439 | if([popUpButtonFirewallServiceType indexOfSelectedItem] == 0) { |
|---|
| 1440 | // tcp only |
|---|
| 1441 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"TCP-Ports-Host"]; |
|---|
| 1442 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"TCP-Ports-Guest"]; |
|---|
| 1443 | [portDict setObject: @"" forKey:@"UDP-Ports-Host"]; |
|---|
| 1444 | [portDict setObject: @"" forKey:@"UDP-Ports-Guest"]; |
|---|
| 1445 | } else if([popUpButtonFirewallServiceType indexOfSelectedItem] == 1) { |
|---|
| 1446 | // udp only |
|---|
| 1447 | [portDict setObject: @"" forKey:@"TCP-Ports-Host"]; |
|---|
| 1448 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"TCP-Ports-Guest"]; |
|---|
| 1449 | [portDict setObject: @"" forKey:@"UDP-Ports-Host"]; |
|---|
| 1450 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"UDP-Ports-Guest"]; |
|---|
| 1451 | } else if([popUpButtonFirewallServiceType indexOfSelectedItem] == 2) { |
|---|
| 1452 | // tcp and udp |
|---|
| 1453 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"TCP-Ports-Host"]; |
|---|
| 1454 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"TCP-Ports-Guest"]; |
|---|
| 1455 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"UDP-Ports-Host"]; |
|---|
| 1456 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"UDP-Ports-Guest"]; |
|---|
| 1457 | } |
|---|
| 1458 | } // end predefined/custom check |
|---|
| 1459 | // set enabled key |
|---|
| 1460 | [portDict setObject:[NSNumber numberWithBool:YES] forKey:@"Enabled"]; |
|---|
| 1461 | // add to list |
|---|
| 1462 | [firewallPortList addObject:portDict]; |
|---|
| 1463 | [self endEditPort:self]; |
|---|
| 1464 | } |
|---|
| 1465 | } |
|---|
| 1466 | |
|---|
| 1467 | - (IBAction) saveEditPort:(id)sender |
|---|
| 1468 | { |
|---|
| 1469 | //NSLog(@"cocoaControlEditPC: saveEditPort"); |
|---|
| 1470 | |
|---|
| 1471 | if([self checkPort:NO] == YES) { |
|---|
| 1472 | // save to edited port |
|---|
| 1473 | int selectedPort = [firewallPortTable selectedRow]; |
|---|
| 1474 | |
|---|
| 1475 | NSMutableDictionary * portDict = [NSMutableDictionary dictionaryWithCapacity:5]; |
|---|
| 1476 | [portDict setObject:[textFieldFirewallPortName stringValue] forKey:@"Name"]; |
|---|
| 1477 | if([popUpButtonFirewallServiceType indexOfSelectedItem] == 0) { |
|---|
| 1478 | // tcp only |
|---|
| 1479 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"TCP-Ports-Host"]; |
|---|
| 1480 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"TCP-Ports-Guest"]; |
|---|
| 1481 | [portDict setObject: @"" forKey:@"UDP-Ports-Host"]; |
|---|
| 1482 | [portDict setObject: @"" forKey:@"UDP-Ports-Guest"]; |
|---|
| 1483 | } else if([popUpButtonFirewallServiceType indexOfSelectedItem] == 1) { |
|---|
| 1484 | // udp only |
|---|
| 1485 | [portDict setObject: @"" forKey:@"TCP-Ports-Host"]; |
|---|
| 1486 | [portDict setObject: @"" forKey:@"TCP-Ports-Guest"]; |
|---|
| 1487 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"UDP-Ports-Host"]; |
|---|
| 1488 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"UDP-Ports-Guest"]; |
|---|
| 1489 | } else if([popUpButtonFirewallServiceType indexOfSelectedItem] == 2) { |
|---|
| 1490 | // tcp and udp |
|---|
| 1491 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"TCP-Ports-Host"]; |
|---|
| 1492 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"TCP-Ports-Guest"]; |
|---|
| 1493 | [portDict setObject:[textFieldFirewallPortHostPorts stringValue] forKey:@"UDP-Ports-Host"]; |
|---|
| 1494 | [portDict setObject:[textFieldFirewallPortGuestPorts stringValue] forKey:@"UDP-Ports-Guest"]; |
|---|
| 1495 | } |
|---|
| 1496 | // set enabled/disabled key |
|---|
| 1497 | [portDict setObject:[[firewallPortList objectAtIndex:selectedPort] objectForKey:@"Enabled"] forKey:@"Enabled"]; |
|---|
| 1498 | // replace in list |
|---|
| 1499 | [firewallPortList replaceObjectAtIndex:selectedPort withObject:portDict]; |
|---|
| 1500 | [self endEditPort:self]; |
|---|
| 1501 | } |
|---|
| 1502 | } |
|---|
| 1503 | |
|---|
| 1504 | - (BOOL) checkPort:(BOOL)newPort |
|---|
| 1505 | { |
|---|
| 1506 | //NSLog(@"cocoaControlEditPC: checkPort"); |
|---|
| 1507 | |
|---|
| 1508 | if([[textFieldFirewallPortName stringValue] isEqualToString:@""]) { |
|---|
| 1509 | // name empty |
|---|
| 1510 | [textFieldFirewallPortError setStringValue: NSLocalizedStringFromTable(@"checkPort:textFieldFirewallPortError:name", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1511 | [textFieldFirewallPortError setHidden:NO]; |
|---|
| 1512 | return NO; |
|---|
| 1513 | } else if([[textFieldFirewallPortHostPorts stringValue] isEqualToString:@""]) { |
|---|
| 1514 | // host ports empty |
|---|
| 1515 | //NSLog(@"No empty host-port entry!"); |
|---|
| 1516 | [textFieldFirewallPortError setStringValue: NSLocalizedStringFromTable(@"checkPort:textFieldFirewallPortError:hostport", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1517 | [textFieldFirewallPortError setHidden:NO]; |
|---|
| 1518 | return NO; |
|---|
| 1519 | } else if([[textFieldFirewallPortGuestPorts stringValue] isEqualToString:@""]) { |
|---|
| 1520 | // guest ports empty |
|---|
| 1521 | //NSLog(@"No empty guest-port entry!"); |
|---|
| 1522 | [textFieldFirewallPortError setStringValue: NSLocalizedStringFromTable(@"checkPort:textFieldFirewallPortError:guestport", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1523 | [textFieldFirewallPortError setHidden:NO]; |
|---|
| 1524 | return NO; |
|---|
| 1525 | } else { |
|---|
| 1526 | // check for valid port ranges |
|---|
| 1527 | int i,j,k; |
|---|
| 1528 | int dcc = 0; // delimiter comma count |
|---|
| 1529 | int dhc = 0; // delimiter haifin count |
|---|
| 1530 | unichar tChar; |
|---|
| 1531 | int invalid = 0; |
|---|
| 1532 | NSString *tForbidden = [NSString stringWithString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"$%&/()=?+*#'_;:.<>"]; |
|---|
| 1533 | NSString *tDelimiters = [NSString stringWithString:@",-"]; |
|---|
| 1534 | NSArray *tPortRanges = [NSArray arrayWithObjects:[textFieldFirewallPortHostPorts stringValue], [textFieldFirewallPortGuestPorts stringValue], nil]; |
|---|
| 1535 | for (i = 0; i < [tPortRanges count]; i++) { |
|---|
| 1536 | for (j = 0; j < [[tPortRanges objectAtIndex:i] length]; j++) { |
|---|
| 1537 | tChar = [[tPortRanges objectAtIndex:i] characterAtIndex:j]; |
|---|
| 1538 | for (k=0; k < [tForbidden length]; k++) { |
|---|
| 1539 | //NSLog(@"%C, %C", tChar, [tForbidden characterAtIndex:k]); |
|---|
| 1540 | if (tChar == [tForbidden characterAtIndex:k]) { |
|---|
| 1541 | // invalid character |
|---|
| 1542 | invalid = 1; |
|---|
| 1543 | } else if(tChar == [tDelimiters characterAtIndex:0]) { |
|---|
| 1544 | // raise comma count |
|---|
| 1545 | dcc++; |
|---|
| 1546 | } else if(tChar == [tDelimiters characterAtIndex:1]) { |
|---|
| 1547 | // raise haifin count |
|---|
| 1548 | dhc++; |
|---|
| 1549 | } |
|---|
| 1550 | } |
|---|
| 1551 | } |
|---|
| 1552 | } |
|---|
| 1553 | if (invalid == 1) { |
|---|
| 1554 | //NSLog(@"Illegal characters in ports!"); |
|---|
| 1555 | [textFieldFirewallPortError setStringValue: NSLocalizedStringFromTable(@"checkPort:textFieldFirewallPortError:illegalchars", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1556 | [textFieldFirewallPortError setHidden:NO]; |
|---|
| 1557 | return NO; |
|---|
| 1558 | } else if(dcc > 0 && dhc > 0) { |
|---|
| 1559 | // both comma and haifin found, not supported/allowed atm |
|---|
| 1560 | //NSLog(@"Combination of , and - not allowed."); |
|---|
| 1561 | [textFieldFirewallPortError setStringValue: NSLocalizedStringFromTable(@"checkPort:textFieldFirewallPortError:combination", @"Localizable", @"cocoaControlEditPC")]; |
|---|
| 1562 | [textFieldFirewallPortError setHidden:NO]; |
|---|
| 1563 | return NO; |
|---|
| 1564 | } |
|---|
| 1565 | } |
|---|
| 1566 | int i; |
|---|
| 1567 | int found = 0; |
|---|
| 1568 | if(newPort) { |
|---|
| 1569 | // check for same name in all entries of current list |
|---|
| 1570 | |
|---|
| 1571 | for(i=0; i<=[firewallPortList count]-1; i++) { |
|---|
| 1572 | if([[textFieldFirewallPortName stringValue] isEqualTo:[[firewallPortList objectAtIndex:i] objectForKey:@"Name"]]) { |
|---|
| 1573 | found = 1; |
|---|
| 1574 | } |
|---|
| 1575 | } |
|---|
| 1576 | } else { |
|---|
| 1577 | // check for same name in fw-default entries of current list |
|---|
| 1578 | for(i=0; i<=[[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-defaults" ofType:@"plist"]] count]-1; i++) { |
|---|
| 1579 | if([[textFieldFirewallPortName stringValue] isEqualTo:[[firewallPortList objectAtIndex:i] objectForKey:@"Name"]]) { |
|---|
| 1580 | found = 1; |
|---|
| 1581 | } |
|---|
| 1582 | } |
|---|
| 1583 | } |
|---|
| 1584 | if(found == 1) return NO; |
|---|
| 1585 | return YES; |
|---|
| 1586 | } |
|---|
| 1587 | |
|---|
| 1588 | - (IBAction) endEditPort:(id)sender |
|---|
| 1589 | { |
|---|
| 1590 | //NSLog(@"cocoaControlEditPC: endEditPort"); |
|---|
| 1591 | |
|---|
| 1592 | // reset |
|---|
| 1593 | [textFieldFirewallPortName setStringValue:@""]; |
|---|
| 1594 | [textFieldFirewallPortHostPorts setStringValue:@""]; |
|---|
| 1595 | [textFieldFirewallPortGuestPorts setStringValue:@""]; |
|---|
| 1596 | [popUpButtonFirewallServiceType selectItemAtIndex:0]; |
|---|
| 1597 | [textFieldFirewallPortError setStringValue:@""]; |
|---|
| 1598 | [textFieldFirewallPortError setHidden:YES]; |
|---|
| 1599 | |
|---|
| 1600 | [textFieldFirewallPortName setEnabled:YES]; |
|---|
| 1601 | [textFieldFirewallPortHostPorts setEnabled:YES]; |
|---|
| 1602 | [textFieldFirewallPortGuestPorts setEnabled:YES]; |
|---|
| 1603 | [popUpButtonFirewallServiceType setEnabled:YES]; |
|---|
| 1604 | |
|---|
| 1605 | [NSApp endSheet:firewallPortEditPanel]; |
|---|
| 1606 | [firewallPortEditPanel orderOut:self]; |
|---|
| 1607 | |
|---|
| 1608 | [firewallPortTable reloadData]; |
|---|
| 1609 | } |
|---|
| 1610 | |
|---|
| 1611 | - (void) saveFirewallPortList |
|---|
| 1612 | { |
|---|
| 1613 | //NSLog(@"cocoaControlEditPC: saveFirewallPortList"); |
|---|
| 1614 | |
|---|
| 1615 | // save the ports in configuration.plist |
|---|
| 1616 | // enumerate through entries and check for defaults, when enabled => save |
|---|
| 1617 | NSArray * firewallDefaults = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fw-defaults" ofType:@"plist"]]; |
|---|
| 1618 | NSMutableArray * customPorts = [[NSMutableArray arrayWithCapacity:10] retain]; |
|---|
| 1619 | int i; |
|---|
| 1620 | int ii; |
|---|
| 1621 | int found = 0; |
|---|
| 1622 | for(i=0; i<=[firewallPortList count]-1; i++) { |
|---|
| 1623 | for(ii=0; ii<=[firewallDefaults count]-1; ii++) { |
|---|
| 1624 | if([[[firewallPortList objectAtIndex:i] objectForKey:@"Name"] isEqualTo:[[firewallDefaults objectAtIndex:ii] objectForKey:@"Name"]]) { |
|---|
| 1625 | // found default port in customs, check for enabled status in firewallPortList |
|---|
| 1626 | found = 1; |
|---|
| 1627 | if([[[firewallPortList objectAtIndex:i] objectForKey:@"Enabled"] isEqualTo:[NSNumber numberWithBool:YES]]) { |
|---|
| 1628 | // default port enabled => save to conf.plist |
|---|
| 1629 | [customPorts addObject:[firewallPortList objectAtIndex:i]]; |
|---|
| 1630 | } |
|---|
| 1631 | } |
|---|
| 1632 | } |
|---|
| 1633 | if(found == 0) { |
|---|
| 1634 | // port is not default port, save to conf.plist regardless of Enabled |
|---|
| 1635 | if ([firewallPortList count] > i) |
|---|
| 1636 | [customPorts addObject:[firewallPortList objectAtIndex:i]]; |
|---|
| 1637 | else |
|---|
| 1638 | NSLog(@"Index overflow: %d out of bounds (%d)", i, [firewallPortList count]); |
|---|
| 1639 | } |
|---|
| 1640 | found = 0; |
|---|
| 1641 | } |
|---|
| 1642 | if([customPorts count] > 0) |
|---|
| 1643 | [thisPC setObject: [NSDictionary dictionaryWithObject: customPorts forKey:@"Redirect"] forKey:@"Network"]; |
|---|
| 1644 | else |
|---|
| 1645 | NSLog(@"Index overflow: out of bounds (%d)", [customPorts count]); |
|---|
| 1646 | } |
|---|
| 1647 | |
|---|
| 1648 | - (NSString *) constructFirewallArguments |
|---|
| 1649 | { |
|---|
| 1650 | //NSLog(@"cocoaControlEditPC: constructFirewallArguments"); |
|---|
| 1651 | |
|---|
| 1652 | NSArray * portlist = [[thisPC objectForKey:@"Network"] objectForKey:@"Redirect"]; |
|---|
| 1653 | NSMutableString * arguments = [NSMutableString stringWithCapacity:10]; |
|---|
| 1654 | |
|---|
| 1655 | int i, ii, j, k; |
|---|
| 1656 | for(i=0; i<[portlist count]; i++) { |
|---|
| 1657 | // enumerate through portlist in conf.plist |
|---|
| 1658 | if([[[portlist objectAtIndex:i] objectForKey:@"Enabled"] isEqualTo:[NSNumber numberWithBool:YES]]) { |
|---|
| 1659 | NSArray * tcpHostComma = [[[portlist objectAtIndex:i] valueForKey:@"TCP-Ports-Host"] componentsSeparatedByString:@","]; |
|---|
| 1660 | NSArray * tcpHostHaifin = [[[portlist objectAtIndex:i] valueForKey:@"TCP-Ports-Host"] componentsSeparatedByString:@"-"]; |
|---|
| 1661 | NSArray * tcpGuestComma = [[[portlist objectAtIndex:i] valueForKey:@"TCP-Ports-Guest"] componentsSeparatedByString:@","]; |
|---|
| 1662 | NSArray * tcpGuestHaifin = [[[portlist objectAtIndex:i] valueForKey:@"TCP-Ports-Guest"] componentsSeparatedByString:@"-"]; |
|---|
| 1663 | |
|---|
| 1664 | NSArray * udpHostComma = [[[portlist objectAtIndex:i] valueForKey:@"UDP-Ports-Host"] componentsSeparatedByString:@","]; |
|---|
| 1665 | NSArray * udpHostHaifin = [[[portlist objectAtIndex:i] valueForKey:@"UDP-Ports-Host"] componentsSeparatedByString:@"-"]; |
|---|
| 1666 | NSArray * udpGuestComma = [[[portlist objectAtIndex:i] valueForKey:@"UDP-Ports-Guest"] componentsSeparatedByString:@","]; |
|---|
| 1667 | NSArray * udpGuestHaifin = [[[portlist objectAtIndex:i] valueForKey:@"UDP-Ports-Guest"] componentsSeparatedByString:@"-"]; |
|---|
| 1668 | |
|---|
| 1669 | NSArray * typeA = [NSArray arrayWithObjects:@"tcp",@"udp",nil]; |
|---|
| 1670 | NSArray * seperatedA = [NSArray arrayWithObjects:[NSArray arrayWithObjects:tcpHostComma, tcpHostHaifin, tcpGuestComma, tcpGuestHaifin, nil], [NSArray arrayWithObjects:udpHostComma, udpHostHaifin, udpGuestComma, udpGuestHaifin, nil], nil]; |
|---|
| 1671 | |
|---|
| 1672 | for(ii=0; ii<[seperatedA count]; ii++) { |
|---|
| 1673 | // tcp/udp |
|---|
| 1674 | |
|---|
| 1675 | id tp = [typeA objectAtIndex:ii]; |
|---|
| 1676 | id hc = ([[seperatedA objectAtIndex:ii] objectAtIndex:0] != nil) ? [[seperatedA objectAtIndex:ii] objectAtIndex:0] : [NSArray array]; |
|---|
| 1677 | id hh = ([[seperatedA objectAtIndex:ii] objectAtIndex:1] != nil) ? [[seperatedA objectAtIndex:ii] objectAtIndex:1] : [NSArray array]; |
|---|
| 1678 | id gc = ([[seperatedA objectAtIndex:ii] objectAtIndex:2] != nil) ? [[seperatedA objectAtIndex:ii] objectAtIndex:2] : [NSArray array]; |
|---|
| 1679 | id gh = ([[seperatedA objectAtIndex:ii] objectAtIndex:3] != nil) ? [[seperatedA objectAtIndex:ii] objectAtIndex:3] : [NSArray array]; |
|---|
| 1680 | |
|---|
| 1681 | /* comma code */ |
|---|
| 1682 | if([hc count] > 1 && [gc count] > 1) { |
|---|
| 1683 | // both seperated by comma |
|---|
| 1684 | if([hc count] == [gc count]) { |
|---|
| 1685 | // both have the same amount of ports |
|---|
| 1686 | // redirect same=>same |
|---|
| 1687 | for(j=0; j < [hc count]; j++) { |
|---|
| 1688 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%@::%@",tp, [hc objectAtIndex:j], [gc objectAtIndex:j]]]; |
|---|
| 1689 | } |
|---|
| 1690 | } else { |
|---|
| 1691 | // both have a different amount of ports |
|---|
| 1692 | // redirect every=>every |
|---|
| 1693 | for(j=0; j < [hc count]; j++) { |
|---|
| 1694 | for(k=0; k < [gc count]; k++) { |
|---|
| 1695 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%@::%@",tp, [hc objectAtIndex:j], [gc objectAtIndex:k]]]; |
|---|
| 1696 | } |
|---|
| 1697 | } |
|---|
| 1698 | } |
|---|
| 1699 | } else if([hc count] == 1 && [gc count] > 1) { |
|---|
| 1700 | // only guest seperated by comma |
|---|
| 1701 | // redirect one=>every |
|---|
| 1702 | for(j=0; j < [gc count]; j++) { |
|---|
| 1703 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%@::%@",tp, [hc objectAtIndex:0], [gc objectAtIndex:j]]]; |
|---|
| 1704 | } |
|---|
| 1705 | } else if([hc count] > 1 && [gc count] == 1) { |
|---|
| 1706 | // only host seperated by comma |
|---|
| 1707 | // redirect one=>every |
|---|
| 1708 | for(j=0; j < [hc count]; j++) { |
|---|
| 1709 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%@::%@",tp, [hc objectAtIndex:j], [gc objectAtIndex:0]]]; |
|---|
| 1710 | } |
|---|
| 1711 | } |
|---|
| 1712 | |
|---|
| 1713 | /* haifin code */ |
|---|
| 1714 | if([hh count] > 1 && [gh count] > 1) { |
|---|
| 1715 | // both seperated by haifin |
|---|
| 1716 | // redirect same=>same |
|---|
| 1717 | j=[[hh objectAtIndex:0] intValue]; |
|---|
| 1718 | k=[[gh objectAtIndex:0] intValue]; |
|---|
| 1719 | while(j <= [[hh objectAtIndex:1] intValue]) { |
|---|
| 1720 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%d::%d",tp, j,k]]; |
|---|
| 1721 | j++; |
|---|
| 1722 | k++; |
|---|
| 1723 | } |
|---|
| 1724 | } else if([hh count] == 1 && [gh count] > 1) { |
|---|
| 1725 | // only guest seperated by haifin |
|---|
| 1726 | // redirect one=>every |
|---|
| 1727 | j=[[gh objectAtIndex:0] intValue]; |
|---|
| 1728 | while(j < [[gh objectAtIndex:1] intValue]) { |
|---|
| 1729 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%@::%d",tp, [hh objectAtIndex:0],j]]; |
|---|
| 1730 | j++; |
|---|
| 1731 | } |
|---|
| 1732 | } else if([hh count] > 1 && [gh count] == 1) { |
|---|
| 1733 | // only host seperated by haifin |
|---|
| 1734 | // redirect one=>every |
|---|
| 1735 | j=[[hh objectAtIndex:0] intValue]; |
|---|
| 1736 | while(j < [[hh objectAtIndex:1] intValue]) { |
|---|
| 1737 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%d::%@", j,[gh objectAtIndex:0]]]; |
|---|
| 1738 | j++; |
|---|
| 1739 | } |
|---|
| 1740 | } |
|---|
| 1741 | |
|---|
| 1742 | /* only one=>one port code */ |
|---|
| 1743 | // check also for empty port ranges, because componentsSeperatedByString: returns count 1 even from an empty string |
|---|
| 1744 | if(([hh count] == 1 && [gh count] == 1) && ([hc count] == 1 && [gc count] == 1)) { |
|---|
| 1745 | if(!([[hh objectAtIndex:0] isEqualTo:@""] && [[gh objectAtIndex:0] isEqualTo:@""]) && !([[hc objectAtIndex:0] isEqualTo:@""] && [[gc objectAtIndex:0] isEqualTo:@""])) { |
|---|
| 1746 | // only one port |
|---|
| 1747 | // redirect one=>one |
|---|
| 1748 | [arguments appendString:[NSString stringWithFormat:@" -redir %@:%@::%@",tp, [hc objectAtIndex:0] ,[gc objectAtIndex:0]]]; |
|---|
| 1749 | } |
|---|
| 1750 | } // end if ([hh count == 1] ... |
|---|
| 1751 | } // end tcp/udp |
|---|
| 1752 | } // end if enabled |
|---|
| 1753 | } // end for portlist |
|---|
| 1754 | return arguments; |
|---|
| 1755 | } |
|---|
| 1756 | |
|---|
| 1757 | @end |
|---|