xref: /haiku/src/add-ons/print/drivers/preview/Driver.cpp (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 /*
2 
3 PDF Writer printer driver.
4 
5 Copyright (c) 2001 OpenBeOS.
6 
7 Authors:
8 	Philippe Houdoin
9 	Simon Gauvin
10 	Michael Pfeiffer
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy of
13 this software and associated documentation files (the "Software"), to deal in
14 the Software without restriction, including without limitation the rights to
15 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
16 of the Software, and to permit persons to whom the Software is furnished to do
17 so, subject to the following conditions:
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 THE SOFTWARE.
29 
30 */
31 
32 
33 #include <stdio.h>
34 #include <string.h>
35 
36 #include <StorageKit.h>
37 
38 #include "Driver.h"
39 #include "PrinterDriver.h"
40 
41 // --------------------------------------------------
42 BMessage*
43 take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
44 {
45 	PrinterDriver *driver;
46 
47 	driver = instanciate_driver(spoolDir);
48 	if (driver->PrintJob(spoolFile, msg) == B_OK) {
49 		msg = new BMessage('okok');
50 	} else {
51 		msg = new BMessage('baad');
52 	}
53 	delete driver;
54 
55 	return msg;
56 }
57 
58 
59 // --------------------------------------------------
60 BMessage*
61 config_page(BNode *spoolDir, BMessage *msg)
62 {
63 	BMessage		*pagesetupMsg = new BMessage(*msg);
64 	PrinterDriver	*driver;
65 	const char		*printerName;
66 	char			buffer[B_ATTR_NAME_LENGTH+1];
67 
68 	// retrieve the printer (spool) name.
69 	printerName = NULL;
70 	if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
71 		printerName = buffer;
72 	}
73 
74 	driver = instanciate_driver(spoolDir);
75 	if (driver->PageSetup(pagesetupMsg, printerName) == B_OK) {
76 		pagesetupMsg->what = 'okok';
77 	} else {
78 		delete pagesetupMsg;
79 		pagesetupMsg = NULL;
80 	}
81 
82 	delete driver;
83 
84 	return pagesetupMsg;
85 }
86 
87 
88 // --------------------------------------------------
89 BMessage*
90 config_job(BNode *spoolDir, BMessage *msg)
91 {
92 	BMessage		*jobsetupMsg = new BMessage(*msg);
93 	PrinterDriver	*driver;
94 	const char		*printerName;
95 	char			buffer[B_ATTR_NAME_LENGTH+1];
96 
97 	// retrieve the printer (spool) name.
98 	printerName = NULL;
99 	if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
100 		printerName = buffer;
101 	}
102 	driver = instanciate_driver(spoolDir);
103 	if (driver->JobSetup(jobsetupMsg, printerName) == B_OK) {
104 		jobsetupMsg->what = 'okok';
105 	} else {
106 		delete jobsetupMsg;
107 		jobsetupMsg = NULL;
108 	}
109 
110 	delete driver;
111 
112 	return jobsetupMsg;
113 }
114 
115 
116 // --------------------------------------------------
117 char*
118 add_printer(char *printerName)
119 {
120 	PrinterDriver* driver;
121 	driver = instanciate_driver(NULL);
122 	if (driver->PrinterSetup(printerName) == B_OK) {
123 		return printerName;
124 	} else {
125 		return NULL;
126 	}
127 }
128 
129 /**
130  * default_settings
131  *
132  * @param BNode* printer spool directory
133  * @return BMessage* the settings
134  */
135 BMessage*
136 default_settings(BNode* spoolDir)
137 {
138 	PrinterDriver* driver;
139 	BMessage* settings;
140 	driver = instanciate_driver(spoolDir);
141 	settings = driver->GetDefaultSettings();
142 	delete driver;
143 	return settings;
144 }
145