1 /* 2 * Copyright 2002-2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Michael Pfeiffer 7 */ 8 #ifndef _SETTINGS_H 9 #define _SETTINGS_H 10 11 #include "BeUtils.h" 12 #include "ObjectList.h" 13 14 #include <String.h> 15 16 class AppSettings { 17 private: 18 BString fMimeType; // application signature 19 BString fPrinter; // printer used by application (default == empty string) 20 21 public: 22 AppSettings(const char* mimeType, const char* printer = NULL); 23 24 const char* GetMimeType() const { return fMimeType.String(); } 25 bool UsesDefaultPrinter() const { return fMimeType.Length() == 0; } 26 const char* GetPrinter() const { return fPrinter.String(); } 27 void SetPrinter(const char* printer) { fPrinter = printer; } 28 void SetDefaultPrinter() { fPrinter = ""; } 29 }; 30 31 32 class PrinterSettings { 33 private: 34 BString fPrinter; 35 BMessage fPageSettings; // default page settings 36 BMessage fJobSettings; // default job settings 37 38 public: 39 PrinterSettings(const char* printer, BMessage* pageSettings = NULL, BMessage* jobSettings = NULL); 40 41 const char* GetPrinter() const { return fPrinter.String(); } 42 BMessage* GetPageSettings() { return &fPageSettings; } 43 BMessage* GetJobSettings() { return &fJobSettings; } 44 45 void SetPrinter(const char* p) { fPrinter = p; } 46 void SetPageSettings(BMessage* s) { fPageSettings = *s; } 47 void SetJobSettings(BMessage* s) { fJobSettings = *s; } 48 }; 49 50 class Settings { 51 private: 52 BObjectList<AppSettings> fApps; 53 BObjectList<PrinterSettings> fPrinters; 54 bool fUseConfigWindow; 55 BRect fConfigWindowFrame; 56 BString fDefaultPrinter; 57 58 static Settings* sSingleton; 59 Settings(); 60 61 public: 62 static Settings* GetSettings(); 63 ~Settings(); 64 65 int AppSettingsCount() const { return fApps.CountItems(); } 66 AppSettings* AppSettingsAt(int i) { return fApps.ItemAt(i); } 67 void AddAppSettings(AppSettings* s) { fApps.AddItem(s); } 68 void RemoveAppSettings(int i); 69 AppSettings* FindAppSettings(const char* mimeType); 70 71 int PrinterSettingsCount() const { return fPrinters.CountItems(); } 72 PrinterSettings* PrinterSettingsAt(int i) { return fPrinters.ItemAt(i); } 73 void AddPrinterSettings(PrinterSettings* s) { fPrinters.AddItem(s); } 74 void RemovePrinterSettings(int i); 75 PrinterSettings* FindPrinterSettings(const char* printer); 76 77 bool UseConfigWindow() const { return fUseConfigWindow; } 78 void SetUseConfigWindow(bool b) { fUseConfigWindow = b; } 79 BRect ConfigWindowFrame() const { return fConfigWindowFrame; } 80 void SetConfigWindowFrame(BRect r) { fConfigWindowFrame = r; } 81 const char* DefaultPrinter() const { return fDefaultPrinter.String(); } 82 void SetDefaultPrinter(const char* n) { fDefaultPrinter = n; } 83 84 void Save(BFile* settings_file); 85 void Load(BFile* settings_file); 86 }; 87 88 #endif 89