16f9cddeaSMichael Pfeiffer/*
26f9cddeaSMichael Pfeiffer * PrinterData.cpp
36f9cddeaSMichael Pfeiffer * Copyright 1999-2000 Y.Takagi All Rights Reserved.
46f9cddeaSMichael Pfeiffer */
56f9cddeaSMichael Pfeiffer
66f9cddeaSMichael Pfeiffer#include <Directory.h>
76f9cddeaSMichael Pfeiffer#include <FindDirectory.h>
86f9cddeaSMichael Pfeiffer#include <Path.h>
96f9cddeaSMichael Pfeiffer#include <StorageDefs.h>
106f9cddeaSMichael Pfeiffer
116f9cddeaSMichael Pfeiffer#include "PrinterData.h"
126f9cddeaSMichael Pfeiffer
136f9cddeaSMichael Pfeifferconst char *PD_DRIVER_NAME      = "Driver Name";
146f9cddeaSMichael Pfeifferconst char *PD_PRINTER_NAME     = "Printer Name";
156f9cddeaSMichael Pfeifferconst char *PD_COMMENTS         = "Comments";
166f9cddeaSMichael Pfeifferconst char *PD_TRANSPORT        = "transport";
178c0bf019SMichael Pfeifferconst char *PD_PROTOCOL_CLASS   = "libprint:protocolClass";
186f9cddeaSMichael Pfeiffer
194410ee12SMichael Pfeiffer
206f9cddeaSMichael PfeifferPrinterData::PrinterData(BNode *node)
214410ee12SMichael Pfeiffer	:
224410ee12SMichael Pfeiffer	fNode(node),
23f7b0c08cSIthamar R. Adema	fProtocolClass(0)
246f9cddeaSMichael Pfeiffer{
256f9cddeaSMichael Pfeiffer}
266f9cddeaSMichael Pfeiffer
274410ee12SMichael Pfeiffer
286f9cddeaSMichael PfeifferPrinterData::~PrinterData()
296f9cddeaSMichael Pfeiffer{
306f9cddeaSMichael Pfeiffer}
316f9cddeaSMichael Pfeiffer
324410ee12SMichael Pfeiffer
334410ee12SMichael Pfeiffervoid
344410ee12SMichael PfeifferPrinterData::Load()
356f9cddeaSMichael Pfeiffer{
368c0bf019SMichael Pfeiffer	if (fNode == NULL) return;
378c0bf019SMichael Pfeiffer
386f9cddeaSMichael Pfeiffer	char buffer[512];
396f9cddeaSMichael Pfeiffer
402f6e49a9SMichael Pfeiffer	fNode->ReadAttr(PD_DRIVER_NAME,  B_STRING_TYPE, 0, buffer, sizeof(buffer));
41fcccd8b7SMichael Pfeiffer	// TODO fix possible buffer overrun (not terminated string).
422f6e49a9SMichael Pfeiffer	fDriverName = buffer;
432f6e49a9SMichael Pfeiffer	fNode->ReadAttr(PD_PRINTER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer));
442f6e49a9SMichael Pfeiffer	fPrinterName = buffer;
452f6e49a9SMichael Pfeiffer	fNode->ReadAttr(PD_COMMENTS,     B_STRING_TYPE, 0, buffer, sizeof(buffer));
462f6e49a9SMichael Pfeiffer	fComments = buffer;
472f6e49a9SMichael Pfeiffer	fNode->ReadAttr(PD_TRANSPORT,    B_STRING_TYPE, 0, buffer, sizeof(buffer));
482f6e49a9SMichael Pfeiffer	fTransport = buffer;
49fcccd8b7SMichael Pfeiffer
50fcccd8b7SMichael Pfeiffer	int32 valueI32;
51fcccd8b7SMichael Pfeiffer	fNode->ReadAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32));
52fcccd8b7SMichael Pfeiffer	fProtocolClass = (int)valueI32;
536f9cddeaSMichael Pfeiffer}
546f9cddeaSMichael Pfeiffer
554410ee12SMichael Pfeiffer
564410ee12SMichael Pfeiffervoid
574410ee12SMichael PfeifferPrinterData::Save()
586f9cddeaSMichael Pfeiffer{
594410ee12SMichael Pfeiffer	if (fNode == NULL)
604410ee12SMichael Pfeiffer		return;
618c0bf019SMichael Pfeiffer
62fcccd8b7SMichael Pfeiffer	int32 valueI32 = (int32)fProtocolClass;
634410ee12SMichael Pfeiffer	fNode->WriteAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32,
644410ee12SMichael Pfeiffer		sizeof(valueI32));
656f9cddeaSMichael Pfeiffer}
666f9cddeaSMichael Pfeiffer
674410ee12SMichael Pfeiffer
684410ee12SMichael Pfeifferbool
694410ee12SMichael PfeifferPrinterData::GetPath(string &path) const
706f9cddeaSMichael Pfeiffer{
714410ee12SMichael Pfeiffer	if (fNode == NULL)
724410ee12SMichael Pfeiffer		return false;
738c0bf019SMichael Pfeiffer
748c0bf019SMichael Pfeiffer	node_ref nref;
754410ee12SMichael Pfeiffer	if (fNode->GetNodeRef(&nref) != B_OK)
764410ee12SMichael Pfeiffer		return false;
778c0bf019SMichael Pfeiffer
788c0bf019SMichael Pfeiffer	BDirectory dir(&nref);
794410ee12SMichael Pfeiffer	if (dir.InitCheck() != B_OK)
804410ee12SMichael Pfeiffer		return false;
818c0bf019SMichael Pfeiffer
828c0bf019SMichael Pfeiffer	BPath path0(&dir, ".");
834410ee12SMichael Pfeiffer	if (path0.InitCheck() != B_OK)
844410ee12SMichael Pfeiffer		return false;
858c0bf019SMichael Pfeiffer
868c0bf019SMichael Pfeiffer	path = path0.Path();
878c0bf019SMichael Pfeiffer	return true;
886f9cddeaSMichael Pfeiffer}
89