Made ConfigWindow position and whether it should be used persistent.

Small bug fixes.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1634 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2002-10-24 15:14:32 +00:00
parent 8109fda8d2
commit 6ec7a3e7be
5 changed files with 81 additions and 42 deletions
+33 -22
View File
@@ -44,7 +44,7 @@
#include <Window.h>
ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMessage* settings, AutoReply* sender)
: BWindow(BRect(30, 30, 200, 125), "Printer Setup",
: BWindow(ConfigWindow::GetWindowFrame(), "Printer Setup",
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
, fKind(kind)
, fDefaultPrinter(defaultPrinter)
@@ -112,9 +112,9 @@ void ConfigWindow::Go() {
void ConfigWindow::MessageReceived(BMessage* m) {
switch (m->what) {
case MSG_PAGE_SETUP: PageSetup(m);
case MSG_PAGE_SETUP: Setup(kPageSetup);
break;
case MSG_JOB_SETUP: JobSetup(m);
case MSG_JOB_SETUP: Setup(kJobSetup);
break;
case MSG_PRINTER_SELECTED: {
BString printer;
@@ -130,6 +130,27 @@ void ConfigWindow::MessageReceived(BMessage* m) {
}
}
void ConfigWindow::FrameMoved(BPoint p) {
BRect frame = GetWindowFrame();
frame.OffsetTo(p);
SetWindowFrame(frame);
}
BRect ConfigWindow::GetWindowFrame() {
BAutolock lock(gLock);
if (lock.IsLocked()) {
return Settings::GetSettings()->ConfigWindowFrame();
}
return BRect(30, 30, 300, 300);
}
void ConfigWindow::SetWindowFrame(BRect r) {
BAutolock lock(gLock);
if (lock.IsLocked()) {
Settings::GetSettings()->SetConfigWindowFrame(r);
}
}
void ConfigWindow::PrinterForMimeType() {
BAutolock lock(gLock);
if (fCurrentPrinter) {
@@ -204,29 +225,19 @@ void ConfigWindow::UpdateSettings(bool read) {
}
}
void ConfigWindow::PageSetup(BMessage* m) {
void ConfigWindow::Setup(config_setup_kind kind) {
if (fCurrentPrinter) {
Hide();
UpdateSettings(true);
bool ok = fCurrentPrinter->ConfigurePage(fPageSettings) == B_OK;
bool ok;
if (kind == kPageSetup) {
ok = fCurrentPrinter->ConfigurePage(fPageSettings) == B_OK;
} else {
ok = fCurrentPrinter->ConfigureJob(fJobSettings) == B_OK;
}
if (ok) UpdateSettings(false);
if (ok && fKind == kPageSetup) {
fSender->SetReply(&fJobSettings);
Quit();
} else {
Show();
}
}
}
void ConfigWindow::JobSetup(BMessage* m) {
if (fCurrentPrinter) {
Hide();
UpdateSettings(true);
bool ok = fCurrentPrinter->ConfigureJob(fJobSettings) == B_OK;
if (ok) UpdateSettings(false);
if (ok && fKind == kJobSetup) {
fSender->SetReply(&fJobSettings);
if (ok && fKind == kind) {
fSender->SetReply(kind == kPageSetup ? &fPageSettings : &fJobSettings);
Quit();
} else {
Show();
+6 -2
View File
@@ -56,13 +56,17 @@ public:
void MessageReceived(BMessage* m);
void FrameMoved(BPoint p);
static BRect GetWindowFrame();
static void SetWindowFrame(BRect frame);
private:
void PrinterForMimeType();
void SetupPrintersMenu(BMenu* menu);
void UpdateAppSettings(const char* mime, const char* printer);
void UpdateSettings(bool read);
void PageSetup(BMessage* m);
void JobSetup(BMessage* m);
void Setup(config_setup_kind);
config_setup_kind fKind;
Printer* fDefaultPrinter;
+8 -2
View File
@@ -605,10 +605,16 @@ bool PrintServerApp::OpenSettings(BFile& file, bool forReading) {
void PrintServerApp::LoadSettings() {
BFile file;
if (OpenSettings(file, true)) fSettings->Load(&file);
if (OpenSettings(file, true)) {
fSettings->Load(&file);
fUseConfigWindow = fSettings->UseConfigWindow();
}
}
void PrintServerApp::SaveSettings() {
BFile file;
if (OpenSettings(file, false)) fSettings->Save(&file);
if (OpenSettings(file, false)) {
fSettings->SetUseConfigWindow(fUseConfigWindow);
fSettings->Save(&file);
}
}
+19 -9
View File
@@ -57,17 +57,18 @@ PrinterSettings::PrinterSettings(const char* printer, BMessage* pageSettings, BM
Settings* Settings::fSingleton = NULL;
static const BRect kConfigWindowFrame(30, 30, 220, 120);
Settings::Settings()
: fApps(true) // owns AppSettings
, fPrinters(true) // owns PrinterSettings
, fUseConfigWindow(true)
, fConfigWindowFrame(kConfigWindowFrame)
{
}
Settings::~Settings() {
fSingleton = NULL;
for (int i = 0; i < AppSettingsCount(); i++) {
AppSettings* app = AppSettingsAt(i);
app->Release();
}
for (int i = 0; i < PrinterSettingsCount(); i++) {
PrinterSettings* p = PrinterSettingsAt(i);
p->Release();
}
}
Settings* Settings::GetSettings() {
@@ -114,6 +115,9 @@ void Settings::Save(BFile* file) {
m.AddMessage("S", p->GetPageSettings());
m.AddMessage("J", p->GetJobSettings());
}
m.AddBool("UseConfigWindow", fUseConfigWindow);
m.AddRect("ConfigWindowFrame", fConfigWindowFrame);
m.Flatten(file);
}
@@ -133,5 +137,11 @@ void Settings::Load(BFile* file) {
m.FindMessage("J", i, &job) == B_OK; i ++) {
AddPrinterSettings(new PrinterSettings(printer.String(), &page, &job));
}
if (m.FindBool("UseConfigWindow", &fUseConfigWindow) != B_OK)
fUseConfigWindow = true;
if (m.FindRect("ConfigWindowFrame", &fConfigWindowFrame) != B_OK)
fConfigWindowFrame = BRect(kConfigWindowFrame);
}
}
+15 -7
View File
@@ -37,10 +37,10 @@
#include <String.h>
class AppSettings : public Object {
class AppSettings {
private:
BString fMimeType;
BString fPrinter;
BString fMimeType; // application signature
BString fPrinter; // printer used by application (default == empty string)
public:
AppSettings(const char* mimeType, const char* printer = NULL);
@@ -53,11 +53,11 @@ public:
};
class PrinterSettings : public Object {
class PrinterSettings {
private:
BString fPrinter;
BMessage fPageSettings;
BMessage fJobSettings;
BMessage fPageSettings; // default page settings
BMessage fJobSettings; // default job settings
public:
PrinterSettings(const char* printer, BMessage* pageSettings = NULL, BMessage* jobSettings = NULL);
@@ -65,6 +65,7 @@ public:
const char* GetPrinter() const { return fPrinter.String(); }
BMessage* GetPageSettings() { return &fPageSettings; }
BMessage* GetJobSettings() { return &fJobSettings; }
void SetPrinter(const char* p) { fPrinter = p; }
void SetPageSettings(BMessage* s) { fPageSettings = *s; }
void SetJobSettings(BMessage* s) { fJobSettings = *s; }
@@ -74,9 +75,11 @@ class Settings {
private:
BObjectList<AppSettings> fApps;
BObjectList<PrinterSettings> fPrinters;
bool fUseConfigWindow;
BRect fConfigWindowFrame;
static Settings* fSingleton;
Settings() { }
Settings();
public:
static Settings* GetSettings();
@@ -93,6 +96,11 @@ public:
void AddPrinterSettings(PrinterSettings* s) { fPrinters.AddItem(s); }
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; }
void Save(BFile* settings_file);
void Load(BFile* settings_file);