xref: /haiku/src/servers/print/Settings.h (revision 25a7b01d15612846f332751841da3579db313082)
1314167cdSDarkWyrm /*
2314167cdSDarkWyrm  * Copyright 2002-2006, Haiku. All rights reserved.
3314167cdSDarkWyrm  * Distributed under the terms of the MIT License.
4314167cdSDarkWyrm  *
5314167cdSDarkWyrm  * Authors:
6314167cdSDarkWyrm  *		Michael Pfeiffer
7314167cdSDarkWyrm  */
87977efcfSMichael Pfeiffer #ifndef _SETTINGS_H
97977efcfSMichael Pfeiffer #define _SETTINGS_H
107977efcfSMichael Pfeiffer 
117977efcfSMichael Pfeiffer #include "BeUtils.h"
127977efcfSMichael Pfeiffer #include "ObjectList.h"
137977efcfSMichael Pfeiffer 
147977efcfSMichael Pfeiffer #include <String.h>
157977efcfSMichael Pfeiffer 
166ec7a3e7SMichael Pfeiffer class AppSettings {
177977efcfSMichael Pfeiffer private:
186ec7a3e7SMichael Pfeiffer 	BString fMimeType; // application signature
196ec7a3e7SMichael Pfeiffer 	BString fPrinter;  // printer used by application (default == empty string)
207977efcfSMichael Pfeiffer 
217977efcfSMichael Pfeiffer public:
227977efcfSMichael Pfeiffer 	AppSettings(const char* mimeType, const char* printer = NULL);
237977efcfSMichael Pfeiffer 
GetMimeType()247977efcfSMichael Pfeiffer 	const char* GetMimeType() const      { return fMimeType.String(); }
UsesDefaultPrinter()257977efcfSMichael Pfeiffer 	bool UsesDefaultPrinter() const      { return fMimeType.Length() == 0; }
GetPrinter()267977efcfSMichael Pfeiffer 	const char* GetPrinter() const       { return fPrinter.String(); }
SetPrinter(const char * printer)277977efcfSMichael Pfeiffer 	void SetPrinter(const char* printer) { fPrinter = printer; }
SetDefaultPrinter()287977efcfSMichael Pfeiffer 	void SetDefaultPrinter()             { fPrinter = ""; }
297977efcfSMichael Pfeiffer };
307977efcfSMichael Pfeiffer 
317977efcfSMichael Pfeiffer 
326ec7a3e7SMichael Pfeiffer class PrinterSettings {
337977efcfSMichael Pfeiffer private:
347977efcfSMichael Pfeiffer 	BString  fPrinter;
356ec7a3e7SMichael Pfeiffer 	BMessage fPageSettings; // default page settings
366ec7a3e7SMichael Pfeiffer 	BMessage fJobSettings;  // default job settings
377977efcfSMichael Pfeiffer 
387977efcfSMichael Pfeiffer public:
397977efcfSMichael Pfeiffer 	PrinterSettings(const char* printer, BMessage* pageSettings = NULL, BMessage* jobSettings = NULL);
407977efcfSMichael Pfeiffer 
GetPrinter()417977efcfSMichael Pfeiffer 	const char* GetPrinter() const       { return fPrinter.String(); }
GetPageSettings()427977efcfSMichael Pfeiffer 	BMessage* GetPageSettings()          { return &fPageSettings; }
GetJobSettings()437977efcfSMichael Pfeiffer 	BMessage* GetJobSettings()           { return &fJobSettings; }
446ec7a3e7SMichael Pfeiffer 
SetPrinter(const char * p)457977efcfSMichael Pfeiffer 	void SetPrinter(const char* p)       { fPrinter = p; }
SetPageSettings(BMessage * s)467977efcfSMichael Pfeiffer 	void SetPageSettings(BMessage* s)    { fPageSettings = *s; }
SetJobSettings(BMessage * s)477977efcfSMichael Pfeiffer 	void SetJobSettings(BMessage* s)     { fJobSettings = *s; }
487977efcfSMichael Pfeiffer };
497977efcfSMichael Pfeiffer 
507977efcfSMichael Pfeiffer class Settings {
517977efcfSMichael Pfeiffer private:
527977efcfSMichael Pfeiffer 	BObjectList<AppSettings>     fApps;
537977efcfSMichael Pfeiffer 	BObjectList<PrinterSettings> fPrinters;
546ec7a3e7SMichael Pfeiffer 	bool                         fUseConfigWindow;
556ec7a3e7SMichael Pfeiffer 	BRect                        fConfigWindowFrame;
565def1197SMichael Pfeiffer 	BString                      fDefaultPrinter;
577977efcfSMichael Pfeiffer 
58*1797be0dSStefano Ceccherini 	static Settings* sSingleton;
596ec7a3e7SMichael Pfeiffer 	Settings();
607977efcfSMichael Pfeiffer 
617977efcfSMichael Pfeiffer public:
627977efcfSMichael Pfeiffer 	static Settings* GetSettings();
637977efcfSMichael Pfeiffer 	~Settings();
647977efcfSMichael Pfeiffer 
AppSettingsCount()657977efcfSMichael Pfeiffer 	int AppSettingsCount() const           { return fApps.CountItems(); }
AppSettingsAt(int i)667977efcfSMichael Pfeiffer 	AppSettings* AppSettingsAt(int i)      { return fApps.ItemAt(i); }
AddAppSettings(AppSettings * s)677977efcfSMichael Pfeiffer 	void AddAppSettings(AppSettings* s)    { fApps.AddItem(s); }
687977efcfSMichael Pfeiffer 	void RemoveAppSettings(int i);
697977efcfSMichael Pfeiffer 	AppSettings* FindAppSettings(const char* mimeType);
707977efcfSMichael Pfeiffer 
PrinterSettingsCount()717977efcfSMichael Pfeiffer 	int PrinterSettingsCount() const            { return fPrinters.CountItems(); }
PrinterSettingsAt(int i)727977efcfSMichael Pfeiffer 	PrinterSettings* PrinterSettingsAt(int i)   { return fPrinters.ItemAt(i); }
AddPrinterSettings(PrinterSettings * s)737977efcfSMichael Pfeiffer 	void AddPrinterSettings(PrinterSettings* s) { fPrinters.AddItem(s); }
747977efcfSMichael Pfeiffer 	void RemovePrinterSettings(int i);
757977efcfSMichael Pfeiffer 	PrinterSettings* FindPrinterSettings(const char* printer);
767977efcfSMichael Pfeiffer 
UseConfigWindow()776ec7a3e7SMichael Pfeiffer 	bool UseConfigWindow() const          { return fUseConfigWindow; }
SetUseConfigWindow(bool b)786ec7a3e7SMichael Pfeiffer 	void SetUseConfigWindow(bool b)       { fUseConfigWindow = b; }
ConfigWindowFrame()796ec7a3e7SMichael Pfeiffer 	BRect ConfigWindowFrame() const       { return fConfigWindowFrame; }
SetConfigWindowFrame(BRect r)806ec7a3e7SMichael Pfeiffer 	void SetConfigWindowFrame(BRect r)    { fConfigWindowFrame = r; }
DefaultPrinter()815def1197SMichael Pfeiffer 	const char* DefaultPrinter() const    { return fDefaultPrinter.String(); }
SetDefaultPrinter(const char * n)825def1197SMichael Pfeiffer 	void SetDefaultPrinter(const char* n) { fDefaultPrinter = n; }
836ec7a3e7SMichael Pfeiffer 
847977efcfSMichael Pfeiffer 	void Save(BFile* settings_file);
857977efcfSMichael Pfeiffer 	void Load(BFile* settings_file);
867977efcfSMichael Pfeiffer };
877977efcfSMichael Pfeiffer 
887977efcfSMichael Pfeiffer #endif
89