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:
parent
15750026e0
commit
5def119705
@ -90,3 +90,21 @@ bool MimeTypeForSender(BMessage* sender, BString& mime) {
|
||||
}
|
||||
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
|
||||
bool MimeTypeForSender(BMessage* sender, BString& mime);
|
||||
bool AddFields(BMessage* to, const BMessage* from);
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "Printer.h"
|
||||
#include "PrintServerApp.h"
|
||||
#include "ConfigWindow.h"
|
||||
#include "BeUtils.h"
|
||||
|
||||
// posix
|
||||
#include <stdlib.h>
|
||||
@ -44,7 +45,7 @@
|
||||
#include <Window.h>
|
||||
|
||||
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)
|
||||
, fKind(kind)
|
||||
, fDefaultPrinter(defaultPrinter)
|
||||
@ -55,40 +56,81 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMes
|
||||
MimeTypeForSender(settings, fSenderMimeType);
|
||||
PrinterForMimeType();
|
||||
|
||||
if (kind == kJobSetup) SetTitle("Print Setup");
|
||||
|
||||
BView* panel = new BBox(Bounds(), "top_panel", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
|
||||
B_PLAIN_BORDER);
|
||||
|
||||
AddChild(panel);
|
||||
|
||||
float left = 10, top = 5;
|
||||
float left = 10, top = 5, width;
|
||||
BRect r(left, top, 160, 15);
|
||||
|
||||
BPopUpMenu* menu = new BPopUpMenu("PrinterMenu");
|
||||
// print selection popup menu
|
||||
BPopUpMenu* menu = new BPopUpMenu("Select a Printer");
|
||||
SetupPrintersMenu(menu);
|
||||
|
||||
fPrinters = new BMenuField(r, "Printer", "Printer", menu);
|
||||
fPrinters->SetDivider(60);
|
||||
fPrinters->SetDivider(40);
|
||||
panel->AddChild(fPrinters);
|
||||
top += fPrinters->Bounds().Height() + 5;
|
||||
top += fPrinters->Bounds().Height() + 10;
|
||||
width = fPrinters->Bounds().Width();
|
||||
|
||||
// page format button
|
||||
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);
|
||||
fPageSetup->ResizeToPreferred();
|
||||
top += fPageSetup->Bounds().Height() + 5;
|
||||
if (fPageSetup->Bounds().Width() > width) width = fPageSetup->Bounds().Width();
|
||||
|
||||
// page selection button
|
||||
fJobSetup = NULL;
|
||||
if (kind == kJobSetup) {
|
||||
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);
|
||||
fJobSetup->SetEnabled(fKind == kJobSetup);
|
||||
fJobSetup->ResizeToPreferred();
|
||||
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);
|
||||
}
|
||||
@ -125,11 +167,57 @@ void ConfigWindow::MessageReceived(BMessage* m) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MSG_OK:
|
||||
UpdateSettings(false);
|
||||
fSender->SetReply(fKind == kPageSetup ? &fPageSettings : &fJobSettings);
|
||||
Quit();
|
||||
break;
|
||||
case B_ABOUT_REQUESTED: AboutRequested();
|
||||
break;
|
||||
default:
|
||||
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) {
|
||||
BRect frame = GetWindowFrame();
|
||||
frame.OffsetTo(p);
|
||||
@ -215,32 +303,47 @@ void ConfigWindow::UpdateSettings(bool read) {
|
||||
fPageSettings = *p->GetPageSettings();
|
||||
fJobSettings = *p->GetJobSettings();
|
||||
} else {
|
||||
if (fJobSettings.IsEmpty()) fJobSettings = fPageSettings;
|
||||
p->SetPageSettings(&fPageSettings);
|
||||
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) {
|
||||
fJobSetup->SetEnabled(fKind == kJobSetup && !fPageSettings.IsEmpty());
|
||||
}
|
||||
fOk->SetEnabled(fKind == kJobSetup && !fJobSettings.IsEmpty() ||
|
||||
fKind == kPageSetup && !fPageSettings.IsEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigWindow::Setup(config_setup_kind kind) {
|
||||
if (fCurrentPrinter) {
|
||||
Hide();
|
||||
UpdateSettings(true);
|
||||
bool ok;
|
||||
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 {
|
||||
ok = fCurrentPrinter->ConfigureJob(fJobSettings) == B_OK;
|
||||
}
|
||||
if (ok) UpdateSettings(false);
|
||||
if (ok && fKind == kind) {
|
||||
fSender->SetReply(kind == kPageSetup ? &fPageSettings : &fJobSettings);
|
||||
Quit();
|
||||
} else {
|
||||
Show();
|
||||
BMessage settings;
|
||||
if (fJobSettings.IsEmpty()) settings = fPageSettings;
|
||||
else settings = fJobSettings;
|
||||
|
||||
if (fCurrentPrinter->ConfigureJob(settings) == B_OK)
|
||||
fJobSettings = settings;
|
||||
}
|
||||
UpdateUI();
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ class ConfigWindow : public BWindow {
|
||||
MSG_PAGE_SETUP = 'cwps',
|
||||
MSG_JOB_SETUP = 'cwjs',
|
||||
MSG_PRINTER_SELECTED = 'cwpr',
|
||||
MSG_OK = 'cwok',
|
||||
MSG_CANCEL = 'cwcl',
|
||||
};
|
||||
|
||||
public:
|
||||
@ -55,7 +57,7 @@ public:
|
||||
void Go();
|
||||
|
||||
void MessageReceived(BMessage* m);
|
||||
|
||||
void AboutRequested();
|
||||
void FrameMoved(BPoint p);
|
||||
|
||||
static BRect GetWindowFrame();
|
||||
@ -66,6 +68,7 @@ private:
|
||||
void SetupPrintersMenu(BMenu* menu);
|
||||
void UpdateAppSettings(const char* mime, const char* printer);
|
||||
void UpdateSettings(bool read);
|
||||
void UpdateUI();
|
||||
void Setup(config_setup_kind);
|
||||
|
||||
config_setup_kind fKind;
|
||||
@ -84,6 +87,7 @@ private:
|
||||
BMenuField* fPrinters;
|
||||
BButton* fPageSetup;
|
||||
BButton* fJobSetup;
|
||||
BButton* fOk;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -83,17 +83,15 @@ status_t PrintServerApp::async_thread(void* data)
|
||||
switch (msg->what) {
|
||||
// Handle showing the page config dialog
|
||||
case PSRV_SHOW_PAGE_SETUP: {
|
||||
if (p->app->fUseConfigWindow) {
|
||||
ConfigWindow* w = new ConfigWindow(kPageSetup, printer, msg, &sender);
|
||||
w->Go();
|
||||
} else if (printer != NULL) {
|
||||
BMessage reply(*msg);
|
||||
if (printer->ConfigurePage(reply) == B_OK) {
|
||||
BMessage reply(*msg);
|
||||
if (printer != NULL) {
|
||||
if (p->app->fUseConfigWindow) {
|
||||
ConfigWindow* w = new ConfigWindow(kPageSetup, printer, msg, &sender);
|
||||
w->Go();
|
||||
} else if (printer->ConfigurePage(reply) == B_OK) {
|
||||
sender.SetReply(&reply);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} 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) {
|
||||
@ -105,14 +103,14 @@ status_t PrintServerApp::async_thread(void* data)
|
||||
|
||||
// Handle showing the print config dialog
|
||||
case PSRV_SHOW_PRINT_SETUP: {
|
||||
if (printer == NULL) break;
|
||||
if (p->app->fUseConfigWindow) {
|
||||
ConfigWindow* w = new ConfigWindow(kJobSetup, printer, msg, &sender);
|
||||
w->Go();
|
||||
} else if (printer != NULL) {
|
||||
} else {
|
||||
BMessage reply(*msg);
|
||||
if (printer->ConfigureJob(reply) == B_OK) {
|
||||
sender.SetReply(&reply);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,8 +188,12 @@ void PrintServerApp::Handle_BeOSR5_Message(BMessage* msg)
|
||||
if (msg->FindString("driver", &driverName) == B_OK &&
|
||||
msg->FindString("transport", &transportName) == B_OK &&
|
||||
msg->FindString("transport path", &transportPath) == B_OK &&
|
||||
msg->FindString("printer name", &printerName) == B_OK &&
|
||||
msg->FindString("connection", &connection) == B_OK) {
|
||||
msg->FindString("printer name", &printerName) == B_OK
|
||||
) {
|
||||
|
||||
if (msg->FindString("connection", &connection) != B_OK)
|
||||
connection = "Local";
|
||||
|
||||
// then create the actual printer
|
||||
if (CreatePrinter(printerName.String(), driverName.String(),
|
||||
connection.String(),
|
||||
|
@ -144,6 +144,11 @@ PrintServerApp::~PrintServerApp() {
|
||||
|
||||
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();
|
||||
if (rc) {
|
||||
// Find directory containing printer definition nodes
|
||||
@ -468,6 +473,8 @@ PrintServerApp::HandleSpooledJobs()
|
||||
}
|
||||
}
|
||||
|
||||
static const char* kPrinterData = "printer_data";
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// RetrieveDefaultPrinter()
|
||||
//
|
||||
@ -483,22 +490,8 @@ PrintServerApp::HandleSpooledJobs()
|
||||
status_t
|
||||
PrintServerApp::RetrieveDefaultPrinter()
|
||||
{
|
||||
printer_data_t prefs;
|
||||
status_t rc = 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;
|
||||
fDefaultPrinter = Printer::Find(fSettings->DefaultPrinter());
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
@ -516,27 +509,11 @@ PrintServerApp::RetrieveDefaultPrinter()
|
||||
status_t
|
||||
PrintServerApp::StoreDefaultPrinter()
|
||||
{
|
||||
printer_data_t prefs;
|
||||
status_t rc = 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_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;
|
||||
if (fDefaultPrinter)
|
||||
fSettings->SetDefaultPrinter(fDefaultPrinter->Name());
|
||||
else
|
||||
fSettings->SetDefaultPrinter("");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
@ -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;
|
||||
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 &&
|
||||
path.Append("print_server_settings") == B_OK &&
|
||||
path.Append(name) == B_OK &&
|
||||
file.SetTo(path.Path(), openMode) == B_OK;
|
||||
}
|
||||
|
||||
static const char* kSettingsName = "print_server_settings";
|
||||
|
||||
void PrintServerApp::LoadSettings() {
|
||||
BFile file;
|
||||
if (OpenSettings(file, true)) {
|
||||
if (OpenSettings(file, kSettingsName, true)) {
|
||||
fSettings->Load(&file);
|
||||
fUseConfigWindow = fSettings->UseConfigWindow();
|
||||
}
|
||||
@ -613,7 +592,7 @@ void PrintServerApp::LoadSettings() {
|
||||
|
||||
void PrintServerApp::SaveSettings() {
|
||||
BFile file;
|
||||
if (OpenSettings(file, false)) {
|
||||
if (OpenSettings(file, kSettingsName, false)) {
|
||||
fSettings->SetUseConfigWindow(fUseConfigWindow);
|
||||
fSettings->Save(&file);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class PrintServerApp : public BApplication
|
||||
public:
|
||||
PrintServerApp(status_t* err);
|
||||
~PrintServerApp();
|
||||
|
||||
|
||||
void Acquire();
|
||||
void Release();
|
||||
|
||||
@ -78,7 +78,7 @@ public:
|
||||
BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
|
||||
int32 form, const char* prop);
|
||||
private:
|
||||
bool OpenSettings(BFile& file, bool forReading);
|
||||
bool OpenSettings(BFile& file, const char* name, bool forReading);
|
||||
void LoadSettings();
|
||||
void SaveSettings();
|
||||
|
||||
|
@ -118,6 +118,7 @@ void Settings::Save(BFile* file) {
|
||||
|
||||
m.AddBool("UseConfigWindow", fUseConfigWindow);
|
||||
m.AddRect("ConfigWindowFrame", fConfigWindowFrame);
|
||||
m.AddString("DefaultPrinter", fDefaultPrinter);
|
||||
m.Flatten(file);
|
||||
}
|
||||
|
||||
@ -143,5 +144,8 @@ void Settings::Load(BFile* file) {
|
||||
|
||||
if (m.FindRect("ConfigWindowFrame", &fConfigWindowFrame) != B_OK)
|
||||
fConfigWindowFrame = BRect(kConfigWindowFrame);
|
||||
|
||||
if (m.FindString("DefaultPrinter", &fDefaultPrinter) != B_OK)
|
||||
fDefaultPrinter = "";
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ private:
|
||||
BObjectList<PrinterSettings> fPrinters;
|
||||
bool fUseConfigWindow;
|
||||
BRect fConfigWindowFrame;
|
||||
BString fDefaultPrinter;
|
||||
|
||||
static Settings* fSingleton;
|
||||
Settings();
|
||||
@ -97,10 +98,12 @@ public:
|
||||
void RemovePrinterSettings(int i);
|
||||
PrinterSettings* FindPrinterSettings(const char* printer);
|
||||
|
||||
bool UseConfigWindow() const { return fUseConfigWindow; }
|
||||
void SetUseConfigWindow(bool b) { fUseConfigWindow = b; }
|
||||
BRect ConfigWindowFrame() const { return fConfigWindowFrame; }
|
||||
void SetConfigWindowFrame(BRect r) { fConfigWindowFrame = r; }
|
||||
bool UseConfigWindow() const { return fUseConfigWindow; }
|
||||
void SetUseConfigWindow(bool b) { fUseConfigWindow = b; }
|
||||
BRect ConfigWindowFrame() const { return fConfigWindowFrame; }
|
||||
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 Load(BFile* settings_file);
|
||||
|
Loading…
Reference in New Issue
Block a user