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 status_t st; 121 PrinterDriver* driver; 122 driver = instanciate_driver(NULL); 123 st = driver->PrinterSetup(printerName); 124 delete driver; 125 if (st == B_OK) { 126 return printerName; 127 } else { 128 return NULL; 129 } 130 } 131 132 /** 133 * default_settings 134 * 135 * @param BNode* printer spool directory 136 * @return BMessage* the settings 137 */ 138 BMessage* 139 default_settings(BNode* spoolDir) 140 { 141 PrinterDriver* driver; 142 BMessage* settings; 143 driver = instanciate_driver(spoolDir); 144 settings = driver->GetDefaultSettings(); 145 delete driver; 146 return settings; 147 } 148