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 { 41 private: 42 BString fMimeType; // application signature 43 BString fPrinter; // printer used by application (default == empty string) 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 { 57 private: 58 BString fPrinter; 59 BMessage fPageSettings; // default page settings 60 BMessage fJobSettings; // default job settings 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 69 void SetPrinter(const char* p) { fPrinter = p; } 70 void SetPageSettings(BMessage* s) { fPageSettings = *s; } 71 void SetJobSettings(BMessage* s) { fJobSettings = *s; } 72 }; 73 74 class Settings { 75 private: 76 BObjectList<AppSettings> fApps; 77 BObjectList<PrinterSettings> fPrinters; 78 bool fUseConfigWindow; 79 BRect fConfigWindowFrame; 80 BString fDefaultPrinter; 81 82 static Settings* fSingleton; 83 Settings(); 84 85 public: 86 static Settings* GetSettings(); 87 ~Settings(); 88 89 int AppSettingsCount() const { return fApps.CountItems(); } 90 AppSettings* AppSettingsAt(int i) { return fApps.ItemAt(i); } 91 void AddAppSettings(AppSettings* s) { fApps.AddItem(s); } 92 void RemoveAppSettings(int i); 93 AppSettings* FindAppSettings(const char* mimeType); 94 95 int PrinterSettingsCount() const { return fPrinters.CountItems(); } 96 PrinterSettings* PrinterSettingsAt(int i) { return fPrinters.ItemAt(i); } 97 void AddPrinterSettings(PrinterSettings* s) { fPrinters.AddItem(s); } 98 void RemovePrinterSettings(int i); 99 PrinterSettings* FindPrinterSettings(const char* printer); 100 101 bool UseConfigWindow() const { return fUseConfigWindow; } 102 void SetUseConfigWindow(bool b) { fUseConfigWindow = b; } 103 BRect ConfigWindowFrame() const { return fConfigWindowFrame; } 104 void SetConfigWindowFrame(BRect r) { fConfigWindowFrame = r; } 105 const char* DefaultPrinter() const { return fDefaultPrinter.String(); } 106 void SetDefaultPrinter(const char* n) { fDefaultPrinter = n; } 107 108 void Save(BFile* settings_file); 109 void Load(BFile* settings_file); 110 }; 111 112 #endif 113