Workaround for Dano/Zeta is required because it does not store all fields from the BMessage returned by config_job in the spool file, we add the missing fields that are stored in an attribute of the printer folder.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5490 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2003-11-27 18:22:46 +00:00
parent 1f62b22aa0
commit c8ec7d9a9b
17 changed files with 109 additions and 109 deletions
@@ -50,8 +50,8 @@ private:
};
Cache::Cache()
: fNextID(0)
, fPass(0)
: fPass(0)
, fNextID(0)
{};
void Cache::NextPass() {
@@ -33,6 +33,7 @@ THE SOFTWARE.
#include "InterfaceUtils.h"
#include <ctype.h>
#if HAVE_FULLVERSION_PDF_LIB
// pdflib 5.x supports password protection and permissions in the commercial license only!
static const PermissionLabels gPermissionLabels[] = {
PermissionLabels("Prevent printing the file.", "noprint"),
@@ -76,6 +77,7 @@ void Permissions::Encode(BString* s) {
}
}
}
#endif
// --------------------------------------------------
DocInfoWindow::DocInfoWindow(BMessage *doc_info)
@@ -90,16 +92,20 @@ DocInfoWindow::DocInfoWindow(BMessage *doc_info)
BString permissions;
fDocInfo = doc_info;
#if HAVE_FULLVERSION_PDF_LIB
if (DocInfo()->FindString("permissions", &permissions) == B_OK) {
fPermissions.Decode(permissions.String());
}
#endif
r = Bounds();
tabView = new BTabView(r, "tab_view");
SetupDocInfoView(CreateTabPanel(tabView, "Information"));
//SetupPasswordView(CreateTabPanel(tabView, "Password"));
//SetupPermissionsView(CreateTabPanel(tabView, "Permissions"));
#if HAVE_FULLVERSION_PDF_LIB
SetupPasswordView(CreateTabPanel(tabView, "Password"));
SetupPermissionsView(CreateTabPanel(tabView, "Permissions"));
#endif
AddChild(tabView);
MoveTo(320, 320);
@@ -207,6 +213,7 @@ DocInfoWindow::SetupDocInfoView(BBox* panel) {
}
#if HAVE_FULLVERSION_PDF_LIB
BTextControl*
DocInfoWindow::AddPasswordControl(BRect r, BView* panel, const char* name, const char* label) {
BString s;
@@ -242,6 +249,7 @@ DocInfoWindow::SetupPermissionsView(BBox* panel) {
SetupButtons(panel);
}
#endif
// --------------------------------------------------
bool
@@ -268,9 +276,12 @@ DocInfoWindow::MessageReceived(BMessage *msg)
case OK_MSG: {
BMessage doc_info;
ReadFieldsFromTable(&doc_info);
DocInfo()->ReplaceMessage("doc_info", &doc_info);
DocInfo()->RemoveName("doc_info");
DocInfo()->AddMessage("doc_info", &doc_info);
#if HAVE_FULLVERSION_PDF_LIB
ReadPasswords();
ReadPermissions();
#endif
Quit();
}
break;
@@ -320,7 +331,7 @@ DocInfoWindow::BuildTable(BMessage *docInfo)
y = 5;
w = r.Width() - 10;
for (int32 i = 0; docInfo->GetInfo(B_STRING_TYPE, i, &name, &type, &count) != B_BAD_INDEX; i++) {
for (int32 i = 0; docInfo->GetInfo(B_STRING_TYPE, i, &name, &type, &count) == B_OK; i++) {
if (type == B_STRING_TYPE) {
BString value;
if (docInfo->FindString(name, &value) == B_OK) {
@@ -352,12 +363,13 @@ DocInfoWindow::BuildTable(BMessage *docInfo)
}
#if HAVE_FULLVERSION_PDF_LIB
// --------------------------------------------------
void
DocInfoWindow::ReadPasswords()
{
//AddString(DocInfo(), "master_password", fMasterPassword->TextView()->Text());
//AddString(DocInfo(), "user_password", fUserPassword->TextView()->Text());
AddString(DocInfo(), "master_password", fMasterPassword->TextView()->Text());
AddString(DocInfo(), "user_password", fUserPassword->TextView()->Text());
}
// --------------------------------------------------
@@ -366,9 +378,9 @@ DocInfoWindow::ReadPermissions()
{
BString permissions;
fPermissions.Encode(&permissions);
// AddString(DocInfo(), "permissions", permissions.String());
AddString(DocInfo(), "permissions", permissions.String());
}
#endif
// --------------------------------------------------
@@ -42,6 +42,9 @@ THE SOFTWARE.
#include "InterfaceUtils.h"
#include "Utils.h"
#define HAVE_FULLVERSION_PDF_LIB 0
#if HAVE_FULLVERSION_PDF_LIB
class PermissionLabels {
private:
const char* fName;
@@ -84,6 +87,7 @@ public:
void Decode(const char* s);
void Encode(BString* s);
};
#endif
class DocInfoWindow : public HWindow
{
@@ -114,22 +118,28 @@ private:
BView *fTable;
BScrollView *fTableScrollView;
BMenu *fKeyList;
#if HAVE_FULLVERSION_PDF_LIB
BTextControl *fMasterPassword;
BTextControl *fUserPassword;
Permissions fPermissions;
#endif
BMessage* DocInfo() { return fDocInfo; }
BBox* CreateTabPanel(BTabView* tabView, const char* label);
void SetupButtons(BBox* panel);
void SetupDocInfoView(BBox* panel);
#if HAVE_FULLVERSION_PDF_LIB
BTextControl* AddPasswordControl(BRect r, BView* panel, const char* name, const char* label);
void SetupPasswordView(BBox* panel);
void SetupPermissionsView(BBox* panel);
#endif
void BuildTable(BMessage *fromDocInfo);
void ReadFieldsFromTable(BMessage* doc_info);
#if HAVE_FULLVERSION_PDF_LIB
void ReadPasswords();
void ReadPermissions();
#endif
void EmptyKeyList();
bool IsValidKey(const char *key);
void AddKey(BMessage* msg, bool textControl);
@@ -87,18 +87,7 @@ config_page(BNode *spoolDir, BMessage *msg)
pagesetupMsg = new BMessage(*msg);
// Validate the message so that it is good for PDF Writer GUI
PrinterSettings *ps = new PrinterSettings(*spoolDir);
if (ps->Validate(pagesetupMsg) != B_OK) {
// check for previously saved settings
if (ps->ReadSettings(pagesetupMsg) != B_OK) {
// if there were none, then create a default set...
ps->GetDefaults(pagesetupMsg);
// ...and save them
ps->WriteSettings(pagesetupMsg);
}
}
delete ps;
PrinterSettings::Update(spoolDir, msg);
/* ======== For testing only ==================
@@ -142,18 +131,7 @@ config_job(BNode *spoolDir, BMessage *msg)
jobsetupMsg = new BMessage(*msg);
// Validate the message so that it is good for PDF Writer GUI
PrinterSettings *ps = new PrinterSettings(*spoolDir);
if (ps->Validate(jobsetupMsg) != B_OK) {
// check for previously saved settings
if (ps->ReadSettings(jobsetupMsg) != B_OK) {
// if there were none, then create a default set...
ps->GetDefaults(jobsetupMsg);
// ...and save them
ps->WriteSettings(jobsetupMsg);
}
}
delete ps;
PrinterSettings::Update(spoolDir, jobsetupMsg);
/* ======== For testing only ==================
@@ -209,19 +187,9 @@ instanciate_driver(BNode *spoolDir)
BMessage*
default_settings(BNode* printer)
{
// (new BAlert("", "default_settings()", "Driver.cpp"))->Go();
PrinterSettings *ps = new PrinterSettings(*printer);
BMessage *msg = new BMessage();
// first read the settings from the spool dir
if (ps->ReadSettings(msg) != B_OK) {
// if there were none, then create a default set...
ps->GetDefaults(msg);
// ...and save them
ps->WriteSettings(msg);
}
delete ps;
PrinterSettings::Update(printer, msg);
return msg;
}
@@ -60,6 +60,7 @@ CacheItem* ImageDescription::NewItem(int id) {
if (image == NULL) {
REPORT(kDebug, -1, "Could not store image in cache!");
}
return image;
}
Image* ImageDescription::Store(PDF* pdf, int id, BBitmap* bitmap, int mask) {
@@ -73,12 +73,11 @@ HWindow::MessageReceived(BMessage* msg)
static const char*
kAbout =
"PDF Writer for BeOS\n"
"© 2001, 2002 OpenBeOS\n"
"© 2001-2003 OpenBeOS\n"
"\n"
"\tPhilippe Houdoin - Project Leader\n"
"\tSimon Gauvin - GUI Design\n"
"\tMichael Pfeiffer - PDF Generation, Configuration, Interactive Features\n"
"\tCelerick Stephens - Documentation\n"
;
void
@@ -2,7 +2,7 @@
PDF Writer printer driver.
Copyright (c) 2001 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -34,11 +34,16 @@ THE SOFTWARE.
#include <stdlib.h>
#include "PrinterDriver.h"
#include "PrinterSettings.h"
#include "JobSetupWindow.h"
#include "DocInfoWindow.h"
static const char* includeKeys[] = {
"doc_info", "master_password", "user_password", "permissions", NULL
"doc_info",
#if HAVE_FULLVERSION_PDF_LIB
"master_password", "user_password", "permissions",
#endif
NULL
};
// --------------------------------------------------
@@ -55,6 +60,7 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
BString title;
title << printerName << " Job Setup";
SetTitle(title.String());
fPrinterName = printerName;
}
// ---- Ok, build a default job setup user interface
@@ -82,9 +88,9 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
doc_info.AddString("Author", "");
doc_info.AddString("Subject", "");
doc_info.AddString("Keywords", "");
msg->AddMessage("doc_info", &doc_info);
fSetupMsg->AddMessage("doc_info", &doc_info);
}
AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys);
AddFields(&fDocInfo, fSetupMsg, true, NULL, includeKeys);
allPages = firstPage == 1 && lastPage == MAX_INT32;
@@ -237,8 +243,6 @@ JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
void
JobSetupWindow::UpdateJobMessage()
{
// int32 copies = atoi(fCopies->Text());
// if (copies <= 0)
int32 copies = 1;
int32 from;
@@ -256,6 +260,12 @@ JobSetupWindow::UpdateJobMessage()
fSetupMsg->ReplaceInt32("first_page", from);
fSetupMsg->ReplaceInt32("last_page", to);
AddFields(fSetupMsg, &fDocInfo);
// save the settings to the new defaults
PrinterSettings ps(fPrinterName.String());
if (ps.InitCheck() == B_OK) {
ps.WriteSettings(fSetupMsg);
}
}
@@ -296,7 +306,6 @@ JobSetupWindow::MessageReceived(BMessage *msg)
break;
case DOC_INFO_MSG:
fDocInfo.PrintToStream(); fflush(stdout);
(new DocInfoWindow(&fDocInfo))->Show();
break;
@@ -66,6 +66,7 @@ public:
// From here, it's none of your business! ;-)
private:
BString fPrinterName;
long fExitSem;
status_t fResult;
BMessage *fSetupMsg;
@@ -264,7 +264,6 @@ PDFWriter::FindFont(char* fontName, bool embed, font_encoding encoding)
if (embed) embed = EmbedFont(fontName);
BString s;
char user_defined[80];
const char* encoding_name;
if (encoding < user_defined_encoding_start) {
encoding_name = encoding_names[encoding];
@@ -427,7 +427,6 @@ PDFWriter::DeclareFonts()
for (int i = 0; i < fFonts->Length(); i++) {
FontFile* f = fFonts->At(i);
// LOG((fLog, "path= %s\n", f->Path()));
if (f->Type() == true_type_type) {
parameter_name = "FontOutline";
} else { // f->Type() == type1_type
@@ -443,8 +442,6 @@ PDFWriter::DeclareFonts()
#else
sprintf(buffer, "%s==%s", f->Name(), f->Path());
#endif
// LOG((fLog, "%s: %s\n", parameter_name, buffer));
PDF_set_parameter(fPdf, parameter_name, buffer);
}
return B_OK;
@@ -504,11 +504,10 @@ PageSetupWindow::UpdateSetupMessage()
}
// save the settings to the new defaults
PrinterSettings *ps = new PrinterSettings(fPrinterDirName.String());
if (ps->InitCheck() == B_OK) {
ps->WriteSettings(fSetupMsg);
PrinterSettings ps(fPrinterDirName.String());
if (ps.InitCheck() == B_OK) {
ps.WriteSettings(fSetupMsg);
}
delete ps;
}
@@ -2,7 +2,7 @@
PDF Writer printer driver.
Copyright (c) 2001 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -133,6 +133,13 @@ PrinterDriver::PrintJob
// read job message
fJobMsg = msg = new BMessage();
msg->Unflatten(fJobFile);
// We have to load the settings here for Dano/Zeta because they don't store
// all fields from the message returned by config_job in the job file!
printf("JobMsg\n");
msg->PrintToStream();
PrinterSettings::Update(printerNode, msg);
printf("\n\nAfter Update:\n");
msg->PrintToStream();
if (msg->HasInt32("copies")) {
copies = msg->FindInt32("copies");
@@ -242,36 +249,6 @@ PrinterDriver::PrinterSetup(char *printerName)
status_t
PrinterDriver::PageSetup(BMessage *setupMsg, const char *printerName)
{
/*
BRect paperRect;
BRect printRect;
// const float kScale = 8.3333f;
const float kScreen = 72.0f;
const float kLetterWidth = 8.5;
const float kLetterHeight = 11;
// set default value if property not set
if (!setupMsg->HasInt64("xres"))
setupMsg->AddInt64("xres", 360);
if (!setupMsg->HasInt64("yres"))
setupMsg->AddInt64("yres", 360);
if (!setupMsg->HasInt32("orientation"))
setupMsg->AddInt32("orientation", PORTRAIT_ORIENTATION);
paperRect = BRect(0, 0, kLetterWidth * kScreen, kLetterHeight * kScreen);
printRect = BRect(0, 0, kLetterWidth * kScreen, kLetterHeight * kScreen);
if (!setupMsg->HasRect("paper_rect"))
setupMsg->AddRect("paper_rect", paperRect);
if (!setupMsg->HasRect("printable_rect"))
setupMsg->AddRect("printable_rect", printRect);
*/
// check to see if the messag is built correctly...
if (setupMsg->HasFloat("scaling") != B_OK) {
PrinterSettings *ps = new PrinterSettings(printerName);
@@ -284,9 +261,6 @@ PrinterDriver::PageSetup(BMessage *setupMsg, const char *printerName)
// ...and save them
ps->WriteSettings(setupMsg);
}
} else {
// Temp
//(new BAlert("", "Problem Loading Settings", "PrinterDriver"))->Go();
}
}
@@ -2,7 +2,7 @@
PDF Writer printer driver.
Copyright (c) 2001 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -2,7 +2,7 @@
Printer Settings helper class
Copyright (c) 2001 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -36,6 +36,7 @@ THE SOFTWARE.
#include <fs_attr.h>
#include "PrinterPrefs.h"
#include "Utils.h"
/**
* Constructor
@@ -276,4 +277,23 @@ PrinterSettings::Validate(const BMessage *msg)
// message ok
return B_OK;
}
void
PrinterSettings::Update(BNode* node, BMessage* msg)
{
// Validate the message so that it is good for PDF Writer GUI
PrinterSettings ps(*node);
if (ps.Validate(msg) != B_OK) {
BMessage settings;
// check for previously saved settings
if (ps.ReadSettings(&settings) != B_OK) {
// if there were none, then create a default set...
ps.GetDefaults(&settings);
// ...and save them
ps.WriteSettings(&settings);
}
AddFields(&settings, msg, false);
}
}
@@ -2,7 +2,7 @@
PrinterSettings.h
Copyright (c) 2001 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -82,7 +82,10 @@ public:
status_t ReadSettings(BMessage *msg);
status_t GetDefaults(BMessage *msg);
status_t Validate(const BMessage *msg);
static void Update(BNode* node, BMessage* msg);
};
#endif
+15 -7
View File
@@ -2,7 +2,7 @@
PDF Writer printer driver.
Copyright (c) 2001, 2002 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -66,28 +66,36 @@ static bool InList(const char* list[], const char* name) {
// --------------------------------------------------
// copied from BeUtils.cpp
void AddFields(BMessage* to, const BMessage* from, const char* excludeList[], const char* includeList[]) {
void AddFields(BMessage* to, const BMessage* from, bool overwrite = true, const char* excludeList[], const char* includeList[]) {
if (to == from) return;
char* name;
type_code type;
int32 count;
for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) {
const void* data;
ssize_t size;
if (excludeList && InList(excludeList, name)) continue;
if (includeList && !InList(includeList, name)) continue;
if (!overwrite && to->FindData(name, type, 0, &data, &size) == B_OK) {
continue;
}
// replace existing data
to->RemoveName(name);
const void* data;
ssize_t size;
for (int32 j = 0; j < count; j ++) {
if (from->FindData(name, type, j, &data, &size) == B_OK) {
// WTF why works AddData not for B_STRING_TYPE in R5.0.3?
if (type == B_STRING_TYPE) to->AddString(name, (const char*)data);
else if (type == B_MESSAGE_TYPE) {
if (type == B_STRING_TYPE) {
to->AddString(name, (const char*)data);
} else if (type == B_MESSAGE_TYPE) {
BMessage m;
from->FindMessage(name, j, &m);
to->AddMessage(name, &m);
} else to->AddData(name, type, data, size);
} else {
to->AddData(name, type, data, size);
}
}
}
}
+2 -2
View File
@@ -2,7 +2,7 @@
PDF Writer printer driver.
Copyright (c) 2001, 2002 OpenBeOS.
Copyright (c) 2001-2003 OpenBeOS.
Authors:
Philippe Houdoin
@@ -38,7 +38,7 @@ THE SOFTWARE.
// adds fields to message or replaces existing fields (copy BeUtils.h)
void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL);
void AddFields(BMessage* to, const BMessage* from, bool overwrite = true, const char* excludeList[] = NULL, const char* includeList[] = NULL);
void AddString(BMessage* m, const char* name, const char* value);
class EscapeMessageFilter : public BMessageFilter