2004-07-10 10:19:34 +00:00
|
|
|
/** <title>GSLPRPrinter</title>
|
|
|
|
|
|
|
|
<abstract>Class representing a printer's or printer model's capabilities.</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Authors: Simon Frankau <sgf@frankau.demon.co.uk>
|
|
|
|
Date: June 1997
|
|
|
|
Modified for Printing Backend Support
|
|
|
|
Author: Chad Hardin <cehardin@mac.com>
|
|
|
|
Date: June 2004
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2004-07-10 10:19:34 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
2004-07-10 10:19:34 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2004-07-10 10:19:34 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
2004-07-10 10:19:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* NB:
|
|
|
|
* There are a few FIXMEs in the functionality left.
|
|
|
|
* Parsing of the PPDs is somewhat suboptimal.
|
|
|
|
* (I think it's best to leave optimisation until more of GNUstep is done).
|
|
|
|
* The *OpenUI, *CloseUI, *OpenGroup and *CloseGroup are not processed.
|
|
|
|
* (This is not required in the OpenStep standard, but could be useful).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2011-02-07 18:08:33 +00:00
|
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import <Foundation/NSBundle.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSException.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import "GSLPRPrinter.h"
|
|
|
|
#import "GNUstepGUI/GSPrinting.h"
|
2004-07-10 10:19:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@implementation GSLPRPrinter
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
2004-08-08 01:08:55 +00:00
|
|
|
+(void) initialize
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
|
|
|
if (self == [GSLPRPrinter class])
|
|
|
|
{
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-08 01:08:55 +00:00
|
|
|
|
|
|
|
+(id) allocWithZone: (NSZone*) zone
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
|
|
|
return NSAllocateObject(self, 0, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Finding an NSPrinter
|
|
|
|
//
|
2004-08-08 01:08:55 +00:00
|
|
|
+ (NSPrinter*) printerWithName: (NSString*) name
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
2004-08-08 01:08:55 +00:00
|
|
|
NSDictionary* printersDict;
|
|
|
|
NSDictionary* printerEntry;
|
|
|
|
NSPrinter* printer;
|
|
|
|
|
|
|
|
printersDict = [self printersDictionary];
|
|
|
|
printerEntry = [printersDict objectForKey: name];
|
|
|
|
|
|
|
|
if( printerEntry == nil)
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
2004-08-08 01:08:55 +00:00
|
|
|
format: @"(GSLPR) Could not find printer named %@", name];
|
|
|
|
return nil;
|
2004-07-10 10:19:34 +00:00
|
|
|
}
|
2004-08-08 01:08:55 +00:00
|
|
|
|
|
|
|
NSDebugMLLog(@"GSPrinting", @"Creating NSPrinter with Printer Entry: %@",
|
|
|
|
[printerEntry description]);
|
|
|
|
|
2004-07-10 10:19:34 +00:00
|
|
|
printer = [(GSLPRPrinter*)[self alloc]
|
2004-08-08 01:08:55 +00:00
|
|
|
initWithName: name
|
|
|
|
withType: [printerEntry objectForKey: @"Type"]
|
|
|
|
withHost: [printerEntry objectForKey: @"Host"]
|
2004-10-08 09:31:11 +00:00
|
|
|
withNote: [printerEntry objectForKey: @"Note"]];
|
|
|
|
|
|
|
|
[printer parsePPDAtPath: [printerEntry objectForKey: @"PPDPath"]];
|
2004-07-10 10:19:34 +00:00
|
|
|
|
2004-10-08 09:31:11 +00:00
|
|
|
return AUTORELEASE(printer);
|
2004-07-10 10:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ (NSArray *)printerNames
|
|
|
|
{
|
2004-08-08 01:08:55 +00:00
|
|
|
return [[self printersDictionary] allKeys];
|
|
|
|
}
|
2004-07-10 10:19:34 +00:00
|
|
|
|
2004-08-08 01:08:55 +00:00
|
|
|
//
|
|
|
|
// Load the printer setup from NSUserDefaults
|
|
|
|
//
|
|
|
|
+ (NSDictionary*) printersDictionary
|
2004-07-10 10:19:34 +00:00
|
|
|
{
|
2004-09-03 23:37:38 +00:00
|
|
|
static BOOL didWarn;
|
2004-08-08 01:08:55 +00:00
|
|
|
NSUserDefaults* defaults;
|
|
|
|
NSDictionary *printers;
|
|
|
|
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
2006-02-22 10:23:13 +00:00
|
|
|
printers = [defaults dictionaryForKey: @"GSLPRPrinters"];
|
2004-08-08 01:08:55 +00:00
|
|
|
|
2004-09-03 23:37:38 +00:00
|
|
|
if (!printers) //Not set, make a default printer because we are nice.
|
2004-08-08 01:08:55 +00:00
|
|
|
{
|
|
|
|
NSString *ppdPath;
|
|
|
|
NSMutableDictionary *printerEntry;
|
|
|
|
|
|
|
|
printers = [NSMutableDictionary dictionary];
|
|
|
|
printerEntry = [NSMutableDictionary dictionary];
|
|
|
|
|
2004-09-03 23:37:38 +00:00
|
|
|
ppdPath = [NSBundle
|
|
|
|
pathForLibraryResource: @"Generic-PostScript_Printer-Postscript"
|
|
|
|
ofType: @"ppd"
|
|
|
|
inDirectory: @"PostScript/PPD"];
|
|
|
|
NSAssert(ppdPath,
|
|
|
|
@"Couldn't find the PPD file for the fallback printer.");
|
2004-08-08 01:08:55 +00:00
|
|
|
|
|
|
|
[printerEntry setObject: ppdPath
|
2004-09-03 23:37:38 +00:00
|
|
|
forKey: @"PPDPath"];
|
2004-08-08 01:08:55 +00:00
|
|
|
|
|
|
|
[printerEntry setObject: @"localhost"
|
|
|
|
forKey: @"Host"];
|
|
|
|
|
|
|
|
[printerEntry setObject: @"Automatically Generated"
|
|
|
|
forKey: @"Note"];
|
|
|
|
|
|
|
|
[printerEntry setObject: @"Unknown"
|
|
|
|
forKey: @"Type"];
|
|
|
|
|
|
|
|
[(NSMutableDictionary*)printers setObject: printerEntry
|
|
|
|
forKey: @"Unnamed"];
|
|
|
|
|
2006-02-22 10:23:13 +00:00
|
|
|
[defaults setObject: printers forKey: @"GSLPRPrinters"];
|
|
|
|
[defaults synchronize];
|
|
|
|
|
2004-09-03 23:37:38 +00:00
|
|
|
if (!didWarn)
|
|
|
|
{
|
|
|
|
NSLog(@"Creating a default printer since no printer has been set "
|
|
|
|
@"in the user defaults (under the GSLPRPrinters key).");
|
|
|
|
didWarn = YES;
|
|
|
|
}
|
|
|
|
}
|
2004-08-08 01:08:55 +00:00
|
|
|
|
|
|
|
return printers;
|
2004-07-10 10:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|