diff --git a/headers/private/print/PrintTransport.h b/headers/private/print/PrintTransport.h new file mode 100644 index 0000000000..c2238fdaa8 --- /dev/null +++ b/headers/private/print/PrintTransport.h @@ -0,0 +1,61 @@ +/* + +PrintTransport + +Copyright (c) 2004 OpenBeOS. + +Authors: + Michael Pfeiffer + Philippe Houdoin + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#ifndef PRINT_TRANSPORT_H +#define PRINT_TRANSPORT_H + +#include +#include +#include +#include + +// The class PrintTransport is intended to be used by +// a printer driver. +class PrintTransport +{ +public: + PrintTransport(); + ~PrintTransport(); + + // opens the transport add-on associated with the printerFolder + status_t Open(BNode* printerFolder); + // returns the output stream created by the transport add-on + BDataIO* GetDataIO(); + // returns false if the user has canceled the save to file dialog + // of the "Print To File" transport add-on. + bool IsPrintToFileCanceled() const; + +private: + BDataIO* fDataIO; + image_id fAddOnID; + void (*fExitProc)(void); +}; + +#endif PRINT_TRANSPORT_H diff --git a/src/add-ons/print/shared/Jamfile b/src/add-ons/print/shared/Jamfile index 0aa52b2999..1c3b08e4f8 100644 --- a/src/add-ons/print/shared/Jamfile +++ b/src/add-ons/print/shared/Jamfile @@ -8,6 +8,7 @@ StaticLibrary PicturePrinter.cpp PrintJobReader.cpp PictureIterator.cpp + PrintTransport.cpp ; StaticLibrary diff --git a/src/add-ons/print/shared/PrintTransport.cpp b/src/add-ons/print/shared/PrintTransport.cpp new file mode 100644 index 0000000000..00e3cacf57 --- /dev/null +++ b/src/add-ons/print/shared/PrintTransport.cpp @@ -0,0 +1,133 @@ +/* + +PrintTransport + +Copyright (c) 2004 OpenBeOS. + +Authors: + Philippe Houdoin + Michael Pfeiffer + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +#include "PrintTransport.h" + +#include +#include +#include +#include +#include + +// implementation of class PrintTransport +PrintTransport::PrintTransport() + : fDataIO(NULL) + , fAddOnID(-1) + , fExitProc(NULL) +{ +} + +PrintTransport::~PrintTransport() +{ + if (fExitProc) { + (*fExitProc)(); + fExitProc = NULL; + } + + if (fAddOnID >= 0) { + unload_add_on(fAddOnID); + fAddOnID = -1; + } +} + +status_t PrintTransport::Open(BNode* printerFolder) +{ + // already opened? + if (fDataIO != NULL) { + return B_ERROR; + } + + // retrieve transport add-on name from printer folder attribute + BString transportName; + if (printerFolder->ReadAttrString("transport", &transportName) != B_OK) { + return B_ERROR; + } + + // try first in user add-ons directory + BPath path; + find_directory(B_USER_ADDONS_DIRECTORY, &path); + path.Append("Print/transport"); + path.Append(transportName.String()); + fAddOnID = load_add_on(path.Path()); + + if (fAddOnID < 0) { + // on failure try in system add-ons directory + find_directory(B_BEOS_ADDONS_DIRECTORY, &path); + path.Append("Print/transport"); + path.Append(transportName.String()); + fAddOnID = load_add_on(path.Path()); + } + + if (fAddOnID < 0) { + // failed to load transport add-on + return B_ERROR; + } + + // get init & exit proc + BDataIO* (*initProc)(BMessage*); + get_image_symbol(fAddOnID, "init_transport", B_SYMBOL_TYPE_TEXT, (void **) &initProc); + get_image_symbol(fAddOnID, "exit_transport", B_SYMBOL_TYPE_TEXT, (void **) &fExitProc); + + if (initProc == NULL || fExitProc == NULL) { + // transport add-on has not the proper interface + return B_ERROR; + } + + // now, initialize the transport add-on + node_ref ref; + BDirectory dir; + + printerFolder->GetNodeRef(&ref); + dir.SetTo(&ref); + + if (path.SetTo(&dir, NULL) != B_OK) { + return B_ERROR; + } + + // request BDataIO object from transport add-on + BMessage input('TRIN'); + input.AddString("printer_file", path.Path()); + fDataIO = (*initProc)(&input); + return B_OK; +} + +BDataIO* +PrintTransport::GetDataIO() +{ + return fDataIO; +} + +bool PrintTransport::IsPrintToFileCanceled() const +{ + // The BeOS "Print To File" transport add-on returns a non-NULL BDataIO * + // even after user filepanel cancellation! + BFile* file = dynamic_cast(fDataIO); + return file != NULL && file->InitCheck() != B_OK; +}