Added GetDefaultSettings().
Fixed start print_server from terminal only if it is not already running. Fixed use pointers to BBitmap in application class. To prevent destruction of BBitmap without valid BApplication object, if BApplication constructor has failed. Clean up. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1531 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f2ee553c1b
commit
dfb355568e
@ -107,6 +107,19 @@ status_t PrintServerApp::async_thread(void* data)
|
||||
}
|
||||
break;
|
||||
|
||||
// Retrieve default configuration message from printer add-on
|
||||
case PSRV_GET_DEFAULT_SETTINGS:
|
||||
if (printer != NULL) {
|
||||
BMessage reply;
|
||||
if (printer->GetDefaultSettings(reply) == B_OK) {
|
||||
msg->SendReply(&reply);
|
||||
break;
|
||||
}
|
||||
}
|
||||
BMessage reply('stop');
|
||||
msg->SendReply(&reply);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (printer) printer->Release();
|
||||
@ -129,24 +142,8 @@ void PrintServerApp::AsyncHandleMessage(BMessage* msg)
|
||||
}
|
||||
}
|
||||
|
||||
#include <be/app/Roster.h>
|
||||
|
||||
void PrintSender(BMessage* msg) {
|
||||
BMessenger msgr = msg->ReturnAddress();
|
||||
// if (msgr.InitCheck() == B_OK) {
|
||||
team_id team = msgr.Team();
|
||||
app_info info;
|
||||
if (be_roster->GetRunningAppInfo(team, &info) == B_OK) {
|
||||
fprintf(stderr, "PrintSender signature = %s\n", info.signature);
|
||||
} else
|
||||
fprintf(stderr, "PrintSender could not get app_info\n");
|
||||
// } else
|
||||
// fprintf(stderr, "PrintSender invalid BMessenger\n");
|
||||
}
|
||||
|
||||
void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
|
||||
{
|
||||
PrintSender(msg);
|
||||
switch(msg->what) {
|
||||
// Get currently selected printer
|
||||
case PSRV_GET_ACTIVE_PRINTER: {
|
||||
@ -196,8 +193,9 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
|
||||
}
|
||||
break;
|
||||
|
||||
case PSRV_SHOW_PAGE_SETUP:
|
||||
case PSRV_SHOW_PRINT_SETUP:
|
||||
case PSRV_SHOW_PAGE_SETUP:
|
||||
case PSRV_SHOW_PRINT_SETUP:
|
||||
case PSRV_GET_DEFAULT_SETTINGS:
|
||||
AsyncHandleMessage(DetachCurrentMessage());
|
||||
break;
|
||||
|
||||
|
@ -83,18 +83,24 @@ typedef char* (*add_printer_func_t)(const char* printer_name);
|
||||
int
|
||||
main()
|
||||
{
|
||||
gLock = new BLocker();
|
||||
// Create our application object
|
||||
status_t rc = B_OK;
|
||||
PrintServerApp print_server(&rc);
|
||||
|
||||
// If all went fine, let's start it
|
||||
if (rc == B_OK) {
|
||||
print_server.Run();
|
||||
|
||||
if (!be_roster->IsRunning(PSRV_SIGNATURE_TYPE)) {
|
||||
gLock = new BLocker();
|
||||
// Create our application object
|
||||
PrintServerApp print_server(&rc);
|
||||
|
||||
// If all went fine, let's start it
|
||||
if (rc == B_OK) {
|
||||
print_server.Run();
|
||||
}
|
||||
|
||||
delete gLock;
|
||||
} else {
|
||||
// restart print server
|
||||
// As we load the printer addon everytime we need it
|
||||
// and unload it afterwards, we have nothing to do here!
|
||||
}
|
||||
|
||||
delete gLock;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -111,23 +117,26 @@ main()
|
||||
|
||||
PrintServerApp::PrintServerApp(status_t* err)
|
||||
: Inherited(PSRV_SIGNATURE_TYPE, err),
|
||||
fSelectedIconMini(BRect(0,0,B_MINI_ICON-1,B_MINI_ICON-1), B_CMAP8),
|
||||
fSelectedIconLarge(BRect(0,0,B_LARGE_ICON-1,B_LARGE_ICON-1), B_CMAP8),
|
||||
fSelectedIconMini(NULL),
|
||||
fSelectedIconLarge(NULL),
|
||||
fNumberOfPrinters(0),
|
||||
fNoPrinterAvailable(0)
|
||||
{
|
||||
// If our superclass initialized ok
|
||||
if (*err == B_OK) {
|
||||
if (*err == B_OK) {
|
||||
fNoPrinterAvailable = create_sem(1, "");
|
||||
|
||||
// let us try as well
|
||||
SetupPrinterList();
|
||||
RetrieveDefaultPrinter();
|
||||
|
||||
fSelectedIconMini = new BBitmap(BRect(0,0,B_MINI_ICON-1,B_MINI_ICON-1), B_CMAP8);
|
||||
fSelectedIconLarge = new BBitmap(BRect(0,0,B_LARGE_ICON-1,B_LARGE_ICON-1), B_CMAP8);
|
||||
|
||||
// Cache icons for selected printer
|
||||
BMimeType type(PRNT_SIGNATURE_TYPE);
|
||||
type.GetIcon(&fSelectedIconMini, B_MINI_ICON);
|
||||
type.GetIcon(&fSelectedIconLarge, B_LARGE_ICON);
|
||||
type.GetIcon(fSelectedIconMini, B_MINI_ICON);
|
||||
type.GetIcon(fSelectedIconLarge, B_LARGE_ICON);
|
||||
|
||||
// Start handling of spooled files
|
||||
PostMessage(PSRV_PRINT_SPOOLED_JOB);
|
||||
@ -163,6 +172,11 @@ bool PrintServerApp::QuitRequested()
|
||||
delete_sem(fNoPrinterAvailable);
|
||||
fNoPrinterAvailable = 0;
|
||||
}
|
||||
|
||||
ASSERT(fSelectedIconMini != NULL);
|
||||
|
||||
delete fSelectedIconMini; fSelectedIconMini = NULL;
|
||||
delete fSelectedIconLarge; fSelectedIconLarge = NULL;
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -296,6 +310,7 @@ PrintServerApp::MessageReceived(BMessage* msg)
|
||||
case PSRV_SHOW_PAGE_SETUP:
|
||||
case PSRV_SHOW_PRINT_SETUP:
|
||||
case PSRV_PRINT_SPOOLED_JOB:
|
||||
case PSRV_GET_DEFAULT_SETTINGS:
|
||||
Handle_BeOSR5_Message(msg);
|
||||
break;
|
||||
|
||||
@ -425,8 +440,8 @@ PrintServerApp::SelectPrinter(const char* printerName)
|
||||
if ((rc=FindPrinterNode(printerName, node)) == B_OK) {
|
||||
// and add the custom icon
|
||||
BNodeInfo info(&node);
|
||||
info.SetIcon(&fSelectedIconMini, B_MINI_ICON);
|
||||
info.SetIcon(&fSelectedIconLarge, B_LARGE_ICON);
|
||||
info.SetIcon(fSelectedIconMini, B_MINI_ICON);
|
||||
info.SetIcon(fSelectedIconLarge, B_LARGE_ICON);
|
||||
}
|
||||
|
||||
fDefaultPrinter = Printer::Find(printerName);
|
||||
|
@ -94,11 +94,11 @@ private:
|
||||
|
||||
ResourceManager fResourceManager;
|
||||
Printer* fDefaultPrinter;
|
||||
BBitmap fSelectedIconMini;
|
||||
BBitmap fSelectedIconLarge;
|
||||
BBitmap* fSelectedIconMini;
|
||||
BBitmap* fSelectedIconLarge;
|
||||
int fNumberOfPrinters; // number of existing Printer objects
|
||||
sem_id fNoPrinterAvailable; // can be acquired if number of printers == 0
|
||||
|
||||
|
||||
// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
|
||||
static status_t async_thread(void* data);
|
||||
void AsyncHandleMessage(BMessage* msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user