* Fixed crash at cancelation.
* Simplified class LprSetupDlg using DialogWindow. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33561 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,6 +2,7 @@ SubDir HAIKU_TOP src add-ons print transports lpr ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
SubDirHdrs [ FDirName $(HAIKU_TOP) headers libs print libprint ] ;
|
||||
SubDirHdrs [ FDirName $(HAIKU_TOP) src add-ons print transports shared ] ;
|
||||
|
||||
Addon LPR :
|
||||
@@ -13,7 +14,11 @@ Addon LPR :
|
||||
Socket.o
|
||||
SocketStream.o
|
||||
DbgMsg.o
|
||||
: be $(TARGET_NETWORK_LIBS) $(TARGET_LIBSTDC++)
|
||||
:
|
||||
be
|
||||
libprint.a
|
||||
$(TARGET_NETWORK_LIBS)
|
||||
$(TARGET_LIBSTDC++)
|
||||
;
|
||||
|
||||
ObjectReferences
|
||||
|
||||
@@ -146,12 +146,15 @@ LprSetupView::UpdateViewData()
|
||||
return false;
|
||||
}
|
||||
|
||||
fDir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer->Text(), strlen(fServer->Text()) + 1);
|
||||
fDir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, fQueue->Text(), strlen(fQueue->Text()) + 1);
|
||||
fDir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer->Text(),
|
||||
strlen(fServer->Text()) + 1);
|
||||
fDir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, fQueue->Text(),
|
||||
strlen(fQueue->Text()) + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
BAlert *alert = new BAlert("", "please input parameters.", "OK");
|
||||
BAlert *alert = new BAlert("", "Please enter server address and printer"
|
||||
"queue name.", "OK");
|
||||
alert->Go();
|
||||
return false;
|
||||
}
|
||||
@@ -159,66 +162,32 @@ LprSetupView::UpdateViewData()
|
||||
|
||||
LprSetupDlg::LprSetupDlg(BDirectory *dir)
|
||||
:
|
||||
BWindow(BRect(100, 100, 100 + DLG_WIDTH, 100 + DLG_HEIGHT),
|
||||
DialogWindow(BRect(100, 100, 100 + DLG_WIDTH, 100 + DLG_HEIGHT),
|
||||
"LPR Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
||||
B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
fResult = 0;
|
||||
|
||||
Lock();
|
||||
LprSetupView *view = new LprSetupView(Bounds(), dir);
|
||||
AddChild(view);
|
||||
Unlock();
|
||||
|
||||
fExitSemaphore = create_sem(0, "lprSetupSem");
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
LprSetupDlg::QuitRequested()
|
||||
{
|
||||
fResult = B_ERROR;
|
||||
release_sem(fExitSemaphore);
|
||||
return true;
|
||||
fSetupView = new LprSetupView(Bounds(), dir);
|
||||
AddChild(fSetupView);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LprSetupDlg::MessageReceived(BMessage *msg)
|
||||
{
|
||||
bool success;
|
||||
|
||||
switch (msg->what) {
|
||||
case M_OK:
|
||||
Lock();
|
||||
success = ((LprSetupView *)ChildAt(0))->UpdateViewData();
|
||||
Unlock();
|
||||
if (success) {
|
||||
fResult = B_NO_ERROR;
|
||||
release_sem(fExitSemaphore);
|
||||
if (fSetupView->UpdateViewData()) {
|
||||
SetResult(B_OK);
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
break;
|
||||
|
||||
case M_CANCEL:
|
||||
fResult = B_ERROR;
|
||||
release_sem(fExitSemaphore);
|
||||
SetResult(B_ERROR);
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
break;
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(msg);
|
||||
break;
|
||||
DialogWindow::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
LprSetupDlg::Go()
|
||||
{
|
||||
Show();
|
||||
acquire_sem(fExitSemaphore);
|
||||
delete_sem(fExitSemaphore);
|
||||
int value = fResult;
|
||||
Lock();
|
||||
Quit();
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -6,19 +6,20 @@
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
class BDirectory;
|
||||
#include "DialogWindow.h"
|
||||
|
||||
class LprSetupDlg : public BWindow {
|
||||
class BDirectory;
|
||||
class LprSetupView;
|
||||
|
||||
|
||||
class LprSetupDlg : public DialogWindow {
|
||||
public:
|
||||
LprSetupDlg(BDirectory *);
|
||||
~LprSetupDlg() {}
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
int Go();
|
||||
|
||||
private:
|
||||
int fResult;
|
||||
sem_id fExitSemaphore;
|
||||
LprSetupView* fSetupView;
|
||||
};
|
||||
|
||||
#endif // __LprSetupDlg_H
|
||||
|
||||
@@ -76,9 +76,21 @@ LprTransport::LprTransport(BMessage *msg)
|
||||
|
||||
|
||||
LprTransport::~LprTransport()
|
||||
{
|
||||
if (!fError)
|
||||
_SendFile();
|
||||
|
||||
if (fFile[0] != '\0')
|
||||
unlink(fFile);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LprTransport::_SendFile()
|
||||
{
|
||||
char hostname[128];
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
if (gethostname(hostname, sizeof(hostname)) != B_OK)
|
||||
strcpy(hostname, "localhost");
|
||||
|
||||
ostringstream cfname;
|
||||
cfname << "cfA" << setw(3) << setfill('0') << fJobId << hostname;
|
||||
@@ -116,8 +128,6 @@ LprTransport::~LprTransport()
|
||||
BAlert *alert = new BAlert("", err.what(), "OK");
|
||||
alert->Go();
|
||||
}
|
||||
|
||||
unlink(fFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
bool fail() const;
|
||||
|
||||
private:
|
||||
void _SendFile();
|
||||
|
||||
char fServer[256];
|
||||
char fQueue[256];
|
||||
char fFile[256];
|
||||
|
||||
Reference in New Issue
Block a user