File: GSPrintOperation.m

package info (click to toggle)
gnustep-gui 0.25.0-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,088 kB
  • ctags: 3,417
  • sloc: objc: 153,800; ansic: 18,239; cpp: 579; yacc: 462; makefile: 143; sh: 5
file content (182 lines) | stat: -rw-r--r-- 4,721 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* 
   GSPrintOperation.m

   Controls operations generating print jobs.

   Copyright (C) 1996,2004 Free Software Foundation, Inc.

   Author:  Scott Christley <scottc@net-community.com>
   Date: 1996
   Author: Fred Kiefer <FredKiefer@gmx.de>
   Date: November 2000
   Started implementation.
   Author: Chad Hardin <cehardin@mac.com>
   Date: June 2004
   Modified for printing backend support, split off from NSPrintOperation.m

   This file is part of the GNUstep GUI Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   Lesser General Public License for more details.

   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.
*/ 

#import <Foundation/NSData.h>
#import <Foundation/NSException.h>
#import <Foundation/NSTask.h>
#import <Foundation/NSUserDefaults.h>
#import "AppKit/NSPrintPanel.h"
#import "AppKit/NSPrintInfo.h"
#import "AppKit/NSView.h"
#import "AppKit/NSWorkspace.h"
#import "GNUstepGUI/GSPrinting.h"
#import "GNUstepGUI/GSPrintOperation.h"
#import "GSGuiPrivate.h"



/**
  <unit>
  <heading>Class Description</heading>
  <p>
  GSPrintOperation is a generic class that should be subclasses
  by printing backend classes for the purpose of controlling and
  sending print jobs to a printing system.
  </p>
  </unit>
*/ 




@implementation GSPrintOperation

/** Load the appropriate bundle for the PrintInfo
    (eg: GSLPRPrintInfo, GSCUPSPrintInfo).
*/
+ (id) allocWithZone: (NSZone*) zone
{
  Class principalClass;

  principalClass = [[GSPrinting printingBundle] principalClass];

  if (principalClass == nil)
    return nil;
	
  return [[principalClass gsPrintOperationClass] allocWithZone: zone];
}



- (id)initWithView:(NSView *)aView
         printInfo:(NSPrintInfo *)aPrintInfo
{
      
  self = [self initWithView: aView
                 insideRect: [aView bounds]
                     toData: [NSMutableData data]
                  printInfo: aPrintInfo];
                  
  [self setShowPanels: YES];

  return self;
}

- (NSGraphicsContext*)createContext
{
  [self subclassResponsibility: _cmd];
  return nil;
}


/**
/ !!!Here is the method that will be overridden in the printer bundle
*/
- (BOOL) _deliverSpooledResult
{
  [self subclassResponsibility: _cmd];
  return NO;
}


- (BOOL) deliverResult
{
  BOOL success;
  NSString *job;
  
  success = YES;
  job = [[self printInfo] jobDisposition];
  if ([job isEqual: NSPrintPreviewJob])
    {
      /* Check to see if there is a GNUstep app that can preview PS files.
	       It's not likely at this point, so also check for a standards
	       previewer, like gv.
      */
      NSTask *task;
      NSString *preview;
      NSWorkspace *ws = [NSWorkspace sharedWorkspace];
      [[self printPanel] _setStatusStringValue: @"Opening in previewer..."];
      
      preview = [ws getBestAppInRole: @"Viewer" 
                        forExtension: @"ps"];
      if (preview)
        {
          [ws openFile: _path withApplication: preview];
        }
      else
        {
          NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
          preview = [def objectForKey: @"NSPreviewApp"];
          
	  if (preview == nil || [preview length] == 0)
	    preview = @"gv";
            
	  NS_DURING
	    {
	      task = AUTORELEASE([NSTask new]);
	      [task setLaunchPath: preview];
	      [task setArguments: [NSArray arrayWithObject: _path]];
	      [task launch];
	    }
	  NS_HANDLER
	    {
	      NSRunAlertPanel(_(@"Preview"),
_(@"Problem running the preview application '%@' perhaps you need to set your NSPreviewApp user default"),
		_(@"Dismiss"), nil, nil, preview);
	    }
	  NS_ENDHANDLER
        }
    }
  else if ([job isEqual: NSPrintSpoolJob])
    {
      success = [self _deliverSpooledResult];
    }
  else if ([job isEqual: NSPrintFaxJob])
    {
    }

  /* We can't remove the temp file because the previewer might still be
     using it, perhaps the printer is also?
  if (_path)
    {
      [[NSFileManager defaultManager] removeFileAtPath: _path
                                               handler: nil];
    }
  */
  return success;
}

@end