Store page and job settings separately. Renamed constants
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6655 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -44,26 +44,11 @@ THE SOFTWARE.
|
|||||||
* @param BNode& the spooler folder
|
* @param BNode& the spooler folder
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
PrinterSettings::PrinterSettings(BNode &printer)
|
PrinterSettings::PrinterSettings(BNode &printer, Kind kind)
|
||||||
{
|
{
|
||||||
fNode = printer;
|
fNode = printer;
|
||||||
fErr = fNode.InitCheck();
|
fErr = fNode.InitCheck();
|
||||||
}
|
fKind = kind;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param const char*, the printer name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
PrinterSettings::PrinterSettings(const char *printer)
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
|
|
||||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
|
||||||
path.Append(PRINTER_SETTINGS_PATH);
|
|
||||||
path.Append(printer);
|
|
||||||
fErr = fNode.SetTo(path.Path());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,14 +88,15 @@ PrinterSettings::ReadSettings(BMessage *msg)
|
|||||||
msg->MakeEmpty();
|
msg->MakeEmpty();
|
||||||
msg->what = 0;
|
msg->what = 0;
|
||||||
|
|
||||||
if (fNode.GetAttrInfo(ATTR_NAME, &info) == B_OK) {
|
if (fNode.GetAttrInfo(GetAttrName(), &info) == B_OK) {
|
||||||
data = (char *)malloc(info.size);
|
data = (char *)malloc(info.size);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
err = fNode.ReadAttr(ATTR_NAME, B_MESSAGE_TYPE, 0, data, info.size);
|
err = fNode.ReadAttr(GetAttrName(), B_MESSAGE_TYPE, 0, data, info.size);
|
||||||
if (err >= 0) {
|
if (err >= 0) {
|
||||||
err = B_OK;
|
err = B_OK;
|
||||||
msg->Unflatten(data);
|
msg->Unflatten(data);
|
||||||
}
|
}
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
} else { // no attributes found, then we create them
|
} else { // no attributes found, then we create them
|
||||||
GetDefaults(msg);
|
GetDefaults(msg);
|
||||||
@@ -133,15 +119,16 @@ PrinterSettings::WriteSettings(BMessage* msg)
|
|||||||
size_t length;
|
size_t length;
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
status_t err = B_ERROR;
|
status_t err = B_ERROR;
|
||||||
|
|
||||||
length = msg->FlattenedSize();
|
length = msg->FlattenedSize();
|
||||||
data = (char *) malloc(length);
|
data = (char *) malloc(length);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
msg->Flatten(data, length);
|
msg->Flatten(data, length);
|
||||||
err = fNode.WriteAttr(ATTR_NAME, B_MESSAGE_TYPE, 0, data, length);
|
err = fNode.WriteAttr(GetAttrName(), B_MESSAGE_TYPE, 0, data, length);
|
||||||
if (err > 0) {
|
if (err > 0) {
|
||||||
err = B_OK;
|
err = B_OK;
|
||||||
}
|
}
|
||||||
|
free(data);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -167,26 +154,28 @@ PrinterSettings::GetDefaults(BMessage *msg)
|
|||||||
*msg = settings;
|
*msg = settings;
|
||||||
} else {
|
} else {
|
||||||
// set default value if property not set
|
// set default value if property not set
|
||||||
msg->AddInt64("xres", XRES);
|
msg->AddInt64("xres", kXRes);
|
||||||
msg->AddInt64("yres", YRES);
|
msg->AddInt64("yres", kYRes);
|
||||||
msg->AddInt32("orientation", ORIENTATION);
|
msg->AddInt32("orientation", kOrientation);
|
||||||
msg->AddRect("paper_rect", PAPER_RECT);
|
msg->AddRect("paper_rect", kPaperRect);
|
||||||
msg->AddRect("printable_rect", PRINT_RECT);
|
msg->AddRect("printable_rect", kPrintRect);
|
||||||
msg->AddFloat("scaling", RES);
|
msg->AddFloat("scaling", kRes);
|
||||||
msg->AddString("pdf_compatibility", PDF_COMPATIBILITY);
|
msg->AddString("pdf_compatibility", kPDFCompatibilty);
|
||||||
msg->AddInt32("pdf_compression", PDF_COMPRESSION);
|
msg->AddInt32("pdf_compression", kPDFCompression);
|
||||||
msg->AddInt32("units", UNITS);
|
msg->AddInt32("units", kUnits);
|
||||||
msg->AddBool("create_web_links", CREATE_WEB_LINKS);
|
msg->AddBool("create_web_links", kCreateWebLinks);
|
||||||
msg->AddFloat("link_border_width", LINK_BORDER_WIDTH);
|
msg->AddFloat("link_border_width", kLinkBorderWidth);
|
||||||
msg->AddBool("create_bookmarks", CREATE_BOOKMARKS);
|
msg->AddBool("create_bookmarks", kCreateBookmarks);
|
||||||
msg->AddString("bookmark_definition_file", BOOKMARK_DEFINITION_FILE);
|
msg->AddString("bookmark_definition_file", kBookmarkDefinitionFile);
|
||||||
msg->AddBool("create_xrefs", CREATE_XREFS);
|
msg->AddBool("create_xrefs", kCreateXRefs);
|
||||||
msg->AddString("xrefs_file", XREFS_FILE);
|
msg->AddString("xrefs_file", kXRefsFile);
|
||||||
msg->AddInt32("close_option", CLOSE_OPTION);
|
msg->AddInt32("close_option", kCloseStatusWindow);
|
||||||
msg->AddString("pdflib_license_key", PDFLIB_LICENSE_KEY);
|
#if HAVE_FULLVERSION_PDF_LIB
|
||||||
msg->AddString("master_password", MASTER_PASSWORD);
|
msg->AddString("pdflib_license_key", kPDFLibLicenseKey);
|
||||||
msg->AddString("user_password", USER_PASSWORD);
|
msg->AddString("master_password", kMasterPassword);
|
||||||
msg->AddString("permissions", PERMISSIONS);
|
msg->AddString("user_password", kUserPassword);
|
||||||
|
msg->AddString("permissions", kPermissions);
|
||||||
|
#endif
|
||||||
|
|
||||||
// create pdf_printer_settings file
|
// create pdf_printer_settings file
|
||||||
prefs.SaveSettings(msg);
|
prefs.SaveSettings(msg);
|
||||||
@@ -262,6 +251,7 @@ PrinterSettings::Validate(const BMessage *msg)
|
|||||||
if (msg->FindInt32("close_option", &i32) != B_OK) {
|
if (msg->FindInt32("close_option", &i32) != B_OK) {
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
#if HAVE_FULLVERSION_PDF_LIB
|
||||||
if (msg->FindString("pdflib_license_key", &s) != B_OK) {
|
if (msg->FindString("pdflib_license_key", &s) != B_OK) {
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
@@ -274,26 +264,42 @@ PrinterSettings::Validate(const BMessage *msg)
|
|||||||
if (msg->FindString("permissions", &s) != B_OK) {
|
if (msg->FindString("permissions", &s) != B_OK) {
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// message ok
|
// message ok
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrinterSettings::Update(BNode* node, BMessage* msg)
|
PrinterSettings::Read(BNode* node, BMessage* msg, Kind kind)
|
||||||
|
{
|
||||||
|
PrinterSettings ps(*node, kind);
|
||||||
|
if (ps.Validate(msg) != B_OK) {
|
||||||
|
msg->MakeEmpty();
|
||||||
|
}
|
||||||
|
BMessage settings;
|
||||||
|
// check for previously saved settings
|
||||||
|
if (ps.ReadSettings(&settings) != B_OK || ps.Validate(&settings) != B_OK) {
|
||||||
|
// if there were none, then create a default set...
|
||||||
|
ps.GetDefaults(&settings);
|
||||||
|
}
|
||||||
|
AddFields(msg, &settings, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PrinterSettings::Update(BNode* node, BMessage* msg, Kind kind)
|
||||||
{
|
{
|
||||||
// Validate the message so that it is good for PDF Writer GUI
|
// Validate the message so that it is good for PDF Writer GUI
|
||||||
PrinterSettings ps(*node);
|
PrinterSettings ps(*node, kind);
|
||||||
if (ps.Validate(msg) != B_OK) {
|
|
||||||
BMessage settings;
|
|
||||||
// check for previously saved settings
|
|
||||||
if (ps.ReadSettings(&settings) != B_OK || ps.Validate(&settings) != B_OK) {
|
|
||||||
// if there were none, then create a default set...
|
|
||||||
ps.GetDefaults(&settings);
|
|
||||||
}
|
|
||||||
AddFields(msg, &settings, false);
|
|
||||||
}
|
|
||||||
// ...and save them
|
|
||||||
ps.WriteSettings(msg);
|
ps.WriteSettings(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
PrinterSettings::GetAttrName() const
|
||||||
|
{
|
||||||
|
if (fKind == kJobSettings) {
|
||||||
|
return kAttrJobSettings;
|
||||||
|
} else {
|
||||||
|
return kAttrPageSettings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,44 +37,49 @@ THE SOFTWARE.
|
|||||||
#include "PrinterDriver.h"
|
#include "PrinterDriver.h"
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const char ATTR_NAME[] = "printer_settings";
|
const char kAttrPageSettings[] = "pdfwriter/page_settings";
|
||||||
const char PDF_COMPATIBILITY[] = "1.3";
|
const char kAttrJobSettings[] = "pdfwriter/job_settings";
|
||||||
const char PRINTER_SETTINGS_PATH[] = "printers/";
|
// page settings
|
||||||
const int64 XRES = 360;
|
const char kPDFCompatibilty[] = "1.3";
|
||||||
const int64 YRES = 360;
|
const char kPrinterSettingsPath[] = "printers/";
|
||||||
const int32 ORIENTATION = PrinterDriver::PORTRAIT_ORIENTATION;
|
const int64 kXRes = 360;
|
||||||
const float RES = 72.0f;
|
const int64 kYRes = 360;
|
||||||
const int32 PDF_COMPRESSION = 3;
|
const int32 kOrientation = PrinterDriver::PORTRAIT_ORIENTATION;
|
||||||
const int32 UNITS = 1;
|
const float kRes = 72.0f;
|
||||||
const float LETTER_W = 8.5f * RES;
|
const int32 kPDFCompression = 3;
|
||||||
const float LETTER_H = 11.0f * RES;
|
const int32 kUnits = 1;
|
||||||
const BRect PAPER_RECT(0, 0, LETTER_W, LETTER_H);
|
const float kLetterW = 8.5f * kRes;
|
||||||
const BRect PRINT_RECT(0, 0, LETTER_W, LETTER_H);
|
const float kLetterH = 11.0f * kRes;
|
||||||
const bool CREATE_WEB_LINKS = false;
|
const BRect kPaperRect(0, 0, kLetterW, kLetterH);
|
||||||
const float LINK_BORDER_WIDTH = 1.0;
|
const BRect kPrintRect(0, 0, kLetterW, kLetterH);
|
||||||
const bool CREATE_BOOKMARKS = false;
|
const bool kCreateWebLinks = false;
|
||||||
const char BOOKMARK_DEFINITION_FILE[] = "";
|
const float kLinkBorderWidth = 1.0;
|
||||||
const bool CREATE_XREFS = false;
|
const bool kCreateBookmarks = false;
|
||||||
const char XREFS_FILE[] = "";
|
const char kBookmarkDefinitionFile[] = "";
|
||||||
const int32 CLOSE_OPTION = 0;
|
const bool kCreateXRefs = false;
|
||||||
const char PDFLIB_LICENSE_KEY[] = "";
|
const char kXRefsFile[] = "";
|
||||||
const char USER_PASSWORD[] = ""; // none if empty
|
const int32 kCloseStatusWindow = 0;
|
||||||
const char MASTER_PASSWORD[] = ""; // none if empty
|
// requires commercial version of PDFlib
|
||||||
const char PERMISSIONS[] = ""; // all is allowed
|
#if HAVE_FULLVERSION_PDF_LIB
|
||||||
|
const char kPDFLibLicenseKey[] = "";
|
||||||
|
const char kUserPassword[] = ""; // none if empty
|
||||||
|
const char kMasterPassword[] = ""; // none if empty
|
||||||
|
const char kPermissions[] = ""; // all is allowed
|
||||||
|
#endif
|
||||||
|
// job settings (we do not have default values for them)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class
|
* Class
|
||||||
*/
|
*/
|
||||||
class PrinterSettings
|
class PrinterSettings
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
BNode fNode;
|
|
||||||
status_t fErr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PrinterSettings() { }
|
enum Kind {
|
||||||
PrinterSettings(const char *printer);
|
kPageSettings,
|
||||||
PrinterSettings(BNode &printer);
|
kJobSettings
|
||||||
|
};
|
||||||
|
|
||||||
|
PrinterSettings(BNode &printer, Kind kind);
|
||||||
~PrinterSettings();
|
~PrinterSettings();
|
||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
@@ -83,7 +88,16 @@ public:
|
|||||||
status_t GetDefaults(BMessage *msg);
|
status_t GetDefaults(BMessage *msg);
|
||||||
status_t Validate(const BMessage *msg);
|
status_t Validate(const BMessage *msg);
|
||||||
|
|
||||||
static void Update(BNode* node, BMessage* msg);
|
static void Read(BNode* node, BMessage* msg, Kind kind);
|
||||||
|
static void Update(BNode* node, BMessage* msg, Kind kind);
|
||||||
|
|
||||||
|
private:
|
||||||
|
PrinterSettings();
|
||||||
|
const char* GetAttrName() const;
|
||||||
|
|
||||||
|
BNode fNode;
|
||||||
|
status_t fErr;
|
||||||
|
enum Kind fKind;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user