xref: /haiku/src/servers/print/Settings.h (revision d7e489f80a82a0dc5974df1e780d7a908129bab4)
1 /*****************************************************************************/
2 // Settings
3 //
4 // Author
5 //   Michael Pfeiffer
6 //
7 // This application and all source files used in its construction, except
8 // where noted, are licensed under the MIT License, and have been written
9 // and are:
10 //
11 // Copyright (c) 2002 OpenBeOS Project
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 /*****************************************************************************/
31 
32 #ifndef _SETTINGS_H
33 #define _SETTINGS_H
34 
35 #include "BeUtils.h"
36 #include "ObjectList.h"
37 
38 #include <String.h>
39 
40 class AppSettings : public Object {
41 private:
42 	BString fMimeType;
43 	BString fPrinter;
44 
45 public:
46 	AppSettings(const char* mimeType, const char* printer = NULL);
47 
48 	const char* GetMimeType() const      { return fMimeType.String(); }
49 	bool UsesDefaultPrinter() const      { return fMimeType.Length() == 0; }
50 	const char* GetPrinter() const       { return fPrinter.String(); }
51 	void SetPrinter(const char* printer) { fPrinter = printer; }
52 	void SetDefaultPrinter()             { fPrinter = ""; }
53 };
54 
55 
56 class PrinterSettings : public Object {
57 private:
58 	BString  fPrinter;
59 	BMessage fPageSettings;
60 	BMessage fJobSettings;
61 
62 public:
63 	PrinterSettings(const char* printer, BMessage* pageSettings = NULL, BMessage* jobSettings = NULL);
64 
65 	const char* GetPrinter() const       { return fPrinter.String(); }
66 	BMessage* GetPageSettings()          { return &fPageSettings; }
67 	BMessage* GetJobSettings()           { return &fJobSettings; }
68 	void SetPrinter(const char* p)       { fPrinter = p; }
69 	void SetPageSettings(BMessage* s)    { fPageSettings = *s; }
70 	void SetJobSettings(BMessage* s)     { fJobSettings = *s; }
71 };
72 
73 class Settings {
74 private:
75 	BObjectList<AppSettings>     fApps;
76 	BObjectList<PrinterSettings> fPrinters;
77 
78 	static Settings* fSingleton;
79 	Settings() { }
80 
81 public:
82 	static Settings* GetSettings();
83 	~Settings();
84 
85 	int AppSettingsCount() const           { return fApps.CountItems(); }
86 	AppSettings* AppSettingsAt(int i)      { return fApps.ItemAt(i); }
87 	void AddAppSettings(AppSettings* s)    { fApps.AddItem(s); }
88 	void RemoveAppSettings(int i);
89 	AppSettings* FindAppSettings(const char* mimeType);
90 
91 	int PrinterSettingsCount() const            { return fPrinters.CountItems(); }
92 	PrinterSettings* PrinterSettingsAt(int i)   { return fPrinters.ItemAt(i); }
93 	void AddPrinterSettings(PrinterSettings* s) { fPrinters.AddItem(s); }
94 	void RemovePrinterSettings(int i);
95 	PrinterSettings* FindPrinterSettings(const char* printer);
96 
97 	void Save(BFile* settings_file);
98 	void Load(BFile* settings_file);
99 };
100 
101 #endif
102