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