* do some simple checking if the printer exists and is usable at
all, otherwise complain or offer to make it the default printer git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24554 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2006, Haiku. All rights reserved.
|
* Copyright 2001-2008, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -382,20 +382,57 @@ PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
|
|||||||
BDirectory printer;
|
BDirectory printer;
|
||||||
|
|
||||||
rc = printersDir.CreateDirectory(printerName, &printer);
|
rc = printersDir.CreateDirectory(printerName, &printer);
|
||||||
if (rc != B_OK)
|
if (rc == B_FILE_EXISTS) {
|
||||||
|
printer.SetTo(&printersDir, printerName);
|
||||||
|
|
||||||
|
BString info;
|
||||||
|
char type[B_MIME_TYPE_LENGTH];
|
||||||
|
BNodeInfo(&printer).GetType(type);
|
||||||
|
if (strcmp(PSRV_PRINTER_FILETYPE, type) == 0) {
|
||||||
|
BPath tmp;
|
||||||
|
if (FindPrinterDriver(printerName, tmp) == B_OK) {
|
||||||
|
if (fDefaultPrinter) {
|
||||||
|
// the printer exists, but is not the default printer
|
||||||
|
if(strcmp(fDefaultPrinter->Name(), printerName) != 0)
|
||||||
|
rc = B_OK;
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
// the printer exists, but no default at all
|
||||||
|
return B_OK;
|
||||||
|
} else {
|
||||||
|
info.SetTo("There already exists an printer you are going to"
|
||||||
|
" create, but it's driver could not be found! Replace?");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info.SetTo("There already exists an printer you are going to"
|
||||||
|
" create, but it's not usable at all! Replace?");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.Length() != 0) {
|
||||||
|
BAlert *alert = new BAlert("Info", info.String(), "Cancel", "OK");
|
||||||
|
alert->SetShortcut(0, B_ESCAPE);
|
||||||
|
if (alert->Go() == 0)
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
} else if (rc != B_OK) {
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
// Set its type to a printer
|
// Set its type to a printer
|
||||||
BNodeInfo info(&printer);
|
BNodeInfo info(&printer);
|
||||||
info.SetType(PSRV_PRINTER_FILETYPE);
|
info.SetType(PSRV_PRINTER_FILETYPE);
|
||||||
|
|
||||||
// Store the settings in its attributes
|
// Store the settings in its attributes
|
||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_PRT_NAME, B_STRING_TYPE, 0, printerName, ::strlen(printerName)+1);
|
printer.WriteAttr(PSRV_PRINTER_ATTR_PRT_NAME, B_STRING_TYPE, 0, printerName,
|
||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_DRV_NAME, B_STRING_TYPE, 0, driverName, ::strlen(driverName)+1);
|
::strlen(printerName) + 1);
|
||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT, B_STRING_TYPE, 0, transportName,::strlen(transportName)+1);
|
printer.WriteAttr(PSRV_PRINTER_ATTR_DRV_NAME, B_STRING_TYPE, 0, driverName,
|
||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, B_STRING_TYPE, 0, transportPath,::strlen(transportPath)+1);
|
::strlen(driverName) + 1);
|
||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection, ::strlen(connection)+1);
|
printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT, B_STRING_TYPE, 0, transportName,
|
||||||
|
::strlen(transportName) + 1);
|
||||||
|
printer.WriteAttr(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, B_STRING_TYPE, 0,
|
||||||
|
transportPath, ::strlen(transportPath) + 1);
|
||||||
|
printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection,
|
||||||
|
::strlen(connection) + 1);
|
||||||
|
|
||||||
// Notify printer driver that a new printer definition node
|
// Notify printer driver that a new printer definition node
|
||||||
// has been created.
|
// has been created.
|
||||||
|
|||||||
Reference in New Issue
Block a user