1 /* 2 * Copyright 2001-2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ithamar R. Adema 7 */ 8 #include "Printer.h" 9 10 11 #include "pr_server.h" 12 13 // BeOS API 14 #include <AppDefs.h> 15 #include <Catalog.h> 16 #include <Locale.h> 17 #include <Message.h> 18 #include <Messenger.h> 19 #include <PropertyInfo.h> 20 21 22 #undef B_TRANSLATION_CONTEXT 23 #define B_TRANSLATION_CONTEXT "Printer Scripting" 24 25 26 static property_info prop_list[] = { 27 { "Name", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 28 B_TRANSLATE_MARK("Get name of printer") }, 29 { "TransportAddon", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 30 B_TRANSLATE_MARK("Get name of the transport add-on used for this printer") }, 31 { "TransportConfig", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 32 B_TRANSLATE_MARK("Get the transport configuration for this printer") }, 33 { "PrinterAddon", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 34 B_TRANSLATE_MARK("Get name of the printer add-on used for this printer") }, 35 { "Comments", { B_GET_PROPERTY }, { B_DIRECT_SPECIFIER }, 36 B_TRANSLATE_MARK("Get comments about this printer") }, 37 38 { 0 } // terminate list 39 }; 40 41 42 void 43 Printer::HandleScriptingCommand(BMessage* msg) 44 { 45 status_t rc = B_ERROR; 46 BString propName; 47 BString result; 48 BMessage spec; 49 int32 idx; 50 51 if ((rc=msg->GetCurrentSpecifier(&idx,&spec)) == B_OK && 52 (rc=spec.FindString("property",&propName)) == B_OK) { 53 switch(msg->what) { 54 case B_GET_PROPERTY: 55 if (propName == "Name") 56 rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &result); 57 else if (propName == "TransportAddon") 58 rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT, &result); 59 else if (propName == "TransportConfig") 60 rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, &result); 61 else if (propName == "PrinterAddon") 62 rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, &result); 63 else if (propName == "Comments") 64 rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_COMMENTS, &result); 65 else { // If unknown scripting request, let super class handle it 66 Inherited::MessageReceived(msg); 67 break; 68 } 69 70 BMessage reply(B_REPLY); 71 reply.AddString("result", result); 72 reply.AddInt32("error", rc); 73 msg->SendReply(&reply); 74 break; 75 } 76 } 77 else { 78 // If GetSpecifier failed 79 if (idx == -1) { 80 BMessage reply(B_REPLY); 81 reply.AddMessenger("result", BMessenger(this)); 82 reply.AddInt32("error", B_OK); 83 msg->SendReply(&reply); 84 } 85 } 86 } 87 88 BHandler* 89 Printer::ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, 90 int32 form, const char* prop) 91 { 92 BPropertyInfo prop_info(prop_list); 93 BHandler* rc = this; 94 95 int32 idx; 96 switch( idx=prop_info.FindMatch(msg,0,spec,form,prop) ) { 97 case B_ERROR: 98 rc = Inherited::ResolveSpecifier(msg,index,spec,form,prop); 99 break; 100 } 101 102 return rc; 103 } 104 105 status_t 106 Printer::GetSupportedSuites(BMessage* msg) 107 { 108 msg->AddString("suites", "application/x-vnd.OpenBeOS-printer"); 109 110 static bool localized = false; 111 if (!localized) { 112 localized = true; 113 for (int i = 0; prop_list[i].name != NULL; i ++) 114 prop_list[i].usage = B_TRANSLATE_NOCOLLECT(prop_list[i].usage); 115 } 116 117 BPropertyInfo prop_info(prop_list); 118 msg->AddFlat("messages", &prop_info); 119 120 return Inherited::GetSupportedSuites(msg); 121 } 122