Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / libs / print / libprint / PrinterData.cpp
blobca92e519dfd50b51fd1b46a17ce18515f8c5f03e
1 /*
2 * PrinterData.cpp
3 * Copyright 1999-2000 Y.Takagi All Rights Reserved.
4 */
6 #include <Directory.h>
7 #include <FindDirectory.h>
8 #include <Path.h>
9 #include <StorageDefs.h>
11 #include "PrinterData.h"
13 const char *PD_DRIVER_NAME = "Driver Name";
14 const char *PD_PRINTER_NAME = "Printer Name";
15 const char *PD_COMMENTS = "Comments";
16 const char *PD_TRANSPORT = "transport";
17 const char *PD_PROTOCOL_CLASS = "libprint:protocolClass";
20 PrinterData::PrinterData(BNode *node)
22 fNode(node),
23 fProtocolClass(0)
28 PrinterData::~PrinterData()
33 void
34 PrinterData::Load()
36 if (fNode == NULL) return;
38 char buffer[512];
40 fNode->ReadAttr(PD_DRIVER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer));
41 // TODO fix possible buffer overrun (not terminated string).
42 fDriverName = buffer;
43 fNode->ReadAttr(PD_PRINTER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer));
44 fPrinterName = buffer;
45 fNode->ReadAttr(PD_COMMENTS, B_STRING_TYPE, 0, buffer, sizeof(buffer));
46 fComments = buffer;
47 fNode->ReadAttr(PD_TRANSPORT, B_STRING_TYPE, 0, buffer, sizeof(buffer));
48 fTransport = buffer;
50 int32 valueI32;
51 fNode->ReadAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32));
52 fProtocolClass = (int)valueI32;
56 void
57 PrinterData::Save()
59 if (fNode == NULL)
60 return;
62 int32 valueI32 = (int32)fProtocolClass;
63 fNode->WriteAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32,
64 sizeof(valueI32));
68 bool
69 PrinterData::GetPath(string &path) const
71 if (fNode == NULL)
72 return false;
74 node_ref nref;
75 if (fNode->GetNodeRef(&nref) != B_OK)
76 return false;
78 BDirectory dir(&nref);
79 if (dir.InitCheck() != B_OK)
80 return false;
82 BPath path0(&dir, ".");
83 if (path0.InitCheck() != B_OK)
84 return false;
86 path = path0.Path();
87 return true;