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 GetMimeType()24 const char* GetMimeType() const { return fMimeType.String(); } UsesDefaultPrinter()25 bool UsesDefaultPrinter() const { return fMimeType.Length() == 0; } GetPrinter()26 const char* GetPrinter() const { return fPrinter.String(); } SetPrinter(const char * printer)27 void SetPrinter(const char* printer) { fPrinter = printer; } SetDefaultPrinter()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 GetPrinter()41 const char* GetPrinter() const { return fPrinter.String(); } GetPageSettings()42 BMessage* GetPageSettings() { return &fPageSettings; } GetJobSettings()43 BMessage* GetJobSettings() { return &fJobSettings; } 44 SetPrinter(const char * p)45 void SetPrinter(const char* p) { fPrinter = p; } SetPageSettings(BMessage * s)46 void SetPageSettings(BMessage* s) { fPageSettings = *s; } SetJobSettings(BMessage * 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 AppSettingsCount()65 int AppSettingsCount() const { return fApps.CountItems(); } AppSettingsAt(int i)66 AppSettings* AppSettingsAt(int i) { return fApps.ItemAt(i); } AddAppSettings(AppSettings * s)67 void AddAppSettings(AppSettings* s) { fApps.AddItem(s); } 68 void RemoveAppSettings(int i); 69 AppSettings* FindAppSettings(const char* mimeType); 70 PrinterSettingsCount()71 int PrinterSettingsCount() const { return fPrinters.CountItems(); } PrinterSettingsAt(int i)72 PrinterSettings* PrinterSettingsAt(int i) { return fPrinters.ItemAt(i); } AddPrinterSettings(PrinterSettings * s)73 void AddPrinterSettings(PrinterSettings* s) { fPrinters.AddItem(s); } 74 void RemovePrinterSettings(int i); 75 PrinterSettings* FindPrinterSettings(const char* printer); 76 UseConfigWindow()77 bool UseConfigWindow() const { return fUseConfigWindow; } SetUseConfigWindow(bool b)78 void SetUseConfigWindow(bool b) { fUseConfigWindow = b; } ConfigWindowFrame()79 BRect ConfigWindowFrame() const { return fConfigWindowFrame; } SetConfigWindowFrame(BRect r)80 void SetConfigWindowFrame(BRect r) { fConfigWindowFrame = r; } DefaultPrinter()81 const char* DefaultPrinter() const { return fDefaultPrinter.String(); } SetDefaultPrinter(const char * n)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