1 /* 2 * Copyright 2010, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 #ifndef _MUTABLE_LOCALE_ROSTER_H_ 6 #define _MUTABLE_LOCALE_ROSTER_H_ 7 8 9 #include <Collator.h> 10 #include <FormattingConventions.h> 11 #include <image.h> 12 #include <Language.h> 13 #include <List.h> 14 #include <Locale.h> 15 #include <Locker.h> 16 #include <LocaleRoster.h> 17 #include <Message.h> 18 #include <Resources.h> 19 #include <TimeZone.h> 20 21 22 class BLocale; 23 class BCatalog; 24 class BCatalogAddOn; 25 26 struct entry_ref; 27 28 29 namespace BPrivate { 30 31 32 class MutableLocaleRoster : public BLocaleRoster { 33 public: 34 MutableLocaleRoster(); 35 ~MutableLocaleRoster(); 36 37 static MutableLocaleRoster* Default(); 38 39 status_t SetDefaultFormattingConventions( 40 const BFormattingConventions& conventions); 41 status_t SetDefaultTimeZone(const BTimeZone& zone); 42 43 status_t SetPreferredLanguages(const BMessage* message); 44 // the message contains one or more 45 // 'language'-string-fields which 46 // contain the language-name(s) 47 status_t SetFilesystemTranslationPreferred(bool preferred); 48 49 status_t GetSystemCatalog(BCatalogAddOn** catalog) const; 50 51 BCatalogAddOn* LoadCatalog(const entry_ref& catalogOwner, 52 const char* language = NULL, 53 int32 fingerprint = 0) const; 54 status_t UnloadCatalog(BCatalogAddOn* addOn); 55 56 BCatalogAddOn* CreateCatalog(const char* type, 57 const char* signature, 58 const char* language); 59 }; 60 61 62 typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const entry_ref& catalogOwner, 63 const char* language, uint32 fingerprint); 64 65 typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name, 66 const char* language); 67 68 typedef BCatalogAddOn* (*InstantiateEmbeddedCatalogFunc)( 69 entry_ref* appOrAddOnRef); 70 71 typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*, 72 const char*, int32); 73 74 /* 75 * info about a single catalog-add-on (representing a catalog type): 76 */ 77 struct CatalogAddOnInfo { 78 InstantiateCatalogFunc fInstantiateFunc; 79 CreateCatalogFunc fCreateFunc; 80 GetAvailableLanguagesFunc fLanguagesFunc; 81 82 BString fName; 83 BString fPath; 84 image_id fAddOnImage; 85 uint8 fPriority; 86 BList fLoadedCatalogs; 87 bool fIsEmbedded; 88 // an embedded add-on actually isn't an 89 // add-on, it is included as part of the 90 // library. 91 // The DefaultCatalog is such a beast! 92 93 CatalogAddOnInfo(const BString& name, 94 const BString& path, uint8 priority); 95 ~CatalogAddOnInfo(); 96 97 bool MakeSureItsLoaded(); 98 void UnloadIfPossible(); 99 }; 100 101 102 /* 103 * The global data that is shared between all roster-objects of a process. 104 */ 105 struct RosterData { 106 BLocker fLock; 107 BList fCatalogAddOnInfos; 108 BMessage fPreferredLanguages; 109 110 BLocale fDefaultLocale; 111 BTimeZone fDefaultTimeZone; 112 113 bool fIsFilesystemTranslationPreferred; 114 115 bool fAreResourcesLoaded; 116 BResources fResources; 117 118 status_t fInitStatus; 119 120 RosterData(const BLanguage& language, 121 const BFormattingConventions& conventions); 122 ~RosterData(); 123 124 static RosterData* Default(); 125 126 status_t InitCheck() const; 127 128 status_t Refresh(); 129 130 static int CompareInfos(const void* left, 131 const void* right); 132 133 status_t SetDefaultFormattingConventions( 134 const BFormattingConventions& convetions); 135 status_t SetDefaultTimeZone(const BTimeZone& zone); 136 status_t SetPreferredLanguages(const BMessage* msg); 137 status_t SetFilesystemTranslationPreferred( 138 bool preferred); 139 private: 140 status_t _Initialize(); 141 142 status_t _InitializeCatalogAddOns(); 143 void _CleanupCatalogAddOns(); 144 145 status_t _LoadLocaleSettings(); 146 status_t _SaveLocaleSettings(); 147 148 status_t _LoadTimeSettings(); 149 status_t _SaveTimeSettings(); 150 151 status_t _SetDefaultFormattingConventions( 152 const BFormattingConventions& conventions); 153 status_t _SetDefaultTimeZone(const BTimeZone& zone); 154 status_t _SetPreferredLanguages(const BMessage* msg); 155 void _SetFilesystemTranslationPreferred( 156 bool preferred); 157 158 status_t _AddDefaultFormattingConventionsToMessage( 159 BMessage* message) const; 160 status_t _AddDefaultTimeZoneToMessage( 161 BMessage* message) const; 162 status_t _AddPreferredLanguagesToMessage( 163 BMessage* message) const; 164 status_t _AddFilesystemTranslationPreferenceToMessage( 165 BMessage* message) const; 166 }; 167 168 169 } // namespace BPrivate 170 171 172 #endif // _MUTABLE_LOCALE_ROSTER_H_ 173