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 PrinterData::PrinterData(BNode *node) 20 : fNode(node), 21 fProtocolClass(0) 22 { 23 } 24 25 PrinterData::~PrinterData() 26 { 27 } 28 29 void PrinterData::load() 30 { 31 if (fNode == NULL) return; 32 33 char buffer[512]; 34 35 fNode->ReadAttr(PD_DRIVER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer)); 36 // TODO fix possible buffer overrun (not terminated string). 37 fDriverName = buffer; 38 fNode->ReadAttr(PD_PRINTER_NAME, B_STRING_TYPE, 0, buffer, sizeof(buffer)); 39 fPrinterName = buffer; 40 fNode->ReadAttr(PD_COMMENTS, B_STRING_TYPE, 0, buffer, sizeof(buffer)); 41 fComments = buffer; 42 fNode->ReadAttr(PD_TRANSPORT, B_STRING_TYPE, 0, buffer, sizeof(buffer)); 43 fTransport = buffer; 44 45 int32 valueI32; 46 fNode->ReadAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32)); 47 fProtocolClass = (int)valueI32; 48 } 49 50 void PrinterData::save() 51 { 52 if (fNode == NULL) return; 53 54 int32 valueI32 = (int32)fProtocolClass; 55 fNode->WriteAttr(PD_PROTOCOL_CLASS, B_INT32_TYPE, 0, &valueI32, sizeof(valueI32)); 56 } 57 58 bool PrinterData::getPath(string &path) const 59 { 60 if (fNode == NULL) return false; 61 62 node_ref nref; 63 if (fNode->GetNodeRef(&nref) != B_OK) return false; 64 65 BDirectory dir(&nref); 66 if (dir.InitCheck() != B_OK) return false; 67 68 BPath path0(&dir, "."); 69 if (path0.InitCheck() != B_OK) return false; 70 71 path = path0.Path(); 72 return true; 73 } 74