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:
parent
247c4fa55f
commit
2c0d45d7c1
|
@ -3,14 +3,26 @@ SubDir OBOS_TOP src servers print ;
|
|||
UsePrivateHeaders interface ;
|
||||
UsePrivateHeaders shared ;
|
||||
|
||||
AddResources print_server : PrintServer.FileTypes.rsrc ;
|
||||
|
||||
Server print_server :
|
||||
Server
|
||||
print_server
|
||||
:
|
||||
PrintServerApp.cpp
|
||||
PrintServerApp.R5.cpp
|
||||
PrintServerApp.Scripting.cpp
|
||||
Printer.Scripting.cpp
|
||||
Printer.cpp
|
||||
BeUtils.cpp
|
||||
;
|
||||
LinkSharedOSLibs print_server : be root ;
|
||||
;
|
||||
|
||||
LinkSharedOSLibs
|
||||
print_server
|
||||
:
|
||||
be
|
||||
root
|
||||
;
|
||||
|
||||
XRes
|
||||
print_server
|
||||
:
|
||||
PrintServer.FileTypes.rsrc
|
||||
;
|
|
@ -47,8 +47,94 @@
|
|||
#include <PrintJob.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)
|
||||
{
|
||||
printf("PrintServerApp::Handle_BeOSR5_Message\n");
|
||||
msg->PrintToStream();
|
||||
fflush(stdout);
|
||||
|
||||
switch(msg->what) {
|
||||
// Get currently selected printer
|
||||
case PSRV_GET_ACTIVE_PRINTER: {
|
||||
|
@ -98,41 +184,9 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
|
|||
}
|
||||
break;
|
||||
|
||||
// Handle showing the page config dialog
|
||||
case PSRV_SHOW_PAGE_SETUP: {
|
||||
if (fDefaultPrinter != NULL) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
case PSRV_SHOW_PAGE_SETUP:
|
||||
case PSRV_SHOW_PRINT_SETUP:
|
||||
AsyncHandleMessage(msg);
|
||||
break;
|
||||
|
||||
// Tell printer addon to print a spooled job
|
||||
|
|
|
@ -107,7 +107,7 @@ PrintServerApp::HandleScriptingCommand(BMessage* msg)
|
|||
status_t rc = B_BAD_VALUE;
|
||||
|
||||
if (printer != NULL && (rc=printer->Remove()) == B_OK) {
|
||||
delete printer;
|
||||
printer->Release();
|
||||
}
|
||||
|
||||
BMessage reply(B_REPLY);
|
||||
|
|
|
@ -82,6 +82,8 @@ private:
|
|||
BBitmap fSelectedIconLarge;
|
||||
|
||||
// "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);
|
||||
};
|
||||
|
||||
|
|
|
@ -108,7 +108,8 @@ Printer* Printer::At(int32 idx)
|
|||
// ---------------------------------------------------------------
|
||||
Printer::Printer(const BNode* node)
|
||||
: Inherited(B_EMPTY_STRING),
|
||||
fNode(*node)
|
||||
fNode(*node),
|
||||
fRefCount(1)
|
||||
{
|
||||
// Set our name to the name of the passed node
|
||||
BString name;
|
||||
|
@ -126,6 +127,17 @@ Printer::~Printer()
|
|||
be_app->RemoveHandler(this);
|
||||
}
|
||||
|
||||
void Printer::Acquire()
|
||||
{
|
||||
fRefCount ++;
|
||||
}
|
||||
|
||||
void Printer::Release()
|
||||
{
|
||||
fRefCount --;
|
||||
if (fRefCount == 0) delete this;
|
||||
}
|
||||
|
||||
status_t Printer::Remove()
|
||||
{
|
||||
status_t rc = B_OK;
|
||||
|
|
|
@ -61,10 +61,14 @@ class Printer;
|
|||
class Printer : public BHandler
|
||||
{
|
||||
typedef BHandler Inherited;
|
||||
|
||||
public:
|
||||
Printer(const BNode* node);
|
||||
~Printer();
|
||||
|
||||
|
||||
void Acquire();
|
||||
void Release();
|
||||
|
||||
// Static helper functions
|
||||
static Printer* Find(const BString& name);
|
||||
static Printer* At(int32 idx);
|
||||
|
@ -87,6 +91,7 @@ private:
|
|||
status_t LoadPrinterAddon(image_id& id);
|
||||
|
||||
BNode fNode;
|
||||
int32 fRefCount;
|
||||
|
||||
static BObjectList<Printer> sPrinters;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue