btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / servers / print_addon / PrintAddOnServerApplication.cpp
blob580fb18118ad4e80da4d1b493bddd25f2058af35
1 /*
2 * Copyright 2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Michael Pfeiffer
7 */
8 #include "PrintAddOnServerApplication.h"
10 #include <PrinterDriverAddOn.h>
12 #include <String.h>
14 PrintAddOnServerApplication::PrintAddOnServerApplication(const char* signature)
16 BApplication(signature)
22 void
23 PrintAddOnServerApplication::MessageReceived(BMessage* message)
25 switch (message->what) {
26 case kMessageAddPrinter:
27 AddPrinter(message);
28 break;
30 case kMessageConfigPage:
31 ConfigPage(message);
32 break;
34 case kMessageConfigJob:
35 ConfigJob(message);
36 break;
38 case kMessageDefaultSettings:
39 DefaultSettings(message);
40 break;
42 case kMessageTakeJob:
43 TakeJob(message);
44 break;
46 default:
47 BApplication::MessageReceived(message);
52 void
53 PrintAddOnServerApplication::AddPrinter(BMessage* message)
55 BString driver;
56 BString name;
57 if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
58 || message->FindString(kPrinterNameAttribute, &name) != B_OK) {
59 SendReply(message, B_BAD_VALUE);
60 return;
63 status_t status = AddPrinter(driver.String(), name.String());
64 SendReply(message, status);
68 status_t
69 PrintAddOnServerApplication::AddPrinter(const char* driver,
70 const char* spoolFolderName)
72 PrinterDriverAddOn addOn(driver);
73 return addOn.AddPrinter(spoolFolderName);
77 void
78 PrintAddOnServerApplication::ConfigPage(BMessage* message)
80 BString driver;
81 BString folder;
82 BMessage settings;
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);
87 return;
90 BDirectory spoolFolder(folder.String());
91 status_t status = ConfigPage(driver.String(), &spoolFolder, &settings);
93 if (status != B_OK)
94 SendReply(message, status);
95 else {
96 BMessage reply(B_REPLY);
97 reply.AddMessage(kPrintSettingsAttribute, &settings);
98 SendReply(message, &reply);
103 status_t
104 PrintAddOnServerApplication::ConfigPage(const char* driver,
105 BDirectory* spoolFolder, BMessage* settings)
107 PrinterDriverAddOn addOn(driver);
108 return addOn.ConfigPage(spoolFolder, settings);
112 void
113 PrintAddOnServerApplication::ConfigJob(BMessage* message)
115 BString driver;
116 BString folder;
117 BMessage settings;
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);
122 return;
125 BDirectory spoolFolder(folder.String());
126 status_t status = ConfigJob(driver.String(), &spoolFolder, &settings);
128 if (status != B_OK)
129 SendReply(message, status);
130 else {
131 BMessage reply(B_REPLY);
132 reply.AddMessage(kPrintSettingsAttribute, &settings);
133 SendReply(message, &reply);
138 status_t
139 PrintAddOnServerApplication::ConfigJob(const char* driver,
140 BDirectory* spoolFolder,
141 BMessage* settings)
143 PrinterDriverAddOn addOn(driver);
144 return addOn.ConfigJob(spoolFolder, settings);
148 void
149 PrintAddOnServerApplication::DefaultSettings(BMessage* message)
151 BString driver;
152 BString folder;
153 if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
154 || message->FindString(kPrinterFolderAttribute, &folder) != B_OK) {
155 SendReply(message, B_BAD_VALUE);
156 return;
159 BMessage settings;
160 BDirectory spoolFolder(folder.String());
161 status_t status = DefaultSettings(driver.String(), &spoolFolder, &settings);
163 if (status != B_OK)
164 SendReply(message, status);
165 else {
166 BMessage reply(B_REPLY);
167 reply.AddMessage(kPrintSettingsAttribute, &settings);
168 SendReply(message, &reply);
173 status_t
174 PrintAddOnServerApplication::DefaultSettings(const char* driver,
175 BDirectory* spoolFolder, BMessage* settings)
177 PrinterDriverAddOn addOn(driver);
178 return addOn.DefaultSettings(spoolFolder, settings);
182 void
183 PrintAddOnServerApplication::TakeJob(BMessage* message)
185 BString driver;
186 BString folder;
187 BString jobFile;
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);
192 return;
195 BDirectory spoolFolder(folder.String());
196 status_t status = TakeJob(driver.String(), jobFile.String(),
197 &spoolFolder);
198 SendReply(message, status);
202 status_t
203 PrintAddOnServerApplication::TakeJob(const char* driver, const char* spoolFile,
204 BDirectory* spoolFolder)
206 PrinterDriverAddOn addOn(driver);
207 return addOn.TakeJob(spoolFile, spoolFolder);
211 void
212 PrintAddOnServerApplication::SendReply(BMessage* message, status_t status)
214 BMessage reply(B_REPLY);
215 reply.AddInt32(kPrintAddOnServerStatusAttribute, status);
216 message->SendReply(&reply);
220 void
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);
233 application.Run();