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