Fixed some style violations (max 80 chars per line).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35640 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2010-02-27 20:09:19 +00:00
parent 80dd024309
commit d90d29facd
3 changed files with 75 additions and 40 deletions
+29 -17
View File
@@ -88,8 +88,10 @@ static void GetPageFormat(float w, float h, BString& label)
w = floor(w + 0.5); h = floor(h + 0.5); w = floor(w + 0.5); h = floor(h + 0.5);
for (uint i = 0; i < sizeof(pageFormat) / sizeof(struct PageFormat); i ++) { for (uint i = 0; i < sizeof(pageFormat) / sizeof(struct PageFormat); i ++) {
struct PageFormat& pf = pageFormat[i]; struct PageFormat& pf = pageFormat[i];
if (pf.width == w && pf.height == h || pf.width == h && pf.height == w) { if (pf.width == w && pf.height == h || pf.width == h
label = TR(pf.label); return; && pf.height == w) {
label = be_catalog->GetString(pf.label, TR_CONTEXT);
return;
} }
} }
@@ -110,7 +112,8 @@ LeftAlign(BView* view)
ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter,
BMessage* settings, AutoReply* sender) BMessage* settings, AutoReply* sender)
: BWindow(ConfigWindow::GetWindowFrame(), TR("Page setup"), : BWindow(ConfigWindow::GetWindowFrame(), TR("Page setup"),
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
, fKind(kind) , fKind(kind)
, fDefaultPrinter(defaultPrinter) , fDefaultPrinter(defaultPrinter)
, fSettings(settings) , fSettings(settings)
@@ -125,7 +128,7 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter,
if (kind == kJobSetup) if (kind == kJobSetup)
SetTitle(TR("Print setup")); SetTitle(TR("Print setup"));
BView* panel = new BBox(Bounds(), "temporary", B_FOLLOW_ALL, B_WILL_DRAW); BView* panel = new BBox(Bounds(), "temporary", B_FOLLOW_ALL, B_WILL_DRAW);
AddChild(panel); AddChild(panel);
BRect dummyRect(0, 0, 1, 1); BRect dummyRect(0, 0, 1, 1);
@@ -137,26 +140,28 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter,
fPrinters = new BMenuField(TR("Printer:"), menu, NULL); fPrinters = new BMenuField(TR("Printer:"), menu, NULL);
// page format button // page format button
fPageSetup = AddPictureButton(panel, dummyRect, "Paper setup", "PAGE_SETUP_ON", fPageSetup = AddPictureButton(panel, dummyRect, "Paper setup",
"PAGE_SETUP_OFF", MSG_PAGE_SETUP); "PAGE_SETUP_ON", "PAGE_SETUP_OFF", MSG_PAGE_SETUP);
// add description to button // add description to button
BStringView *pageFormatTitle = new BStringView("paperSetupTitle", TR("Paper setup:")); BStringView *pageFormatTitle = new BStringView("paperSetupTitle",
TR("Paper setup:"));
fPageFormatText = new BStringView("paperSetupText", ""); fPageFormatText = new BStringView("paperSetupText", "");
// page selection button // page selection button
fJobSetup = NULL; fJobSetup = NULL;
BStringView* jobSetupTitle = NULL; BStringView* jobSetupTitle = NULL;
if (kind == kJobSetup) { if (kind == kJobSetup) {
fJobSetup = AddPictureButton(panel, dummyRect, "Page setup", "JOB_SETUP_ON", fJobSetup = AddPictureButton(panel, dummyRect, "Page setup",
"JOB_SETUP_OFF", MSG_JOB_SETUP); "JOB_SETUP_ON", "JOB_SETUP_OFF", MSG_JOB_SETUP);
// add description to button // add description to button
jobSetupTitle = new BStringView("jobSetupTitle", TR("Page setup:")); jobSetupTitle = new BStringView("jobSetupTitle", TR("Page setup:"));
fJobSetupText = new BStringView("jobSetupText", ""); fJobSetupText = new BStringView("jobSetupText", "");
} }
// separator line // separator line
BBox* separator = new BBox(dummyRect, "line", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); BBox* separator = new BBox(dummyRect, "line",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1));
// Cancel & OK button // Cancel & OK button
@@ -254,7 +259,8 @@ void ConfigWindow::MessageReceived(BMessage* m)
case MSG_PRINTER_SELECTED: { case MSG_PRINTER_SELECTED: {
BString printer; BString printer;
if (m->FindString("name", &printer) == B_OK) { if (m->FindString("name", &printer) == B_OK) {
UpdateAppSettings(fSenderMimeType.String(), printer.String()); UpdateAppSettings(fSenderMimeType.String(),
printer.String());
PrinterForMimeType(); PrinterForMimeType();
UpdateSettings(true); UpdateSettings(true);
} }
@@ -262,7 +268,10 @@ void ConfigWindow::MessageReceived(BMessage* m)
break; break;
case MSG_OK: case MSG_OK:
UpdateSettings(false); UpdateSettings(false);
fSender->SetReply(fKind == kPageSetup ? &fPageSettings : &fJobSettings); if (fKind == kPageSetup)
fSender->SetReply(&fPageSettings);
else
fSender->SetReply(&fJobSettings);
Quit(); Quit();
break; break;
case B_ABOUT_REQUESTED: AboutRequested(); case B_ABOUT_REQUESTED: AboutRequested();
@@ -329,12 +338,13 @@ BPictureButton* ConfigWindow::AddPictureButton(BView* panel, BRect frame,
BPictureButton* button = NULL; BPictureButton* button = NULL;
if (onPict != NULL && offPict != NULL) { if (onPict != NULL && offPict != NULL) {
button = new BPictureButton(frame, name, onPict, offPict, new BMessage(what)); button = new BPictureButton(frame, name, onPict, offPict,
new BMessage(what));
button->SetViewColor(B_TRANSPARENT_COLOR); button->SetViewColor(B_TRANSPARENT_COLOR);
panel->AddChild(button); panel->AddChild(button);
onBM->Lock(); onBM->Lock();
int32 width = onBM->Bounds().Width(); int32 width = (int32)onBM->Bounds().Width();
int32 height = onBM->Bounds().Height(); int32 height = (int32)onBM->Bounds().Height();
button->ResizeTo(width, height); button->ResizeTo(width, height);
button->SetExplicitMaxSize(BSize(width, height)); button->SetExplicitMaxSize(BSize(width, height));
onBM->Unlock(); onBM->Unlock();
@@ -454,7 +464,8 @@ void ConfigWindow::UpdateUI()
fPageSetup->SetEnabled(true); fPageSetup->SetEnabled(true);
if (fJobSetup) if (fJobSetup)
fJobSetup->SetEnabled(fKind == kJobSetup && !fPageSettings.IsEmpty()); fJobSetup->SetEnabled(fKind == kJobSetup
&& !fPageSettings.IsEmpty());
fOk->SetEnabled(fKind == kJobSetup && !fJobSettings.IsEmpty() || fOk->SetEnabled(fKind == kJobSetup && !fJobSettings.IsEmpty() ||
fKind == kPageSetup && !fPageSettings.IsEmpty()); fKind == kPageSetup && !fPageSettings.IsEmpty());
@@ -483,7 +494,8 @@ void ConfigWindow::UpdateUI()
if (fJobSettings.FindInt32(PSRV_FIELD_FIRST_PAGE, &first) == B_OK && if (fJobSettings.FindInt32(PSRV_FIELD_FIRST_PAGE, &first) == B_OK &&
fJobSettings.FindInt32(PSRV_FIELD_LAST_PAGE, &last) == B_OK) { fJobSettings.FindInt32(PSRV_FIELD_LAST_PAGE, &last) == B_OK) {
if (first >= 1 && first <= last && last != INT_MAX) { if (first >= 1 && first <= last && last != INT_MAX) {
job << TR("Page") << " " << first << " " << TR("to") << " " << last; job << TR("Page") << " " << first << " " << TR("to") << " "
<< last;
} else { } else {
job << TR("All pages"); job << TR("All pages");
} }
+17 -8
View File
@@ -85,7 +85,8 @@ status_t PrintServerApp::async_thread(void* data)
int32 count = Printer::CountPrinters(); int32 count = Printer::CountPrinters();
BString alertText(TR("There are no printers set up.")); BString alertText(TR("There are no printers set up."));
if (count > 0) if (count > 0)
alertText.SetTo(TR("There is no default printer set up.")); alertText.SetTo(
TR("There is no default printer set up."));
alertText.Append(" "); alertText.Append(" ");
alertText.Append(TR("Would you like to set one up now?")); alertText.Append(TR("Would you like to set one up now?"));
@@ -128,9 +129,12 @@ status_t PrintServerApp::async_thread(void* data)
// then create the actual printer // then create the actual printer
if (p->app->CreatePrinter(printerName.String(), if (p->app->CreatePrinter(printerName.String(),
driverName.String(), connection.String(), driverName.String(), connection.String(),
transportName.String(), transportPath.String()) == B_OK) { transportName.String(),
// If printer was created ok, ask if it needs to be the default transportPath.String()) == B_OK) {
BString text(TR("Would you like to make @ the default printer?")); // If printer was created ok,
// ask if it needs to be the default
BString text(TR("Would you like to make @ "
"the default printer?"));
text.ReplaceFirst("@", printerName.String()); text.ReplaceFirst("@", printerName.String());
BAlert* alert = new BAlert("", text.String(), TR("No"), BAlert* alert = new BAlert("", text.String(), TR("No"),
TR("Yes")); TR("Yes"));
@@ -151,7 +155,8 @@ void PrintServerApp::AsyncHandleMessage(BMessage* msg)
{ {
AsyncThreadParams* data = new AsyncThreadParams(this, fDefaultPrinter, msg); AsyncThreadParams* data = new AsyncThreadParams(this, fDefaultPrinter, msg);
thread_id tid = spawn_thread(async_thread, "async", B_NORMAL_PRIORITY, (void*)data); thread_id tid = spawn_thread(async_thread, "async", B_NORMAL_PRIORITY,
(void*)data);
if (tid > 0) { if (tid > 0) {
resume_thread(tid); resume_thread(tid);
@@ -166,14 +171,18 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
// Get currently selected printer // Get currently selected printer
case PSRV_GET_ACTIVE_PRINTER: { case PSRV_GET_ACTIVE_PRINTER: {
BMessage reply('okok'); BMessage reply('okok');
BString printerName = fDefaultPrinter ? fDefaultPrinter->Name() : ""; BString printerName;
if (fDefaultPrinter)
printerName = fDefaultPrinter->Name();
BString mime; BString mime;
if (fUseConfigWindow && MimeTypeForSender(msg, mime)) { if (fUseConfigWindow && MimeTypeForSender(msg, mime)) {
BAutolock lock(gLock); BAutolock lock(gLock);
if (lock.IsLocked()) { if (lock.IsLocked()) {
// override with printer for application // override with printer for application
PrinterSettings* p = fSettings->FindPrinterSettings(mime.String()); PrinterSettings* p = fSettings->FindPrinterSettings(
if (p) printerName = p->GetPrinter(); mime.String());
if (p)
printerName = p->GetPrinter();
} }
} }
reply.AddString("printer_name", printerName); reply.AddString("printer_name", printerName);
+29 -15
View File
@@ -200,7 +200,8 @@ PrintServerApp::RegisterPrinter(BDirectory* printer)
BString transport, address, connection, state; BString transport, address, connection, state;
if (printer->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT, &transport) == B_OK if (printer->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT, &transport) == B_OK
&& printer->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, &address) == B_OK && printer->ReadAttrString(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, &address)
== B_OK
&& printer->ReadAttrString(PSRV_PRINTER_ATTR_CNX, &connection) == B_OK && printer->ReadAttrString(PSRV_PRINTER_ATTR_CNX, &connection) == B_OK
&& printer->ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) == B_OK && printer->ReadAttrString(PSRV_PRINTER_ATTR_STATE, &state) == B_OK
&& state == "free") { && state == "free") {
@@ -216,7 +217,8 @@ PrintServerApp::RegisterPrinter(BDirectory* printer)
return; return;
// register new printer // register new printer
Resource* r = fResourceManager.Allocate(transport.String(), address.String(), connection.String()); Resource* r = fResourceManager.Allocate(transport.String(),
address.String(), connection.String());
AddHandler(new Printer(printer, r)); AddHandler(new Printer(printer, r));
Acquire(); Acquire();
} }
@@ -318,7 +320,8 @@ PrintServerApp::SetupPrinterList()
BDirectory node(&entry); BDirectory node(&entry);
BNodeInfo info(&node); BNodeInfo info(&node);
char buffer[256]; char buffer[256];
if (info.GetType(buffer) == B_OK && strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) { if (info.GetType(buffer) == B_OK
&& strcmp(buffer, PSRV_PRINTER_FILETYPE) == 0) {
RegisterPrinter(&node); RegisterPrinter(&node);
} }
} }
@@ -391,7 +394,8 @@ PrintServerApp::MessageReceived(BMessage* msg)
// --------------------------------------------------------------- // ---------------------------------------------------------------
status_t status_t
PrintServerApp::CreatePrinter(const char* printerName, const char* driverName, PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
const char* connection, const char* transportName, const char* transportPath) const char* connection, const char* transportName,
const char* transportPath)
{ {
status_t rc; status_t rc;
@@ -424,14 +428,17 @@ PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
// the printer exists, but no default at all // the printer exists, but no default at all
return B_OK; return B_OK;
} else { } else {
info.SetTo(TR("There already exists a printer you are going to create, but it's driver could not be found! Replace?")); info.SetTo(TR("There already exists a printer you are going to "
"create, but it's driver could not be found! Replace?"));
} }
} else { } else {
info.SetTo(TR("There already exists a printer you are going to create, but it's not usable at all! Replace?")); info.SetTo(TR("There already exists a printer you are going to "
"create, but it's not usable at all! Replace?"));
} }
if (info.Length() != 0) { if (info.Length() != 0) {
BAlert *alert = new BAlert("Info", info.String(), TR("Cancel"), TR("OK")); BAlert *alert = new BAlert("Info", info.String(), TR("Cancel"),
TR("OK"));
alert->SetShortcut(0, B_ESCAPE); alert->SetShortcut(0, B_ESCAPE);
if (alert->Go() == 0) if (alert->Go() == 0)
return rc; return rc;
@@ -449,8 +456,8 @@ PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
::strlen(printerName) + 1); ::strlen(printerName) + 1);
printer.WriteAttr(PSRV_PRINTER_ATTR_DRV_NAME, B_STRING_TYPE, 0, driverName, printer.WriteAttr(PSRV_PRINTER_ATTR_DRV_NAME, B_STRING_TYPE, 0, driverName,
::strlen(driverName) + 1); ::strlen(driverName) + 1);
printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT, B_STRING_TYPE, 0, transportName, printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT, B_STRING_TYPE, 0,
::strlen(transportName) + 1); transportName, ::strlen(transportName) + 1);
printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, B_STRING_TYPE, 0, printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, B_STRING_TYPE, 0,
transportPath, ::strlen(transportPath) + 1); transportPath, ::strlen(transportPath) + 1);
printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection, printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection,
@@ -479,7 +486,8 @@ PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
if ((*func)(printerName) == NULL) if ((*func)(printerName) == NULL)
rc = B_ERROR; rc = B_ERROR;
else else
printer.WriteAttr(PSRV_PRINTER_ATTR_STATE, B_STRING_TYPE, 0, "free", ::strlen("free")+1); printer.WriteAttr(PSRV_PRINTER_ATTR_STATE, B_STRING_TYPE, 0, "free",
::strlen("free")+1);
error: error:
if (rc != B_OK) { if (rc != B_OK) {
@@ -646,17 +654,23 @@ PrintServerApp::FindPrinterNode(const char* name, BNode& node)
status_t status_t
PrintServerApp::FindPrinterDriver(const char* name, BPath& outPath) PrintServerApp::FindPrinterDriver(const char* name, BPath& outPath)
{ {
if (::TestForAddonExistence(name, B_USER_ADDONS_DIRECTORY, "Print", outPath) != B_OK if (::TestForAddonExistence(name, B_USER_ADDONS_DIRECTORY, "Print", outPath)
&& TestForAddonExistence(name, B_COMMON_ADDONS_DIRECTORY, "Print", outPath) != B_OK) != B_OK
return ::TestForAddonExistence(name, B_BEOS_ADDONS_DIRECTORY, "Print", outPath); && TestForAddonExistence(name, B_COMMON_ADDONS_DIRECTORY, "Print",
outPath) != B_OK)
return ::TestForAddonExistence(name, B_BEOS_ADDONS_DIRECTORY, "Print",
outPath);
return B_OK; return B_OK;
} }
bool PrintServerApp::OpenSettings(BFile& file, const char* name, bool forReading) { bool PrintServerApp::OpenSettings(BFile& file, const char* name,
bool forReading)
{
BPath path; BPath path;
uint32 openMode = forReading ? B_READ_ONLY : B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY; uint32 openMode = forReading ? B_READ_ONLY : B_CREATE_FILE | B_ERASE_FILE
| B_WRITE_ONLY;
return find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK return find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK
&& path.Append(name) == B_OK && path.Append(name) == B_OK
&& file.SetTo(path.Path(), openMode) == B_OK; && file.SetTo(path.Path(), openMode) == B_OK;