Added Add Printer dialog.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11274 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* AddPrinterDlg.cpp
|
||||
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "DialogWindow.h"
|
||||
|
||||
#include <ListItem.h>
|
||||
#include <View.h>
|
||||
|
||||
class BListView;
|
||||
class BTextView;
|
||||
|
||||
class PrinterData;
|
||||
class PrinterCap;
|
||||
class ProtocolClassCap;
|
||||
|
||||
class ProtocolClassItem : public BStringItem {
|
||||
public:
|
||||
ProtocolClassItem(const ProtocolClassCap* cap);
|
||||
|
||||
int getProtocolClass();
|
||||
const char *getDescription();
|
||||
|
||||
private:
|
||||
const ProtocolClassCap *fProtocolClassCap;
|
||||
};
|
||||
|
||||
class AddPrinterView : public BView {
|
||||
public:
|
||||
AddPrinterView(BRect frame, PrinterData *printer_data, const PrinterCap *printer_cap);
|
||||
~AddPrinterView();
|
||||
virtual void AttachedToWindow();
|
||||
void MessageReceived(BMessage *msg);
|
||||
|
||||
void Save();
|
||||
private:
|
||||
ProtocolClassItem *CurrentSelection();
|
||||
|
||||
PrinterData *fPrinterData;
|
||||
const PrinterCap *fPrinterCap;
|
||||
|
||||
BListView *fProtocolClassList;
|
||||
BTextView *fDescription;
|
||||
};
|
||||
|
||||
|
||||
class AddPrinterDlg : public DialogWindow {
|
||||
public:
|
||||
AddPrinterDlg(PrinterData *printerData, const PrinterCap *printerCap);
|
||||
void MessageReceived(BMessage *msg);
|
||||
|
||||
private:
|
||||
AddPrinterView *fAddPrinterView;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define __GRAPHICSDRIVER_H
|
||||
|
||||
#include "JobData.h"
|
||||
#include "PrinterData.h"
|
||||
#include "PrintProcess.h"
|
||||
#include "SpoolMetaData.h"
|
||||
#include "Transport.h"
|
||||
@@ -45,6 +46,7 @@ protected:
|
||||
const PrinterData *getPrinterData() const;
|
||||
const PrinterCap *getPrinterCap() const;
|
||||
const SpoolMetaData *getSpoolMetaData() const;
|
||||
int getProtocolClass() const;
|
||||
|
||||
int getPageWidth() const;
|
||||
int getPageHeight() const;
|
||||
@@ -111,6 +113,11 @@ inline const SpoolMetaData *GraphicsDriver::getSpoolMetaData() const
|
||||
return fSpoolMetaData;
|
||||
}
|
||||
|
||||
inline int GraphicsDriver::getProtocolClass() const
|
||||
{
|
||||
return fPrinterData->getProtocolClass();
|
||||
}
|
||||
|
||||
inline int GraphicsDriver::getPageWidth() const
|
||||
{
|
||||
return fPageWidth;
|
||||
|
||||
@@ -71,16 +71,23 @@ struct ColorCap : public BaseCap {
|
||||
: BaseCap(n, d), color(c) {}
|
||||
};
|
||||
|
||||
struct ProtocolClassCap : public BaseCap {
|
||||
int protocolClass;
|
||||
string description;
|
||||
ProtocolClassCap(const string &n, bool d, int p, const string &desc)
|
||||
: BaseCap(n, d)
|
||||
, protocolClass(p)
|
||||
, description(desc) {}
|
||||
};
|
||||
|
||||
|
||||
class PrinterData;
|
||||
|
||||
class PrinterCap {
|
||||
public:
|
||||
PrinterCap(const PrinterData *printer_data);
|
||||
virtual ~PrinterCap();
|
||||
/*
|
||||
PrinterCap(const PrinterCap &printer_cap);
|
||||
PrinterCap &operator = (const PrinterCap &printer_cap);
|
||||
*/
|
||||
|
||||
enum CapID {
|
||||
kPaper,
|
||||
kPaperSource,
|
||||
@@ -89,6 +96,7 @@ public:
|
||||
kPrintStyle,
|
||||
kBindingLocation,
|
||||
kColor,
|
||||
kProtocolClass,
|
||||
// Static boolean settings follow.
|
||||
// For them isSupport() has to be implemented only.
|
||||
kCopyCommand, // supports printer page copy command?
|
||||
@@ -99,6 +107,7 @@ public:
|
||||
virtual const BaseCap **enumCap(CapID) const = 0;
|
||||
const BaseCap *getDefaultCap(CapID) const;
|
||||
int getPrinterId() const;
|
||||
int getProtocolClass() const;
|
||||
|
||||
protected:
|
||||
PrinterCap(const PrinterCap &);
|
||||
|
||||
@@ -21,23 +21,20 @@ class PrinterData {
|
||||
public:
|
||||
PrinterData(BNode *node = NULL);
|
||||
~PrinterData();
|
||||
/*
|
||||
PrinterData(const PrinterData &printer_data);
|
||||
PrinterData &operator = (const PrinterData &printer_data);
|
||||
*/
|
||||
void load(BNode *node);
|
||||
// void save(BNode *node = NULL);
|
||||
void load();
|
||||
void save();
|
||||
|
||||
const string &getDriverName() const;
|
||||
const string &getPrinterName() const;
|
||||
const string &getComments() const;
|
||||
const string &getTransport() const;
|
||||
int getProtocolClass() const;
|
||||
|
||||
// void setDriverName(const char *s) { fDriverName = driver_name; }
|
||||
void setPrinterName(const char *printer_name);
|
||||
void setComments(const char *comments);
|
||||
void setProtocolClass(int protocolClass);
|
||||
|
||||
bool getPath(char *path) const;
|
||||
bool getPath(string &path) const;
|
||||
|
||||
protected:
|
||||
PrinterData(const PrinterData &printer_data);
|
||||
@@ -48,6 +45,8 @@ private:
|
||||
string fPrinterName;
|
||||
string fComments;
|
||||
string fTransport;
|
||||
int fProtocolClass;
|
||||
|
||||
BNode *fNode;
|
||||
};
|
||||
|
||||
@@ -71,6 +70,11 @@ inline const string &PrinterData::getTransport() const
|
||||
return fTransport;
|
||||
}
|
||||
|
||||
inline int PrinterData::getProtocolClass() const
|
||||
{
|
||||
return fProtocolClass;
|
||||
}
|
||||
|
||||
inline void PrinterData::setPrinterName(const char *printer_name)
|
||||
{
|
||||
fPrinterName = printer_name;
|
||||
@@ -81,4 +85,9 @@ inline void PrinterData::setComments(const char *comments)
|
||||
fComments = comments;
|
||||
}
|
||||
|
||||
inline void PrinterData::setProtocolClass(int protocolClass)
|
||||
{
|
||||
fProtocolClass = protocolClass;
|
||||
}
|
||||
|
||||
#endif // __PRINTERDATA_H
|
||||
|
||||
@@ -26,18 +26,26 @@ public:
|
||||
virtual PrinterCap* InstantiatePrinterCap(PrinterData* printerData) = 0;
|
||||
virtual GraphicsDriver* InstantiateGraphicsDriver(BMessage* settings, PrinterData* printerData, PrinterCap* printerCap) = 0;
|
||||
|
||||
void InitPrinterDataAndCap();
|
||||
|
||||
virtual void About();
|
||||
virtual char* AddPrinter(char* printerName);
|
||||
BMessage* ConfigPage(BMessage* settings);
|
||||
BMessage* ConfigJob(BMessage* settings);
|
||||
BMessage* TakeJob(BFile* printJob, BMessage* settings);
|
||||
|
||||
protected:
|
||||
|
||||
PrinterData* GetPrinterData() { return fPrinterData; }
|
||||
PrinterCap* GetPrinterCap() { return fPrinterCap; }
|
||||
|
||||
private:
|
||||
bool ReadSettings(const char* attrName, BMessage* settings);
|
||||
void WriteSettings(const char* attrName, BMessage* settings);
|
||||
void MergeWithPreviousSettings(const char* attrName, BMessage* settings);
|
||||
|
||||
BNode* fSpoolFolder;
|
||||
PrinterData* fPrinterData;
|
||||
PrinterCap* fPrinterCap;
|
||||
GraphicsDriver* fGraphicsDriver;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
#include "AddPrinterDlg.h"
|
||||
|
||||
#include "PrinterCap.h"
|
||||
#include "PrinterData.h"
|
||||
|
||||
#define DIALOG_WIDTH 400
|
||||
|
||||
#define BUTTON_WIDTH 70
|
||||
#define BUTTON_HEIGHT 20
|
||||
#define TEXT_HEIGHT 16
|
||||
|
||||
#define BOX_TOP_INSET 18
|
||||
#define BOX_BOTTOM_INSET 10
|
||||
#define BOX_H_INSET 10
|
||||
|
||||
#define PROTOCOL_CLASS_BOX_H 10
|
||||
#define PROTOCOL_CLASS_BOX_V 10
|
||||
#define PROTOCOL_CLASS_BOX_WIDTH DIALOG_WIDTH - 20
|
||||
#define PROTOCOL_CLASS_BOX_HEIGHT 125
|
||||
|
||||
#define PROTOCOL_CLASS_H BOX_H_INSET
|
||||
#define PROTOCOL_CLASS_V BOX_TOP_INSET
|
||||
#define PROTOCOL_CLASS_WIDTH PROTOCOL_CLASS_BOX_WIDTH - 2 * BOX_H_INSET
|
||||
#define PROTOCOL_CLASS_HEIGHT PROTOCOL_CLASS_BOX_HEIGHT - BOX_TOP_INSET - BOX_BOTTOM_INSET
|
||||
|
||||
#define DESCRIPTION_BOX_H PROTOCOL_CLASS_BOX_H
|
||||
#define DESCRIPTION_BOX_V PROTOCOL_CLASS_BOX_V + PROTOCOL_CLASS_BOX_HEIGHT + 10
|
||||
#define DESCRIPTION_BOX_WIDTH PROTOCOL_CLASS_BOX_WIDTH
|
||||
#define DESCRIPTION_BOX_HEIGHT 125
|
||||
|
||||
#define DESCRIPTION_H BOX_H_INSET
|
||||
#define DESCRIPTION_V BOX_TOP_INSET
|
||||
#define DESCRIPTION_WIDTH DESCRIPTION_BOX_WIDTH - 2 * BOX_H_INSET
|
||||
#define DESCRIPTION_HEIGHT DESCRIPTION_BOX_HEIGHT - BOX_TOP_INSET - BOX_BOTTOM_INSET
|
||||
|
||||
#define DIALOG_HEIGHT DESCRIPTION_BOX_V + DESCRIPTION_BOX_HEIGHT + BUTTON_HEIGHT + 20
|
||||
|
||||
#define OK_H (DIALOG_WIDTH - BUTTON_WIDTH - 11)
|
||||
#define OK_V (DIALOG_HEIGHT - BUTTON_HEIGHT - 11)
|
||||
#define OK_TEXT "OK"
|
||||
|
||||
#define CANCEL_H (OK_H - BUTTON_WIDTH - 12)
|
||||
#define CANCEL_V OK_V
|
||||
#define CANCEL_TEXT "Cancel"
|
||||
|
||||
const BRect PROTOCOL_CLASS_BOX_RECT(
|
||||
PROTOCOL_CLASS_BOX_H,
|
||||
PROTOCOL_CLASS_BOX_V,
|
||||
PROTOCOL_CLASS_BOX_H + PROTOCOL_CLASS_BOX_WIDTH ,
|
||||
PROTOCOL_CLASS_BOX_V + PROTOCOL_CLASS_BOX_HEIGHT);
|
||||
|
||||
const BRect PROTOCOL_CLASS_RECT(
|
||||
PROTOCOL_CLASS_H,
|
||||
PROTOCOL_CLASS_V,
|
||||
PROTOCOL_CLASS_H + PROTOCOL_CLASS_WIDTH - B_V_SCROLL_BAR_WIDTH,
|
||||
PROTOCOL_CLASS_V + PROTOCOL_CLASS_HEIGHT);
|
||||
|
||||
const BRect DESCRIPTION_BOX_RECT(
|
||||
DESCRIPTION_BOX_H,
|
||||
DESCRIPTION_BOX_V,
|
||||
DESCRIPTION_BOX_H + DESCRIPTION_BOX_WIDTH,
|
||||
DESCRIPTION_BOX_V + DESCRIPTION_BOX_HEIGHT);
|
||||
|
||||
const BRect DESCRIPTION_RECT(
|
||||
DESCRIPTION_H,
|
||||
DESCRIPTION_V,
|
||||
DESCRIPTION_H + DESCRIPTION_WIDTH - B_V_SCROLL_BAR_WIDTH,
|
||||
DESCRIPTION_V + DESCRIPTION_HEIGHT);
|
||||
|
||||
const BRect OK_RECT(
|
||||
OK_H,
|
||||
OK_V,
|
||||
OK_H + BUTTON_WIDTH,
|
||||
OK_V + BUTTON_HEIGHT);
|
||||
|
||||
const BRect CANCEL_RECT(
|
||||
CANCEL_H,
|
||||
CANCEL_V,
|
||||
CANCEL_H + BUTTON_WIDTH,
|
||||
CANCEL_V + BUTTON_HEIGHT);
|
||||
|
||||
|
||||
enum MSGS {
|
||||
kMsgCancel = 1,
|
||||
kMsgOK,
|
||||
kMsgProtocolClassChanged,
|
||||
};
|
||||
|
||||
ProtocolClassItem::ProtocolClassItem(const ProtocolClassCap* cap)
|
||||
: BStringItem(cap->label.c_str())
|
||||
, fProtocolClassCap(cap)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ProtocolClassItem::getProtocolClass()
|
||||
{
|
||||
return fProtocolClassCap->protocolClass;
|
||||
}
|
||||
|
||||
const char *
|
||||
ProtocolClassItem::getDescription()
|
||||
{
|
||||
return fProtocolClassCap->description.c_str();
|
||||
}
|
||||
|
||||
|
||||
AddPrinterView::AddPrinterView(BRect frame, PrinterData *printer_data, const PrinterCap *printer_cap)
|
||||
: BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), fPrinterData(printer_data), fPrinterCap(printer_cap)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
|
||||
AddPrinterView::~AddPrinterView()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
AddPrinterView::AttachedToWindow()
|
||||
{
|
||||
/* protocol class box */
|
||||
BBox *box;
|
||||
box = new BBox(PROTOCOL_CLASS_BOX_RECT);
|
||||
box->SetLabel("Protocol Classes:");
|
||||
AddChild(box);
|
||||
|
||||
/* protocol class */
|
||||
fProtocolClassList = new BListView(PROTOCOL_CLASS_RECT, "protocolClassList");
|
||||
box->AddChild(new BScrollView("protocolClassListScroller", fProtocolClassList,
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true));
|
||||
fProtocolClassList->SetSelectionMessage(new BMessage(kMsgProtocolClassChanged));
|
||||
fProtocolClassList->SetTarget(this);
|
||||
|
||||
int count = fPrinterCap->countCap(PrinterCap::kProtocolClass);
|
||||
ProtocolClassCap **protocolClasses = (ProtocolClassCap **)fPrinterCap->enumCap(PrinterCap::kProtocolClass);
|
||||
while (count--) {
|
||||
const ProtocolClassCap *protocolClass = *protocolClasses;
|
||||
|
||||
BStringItem* item = new ProtocolClassItem(protocolClass);
|
||||
fProtocolClassList->AddItem(item);
|
||||
if (protocolClass->is_default) {
|
||||
int index = fProtocolClassList->IndexOf(item);
|
||||
fProtocolClassList->Select(index);
|
||||
}
|
||||
protocolClasses ++;
|
||||
}
|
||||
|
||||
/* description of protocol class box */
|
||||
box = new BBox(DESCRIPTION_BOX_RECT);
|
||||
box->SetLabel("Description:");
|
||||
AddChild(box);
|
||||
|
||||
/* description of protocol class */
|
||||
BRect textRect(DESCRIPTION_RECT);
|
||||
textRect.OffsetTo(0, 0);
|
||||
fDescription = new BTextView(DESCRIPTION_RECT, "description", textRect, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
|
||||
fDescription->SetViewColor(box->ViewColor());
|
||||
box->AddChild(new BScrollView("descriptionScroller", fDescription,
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true, B_NO_BORDER));
|
||||
fDescription->MakeEditable(false);
|
||||
|
||||
/* cancel */
|
||||
BButton *button;
|
||||
button = new BButton(CANCEL_RECT, "", CANCEL_TEXT, new BMessage(kMsgCancel));
|
||||
AddChild(button);
|
||||
|
||||
/* ok */
|
||||
|
||||
button = new BButton(OK_RECT, "", OK_TEXT, new BMessage(kMsgOK));
|
||||
AddChild(button);
|
||||
button->MakeDefault(true);
|
||||
|
||||
// update description
|
||||
BMessage updateDescription(kMsgProtocolClassChanged);
|
||||
MessageReceived(&updateDescription);
|
||||
}
|
||||
|
||||
ProtocolClassItem *
|
||||
AddPrinterView::CurrentSelection()
|
||||
{
|
||||
int selected = fProtocolClassList->CurrentSelection();
|
||||
if (selected >= 0) {
|
||||
return (ProtocolClassItem*)fProtocolClassList->ItemAt(selected);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
AddPrinterView::MessageReceived(BMessage *msg)
|
||||
{
|
||||
if (msg->what == kMsgProtocolClassChanged) {
|
||||
ProtocolClassItem *item = CurrentSelection();
|
||||
if (item != NULL) {
|
||||
fDescription->SetText(item->getDescription());
|
||||
}
|
||||
} else {
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AddPrinterView::Save()
|
||||
{
|
||||
ProtocolClassItem *item = CurrentSelection();
|
||||
if (item != NULL) {
|
||||
fPrinterData->setProtocolClass(item->getProtocolClass());
|
||||
fPrinterData->save();
|
||||
}
|
||||
}
|
||||
|
||||
AddPrinterDlg::AddPrinterDlg(PrinterData *printerData, const PrinterCap *printerCap)
|
||||
: DialogWindow(BRect(100, 100, 100 + DIALOG_WIDTH, 100 + DIALOG_HEIGHT),
|
||||
"Add Printer", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
||||
B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
|
||||
{
|
||||
SetResult(B_ERROR);
|
||||
|
||||
fAddPrinterView = new AddPrinterView(Bounds(), printerData, printerCap);
|
||||
AddChild(fAddPrinterView);
|
||||
}
|
||||
|
||||
void
|
||||
AddPrinterDlg::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case kMsgOK:
|
||||
fAddPrinterView->Save();
|
||||
SetResult(B_NO_ERROR);
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
break;
|
||||
|
||||
case kMsgCancel:
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
break;
|
||||
|
||||
default:
|
||||
DialogWindow::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ SubDirHdrs [ FDirName $(OBOS_TOP) headers private print ] ;
|
||||
|
||||
StaticLibrary print :
|
||||
AboutBox.cpp
|
||||
AddPrinterDlg.cpp
|
||||
DbgMsg.cpp
|
||||
DialogWindow.cpp
|
||||
GraphicsDriver.cpp
|
||||
|
||||
@@ -338,6 +338,7 @@ PageSetupView::UpdateJobData()
|
||||
PaperCap *paperCap = GetPaperCap();
|
||||
BRect paper_rect = paperCap->paper_rect;
|
||||
BRect physical_rect = paperCap->physical_rect;
|
||||
fJobData->setPaper(paperCap->paper);
|
||||
|
||||
int count;
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
*/
|
||||
|
||||
#include "PrinterCap.h"
|
||||
#include "PrinterData.h"
|
||||
|
||||
PrinterCap::PrinterCap(const PrinterData *printer_data)
|
||||
: fPrinterData(printer_data), fPrinterID(kUnknownPrinter)
|
||||
: fPrinterData(printer_data),
|
||||
fPrinterID(kUnknownPrinter)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,21 +16,6 @@ PrinterCap::~PrinterCap()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
PrinterCap::PrinterCap(const PrinterCap &printer_cap)
|
||||
{
|
||||
fPrinterData = printer_cap.fPrinterData;
|
||||
fPrinterID = printer_cap.fPrinterID;
|
||||
}
|
||||
|
||||
PrinterCap::PrinterCap &operator = (const PrinterCap &printer_cap)
|
||||
{
|
||||
fPrinterData = printer_cap.fPrinterData;
|
||||
fPrinterID = printer_cap.fPrinterID;
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
const BaseCap *PrinterCap::getDefaultCap(CapID id) const
|
||||
{
|
||||
int count = countCap(id);
|
||||
@@ -43,3 +30,7 @@ const BaseCap *PrinterCap::getDefaultCap(CapID id) const
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int PrinterCap::getProtocolClass() const {
|
||||
return fPrinterData->getProtocolClass();
|
||||
}
|
||||
@@ -14,45 +14,25 @@ const char *PD_DRIVER_NAME = "Driver Name";
|
||||
const char *PD_PRINTER_NAME = "Printer Name";
|
||||
const char *PD_COMMENTS = "Comments";
|
||||
const char *PD_TRANSPORT = "transport";
|
||||
const char *PD_PROTOCOL_CLASS = "libprint:protocolClass";
|
||||
|
||||
PrinterData::PrinterData(BNode *node)
|
||||
: fProtocolClass(0)
|
||||
, fNode(node)
|
||||
{
|
||||
if (node) {
|
||||
load(node);
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
PrinterData::~PrinterData()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
PrinterData::PrinterData(const PrinterData &printer_data)
|
||||
{
|
||||
fDriverName = printer_data.fDriverName;
|
||||
fPrinterName = printer_data.fPrinterName;
|
||||
fComments = printer_data.fComments;
|
||||
fTransport = printer_data.fTransport;
|
||||
fNode = printer_data.fNode;
|
||||
}
|
||||
|
||||
PrinterData &PrinterData::operator = (const PrinterData &printer_data)
|
||||
{
|
||||
fDriverName = printer_data.fDriverName;
|
||||
fPrinterName = printer_data.fPrinterName;
|
||||
fComments = printer_data.fComments;
|
||||
fTransport = printer_data.fTransport;
|
||||
fNode = printer_data.fNode;
|
||||
return *this;
|
||||
}
|
||||
*/
|
||||
|
||||
void PrinterData::load(BNode *node)
|
||||
void PrinterData::load()
|
||||
{
|
||||
if (fNode == NULL) return;
|
||||
|
||||
char buffer[512];
|
||||
|
||||
fNode = node;
|
||||
|
||||
fNode->ReadAttr(PD_DRIVER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer));
|
||||
fDriverName = buffer;
|
||||
fNode->ReadAttr(PD_PRINTER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer));
|
||||
@@ -61,37 +41,29 @@ void PrinterData::load(BNode *node)
|
||||
fComments = buffer;
|
||||
fNode->ReadAttr(PD_TRANSPORT, B_STRING_TYPE, 0, buffer, sizeof(buffer));
|
||||
fTransport = buffer;
|
||||
fNode->ReadAttr(PD_PROTOCOL_CLASS, B_BOOL_TYPE, 0, &fProtocolClass, sizeof(fProtocolClass));
|
||||
}
|
||||
|
||||
/*
|
||||
void PrinterData::save(BNode *node)
|
||||
void PrinterData::save()
|
||||
{
|
||||
BDirectory dir;
|
||||
if (node == NULL) {
|
||||
BPath path;
|
||||
::find_directory(B_USER_PRINTERS_DIRECTORY, &path, false);
|
||||
path.Append(fPrinterName.c_str());
|
||||
BDirectory base_dir;
|
||||
base_dir.CreateDirectory(path.Path(), &dir);
|
||||
node = &dir;
|
||||
}
|
||||
node->WriteAttr(PD_DRIVER_NAME, B_STRING_TYPE, 0, driver_name_.c_str(), driver_name_.length() + 1);
|
||||
node->WriteAttr(PD_PRINTER_NAME, B_STRING_TYPE, 0, printer_name_.c_str(), printer_name_.length() + 1);
|
||||
node->WriteAttr(PD_COMMENTS, B_STRING_TYPE, 0, comments_.c_str(), comments_.length() + 1);
|
||||
}
|
||||
*/
|
||||
if (fNode == NULL) return;
|
||||
|
||||
bool PrinterData::getPath(char *buf) const
|
||||
{
|
||||
if (fNode) {
|
||||
node_ref nref;
|
||||
fNode->GetNodeRef(&nref);
|
||||
BDirectory dir;
|
||||
dir.SetTo(&nref);
|
||||
BPath path(&dir, NULL);
|
||||
strcpy(buf, path.Path());
|
||||
return true;
|
||||
}
|
||||
*buf = '\0';
|
||||
return false;
|
||||
fNode->WriteAttr(PD_PROTOCOL_CLASS, B_BOOL_TYPE, 0, &fProtocolClass, sizeof(fProtocolClass));
|
||||
}
|
||||
|
||||
bool PrinterData::getPath(string &path) const
|
||||
{
|
||||
if (fNode == NULL) return false;
|
||||
|
||||
node_ref nref;
|
||||
if (fNode->GetNodeRef(&nref) != B_OK) return false;
|
||||
|
||||
BDirectory dir(&nref);
|
||||
if (dir.InitCheck() != B_OK) return false;
|
||||
|
||||
BPath path0(&dir, ".");
|
||||
if (path0.InitCheck() != B_OK) return false;
|
||||
|
||||
path = path0.Path();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "BeUtils.h"
|
||||
#include "AboutBox.h"
|
||||
#include "AddPrinterDlg.h"
|
||||
#include "DbgMsg.h"
|
||||
#include "Exports.h"
|
||||
#include "GraphicsDriver.h"
|
||||
@@ -27,6 +28,7 @@
|
||||
|
||||
PrinterDriver::PrinterDriver(BNode* spoolFolder)
|
||||
: fSpoolFolder(spoolFolder)
|
||||
, fPrinterData(NULL)
|
||||
, fPrinterCap(NULL)
|
||||
, fGraphicsDriver(NULL)
|
||||
{
|
||||
@@ -39,9 +41,19 @@ PrinterDriver::~PrinterDriver()
|
||||
|
||||
delete fPrinterCap;
|
||||
fPrinterCap = NULL;
|
||||
|
||||
delete fPrinterData;
|
||||
fPrinterData = NULL;
|
||||
}
|
||||
|
||||
void PrinterDriver::About()
|
||||
void
|
||||
PrinterDriver::InitPrinterDataAndCap() {
|
||||
fPrinterData = new PrinterData(fSpoolFolder);
|
||||
fPrinterCap = InstantiatePrinterCap(fPrinterData);
|
||||
}
|
||||
|
||||
void
|
||||
PrinterDriver::About()
|
||||
{
|
||||
BString copyright;
|
||||
copyright = "libprint Copyright © 1999-2000 Y.Takagi\n";
|
||||
@@ -52,7 +64,8 @@ void PrinterDriver::About()
|
||||
app.Run();
|
||||
}
|
||||
|
||||
char* PrinterDriver::AddPrinter(char* printerName)
|
||||
char*
|
||||
PrinterDriver::AddPrinter(char* printerName)
|
||||
{
|
||||
// print_server has created a spool folder with name printerName in
|
||||
// folder B_USER_PRINTERS_DIRECTORY. It can be used to store
|
||||
@@ -60,10 +73,29 @@ char* PrinterDriver::AddPrinter(char* printerName)
|
||||
DBGMSG((">%s: add_printer\n", GetDriverName()));
|
||||
DBGMSG(("\tprinter_name: %s\n", printerName));
|
||||
DBGMSG(("<%s: add_printer\n", GetDriverName()));
|
||||
|
||||
if (fPrinterCap->isSupport(PrinterCap::kProtocolClass)) {
|
||||
if (fPrinterCap->countCap(PrinterCap::kProtocolClass) > 1) {
|
||||
AddPrinterDlg *dialog;
|
||||
dialog = new AddPrinterDlg(fPrinterData, fPrinterCap);
|
||||
if (dialog->Go() != B_OK) {
|
||||
// dialog canceled
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
const ProtocolClassCap* pcCap;
|
||||
pcCap = (const ProtocolClassCap*)fPrinterCap->getDefaultCap(PrinterCap::kProtocolClass);
|
||||
if (pcCap != NULL) {
|
||||
fPrinterData->setProtocolClass(pcCap->protocolClass);
|
||||
fPrinterData->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
return printerName;
|
||||
}
|
||||
|
||||
BMessage* PrinterDriver::ConfigPage(BMessage* settings)
|
||||
BMessage*
|
||||
PrinterDriver::ConfigPage(BMessage* settings)
|
||||
{
|
||||
DBGMSG((">%s: config_page\n", GetDriverName()));
|
||||
DUMP_BMESSAGE(settings);
|
||||
@@ -71,9 +103,7 @@ BMessage* PrinterDriver::ConfigPage(BMessage* settings)
|
||||
|
||||
BMessage pageSettings(*settings);
|
||||
MergeWithPreviousSettings(kAttrPageSettings, &pageSettings);
|
||||
PrinterData printerData(fSpoolFolder);
|
||||
fPrinterCap = InstantiatePrinterCap(&printerData);
|
||||
UIDriver drv(&pageSettings, &printerData, fPrinterCap);
|
||||
UIDriver drv(&pageSettings, fPrinterData, fPrinterCap);
|
||||
BMessage *result = drv.configPage();
|
||||
WriteSettings(kAttrPageSettings, result);
|
||||
|
||||
@@ -82,7 +112,8 @@ BMessage* PrinterDriver::ConfigPage(BMessage* settings)
|
||||
return result;
|
||||
}
|
||||
|
||||
BMessage* PrinterDriver::ConfigJob(BMessage* settings)
|
||||
BMessage*
|
||||
PrinterDriver::ConfigJob(BMessage* settings)
|
||||
{
|
||||
DBGMSG((">%s: config_job\n", GetDriverName()));
|
||||
DUMP_BMESSAGE(settings);
|
||||
@@ -90,9 +121,7 @@ BMessage* PrinterDriver::ConfigJob(BMessage* settings)
|
||||
|
||||
BMessage jobSettings(*settings);
|
||||
MergeWithPreviousSettings(kAttrJobSettings, &jobSettings);
|
||||
PrinterData printerData(fSpoolFolder);
|
||||
fPrinterCap = InstantiatePrinterCap(&printerData);
|
||||
UIDriver drv(&jobSettings, &printerData, fPrinterCap);
|
||||
UIDriver drv(&jobSettings, fPrinterData, fPrinterCap);
|
||||
BMessage *result = drv.configJob();
|
||||
WriteSettings(kAttrJobSettings, result);
|
||||
|
||||
@@ -101,15 +130,14 @@ BMessage* PrinterDriver::ConfigJob(BMessage* settings)
|
||||
return result;
|
||||
}
|
||||
|
||||
BMessage* PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
|
||||
BMessage*
|
||||
PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
|
||||
{
|
||||
DBGMSG((">%s: take_job\n", GetDriverName()));
|
||||
DUMP_BMESSAGE(settings);
|
||||
DUMP_BNODE(fSpoolFolder);
|
||||
|
||||
PrinterData printerData(fSpoolFolder);
|
||||
fPrinterCap = InstantiatePrinterCap(&printerData);
|
||||
fGraphicsDriver = InstantiateGraphicsDriver(settings, &printerData, fPrinterCap);
|
||||
fGraphicsDriver = InstantiateGraphicsDriver(settings, fPrinterData, fPrinterCap);
|
||||
BMessage *result = fGraphicsDriver->takeJob(printJob);
|
||||
|
||||
DUMP_BMESSAGE(result);
|
||||
@@ -118,7 +146,8 @@ BMessage* PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
|
||||
}
|
||||
|
||||
// read settings from spool folder attribute
|
||||
bool PrinterDriver::ReadSettings(const char* attrName, BMessage* settings)
|
||||
bool
|
||||
PrinterDriver::ReadSettings(const char* attrName, BMessage* settings)
|
||||
{
|
||||
attr_info info;
|
||||
char* data;
|
||||
@@ -138,7 +167,8 @@ bool PrinterDriver::ReadSettings(const char* attrName, BMessage* settings)
|
||||
}
|
||||
|
||||
// write settings to spool folder attribute
|
||||
void PrinterDriver::WriteSettings(const char* attrName, BMessage* settings)
|
||||
void
|
||||
PrinterDriver::WriteSettings(const char* attrName, BMessage* settings)
|
||||
{
|
||||
if (settings == NULL || settings->what != 'okok') return;
|
||||
|
||||
@@ -155,7 +185,8 @@ void PrinterDriver::WriteSettings(const char* attrName, BMessage* settings)
|
||||
}
|
||||
|
||||
// read settings from spool folder attribute and merge them to current settings
|
||||
void PrinterDriver::MergeWithPreviousSettings(const char* attrName, BMessage* settings)
|
||||
void
|
||||
PrinterDriver::MergeWithPreviousSettings(const char* attrName, BMessage* settings)
|
||||
{
|
||||
if (settings == NULL) return;
|
||||
|
||||
@@ -182,6 +213,9 @@ private:
|
||||
PrinterDriverInstance::PrinterDriverInstance(BNode* spoolFolder)
|
||||
{
|
||||
fInstance = instantiate_printer_driver(spoolFolder);
|
||||
if (fInstance != NULL) {
|
||||
fInstance->InitPrinterDataAndCap();
|
||||
}
|
||||
}
|
||||
|
||||
PrinterDriverInstance::~PrinterDriverInstance()
|
||||
|
||||
@@ -62,10 +62,10 @@ Transport::Transport(const PrinterData *printer_data)
|
||||
}
|
||||
|
||||
if (fInitTransport) {
|
||||
char spool_path[256];
|
||||
string spool_path;
|
||||
printer_data->getPath(spool_path);
|
||||
BMessage *msg = new BMessage('TRIN');
|
||||
msg->AddString("printer_file", spool_path);
|
||||
msg->AddString("printer_file", spool_path.c_str());
|
||||
fDataStream = (*fInitTransport)(msg);
|
||||
delete msg;
|
||||
if (fDataStream == 0) {
|
||||
|
||||
Reference in New Issue
Block a user