2 * Copyright 2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
8 #include "PrintAddOnServerApplication.h"
10 #include <PrinterDriverAddOn.h>
14 PrintAddOnServerApplication::PrintAddOnServerApplication(const char* signature
)
16 BApplication(signature
)
23 PrintAddOnServerApplication::MessageReceived(BMessage
* message
)
25 switch (message
->what
) {
26 case kMessageAddPrinter
:
30 case kMessageConfigPage
:
34 case kMessageConfigJob
:
38 case kMessageDefaultSettings
:
39 DefaultSettings(message
);
47 BApplication::MessageReceived(message
);
53 PrintAddOnServerApplication::AddPrinter(BMessage
* message
)
57 if (message
->FindString(kPrinterDriverAttribute
, &driver
) != B_OK
58 || message
->FindString(kPrinterNameAttribute
, &name
) != B_OK
) {
59 SendReply(message
, B_BAD_VALUE
);
63 status_t status
= AddPrinter(driver
.String(), name
.String());
64 SendReply(message
, status
);
69 PrintAddOnServerApplication::AddPrinter(const char* driver
,
70 const char* spoolFolderName
)
72 PrinterDriverAddOn
addOn(driver
);
73 return addOn
.AddPrinter(spoolFolderName
);
78 PrintAddOnServerApplication::ConfigPage(BMessage
* message
)
83 if (message
->FindString(kPrinterDriverAttribute
, &driver
) != B_OK
84 || message
->FindString(kPrinterFolderAttribute
, &folder
) != B_OK
85 || message
->FindMessage(kPrintSettingsAttribute
, &settings
) != B_OK
) {
86 SendReply(message
, B_BAD_VALUE
);
90 BDirectory
spoolFolder(folder
.String());
91 status_t status
= ConfigPage(driver
.String(), &spoolFolder
, &settings
);
94 SendReply(message
, status
);
96 BMessage
reply(B_REPLY
);
97 reply
.AddMessage(kPrintSettingsAttribute
, &settings
);
98 SendReply(message
, &reply
);
104 PrintAddOnServerApplication::ConfigPage(const char* driver
,
105 BDirectory
* spoolFolder
, BMessage
* settings
)
107 PrinterDriverAddOn
addOn(driver
);
108 return addOn
.ConfigPage(spoolFolder
, settings
);
113 PrintAddOnServerApplication::ConfigJob(BMessage
* message
)
118 if (message
->FindString(kPrinterDriverAttribute
, &driver
) != B_OK
119 || message
->FindString(kPrinterFolderAttribute
, &folder
) != B_OK
120 || message
->FindMessage(kPrintSettingsAttribute
, &settings
) != B_OK
) {
121 SendReply(message
, B_BAD_VALUE
);
125 BDirectory
spoolFolder(folder
.String());
126 status_t status
= ConfigJob(driver
.String(), &spoolFolder
, &settings
);
129 SendReply(message
, status
);
131 BMessage
reply(B_REPLY
);
132 reply
.AddMessage(kPrintSettingsAttribute
, &settings
);
133 SendReply(message
, &reply
);
139 PrintAddOnServerApplication::ConfigJob(const char* driver
,
140 BDirectory
* spoolFolder
,
143 PrinterDriverAddOn
addOn(driver
);
144 return addOn
.ConfigJob(spoolFolder
, settings
);
149 PrintAddOnServerApplication::DefaultSettings(BMessage
* message
)
153 if (message
->FindString(kPrinterDriverAttribute
, &driver
) != B_OK
154 || message
->FindString(kPrinterFolderAttribute
, &folder
) != B_OK
) {
155 SendReply(message
, B_BAD_VALUE
);
160 BDirectory
spoolFolder(folder
.String());
161 status_t status
= DefaultSettings(driver
.String(), &spoolFolder
, &settings
);
164 SendReply(message
, status
);
166 BMessage
reply(B_REPLY
);
167 reply
.AddMessage(kPrintSettingsAttribute
, &settings
);
168 SendReply(message
, &reply
);
174 PrintAddOnServerApplication::DefaultSettings(const char* driver
,
175 BDirectory
* spoolFolder
, BMessage
* settings
)
177 PrinterDriverAddOn
addOn(driver
);
178 return addOn
.DefaultSettings(spoolFolder
, settings
);
183 PrintAddOnServerApplication::TakeJob(BMessage
* message
)
188 if (message
->FindString(kPrinterDriverAttribute
, &driver
) != B_OK
189 || message
->FindString(kPrinterFolderAttribute
, &folder
) != B_OK
190 || message
->FindString(kPrintJobFileAttribute
, &jobFile
) != B_OK
) {
191 SendReply(message
, B_BAD_VALUE
);
195 BDirectory
spoolFolder(folder
.String());
196 status_t status
= TakeJob(driver
.String(), jobFile
.String(),
198 SendReply(message
, status
);
203 PrintAddOnServerApplication::TakeJob(const char* driver
, const char* spoolFile
,
204 BDirectory
* spoolFolder
)
206 PrinterDriverAddOn
addOn(driver
);
207 return addOn
.TakeJob(spoolFile
, spoolFolder
);
212 PrintAddOnServerApplication::SendReply(BMessage
* message
, status_t status
)
214 BMessage
reply(B_REPLY
);
215 reply
.AddInt32(kPrintAddOnServerStatusAttribute
, status
);
216 message
->SendReply(&reply
);
221 PrintAddOnServerApplication::SendReply(BMessage
* message
, BMessage
* reply
)
223 reply
->AddInt32(kPrintAddOnServerStatusAttribute
, B_OK
);
224 message
->SendReply(reply
);
229 main(int argc
, char* argv
[])
231 PrintAddOnServerApplication
application(
232 kPrintAddOnServerApplicationSignature
);