Async. start Page/Printer Config Dialog.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@499 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2002-07-28 17:05:03 +00:00
parent 247c4fa55f
commit 2c0d45d7c1
6 changed files with 128 additions and 43 deletions

View File

@ -3,14 +3,26 @@ SubDir OBOS_TOP src servers print ;
UsePrivateHeaders interface ; UsePrivateHeaders interface ;
UsePrivateHeaders shared ; UsePrivateHeaders shared ;
AddResources print_server : PrintServer.FileTypes.rsrc ; Server
print_server
Server print_server : :
PrintServerApp.cpp PrintServerApp.cpp
PrintServerApp.R5.cpp PrintServerApp.R5.cpp
PrintServerApp.Scripting.cpp PrintServerApp.Scripting.cpp
Printer.Scripting.cpp Printer.Scripting.cpp
Printer.cpp Printer.cpp
BeUtils.cpp BeUtils.cpp
; ;
LinkSharedOSLibs print_server : be root ;
LinkSharedOSLibs
print_server
:
be
root
;
XRes
print_server
:
PrintServer.FileTypes.rsrc
;

View File

@ -47,8 +47,94 @@
#include <PrintJob.h> #include <PrintJob.h>
#include <Alert.h> #include <Alert.h>
// TODO:
// Somehow block application that wants to show page/printer config dialog
// Handle situation where there are pending print jobs but printer is requested for deletion
struct AsyncThreadParams {
Printer* printer;
BMessage message;
AsyncThreadParams(Printer* p, BMessage* m)
: printer(p)
, message(*m)
{ }
};
status_t PrintServerApp::async_thread(void* data)
{
AsyncThreadParams* p = (AsyncThreadParams*)data;
Printer* printer = p->printer;
BMessage* msg = &p->message;
switch (msg->what) {
// Handle showing the page config dialog
case PSRV_SHOW_PAGE_SETUP: {
if (printer != NULL) {
BMessage reply(*msg);
if (printer->ConfigurePage(reply) == B_OK) {
msg->SendReply(&reply);
break;
}
}
else {
// If no default printer, give user choice of aborting or setting up a printer
BAlert* alert = new BAlert("Info", "Hang on there! You don't have any printers set up!\nYou'll need to do that before trying to print\n\nWould you like to set up a printer now?", "No thanks", "Sure!");
if (alert->Go() == 1) {
run_add_printer_panel();
}
}
// Always stop dialog flow
BMessage reply('stop');
msg->SendReply(&reply);
}
break;
// Handle showing the print config dialog
case PSRV_SHOW_PRINT_SETUP: {
if (printer != NULL) {
BMessage reply(*msg);
if (printer->ConfigureJob(reply) == B_OK) {
msg->SendReply(&reply);
break;
}
}
BMessage reply('stop');
msg->SendReply(&reply);
}
break;
}
if (printer) printer->Release();
delete p;
}
// Async. processing of received message
void PrintServerApp::AsyncHandleMessage(BMessage* msg)
{
AsyncThreadParams* data = new AsyncThreadParams(fDefaultPrinter, msg);
thread_id tid = spawn_thread(async_thread, "async", B_NORMAL_PRIORITY, (void*)data);
if (tid > 0) {
if (fDefaultPrinter) fDefaultPrinter->Acquire();
resume_thread(tid);
} else {
delete data;
}
}
void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg) void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
{ {
printf("PrintServerApp::Handle_BeOSR5_Message\n");
msg->PrintToStream();
fflush(stdout);
switch(msg->what) { switch(msg->what) {
// Get currently selected printer // Get currently selected printer
case PSRV_GET_ACTIVE_PRINTER: { case PSRV_GET_ACTIVE_PRINTER: {
@ -98,41 +184,9 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
} }
break; break;
// Handle showing the page config dialog case PSRV_SHOW_PAGE_SETUP:
case PSRV_SHOW_PAGE_SETUP: { case PSRV_SHOW_PRINT_SETUP:
if (fDefaultPrinter != NULL) { AsyncHandleMessage(msg);
BMessage reply(*msg);
if (fDefaultPrinter->ConfigurePage(reply) == B_OK) {
msg->SendReply(&reply);
}
}
else {
// If no default printer, give user choice of aborting or setting up a printer
BAlert* alert = new BAlert("Info", "Hang on there! You don't have any printers set up!\nYou'll need to do that before trying to print\n\nWould you like to set up a printer now?", "No thanks", "Sure!");
if (alert->Go() == 1) {
run_add_printer_panel();
}
// Always stop dialog flow
BMessage reply('stop');
msg->SendReply(&reply);
}
}
break;
// Handle showing the print config dialog
case PSRV_SHOW_PRINT_SETUP: {
if (fDefaultPrinter != NULL) {
BMessage reply(*msg);
if (fDefaultPrinter->ConfigureJob(reply) == B_OK) {
msg->SendReply(&reply);
}
}
else {
BMessage reply('stop');
msg->SendReply(&reply);
}
}
break; break;
// Tell printer addon to print a spooled job // Tell printer addon to print a spooled job

View File

@ -107,7 +107,7 @@ PrintServerApp::HandleScriptingCommand(BMessage* msg)
status_t rc = B_BAD_VALUE; status_t rc = B_BAD_VALUE;
if (printer != NULL && (rc=printer->Remove()) == B_OK) { if (printer != NULL && (rc=printer->Remove()) == B_OK) {
delete printer; printer->Release();
} }
BMessage reply(B_REPLY); BMessage reply(B_REPLY);

View File

@ -82,6 +82,8 @@ private:
BBitmap fSelectedIconLarge; BBitmap fSelectedIconLarge;
// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp // "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
static status_t async_thread(void* data);
void AsyncHandleMessage(BMessage* msg);
void Handle_BeOSR5_Message(BMessage* msg); void Handle_BeOSR5_Message(BMessage* msg);
}; };

View File

@ -108,7 +108,8 @@ Printer* Printer::At(int32 idx)
// --------------------------------------------------------------- // ---------------------------------------------------------------
Printer::Printer(const BNode* node) Printer::Printer(const BNode* node)
: Inherited(B_EMPTY_STRING), : Inherited(B_EMPTY_STRING),
fNode(*node) fNode(*node),
fRefCount(1)
{ {
// Set our name to the name of the passed node // Set our name to the name of the passed node
BString name; BString name;
@ -126,6 +127,17 @@ Printer::~Printer()
be_app->RemoveHandler(this); be_app->RemoveHandler(this);
} }
void Printer::Acquire()
{
fRefCount ++;
}
void Printer::Release()
{
fRefCount --;
if (fRefCount == 0) delete this;
}
status_t Printer::Remove() status_t Printer::Remove()
{ {
status_t rc = B_OK; status_t rc = B_OK;

View File

@ -61,10 +61,14 @@ class Printer;
class Printer : public BHandler class Printer : public BHandler
{ {
typedef BHandler Inherited; typedef BHandler Inherited;
public: public:
Printer(const BNode* node); Printer(const BNode* node);
~Printer(); ~Printer();
void Acquire();
void Release();
// Static helper functions // Static helper functions
static Printer* Find(const BString& name); static Printer* Find(const BString& name);
static Printer* At(int32 idx); static Printer* At(int32 idx);
@ -87,6 +91,7 @@ private:
status_t LoadPrinterAddon(image_id& id); status_t LoadPrinterAddon(image_id& id);
BNode fNode; BNode fNode;
int32 fRefCount;
static BObjectList<Printer> sPrinters; static BObjectList<Printer> sPrinters;
}; };