1/* 2 GSLPRPrintInfo.m 3 4 Stores information used in printing 5 6 Copyright (C) 1996,1997,2004 Free Software Foundation, Inc. 7 8 Author: Simon Frankau <sgf@frankau.demon.co.uk> 9 Date: July 1997 10 Modified for Printing Backend Support 11 Author: Chad Hardin <cehardin@mac.com> 12 Date: June 2004 13 14 This file is part of the GNUstep GUI Library. 15 16 This library is free software; you can redistribute it and/or 17 modify it under the terms of the GNU Lesser General Public 18 License as published by the Free Software Foundation; either 19 version 2 of the License, or (at your option) any later version. 20 21 This library is distributed in the hope that it will be useful, 22 but WITHOUT ANY WARRANTY; without even the implied warranty of 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 Lesser General Public License for more details. 25 26 You should have received a copy of the GNU Lesser General Public 27 License along with this library; see the file COPYING.LIB. 28 If not, see <http://www.gnu.org/licenses/> or write to the 29 Free Software Foundation, 51 Franklin Street, Fifth Floor, 30 Boston, MA 02110-1301, USA. 31*/ 32 33#import <Foundation/NSArray.h> 34#import <Foundation/NSDebug.h> 35#import <Foundation/NSDictionary.h> 36#import <Foundation/NSUserDefaults.h> 37#import <Foundation/NSValue.h> 38#import "AppKit/NSPrinter.h" 39#import "GSLPRPrintInfo.h" 40 41 42@implementation GSLPRPrintInfo 43 44// 45// Class methods 46// 47+ (void)initialize 48{ 49 if (self == [GSLPRPrintInfo class]) 50 { 51 // Initial version 52 [self setVersion:1]; 53 } 54} 55 56 57+ (id) allocWithZone: (NSZone*)zone 58{ 59 return NSAllocateObject(self, 0, zone); 60} 61 62 63+(NSPrinter*) defaultPrinter 64{ 65 NSUserDefaults *defaults; 66 NSString *name; 67 68 NSDebugMLLog(@"GSPrinting", @"defaultPrinter"); 69 defaults = [NSUserDefaults standardUserDefaults]; 70 name = [defaults objectForKey: @"GSLPRDefaultPrinter"]; 71 72 if (name == nil) 73 { 74 name = [[NSPrinter printerNames] objectAtIndex: 0]; 75 } 76 else 77 { 78 if ([NSPrinter printerWithName: name] == nil) 79 { 80 name = [[NSPrinter printerNames] objectAtIndex: 0]; 81 } 82 } 83 return [NSPrinter printerWithName: name]; 84} 85 86 87+ (void)setDefaultPrinter:(NSPrinter *)printer 88{ 89 NSUserDefaults *defaults; 90 NSMutableDictionary *globalDomain; 91 92 NSDebugMLLog(@"GSPrinting", @"setDefaultPrinter"); 93 defaults = [NSUserDefaults standardUserDefaults]; 94 95 globalDomain = (NSMutableDictionary*)[defaults persistentDomainForName: NSGlobalDomain]; 96 97 if (globalDomain) 98 { 99 globalDomain = [globalDomain mutableCopy]; 100 101 [globalDomain setObject: [printer name] 102 forKey: @"GSLPRDefaultPrinter"]; 103 104 [defaults setPersistentDomain: globalDomain 105 forName: NSGlobalDomain]; 106 RELEASE(globalDomain); 107 } 108 else 109 { 110 NSDebugMLLog(@"GSPrinting", @"(GSLPR) Could not save default printer named %@ to NSUserDefaults GSLPRDefaultPrinter in NSGlobalDomain.", [printer name]); 111 } 112} 113 114@end 115