1 /* 2 * PrinterData.cpp 3 * Copyright 1999-2000 Y.Takagi All Rights Reserved. 4 */ 5 6 #include <Directory.h> 7 #include <FindDirectory.h> 8 #include <Path.h> 9 #include <StorageDefs.h> 10 11 #include "PrinterData.h" 12 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"; 18 19 20 PrinterData::PrinterData(BNode *node) 21 : 22 fNode(node), 23 fProtocolClass(0) 24 { 25 } 26 27 28 PrinterData::~PrinterData() 29 { 30 } 31 32 33 void 34 PrinterData::Load() 35 { 36 if (fNode == NULL) return; 37 38 char buffer[512]; 39 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; 49 50 int32 valueI32; 51 fNode->ReadAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32)); 52 fProtocolClass = (int)valueI32; 53 } 54 55 56 void 57 PrinterData::Save() 58 { 59 if (fNode == NULL) 60 return; 61 62 int32 valueI32 = (int32)fProtocolClass; 63 fNode->WriteAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, 64 sizeof(valueI32)); 65 } 66 67 68 bool 69 PrinterData::GetPath(string &path) const 70 { 71 if (fNode == NULL) 72 return false; 73 74 node_ref nref; 75 if (fNode->GetNodeRef(&nref) != B_OK) 76 return false; 77 78 BDirectory dir(&nref); 79 if (dir.InitCheck() != B_OK) 80 return false; 81 82 BPath path0(&dir, "."); 83 if (path0.InitCheck() != B_OK) 84 return false; 85 86 path = path0.Path(); 87 return true; 88 } 89