| 441 | */ |
| 442 | |
| 443 | void |
| 444 | _cupsAppleSetDefaultPrinter( |
| 445 | CFStringRef name) /* I - Default printer/class name */ |
| 446 | { |
| 447 | # if _CUPS_LOCATION_DEFAULTS |
| 448 | CFStringRef network; /* Current network */ |
| 449 | CFArrayRef locations; /* Old locations array */ |
| 450 | CFIndex locindex; /* Index in locations array */ |
| 451 | CFStringRef locprinter; /* Current printer */ |
| 452 | CFMutableArrayRef newlocations; /* New locations array */ |
| 453 | CFMutableDictionaryRef newlocation; /* New location */ |
| 454 | |
| 455 | |
| 456 | /* |
| 457 | * Get the current location... |
| 458 | */ |
| 459 | |
| 460 | if ((network = appleCopyNetwork()) == NULL) |
| 461 | { |
| 462 | DEBUG_puts("1_cupsAppleSetDefaultPrinter: Unable to get current network..."); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | /* |
| 467 | * Lookup the network in the preferences... |
| 468 | */ |
| 469 | |
| 470 | if ((locations = appleCopyLocations()) != NULL) |
| 471 | locprinter = appleGetPrinter(locations, network, &locindex); |
| 472 | else |
| 473 | { |
| 474 | locprinter = NULL; |
| 475 | locindex = -1; |
| 476 | } |
| 477 | |
| 478 | if (!locprinter || CFStringCompare(locprinter, name, 0) != kCFCompareEqualTo) |
| 479 | { |
| 480 | /* |
| 481 | * Need to change the locations array... |
| 482 | */ |
| 483 | |
| 484 | if (locations) |
| 485 | { |
| 486 | newlocations = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, |
| 487 | locations); |
| 488 | |
| 489 | if (locprinter) |
| 490 | CFArrayRemoveValueAtIndex(newlocations, locindex); |
| 491 | } |
| 492 | else |
| 493 | newlocations = CFArrayCreateMutable(kCFAllocatorDefault, 0, |
| 494 | &kCFTypeArrayCallBacks); |
| 495 | |
| 496 | newlocation = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 497 | &kCFTypeDictionaryKeyCallBacks, |
| 498 | &kCFTypeDictionaryValueCallBacks); |
| 499 | |
| 500 | if (newlocation && newlocations) |
no test coverage detected