Improved error reporting.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39667 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fad059587c
commit
c0aa3379bb
@ -186,21 +186,26 @@ GPBinding::EndPage() throw(TransportException)
|
||||
{
|
||||
status_t status = fJob.PrintPage(fBands);
|
||||
DeleteBands();
|
||||
if (status != B_OK)
|
||||
if (status == B_IO_ERROR)
|
||||
throw TransportException("I/O Error");
|
||||
if (status == B_ERROR) {
|
||||
BString message;
|
||||
fJob.GetErrorMessage(message);
|
||||
throw TransportException(message.String());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
status_t
|
||||
GPBinding::AddBitmapToPage(BBitmap* bitmap, BRect validRect, BPoint where)
|
||||
{
|
||||
GPBand* band = new(nothrow) GPBand(bitmap, validRect, where);
|
||||
if (band == NULL) {
|
||||
// TODO report error
|
||||
return;
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
fBands.push_back(band);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -210,8 +215,9 @@ GPBinding::InitGutenprint()
|
||||
if (fInitialized)
|
||||
return;
|
||||
fInitialized = true;
|
||||
// TODO make sure this creates no memory leaks,
|
||||
// as there is no "destroy" counter part
|
||||
// there is no "destroy" counter part so this creates memory leaks
|
||||
// this is no problem because the print server loads printer add-ons
|
||||
// in a new application instance that is terminated when not used anymore
|
||||
stp_init();
|
||||
stp_set_output_codeset("UTF-8");
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
void EndJob() throw(TransportException);
|
||||
void BeginPage() throw(TransportException);
|
||||
void EndPage() throw(TransportException);
|
||||
void AddBitmapToPage(BBitmap* bitmap, BRect validRect, BPoint where);
|
||||
status_t AddBitmapToPage(BBitmap* bitmap, BRect validRect, BPoint where);
|
||||
|
||||
private:
|
||||
void InitGutenprint();
|
||||
|
@ -207,6 +207,7 @@ GPDriver::endPage(int)
|
||||
return true;
|
||||
}
|
||||
catch (TransportException& err) {
|
||||
ShowError(err.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -220,6 +221,7 @@ GPDriver::endDoc(bool)
|
||||
return true;
|
||||
}
|
||||
catch (TransportException& err) {
|
||||
ShowError(err.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -261,25 +263,25 @@ GPDriver::nextBand(BBitmap* bitmap, BPoint* offset)
|
||||
|
||||
x = rc.left;
|
||||
y += rc.top;
|
||||
/*
|
||||
int width = rc.right - rc.left + 1;
|
||||
int height = rc.bottom - rc.top + 1;
|
||||
int delta = bitmap->BytesPerRow();
|
||||
|
||||
DBGMSG(("width = %d\n", width));
|
||||
DBGMSG(("height = %d\n", height));
|
||||
DBGMSG(("delta = %d\n", delta));
|
||||
DBGMSG(("renderobj->get_pixel_depth() = %d\n", fHalftone->getPixelDepth()));
|
||||
*/
|
||||
int width = rc.right - rc.left + 1;
|
||||
int height = rc.bottom - rc.top + 1;
|
||||
fprintf(stderr, "GPDriver nextBand x %d, y %d, width %d,"
|
||||
" height %d\n",
|
||||
x, y, width, height);
|
||||
BRect imageRect(rc.left, rc.top, rc.right, rc.bottom);
|
||||
fBinding.AddBitmapToPage(bitmap, imageRect, BPoint(x, y));
|
||||
status_t status;
|
||||
status = fBinding.AddBitmapToPage(bitmap, imageRect, BPoint(x, y));
|
||||
if (status == B_NO_MEMORY) {
|
||||
ShowError("Out of memory");
|
||||
return false;
|
||||
} else if (status != B_OK) {
|
||||
ShowError("Unknown error");
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
DBGMSG(("band bitmap is clean.\n"));
|
||||
DBGMSG(("band bitmap is empty.\n"));
|
||||
}
|
||||
|
||||
if (y >= page_height) {
|
||||
@ -292,8 +294,19 @@ GPDriver::nextBand(BBitmap* bitmap, BPoint* offset)
|
||||
return true;
|
||||
}
|
||||
catch (TransportException& err) {
|
||||
BAlert* alert = new BAlert("", err.what(), "OK");
|
||||
alert->Go();
|
||||
ShowError(err.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GPDriver::ShowError(const char* message)
|
||||
{
|
||||
BString text;
|
||||
text << "An error occurred attempting to print with Gutenprint:";
|
||||
text << "\n";
|
||||
text << message;
|
||||
BAlert* alert = new BAlert("", text.String(), "OK");
|
||||
alert->Go();
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ protected:
|
||||
bool nextBand(BBitmap* bitmap, BPoint* offset);
|
||||
bool endPage(int page);
|
||||
bool endDoc(bool success);
|
||||
void ShowError(const char* message);
|
||||
|
||||
private:
|
||||
GPBinding fBinding;
|
||||
|
@ -19,7 +19,7 @@ GPJob::GPJob()
|
||||
fVariables(NULL),
|
||||
fBands(NULL),
|
||||
fCachedBand(NULL),
|
||||
fWriteError(B_OK)
|
||||
fStatus(B_OK)
|
||||
{
|
||||
fImage.init = ImageInit;
|
||||
fImage.reset = ImageReset;
|
||||
@ -61,7 +61,7 @@ GPJob::SetOutputStream(OutputStream* outputStream)
|
||||
status_t
|
||||
GPJob::Begin()
|
||||
{
|
||||
fWriteError = B_OK;
|
||||
fStatus = B_OK;
|
||||
|
||||
stp_init();
|
||||
|
||||
@ -217,8 +217,8 @@ from72dpi(int value, int toUnit)
|
||||
|
||||
status_t
|
||||
GPJob::PrintPage(list<GPBand*>& bands) {
|
||||
if (fWriteError != B_OK)
|
||||
return fWriteError;
|
||||
if (fStatus != B_OK)
|
||||
return fStatus;
|
||||
|
||||
fPrintRect = GetPrintRectangle(bands);
|
||||
fBands = &bands;
|
||||
@ -304,7 +304,14 @@ GPJob::PrintPage(list<GPBand*>& bands) {
|
||||
|
||||
stp_print(fVariables, &fImage);
|
||||
|
||||
return fWriteError;
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GPJob::GetErrorMessage(BString& message)
|
||||
{
|
||||
message = fErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
@ -356,7 +363,7 @@ GPJob::Height()
|
||||
stp_image_status_t
|
||||
GPJob::GetRow(unsigned char* data, size_t size, int row)
|
||||
{
|
||||
if (fWriteError != B_OK)
|
||||
if (fStatus != B_OK)
|
||||
return STP_IMAGE_STATUS_ABORT;
|
||||
|
||||
// row is relative to left, top of image
|
||||
@ -454,7 +461,7 @@ GPJob::Write(const char* data, size_t size)
|
||||
try {
|
||||
fOutputStream->Write(data, size);
|
||||
} catch (TransportException e) {
|
||||
fWriteError = B_IO_ERROR;
|
||||
fStatus = B_IO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -462,8 +469,9 @@ GPJob::Write(const char* data, size_t size)
|
||||
void
|
||||
GPJob::ReportError(const char* data, size_t size)
|
||||
{
|
||||
// TODO report error in printer add-on
|
||||
fprintf(stderr, "GPJob Gutenprint Error: %*s\n", (int)size, data);
|
||||
if (fStatus == B_OK)
|
||||
fStatus = B_ERROR;
|
||||
fErrorMessage.Append(data, size);
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
|
||||
status_t PrintPage(list<GPBand*>& bands);
|
||||
|
||||
void GetErrorMessage(BString& message);
|
||||
|
||||
private:
|
||||
BRect GetPrintRectangle(list<GPBand*>& bands);
|
||||
GPBand* FindBand(int line);
|
||||
@ -75,6 +77,7 @@ private:
|
||||
BRect fPrintRect;
|
||||
list<GPBand*>* fBands;
|
||||
GPBand* fCachedBand;
|
||||
status_t fWriteError;
|
||||
status_t fStatus;
|
||||
BString fErrorMessage;
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user