xref: /haiku/src/add-ons/print/drivers/preview/Driver.cpp (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2  * Copyright 2001-2007, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Philippe Houdoin
7  *		Simon Gauvin
8  *		Michael Pfeiffer
9  */
10 
11 
12 #include <stdio.h>
13 #include <string.h>
14 
15 #include <StorageKit.h>
16 
17 #include "Driver.h"
18 #include "PrinterDriver.h"
19 
20 // --------------------------------------------------
21 BMessage*
22 take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg)
23 {
24 	PrinterDriver *driver;
25 
26 	driver = instanciate_driver(spoolDir);
27 	if (driver->PrintJob(spoolFile, msg) == B_OK) {
28 		msg = new BMessage('okok');
29 	} else {
30 		msg = new BMessage('baad');
31 	}
32 	delete driver;
33 
34 	return msg;
35 }
36 
37 
38 // --------------------------------------------------
39 BMessage*
40 config_page(BNode *spoolDir, BMessage *msg)
41 {
42 	BMessage		*pagesetupMsg = new BMessage(*msg);
43 	PrinterDriver	*driver;
44 	const char		*printerName;
45 	char			buffer[B_ATTR_NAME_LENGTH+1];
46 
47 	// retrieve the printer (spool) name.
48 	printerName = NULL;
49 	if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
50 		printerName = buffer;
51 	}
52 
53 	driver = instanciate_driver(spoolDir);
54 	if (driver->PageSetup(pagesetupMsg, printerName) == B_OK) {
55 		pagesetupMsg->what = 'okok';
56 	} else {
57 		delete pagesetupMsg;
58 		pagesetupMsg = NULL;
59 	}
60 
61 	delete driver;
62 
63 	return pagesetupMsg;
64 }
65 
66 
67 // --------------------------------------------------
68 BMessage*
69 config_job(BNode *spoolDir, BMessage *msg)
70 {
71 	BMessage		*jobsetupMsg = new BMessage(*msg);
72 	PrinterDriver	*driver;
73 	const char		*printerName;
74 	char			buffer[B_ATTR_NAME_LENGTH+1];
75 
76 	// retrieve the printer (spool) name.
77 	printerName = NULL;
78 	if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) {
79 		printerName = buffer;
80 	}
81 	driver = instanciate_driver(spoolDir);
82 	if (driver->JobSetup(jobsetupMsg, printerName) == B_OK) {
83 		jobsetupMsg->what = 'okok';
84 	} else {
85 		delete jobsetupMsg;
86 		jobsetupMsg = NULL;
87 	}
88 
89 	delete driver;
90 
91 	return jobsetupMsg;
92 }
93 
94 
95 // --------------------------------------------------
96 char*
97 add_printer(char *printerName)
98 {
99 	status_t st;
100 	PrinterDriver* driver;
101 	driver = instanciate_driver(NULL);
102 	st = driver->PrinterSetup(printerName);
103 	delete driver;
104 	if (st == B_OK) {
105 		return printerName;
106 	} else {
107 		return NULL;
108 	}
109 }
110 
111 /**
112  * default_settings
113  *
114  * @param BNode* printer spool directory
115  * @return BMessage* the settings
116  */
117 BMessage*
118 default_settings(BNode* spoolDir)
119 {
120 	PrinterDriver* driver;
121 	BMessage* settings;
122 	driver = instanciate_driver(spoolDir);
123 	settings = driver->GetDefaultSettings();
124 	delete driver;
125 	return settings;
126 }
127