Refinement of ConfigWindow.
Some bug fixes. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1656 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -90,3 +90,21 @@ bool MimeTypeForSender(BMessage* sender, BString& mime) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AddFields(BMessage* to, const BMessage* from) {
|
||||||
|
char* name;
|
||||||
|
uint32 type;
|
||||||
|
int32 count;
|
||||||
|
for (int32 i = 0; from->GetInfo(B_ANY_TYPE, i, &name, &type, &count) == B_OK; i ++) {
|
||||||
|
// replace existing data
|
||||||
|
to->RemoveName(name);
|
||||||
|
|
||||||
|
const void* data;
|
||||||
|
ssize_t size;
|
||||||
|
for (int32 i = 0; i < count; i ++) {
|
||||||
|
if (from->FindData(name, type, i, &data, &size) == B_OK) {
|
||||||
|
to->AddData(name, type, data, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -86,5 +86,6 @@ public:
|
|||||||
|
|
||||||
// mimetype from sender
|
// mimetype from sender
|
||||||
bool MimeTypeForSender(BMessage* sender, BString& mime);
|
bool MimeTypeForSender(BMessage* sender, BString& mime);
|
||||||
|
bool AddFields(BMessage* to, const BMessage* from);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "Printer.h"
|
#include "Printer.h"
|
||||||
#include "PrintServerApp.h"
|
#include "PrintServerApp.h"
|
||||||
#include "ConfigWindow.h"
|
#include "ConfigWindow.h"
|
||||||
|
#include "BeUtils.h"
|
||||||
|
|
||||||
// posix
|
// posix
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -44,7 +45,7 @@
|
|||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMessage* settings, AutoReply* sender)
|
ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMessage* settings, AutoReply* sender)
|
||||||
: BWindow(ConfigWindow::GetWindowFrame(), "Printer Setup",
|
: BWindow(ConfigWindow::GetWindowFrame(), "Page Setup",
|
||||||
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||||
, fKind(kind)
|
, fKind(kind)
|
||||||
, fDefaultPrinter(defaultPrinter)
|
, fDefaultPrinter(defaultPrinter)
|
||||||
@@ -55,40 +56,81 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMes
|
|||||||
MimeTypeForSender(settings, fSenderMimeType);
|
MimeTypeForSender(settings, fSenderMimeType);
|
||||||
PrinterForMimeType();
|
PrinterForMimeType();
|
||||||
|
|
||||||
|
if (kind == kJobSetup) SetTitle("Print Setup");
|
||||||
|
|
||||||
BView* panel = new BBox(Bounds(), "top_panel", B_FOLLOW_ALL,
|
BView* panel = new BBox(Bounds(), "top_panel", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||||
B_PLAIN_BORDER);
|
B_PLAIN_BORDER);
|
||||||
|
|
||||||
AddChild(panel);
|
AddChild(panel);
|
||||||
|
|
||||||
float left = 10, top = 5;
|
float left = 10, top = 5, width;
|
||||||
BRect r(left, top, 160, 15);
|
BRect r(left, top, 160, 15);
|
||||||
|
|
||||||
BPopUpMenu* menu = new BPopUpMenu("PrinterMenu");
|
// print selection popup menu
|
||||||
|
BPopUpMenu* menu = new BPopUpMenu("Select a Printer");
|
||||||
SetupPrintersMenu(menu);
|
SetupPrintersMenu(menu);
|
||||||
|
|
||||||
fPrinters = new BMenuField(r, "Printer", "Printer", menu);
|
fPrinters = new BMenuField(r, "Printer", "Printer", menu);
|
||||||
fPrinters->SetDivider(60);
|
fPrinters->SetDivider(40);
|
||||||
panel->AddChild(fPrinters);
|
panel->AddChild(fPrinters);
|
||||||
top += fPrinters->Bounds().Height() + 5;
|
top += fPrinters->Bounds().Height() + 10;
|
||||||
|
width = fPrinters->Bounds().Width();
|
||||||
|
|
||||||
|
// page format button
|
||||||
r.OffsetTo(left, top);
|
r.OffsetTo(left, top);
|
||||||
fPageSetup = new BButton(r, "Page Setup", "Page Setup", new BMessage(MSG_PAGE_SETUP));
|
fPageSetup = new BButton(r, "Page Format", "Page Format", new BMessage(MSG_PAGE_SETUP));
|
||||||
panel->AddChild(fPageSetup);
|
panel->AddChild(fPageSetup);
|
||||||
fPageSetup->ResizeToPreferred();
|
fPageSetup->ResizeToPreferred();
|
||||||
top += fPageSetup->Bounds().Height() + 5;
|
top += fPageSetup->Bounds().Height() + 5;
|
||||||
|
if (fPageSetup->Bounds().Width() > width) width = fPageSetup->Bounds().Width();
|
||||||
|
|
||||||
|
// page selection button
|
||||||
fJobSetup = NULL;
|
fJobSetup = NULL;
|
||||||
if (kind == kJobSetup) {
|
if (kind == kJobSetup) {
|
||||||
r.OffsetTo(left, top);
|
r.OffsetTo(left, top);
|
||||||
fJobSetup = new BButton(r, "Job Setup", "Job Setup", new BMessage(MSG_JOB_SETUP));
|
fJobSetup = new BButton(r, "Page Selection", "Page Selection", new BMessage(MSG_JOB_SETUP));
|
||||||
panel->AddChild(fJobSetup);
|
panel->AddChild(fJobSetup);
|
||||||
fJobSetup->SetEnabled(fKind == kJobSetup);
|
|
||||||
fJobSetup->ResizeToPreferred();
|
fJobSetup->ResizeToPreferred();
|
||||||
top += fJobSetup->Bounds().Height() + 5;
|
top += fJobSetup->Bounds().Height() + 5;
|
||||||
|
if (fJobSetup->Bounds().Width() > width) width = fJobSetup->Bounds().Width();
|
||||||
}
|
}
|
||||||
|
top += 5;
|
||||||
|
|
||||||
ResizeTo(Bounds().Width(), top);
|
// separator line
|
||||||
|
BRect line(Bounds());
|
||||||
|
line.OffsetTo(0, top);
|
||||||
|
line.bottom = line.top+1;
|
||||||
|
AddChild(new BBox(line, "line", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP));
|
||||||
|
top += 10;
|
||||||
|
|
||||||
|
// Cancel button
|
||||||
|
r.OffsetTo(left, top);
|
||||||
|
BButton* cancel = new BButton(r, "Cancel", "Cancel", new BMessage(B_QUIT_REQUESTED));
|
||||||
|
panel->AddChild(cancel);
|
||||||
|
cancel->ResizeToPreferred();
|
||||||
|
left = cancel->Frame().right + 10;
|
||||||
|
|
||||||
|
// OK button
|
||||||
|
r.OffsetTo(left, top);
|
||||||
|
fOk = new BButton(r, "OK", "OK", new BMessage(MSG_OK));
|
||||||
|
panel->AddChild(fOk);
|
||||||
|
fOk->ResizeToPreferred();
|
||||||
|
top += fOk->Bounds().Height() + 10;
|
||||||
|
|
||||||
|
// resize buttons to equal width
|
||||||
|
float height = fOk->Bounds().Height();
|
||||||
|
fPageSetup->ResizeTo(width, height);
|
||||||
|
if (fJobSetup) fJobSetup->ResizeTo(width, height);
|
||||||
|
|
||||||
|
// resize window
|
||||||
|
ResizeTo(fOk->Frame().right + 10, top);
|
||||||
|
|
||||||
|
AddShortcut('i', 0, new BMessage(B_ABOUT_REQUESTED));
|
||||||
|
|
||||||
|
SetDefaultButton(fOk);
|
||||||
|
|
||||||
|
fPrinters->MakeFocus(true);
|
||||||
|
|
||||||
UpdateSettings(true);
|
UpdateSettings(true);
|
||||||
}
|
}
|
||||||
@@ -125,11 +167,57 @@ void ConfigWindow::MessageReceived(BMessage* m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MSG_OK:
|
||||||
|
UpdateSettings(false);
|
||||||
|
fSender->SetReply(fKind == kPageSetup ? &fPageSettings : &fJobSettings);
|
||||||
|
Quit();
|
||||||
|
break;
|
||||||
|
case B_ABOUT_REQUESTED: AboutRequested();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
inherited::MessageReceived(m);
|
inherited::MessageReceived(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char*
|
||||||
|
kAbout =
|
||||||
|
"Printer Server\n"
|
||||||
|
"© 2001, 2002 OpenBeOS\n"
|
||||||
|
"\n"
|
||||||
|
"\tIthamar R. Adema - Initial Implementation\n"
|
||||||
|
"\tMichael Pfeiffer - Release 1 and beyond\n"
|
||||||
|
;
|
||||||
|
|
||||||
|
void
|
||||||
|
ConfigWindow::AboutRequested()
|
||||||
|
{
|
||||||
|
BAlert *about = new BAlert("About Printer Server", kAbout, "Cool");
|
||||||
|
BTextView *v = about->TextView();
|
||||||
|
if (v) {
|
||||||
|
rgb_color red = {255, 0, 51, 255};
|
||||||
|
rgb_color blue = {0, 102, 255, 255};
|
||||||
|
|
||||||
|
v->SetStylable(true);
|
||||||
|
char *text = (char*)v->Text();
|
||||||
|
char *s = text;
|
||||||
|
// set all Be in blue and red
|
||||||
|
while ((s = strstr(s, "Be")) != NULL) {
|
||||||
|
int32 i = s - text;
|
||||||
|
v->SetFontAndColor(i, i+1, NULL, 0, &blue);
|
||||||
|
v->SetFontAndColor(i+1, i+2, NULL, 0, &red);
|
||||||
|
s += 2;
|
||||||
|
}
|
||||||
|
// first text line
|
||||||
|
s = strchr(text, '\n');
|
||||||
|
BFont font;
|
||||||
|
v->GetFontAndColor(0, &font);
|
||||||
|
font.SetSize(12);
|
||||||
|
v->SetFontAndColor(0, s-text+1, &font, B_FONT_SIZE);
|
||||||
|
};
|
||||||
|
about->Go();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConfigWindow::FrameMoved(BPoint p) {
|
void ConfigWindow::FrameMoved(BPoint p) {
|
||||||
BRect frame = GetWindowFrame();
|
BRect frame = GetWindowFrame();
|
||||||
frame.OffsetTo(p);
|
frame.OffsetTo(p);
|
||||||
@@ -215,32 +303,47 @@ void ConfigWindow::UpdateSettings(bool read) {
|
|||||||
fPageSettings = *p->GetPageSettings();
|
fPageSettings = *p->GetPageSettings();
|
||||||
fJobSettings = *p->GetJobSettings();
|
fJobSettings = *p->GetJobSettings();
|
||||||
} else {
|
} else {
|
||||||
if (fJobSettings.IsEmpty()) fJobSettings = fPageSettings;
|
|
||||||
p->SetPageSettings(&fPageSettings);
|
p->SetPageSettings(&fPageSettings);
|
||||||
p->SetJobSettings(&fJobSettings);
|
p->SetJobSettings(&fJobSettings);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
UpdateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigWindow::UpdateUI() {
|
||||||
|
if (fCurrentPrinter == NULL) {
|
||||||
|
fPageSetup->SetEnabled(false);
|
||||||
|
if (fJobSetup) fJobSetup->SetEnabled(false);
|
||||||
|
fOk->SetEnabled(false);
|
||||||
|
} else {
|
||||||
|
fPageSetup->SetEnabled(true);
|
||||||
|
|
||||||
if (fJobSetup) {
|
if (fJobSetup) {
|
||||||
fJobSetup->SetEnabled(fKind == kJobSetup && !fPageSettings.IsEmpty());
|
fJobSetup->SetEnabled(fKind == kJobSetup && !fPageSettings.IsEmpty());
|
||||||
}
|
}
|
||||||
|
fOk->SetEnabled(fKind == kJobSetup && !fJobSettings.IsEmpty() ||
|
||||||
|
fKind == kPageSetup && !fPageSettings.IsEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigWindow::Setup(config_setup_kind kind) {
|
void ConfigWindow::Setup(config_setup_kind kind) {
|
||||||
if (fCurrentPrinter) {
|
if (fCurrentPrinter) {
|
||||||
Hide();
|
Hide();
|
||||||
UpdateSettings(true);
|
|
||||||
bool ok;
|
|
||||||
if (kind == kPageSetup) {
|
if (kind == kPageSetup) {
|
||||||
ok = fCurrentPrinter->ConfigurePage(fPageSettings) == B_OK;
|
BMessage settings = fPageSettings;
|
||||||
|
if (fCurrentPrinter->ConfigurePage(settings) == B_OK) {
|
||||||
|
fPageSettings = settings;
|
||||||
|
if (!fJobSettings.IsEmpty()) AddFields(&fJobSettings, &fPageSettings);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ok = fCurrentPrinter->ConfigureJob(fJobSettings) == B_OK;
|
BMessage settings;
|
||||||
}
|
if (fJobSettings.IsEmpty()) settings = fPageSettings;
|
||||||
if (ok) UpdateSettings(false);
|
else settings = fJobSettings;
|
||||||
if (ok && fKind == kind) {
|
|
||||||
fSender->SetReply(kind == kPageSetup ? &fPageSettings : &fJobSettings);
|
if (fCurrentPrinter->ConfigureJob(settings) == B_OK)
|
||||||
Quit();
|
fJobSettings = settings;
|
||||||
} else {
|
|
||||||
Show();
|
|
||||||
}
|
}
|
||||||
|
UpdateUI();
|
||||||
|
Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ class ConfigWindow : public BWindow {
|
|||||||
MSG_PAGE_SETUP = 'cwps',
|
MSG_PAGE_SETUP = 'cwps',
|
||||||
MSG_JOB_SETUP = 'cwjs',
|
MSG_JOB_SETUP = 'cwjs',
|
||||||
MSG_PRINTER_SELECTED = 'cwpr',
|
MSG_PRINTER_SELECTED = 'cwpr',
|
||||||
|
MSG_OK = 'cwok',
|
||||||
|
MSG_CANCEL = 'cwcl',
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -55,7 +57,7 @@ public:
|
|||||||
void Go();
|
void Go();
|
||||||
|
|
||||||
void MessageReceived(BMessage* m);
|
void MessageReceived(BMessage* m);
|
||||||
|
void AboutRequested();
|
||||||
void FrameMoved(BPoint p);
|
void FrameMoved(BPoint p);
|
||||||
|
|
||||||
static BRect GetWindowFrame();
|
static BRect GetWindowFrame();
|
||||||
@@ -66,6 +68,7 @@ private:
|
|||||||
void SetupPrintersMenu(BMenu* menu);
|
void SetupPrintersMenu(BMenu* menu);
|
||||||
void UpdateAppSettings(const char* mime, const char* printer);
|
void UpdateAppSettings(const char* mime, const char* printer);
|
||||||
void UpdateSettings(bool read);
|
void UpdateSettings(bool read);
|
||||||
|
void UpdateUI();
|
||||||
void Setup(config_setup_kind);
|
void Setup(config_setup_kind);
|
||||||
|
|
||||||
config_setup_kind fKind;
|
config_setup_kind fKind;
|
||||||
@@ -84,6 +87,7 @@ private:
|
|||||||
BMenuField* fPrinters;
|
BMenuField* fPrinters;
|
||||||
BButton* fPageSetup;
|
BButton* fPageSetup;
|
||||||
BButton* fJobSetup;
|
BButton* fJobSetup;
|
||||||
|
BButton* fOk;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -83,17 +83,15 @@ status_t PrintServerApp::async_thread(void* data)
|
|||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
// Handle showing the page config dialog
|
// Handle showing the page config dialog
|
||||||
case PSRV_SHOW_PAGE_SETUP: {
|
case PSRV_SHOW_PAGE_SETUP: {
|
||||||
if (p->app->fUseConfigWindow) {
|
BMessage reply(*msg);
|
||||||
ConfigWindow* w = new ConfigWindow(kPageSetup, printer, msg, &sender);
|
if (printer != NULL) {
|
||||||
w->Go();
|
if (p->app->fUseConfigWindow) {
|
||||||
} else if (printer != NULL) {
|
ConfigWindow* w = new ConfigWindow(kPageSetup, printer, msg, &sender);
|
||||||
BMessage reply(*msg);
|
w->Go();
|
||||||
if (printer->ConfigurePage(reply) == B_OK) {
|
} else if (printer->ConfigurePage(reply) == B_OK) {
|
||||||
sender.SetReply(&reply);
|
sender.SetReply(&reply);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// If no default printer, give user choice of aborting or setting up a printer
|
// 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!");
|
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) {
|
if (alert->Go() == 1) {
|
||||||
@@ -105,14 +103,14 @@ status_t PrintServerApp::async_thread(void* data)
|
|||||||
|
|
||||||
// Handle showing the print config dialog
|
// Handle showing the print config dialog
|
||||||
case PSRV_SHOW_PRINT_SETUP: {
|
case PSRV_SHOW_PRINT_SETUP: {
|
||||||
|
if (printer == NULL) break;
|
||||||
if (p->app->fUseConfigWindow) {
|
if (p->app->fUseConfigWindow) {
|
||||||
ConfigWindow* w = new ConfigWindow(kJobSetup, printer, msg, &sender);
|
ConfigWindow* w = new ConfigWindow(kJobSetup, printer, msg, &sender);
|
||||||
w->Go();
|
w->Go();
|
||||||
} else if (printer != NULL) {
|
} else {
|
||||||
BMessage reply(*msg);
|
BMessage reply(*msg);
|
||||||
if (printer->ConfigureJob(reply) == B_OK) {
|
if (printer->ConfigureJob(reply) == B_OK) {
|
||||||
sender.SetReply(&reply);
|
sender.SetReply(&reply);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,8 +188,12 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
|
|||||||
if (msg->FindString("driver", &driverName) == B_OK &&
|
if (msg->FindString("driver", &driverName) == B_OK &&
|
||||||
msg->FindString("transport", &transportName) == B_OK &&
|
msg->FindString("transport", &transportName) == B_OK &&
|
||||||
msg->FindString("transport path", &transportPath) == B_OK &&
|
msg->FindString("transport path", &transportPath) == B_OK &&
|
||||||
msg->FindString("printer name", &printerName) == B_OK &&
|
msg->FindString("printer name", &printerName) == B_OK
|
||||||
msg->FindString("connection", &connection) == B_OK) {
|
) {
|
||||||
|
|
||||||
|
if (msg->FindString("connection", &connection) != B_OK)
|
||||||
|
connection = "Local";
|
||||||
|
|
||||||
// then create the actual printer
|
// then create the actual printer
|
||||||
if (CreatePrinter(printerName.String(), driverName.String(),
|
if (CreatePrinter(printerName.String(), driverName.String(),
|
||||||
connection.String(),
|
connection.String(),
|
||||||
|
|||||||
@@ -144,6 +144,11 @@ PrintServerApp::~PrintServerApp() {
|
|||||||
|
|
||||||
bool PrintServerApp::QuitRequested()
|
bool PrintServerApp::QuitRequested()
|
||||||
{
|
{
|
||||||
|
BMessage* m = CurrentMessage();
|
||||||
|
bool shortcut;
|
||||||
|
// don't quit when user types Command+Q!
|
||||||
|
if (m && m->FindBool("shortcut", &shortcut) == B_OK && shortcut) return false;
|
||||||
|
|
||||||
bool rc = Inherited::QuitRequested();
|
bool rc = Inherited::QuitRequested();
|
||||||
if (rc) {
|
if (rc) {
|
||||||
// Find directory containing printer definition nodes
|
// Find directory containing printer definition nodes
|
||||||
@@ -468,6 +473,8 @@ PrintServerApp::HandleSpooledJobs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* kPrinterData = "printer_data";
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// RetrieveDefaultPrinter()
|
// RetrieveDefaultPrinter()
|
||||||
//
|
//
|
||||||
@@ -483,22 +490,8 @@ PrintServerApp::HandleSpooledJobs()
|
|||||||
status_t
|
status_t
|
||||||
PrintServerApp::RetrieveDefaultPrinter()
|
PrintServerApp::RetrieveDefaultPrinter()
|
||||||
{
|
{
|
||||||
printer_data_t prefs;
|
fDefaultPrinter = Printer::Find(fSettings->DefaultPrinter());
|
||||||
status_t rc = B_OK;
|
return B_OK;
|
||||||
BPath path;
|
|
||||||
|
|
||||||
if ((rc=find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)) == B_OK) {
|
|
||||||
BFile file;
|
|
||||||
|
|
||||||
path.Append("printer_data");
|
|
||||||
|
|
||||||
if ((rc=file.SetTo(path.Path(), B_READ_ONLY)) == B_OK) {
|
|
||||||
file.ReadAt(0, &prefs, sizeof(prefs));
|
|
||||||
fDefaultPrinter = Printer::Find(prefs.defaultPrinterName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@@ -516,27 +509,11 @@ PrintServerApp::RetrieveDefaultPrinter()
|
|||||||
status_t
|
status_t
|
||||||
PrintServerApp::StoreDefaultPrinter()
|
PrintServerApp::StoreDefaultPrinter()
|
||||||
{
|
{
|
||||||
printer_data_t prefs;
|
if (fDefaultPrinter)
|
||||||
status_t rc = B_OK;
|
fSettings->SetDefaultPrinter(fDefaultPrinter->Name());
|
||||||
BPath path;
|
else
|
||||||
|
fSettings->SetDefaultPrinter("");
|
||||||
if ((rc=find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)) == B_OK) {
|
return B_OK;
|
||||||
BFile file;
|
|
||||||
|
|
||||||
path.Append("printer_data");
|
|
||||||
|
|
||||||
if ((rc=file.SetTo(path.Path(), B_WRITE_ONLY)) == B_OK) {
|
|
||||||
|
|
||||||
if (fDefaultPrinter != NULL)
|
|
||||||
::strcpy(prefs.defaultPrinterName, fDefaultPrinter->Name());
|
|
||||||
else
|
|
||||||
prefs.defaultPrinterName[0] = '\0';
|
|
||||||
|
|
||||||
file.WriteAt(0, &prefs, sizeof(prefs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
@@ -595,17 +572,19 @@ PrintServerApp::FindPrinterDriver(const char* name, BPath& outPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PrintServerApp::OpenSettings(BFile& file, bool forReading) {
|
bool PrintServerApp::OpenSettings(BFile& file, const char* name, bool forReading) {
|
||||||
BPath path;
|
BPath path;
|
||||||
uint32 openMode = forReading ? B_READ_ONLY : B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY;
|
uint32 openMode = forReading ? B_READ_ONLY : B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY;
|
||||||
return find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK &&
|
return find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK &&
|
||||||
path.Append("print_server_settings") == B_OK &&
|
path.Append(name) == B_OK &&
|
||||||
file.SetTo(path.Path(), openMode) == B_OK;
|
file.SetTo(path.Path(), openMode) == B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* kSettingsName = "print_server_settings";
|
||||||
|
|
||||||
void PrintServerApp::LoadSettings() {
|
void PrintServerApp::LoadSettings() {
|
||||||
BFile file;
|
BFile file;
|
||||||
if (OpenSettings(file, true)) {
|
if (OpenSettings(file, kSettingsName, true)) {
|
||||||
fSettings->Load(&file);
|
fSettings->Load(&file);
|
||||||
fUseConfigWindow = fSettings->UseConfigWindow();
|
fUseConfigWindow = fSettings->UseConfigWindow();
|
||||||
}
|
}
|
||||||
@@ -613,7 +592,7 @@ void PrintServerApp::LoadSettings() {
|
|||||||
|
|
||||||
void PrintServerApp::SaveSettings() {
|
void PrintServerApp::SaveSettings() {
|
||||||
BFile file;
|
BFile file;
|
||||||
if (OpenSettings(file, false)) {
|
if (OpenSettings(file, kSettingsName, false)) {
|
||||||
fSettings->SetUseConfigWindow(fUseConfigWindow);
|
fSettings->SetUseConfigWindow(fUseConfigWindow);
|
||||||
fSettings->Save(&file);
|
fSettings->Save(&file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public:
|
|||||||
BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
|
BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
|
||||||
int32 form, const char* prop);
|
int32 form, const char* prop);
|
||||||
private:
|
private:
|
||||||
bool OpenSettings(BFile& file, bool forReading);
|
bool OpenSettings(BFile& file, const char* name, bool forReading);
|
||||||
void LoadSettings();
|
void LoadSettings();
|
||||||
void SaveSettings();
|
void SaveSettings();
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ void Settings::Save(BFile* file) {
|
|||||||
|
|
||||||
m.AddBool("UseConfigWindow", fUseConfigWindow);
|
m.AddBool("UseConfigWindow", fUseConfigWindow);
|
||||||
m.AddRect("ConfigWindowFrame", fConfigWindowFrame);
|
m.AddRect("ConfigWindowFrame", fConfigWindowFrame);
|
||||||
|
m.AddString("DefaultPrinter", fDefaultPrinter);
|
||||||
m.Flatten(file);
|
m.Flatten(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,5 +144,8 @@ void Settings::Load(BFile* file) {
|
|||||||
|
|
||||||
if (m.FindRect("ConfigWindowFrame", &fConfigWindowFrame) != B_OK)
|
if (m.FindRect("ConfigWindowFrame", &fConfigWindowFrame) != B_OK)
|
||||||
fConfigWindowFrame = BRect(kConfigWindowFrame);
|
fConfigWindowFrame = BRect(kConfigWindowFrame);
|
||||||
|
|
||||||
|
if (m.FindString("DefaultPrinter", &fDefaultPrinter) != B_OK)
|
||||||
|
fDefaultPrinter = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ private:
|
|||||||
BObjectList<PrinterSettings> fPrinters;
|
BObjectList<PrinterSettings> fPrinters;
|
||||||
bool fUseConfigWindow;
|
bool fUseConfigWindow;
|
||||||
BRect fConfigWindowFrame;
|
BRect fConfigWindowFrame;
|
||||||
|
BString fDefaultPrinter;
|
||||||
|
|
||||||
static Settings* fSingleton;
|
static Settings* fSingleton;
|
||||||
Settings();
|
Settings();
|
||||||
@@ -97,10 +98,12 @@ public:
|
|||||||
void RemovePrinterSettings(int i);
|
void RemovePrinterSettings(int i);
|
||||||
PrinterSettings* FindPrinterSettings(const char* printer);
|
PrinterSettings* FindPrinterSettings(const char* printer);
|
||||||
|
|
||||||
bool UseConfigWindow() const { return fUseConfigWindow; }
|
bool UseConfigWindow() const { return fUseConfigWindow; }
|
||||||
void SetUseConfigWindow(bool b) { fUseConfigWindow = b; }
|
void SetUseConfigWindow(bool b) { fUseConfigWindow = b; }
|
||||||
BRect ConfigWindowFrame() const { return fConfigWindowFrame; }
|
BRect ConfigWindowFrame() const { return fConfigWindowFrame; }
|
||||||
void SetConfigWindowFrame(BRect r) { fConfigWindowFrame = r; }
|
void SetConfigWindowFrame(BRect r) { fConfigWindowFrame = r; }
|
||||||
|
const char* DefaultPrinter() const { return fDefaultPrinter.String(); }
|
||||||
|
void SetDefaultPrinter(const char* n) { fDefaultPrinter = n; }
|
||||||
|
|
||||||
void Save(BFile* settings_file);
|
void Save(BFile* settings_file);
|
||||||
void Load(BFile* settings_file);
|
void Load(BFile* settings_file);
|
||||||
|
|||||||
Reference in New Issue
Block a user