* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34445 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-12-02 13:27:04 +00:00
parent 969279e36c
commit e90df81946
+78 -74
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku. * Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -9,6 +9,13 @@
* julun <[email protected]> * julun <[email protected]>
*/ */
#include <PrintJob.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <Button.h> #include <Button.h>
@@ -20,68 +27,58 @@
#include <NodeInfo.h> #include <NodeInfo.h>
#include <OS.h> #include <OS.h>
#include <Path.h> #include <Path.h>
#include <PrintJob.h>
#include <Region.h> #include <Region.h>
#include <Roster.h> #include <Roster.h>
#include <View.h> #include <View.h>
#include <pr_server.h> #include <pr_server.h>
#include <ViewPrivate.h> #include <ViewPrivate.h>
#include <stdio.h> /*! Summary of spool file:
#include <stdlib.h>
#include <string.h>
|-----------------------------------|
| print_file_header |
|-----------------------------------|
| BMessage print_job_settings |
|-----------------------------------|
| |
| ********** (first page) ********* |
| * * |
| * _page_header_ * |
| * ----------------------------- * |
| * |---------------------------| * |
| * | BPoint where | * |
| * | BRect bounds | * |
| * | BPicture pic | * |
| * |---------------------------| * |
| * |---------------------------| * |
| * | BPoint where | * |
| * | BRect bounds | * |
| * | BPicture pic | * |
| * |---------------------------| * |
| ********************************* |
| |
| ********* (second page) ********* |
| * * |
| * _page_header_ * |
| * ----------------------------- * |
| * |---------------------------| * |
| * | BPoint where | * |
| * | BRect bounds | * |
| * | BPicture pic | * |
| * |---------------------------| * |
| ********************************* |
|-----------------------------------|
/* ! BeOS R5 print_file_header.version is 1 << 16
* BeOS R5 print_file_header.first_page is -1
* Summery of R5 spool file:
* each page can consist of a collection of picture structures
* |-----------------------------------| remaining pages start at _page_header_.next_page of previous _page_header_
* | print_file_header |
* |-----------------------------------| See also: "How to Write a BeOS R5 Printer Driver" for description of spool
* | BMessage print_job_settings | file format: http://haiku-os.org/documents/dev/how_to_write_a_printer_driver
* |-----------------------------------|
* | |
* | ********** (first page) ********* |
* | * * |
* | * _page_header_ * |
* | * ----------------------------- * |
* | * |---------------------------| * |
* | * | BPoint where | * |
* | * | BRect bounds | * |
* | * | BPicture pic | * |
* | * |---------------------------| * |
* | * |---------------------------| * |
* | * | BPoint where | * |
* | * | BRect bounds | * |
* | * | BPicture pic | * |
* | * |---------------------------| * |
* | ********************************* |
* | |
* | ********* (second page) ********* |
* | * * |
* | * _page_header_ * |
* | * ----------------------------- * |
* | * |---------------------------| * |
* | * | BPoint where | * |
* | * | BRect bounds | * |
* | * | BPicture pic | * |
* | * |---------------------------| * |
* | ********************************* |
* |-----------------------------------|
*
* BeOS R5 print_file_header.version is 1 << 16
* BeOS R5 print_file_header.first_page is -1
*
* each page can consist of a collection of picture structures
* remaining pages start at _page_header_.next_page of previous _page_header_
*
* See also: "How to Write a BeOS R5 Printer Driver" for description of spool
* file format: http://haiku-os.org/documents/dev/how_to_write_a_printer_driver
*
*/ */
@@ -117,7 +114,7 @@ namespace BPrivate {
void SetResult(BMessage* result); void SetResult(BMessage* result);
BMessage* Result() const { return fResult; } BMessage* Result() const { return fResult; }
static status_t GetPrintServerMessenger(BMessenger& msngr); static status_t GetPrintServerMessenger(BMessenger& messenger);
private: private:
void RejectUserInput(); void RejectUserInput();
@@ -135,14 +132,17 @@ namespace BPrivate {
} // namespace BPrivate } // namespace BPrivate
using namespace BPrivate; using namespace BPrivate;
// #pragma mark -- BPrintJob // #pragma mark -- BPrintJob
BPrintJob::BPrintJob(const char *job_name) BPrintJob::BPrintJob(const char* jobName)
: fPrintJobName(NULL), :
fPrintJobName(NULL),
fSpoolFile(NULL), fSpoolFile(NULL),
fError(B_ERROR), fError(B_ERROR),
fSetupMessage(NULL), fSetupMessage(NULL),
@@ -151,8 +151,8 @@ BPrintJob::BPrintJob(const char *job_name)
{ {
memset(&fSpoolFileHeader, 0, sizeof(print_file_header)); memset(&fSpoolFileHeader, 0, sizeof(print_file_header));
if (job_name != NULL) if (jobName != NULL && jobName[0])
fPrintJobName = strdup(job_name); fPrintJobName = strdup(jobName);
fCurrentPageHeader = new _page_header_; fCurrentPageHeader = new _page_header_;
if (fCurrentPageHeader != NULL) if (fCurrentPageHeader != NULL)
@@ -235,7 +235,8 @@ BPrintJob::BeginJob()
if (path.InitCheck() != B_OK) if (path.InitCheck() != B_OK)
return; return;
// TODO: fSpoolFileName should store the name only (not path which can be 1024 bytes long) // TODO: fSpoolFileName should store the name only (not path which can be
// 1024 bytes long)
strncpy(fSpoolFileName, path.Path(), sizeof(fSpoolFileName)); strncpy(fSpoolFileName, path.Path(), sizeof(fSpoolFileName));
fSpoolFile = new BFile(fSpoolFileName, B_READ_WRITE | B_CREATE_FILE); fSpoolFile = new BFile(fSpoolFileName, B_READ_WRITE | B_CREATE_FILE);
@@ -302,8 +303,8 @@ BPrintJob::CommitJob()
&fSpoolFileHeader.page_count, sizeof(int32)); &fSpoolFileHeader.page_count, sizeof(int32));
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_DESCRIPTION, B_STRING_TYPE, 0, fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_DESCRIPTION, B_STRING_TYPE, 0,
fPrintJobName, strlen(fPrintJobName) + 1); fPrintJobName, strlen(fPrintJobName) + 1);
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_PRINTER, B_STRING_TYPE, 0, printerName, fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_PRINTER, B_STRING_TYPE, 0,
strlen(printerName) + 1); printerName, strlen(printerName) + 1);
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, 0, fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, 0,
PSRV_JOB_STATUS_WAITING, strlen(PSRV_JOB_STATUS_WAITING) + 1); PSRV_JOB_STATUS_WAITING, strlen(PSRV_JOB_STATUS_WAITING) + 1);
fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_MIMETYPE, B_STRING_TYPE, 0, fSpoolFile->WriteAttr(PSRV_SPOOL_ATTR_MIMETYPE, B_STRING_TYPE, 0,
@@ -326,6 +327,7 @@ BPrintJob::CommitJob()
printServer.SendMessage(&request, &reply); printServer.SendMessage(&request, &reply);
} }
void void
BPrintJob::CancelJob() BPrintJob::CancelJob()
{ {
@@ -496,8 +498,7 @@ BPrintJob::PrinterType(void *) const
} }
// #pragma mark - private
// #pragma mark ----- PRIVATE -----
void void
@@ -533,14 +534,15 @@ BPrintJob::_RecurseView(BView *view, BPoint origin, BPicture *picture,
while (child != NULL) { while (child != NULL) {
if ((child->Flags() & B_WILL_DRAW) && !child->IsHidden()) { if ((child->Flags() & B_WILL_DRAW) && !child->IsHidden()) {
BPoint leftTop(view->Bounds().LeftTop() + child->Frame().LeftTop()); BPoint leftTop(view->Bounds().LeftTop() + child->Frame().LeftTop());
BRect printRect(rect.OffsetToCopy(rect.LeftTop() - leftTop) & child->Bounds()); BRect printRect(rect.OffsetToCopy(rect.LeftTop() - leftTop)
& child->Bounds());
if (printRect.IsValid()) if (printRect.IsValid())
_RecurseView(child, origin + leftTop, picture, printRect); _RecurseView(child, origin + leftTop, picture, printRect);
} }
child = child->NextSibling(); child = child->NextSibling();
} }
if (view->Flags() & B_DRAW_ON_CHILDREN) { if ((view->Flags() & B_DRAW_ON_CHILDREN) != 0) {
view->AppendToPicture(picture); view->AppendToPicture(picture);
view->PushState(); view->PushState();
view->SetOrigin(origin); view->SetOrigin(origin);
@@ -557,7 +559,8 @@ BPrintJob::_RecurseView(BView *view, BPoint origin, BPicture *picture,
void void
BPrintJob::_GetMangledName(char* buffer, size_t bufferSize) const BPrintJob::_GetMangledName(char* buffer, size_t bufferSize) const
{ {
snprintf(buffer, bufferSize, "%s@%lld", fPrintJobName, system_time() / 1000); snprintf(buffer, bufferSize, "%s@%lld", fPrintJobName,
system_time() / 1000);
} }
@@ -642,11 +645,10 @@ BPrintJob::_AddPicture(BPicture &picture, BRect &rect, BPoint &where)
picture.Flatten(fSpoolFile); picture.Flatten(fSpoolFile);
} }
/* !
* /*! Returns a copy of the applications default printer name or NULL if it
* Returns a copy of the applications default printer name or NULL if it could not be obtained. Caller is responsible to free the string using
* could not be obtained. Caller is responsible to free the string using free(). free().
*
*/ */
char* char*
BPrintJob::_GetCurrentPrinterName() const BPrintJob::_GetCurrentPrinterName() const
@@ -703,7 +705,8 @@ namespace BPrivate {
PrintServerMessenger::PrintServerMessenger(uint32 what, BMessage *input) PrintServerMessenger::PrintServerMessenger(uint32 what, BMessage *input)
: fWhat(what), :
fWhat(what),
fInput(input), fInput(input),
fRequest(NULL), fRequest(NULL),
fResult(NULL), fResult(NULL),
@@ -766,8 +769,9 @@ namespace BPrivate {
return B_ERROR; return B_ERROR;
// Get the originating window, if it exists // Get the originating window, if it exists
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL))); BWindow* window = dynamic_cast<BWindow*>(
if (window) { BLooper::LooperForThread(find_thread(NULL)));
if (window != NULL) {
status_t err; status_t err;
while (true) { while (true) {
do { do {