Printers window peristence
implemented using same pattern as Screen preferences made corrections from review Fixes #4262 Change-Id: I658baebcdc6ef7809d871b61db75d0b4099937ed Reviewed-on: https://review.haiku-os.org/c/haiku/+/3870 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
375a70e9fd
commit
572e0095c2
@ -8,6 +8,7 @@ Preference Printers :
|
||||
PrintersWindow.cpp
|
||||
PrinterListView.cpp
|
||||
JobListView.cpp
|
||||
ScreenSettings.cpp
|
||||
SpoolFolder.cpp
|
||||
TestPageView.cpp
|
||||
TransportMenu.cpp
|
||||
|
@ -14,13 +14,14 @@
|
||||
#include "pr_server.h"
|
||||
#include "Messages.h"
|
||||
#include "PrintersWindow.h"
|
||||
#include "ScreenSettings.h"
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
PrintersApp app;
|
||||
app.Run();
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -34,7 +35,7 @@ PrintersApp::PrintersApp()
|
||||
void
|
||||
PrintersApp::ReadyToRun()
|
||||
{
|
||||
PrintersWindow* win = new PrintersWindow(BRect(78, 71, 561, 409));
|
||||
PrintersWindow* win = new PrintersWindow(new ScreenSettings());
|
||||
win->Show();
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <Application.h>
|
||||
#include <Catalog.h>
|
||||
|
||||
#include "ScreenSettings.h"
|
||||
|
||||
|
||||
#define PRINTERS_SIGNATURE "application/x-vnd.Be-PRNT"
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "Messages.h"
|
||||
#include "PrinterListView.h"
|
||||
#include "TestPageView.h"
|
||||
#include "ScreenSettings.h"
|
||||
#include "SpoolFolder.h"
|
||||
|
||||
|
||||
@ -44,15 +45,16 @@ public:
|
||||
TestPageWindow(BPrintJob* job, PrinterItem* printer);
|
||||
virtual ~TestPageWindow();
|
||||
|
||||
void MessageReceived(BMessage* message);
|
||||
void MessageReceived(BMessage* message);
|
||||
private:
|
||||
BPrintJob* fJob;
|
||||
TestPageView* fTestPage;
|
||||
BPrintJob* fJob;
|
||||
TestPageView* fTestPage;
|
||||
};
|
||||
|
||||
|
||||
TestPageWindow::TestPageWindow(BPrintJob* job, PrinterItem* printer)
|
||||
: BWindow(job->PaperRect().OffsetByCopy(-20000, -20000), B_TRANSLATE("Test page"),
|
||||
: BWindow(job->PaperRect().OffsetByCopy(-20000, -20000),
|
||||
B_TRANSLATE("Test page"),
|
||||
B_TITLED_WINDOW, 0), fJob(job)
|
||||
{
|
||||
fTestPage = new TestPageView(job->PrintableRect(), printer);
|
||||
@ -93,10 +95,11 @@ TestPageWindow::MessageReceived(BMessage* message)
|
||||
// #pragma mark PrintersWindow main class
|
||||
|
||||
|
||||
PrintersWindow::PrintersWindow(BRect frame)
|
||||
PrintersWindow::PrintersWindow(ScreenSettings* settings)
|
||||
:
|
||||
BWindow(BRect(78, 71, 761, 509), B_TRANSLATE_SYSTEM_NAME("Printers"),
|
||||
BWindow(settings->WindowFrame(), B_TRANSLATE_SYSTEM_NAME("Printers"),
|
||||
B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS),
|
||||
fSettings(settings),
|
||||
fSelectedPrinter(NULL),
|
||||
fAddingPrinter(false)
|
||||
{
|
||||
@ -104,9 +107,17 @@ PrintersWindow::PrintersWindow(BRect frame)
|
||||
}
|
||||
|
||||
|
||||
PrintersWindow::~PrintersWindow()
|
||||
{
|
||||
delete fSettings;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PrintersWindow::QuitRequested()
|
||||
{
|
||||
fSettings->SetWindowFrame(Frame());
|
||||
|
||||
bool result = Inherited::QuitRequested();
|
||||
if (result)
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
@ -118,7 +129,7 @@ PrintersWindow::QuitRequested()
|
||||
void
|
||||
PrintersWindow::MessageReceived(BMessage* msg)
|
||||
{
|
||||
switch(msg->what) {
|
||||
switch (msg->what) {
|
||||
case kMsgPrinterSelected:
|
||||
{
|
||||
fSelectedPrinter = fPrinterListView->SelectedItem();
|
||||
|
@ -19,26 +19,29 @@ class JobListView;
|
||||
class Job;
|
||||
class SpoolFolder;
|
||||
class PrinterItem;
|
||||
class ScreenSettings;
|
||||
|
||||
|
||||
class PrintersWindow : public BWindow {
|
||||
public:
|
||||
PrintersWindow(BRect frame);
|
||||
PrintersWindow(ScreenSettings *settings);
|
||||
virtual ~PrintersWindow();
|
||||
|
||||
void MessageReceived(BMessage* msg);
|
||||
bool QuitRequested();
|
||||
void MessageReceived(BMessage* msg);
|
||||
bool QuitRequested();
|
||||
|
||||
void PrintTestPage(PrinterItem* printer);
|
||||
void PrintTestPage(PrinterItem* printer);
|
||||
|
||||
void AddJob(SpoolFolder* folder, Job* job);
|
||||
void RemoveJob(SpoolFolder* folder, Job* job);
|
||||
void UpdateJob(SpoolFolder* folder, Job* job);
|
||||
void AddJob(SpoolFolder* folder, Job* job);
|
||||
void RemoveJob(SpoolFolder* folder, Job* job);
|
||||
void UpdateJob(SpoolFolder* folder, Job* job);
|
||||
|
||||
private:
|
||||
void _BuildGUI();
|
||||
bool _IsSelected(PrinterItem* printer);
|
||||
void _UpdatePrinterButtons();
|
||||
void _UpdateJobButtons();
|
||||
ScreenSettings* fSettings;
|
||||
void _BuildGUI();
|
||||
bool _IsSelected(PrinterItem* printer);
|
||||
void _UpdatePrinterButtons();
|
||||
void _UpdateJobButtons();
|
||||
|
||||
typedef BWindow Inherited;
|
||||
|
||||
@ -53,9 +56,9 @@ private:
|
||||
|
||||
BBox* fJobsBox;
|
||||
|
||||
PrinterItem* fSelectedPrinter;
|
||||
PrinterItem* fSelectedPrinter;
|
||||
|
||||
bool fAddingPrinter;
|
||||
bool fAddingPrinter;
|
||||
};
|
||||
|
||||
#endif // _PRINTERS_WINDOW_H
|
||||
|
60
src/preferences/printers/ScreenSettings.cpp
Normal file
60
src/preferences/printers/ScreenSettings.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2001-2015, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Rafael Romo
|
||||
* Stefano Ceccherini (burton666@libero.it)
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
*/
|
||||
|
||||
|
||||
#include "ScreenSettings.h"
|
||||
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
static const char* kSettingsFileName = "Screen_data";
|
||||
|
||||
|
||||
ScreenSettings::ScreenSettings()
|
||||
{
|
||||
fWindowFrame.Set(0, 0, 450, 250);
|
||||
BPoint offset;
|
||||
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||
path.Append(kSettingsFileName);
|
||||
|
||||
BFile file(path.Path(), B_READ_ONLY);
|
||||
if (file.InitCheck() == B_OK)
|
||||
file.Read(&offset, sizeof(BPoint));
|
||||
}
|
||||
|
||||
fWindowFrame.OffsetBy(offset);
|
||||
}
|
||||
|
||||
|
||||
ScreenSettings::~ScreenSettings()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
||||
return;
|
||||
|
||||
path.Append(kSettingsFileName);
|
||||
|
||||
BPoint offset = fWindowFrame.LeftTop();
|
||||
|
||||
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
|
||||
if (file.InitCheck() == B_OK)
|
||||
file.Write(&offset, sizeof(BPoint));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScreenSettings::SetWindowFrame(BRect frame)
|
||||
{
|
||||
fWindowFrame = frame;
|
||||
}
|
29
src/preferences/printers/ScreenSettings.h
Normal file
29
src/preferences/printers/ScreenSettings.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2001-2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Rafael Romo
|
||||
* Stefano Ceccherini (burton666@libero.it)
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
*/
|
||||
#ifndef SCREEN_SETTINGS_H
|
||||
#define SCREEN_SETTINGS_H
|
||||
|
||||
|
||||
#include <Rect.h>
|
||||
|
||||
|
||||
class ScreenSettings {
|
||||
public:
|
||||
ScreenSettings();
|
||||
virtual ~ScreenSettings();
|
||||
|
||||
BRect WindowFrame() const { return fWindowFrame; };
|
||||
void SetWindowFrame(BRect);
|
||||
|
||||
private:
|
||||
BRect fWindowFrame;
|
||||
};
|
||||
|
||||
#endif // SCREEN_SETTINGS_H
|
Loading…
Reference in New Issue
Block a user