2 * Copyright 2001-2006, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
11 #include "pr_server.h"
18 #include <Messenger.h>
19 #include <PropertyInfo.h>
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Printer Scripting"
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") },
38 { 0 } // terminate list
43 Printer::HandleScriptingCommand(BMessage
* msg
)
45 status_t rc
= B_ERROR
;
51 if ((rc
=msg
->GetCurrentSpecifier(&idx
,&spec
)) == B_OK
&&
52 (rc
=spec
.FindString("property",&propName
)) == B_OK
) {
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
);
70 BMessage
reply(B_REPLY
);
71 reply
.AddString("result", result
);
72 reply
.AddInt32("error", rc
);
73 msg
->SendReply(&reply
);
78 // If GetSpecifier failed
80 BMessage
reply(B_REPLY
);
81 reply
.AddMessenger("result", BMessenger(this));
82 reply
.AddInt32("error", B_OK
);
83 msg
->SendReply(&reply
);
89 Printer::ResolveSpecifier(BMessage
* msg
, int32 index
, BMessage
* spec
,
90 int32 form
, const char* prop
)
92 BPropertyInfo
prop_info(prop_list
);
96 switch( idx
=prop_info
.FindMatch(msg
,0,spec
,form
,prop
) ) {
98 rc
= Inherited::ResolveSpecifier(msg
,index
,spec
,form
,prop
);
106 Printer::GetSupportedSuites(BMessage
* msg
)
108 msg
->AddString("suites", "application/x-vnd.OpenBeOS-printer");
110 static bool localized
= false;
113 for (int i
= 0; prop_list
[i
].name
!= NULL
; i
++)
114 prop_list
[i
].usage
= B_TRANSLATE_NOCOLLECT(prop_list
[i
].usage
);
117 BPropertyInfo
prop_info(prop_list
);
118 msg
->AddFlat("messages", &prop_info
);
120 return Inherited::GetSupportedSuites(msg
);