xref: /haiku/headers/private/locale/MutableLocaleRoster.h (revision 93e30a47bed879ad448b3e2d9e10333d3f2e60ae)
1 /*
2  * Copyright 2010-2012, 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 BCatalogData;
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(
48 									bool preferred);
49 
50 			status_t			LoadSystemCatalog(BCatalog* catalog) const;
51 
52 			BCatalogData*		LoadCatalog(const entry_ref& catalogOwner,
53 									const char* language = NULL,
54 									int32 fingerprint = 0) const;
55 			status_t			UnloadCatalog(BCatalogData* catalogData);
56 
57 			BCatalogData*		CreateCatalog(const char* type,
58 									const char* signature,
59 									const char* language);
60 };
61 
62 
63 typedef BCatalogData* (*InstantiateCatalogFunc)(const entry_ref& catalogOwner,
64 	const char* language, uint32 fingerprint);
65 
66 typedef BCatalogData* (*CreateCatalogFunc)(const char* name,
67 	const char* language);
68 
69 typedef BCatalogData* (*InstantiateEmbeddedCatalogFunc)(
70 	entry_ref* appOrAddOnRef);
71 
72 typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
73 	const char*, int32);
74 
75 /*
76  * info about a single catalog-add-on (representing a catalog type):
77  */
78 struct CatalogAddOnInfo {
79 			InstantiateCatalogFunc 			fInstantiateFunc;
80 			CreateCatalogFunc				fCreateFunc;
81 			GetAvailableLanguagesFunc 		fLanguagesFunc;
82 
83 			BString				fName;
84 			BString				fPath;
85 			image_id			fAddOnImage;
86 			uint8				fPriority;
87 			BList				fLoadedCatalogs;
88 			bool				fIsEmbedded;
89 									// an embedded add-on actually isn't an
90 									// add-on, it is included as part of the
91 									// library.
92 									// The DefaultCatalog is such a beast!
93 
94 								CatalogAddOnInfo(const BString& name,
95 									const BString& path, uint8 priority);
96 								~CatalogAddOnInfo();
97 
98 			bool				MakeSureItsLoaded();
99 			void				UnloadIfPossible();
100 };
101 
102 
103 /*
104  * The global data that is shared between all roster-objects of a process.
105  */
106 struct RosterData {
107 			BLocker				fLock;
108 			BList				fCatalogAddOnInfos;
109 			BMessage			fPreferredLanguages;
110 
111 			BLocale				fDefaultLocale;
112 			BTimeZone			fDefaultTimeZone;
113 
114 			bool				fIsFilesystemTranslationPreferred;
115 
116 			bool				fAreResourcesLoaded;
117 			BResources			fResources;
118 
119 			status_t			fInitStatus;
120 
121 								RosterData(const BLanguage& language,
122 									const BFormattingConventions& conventions);
123 								~RosterData();
124 
125 	static	RosterData*			Default();
126 
127 			status_t			InitCheck() const;
128 
129 			status_t			Refresh();
130 
131 	static	int					CompareInfos(const void* left,
132 									const void* right);
133 
134 			status_t			SetDefaultFormattingConventions(
135 									const BFormattingConventions& convetions);
136 			status_t			SetDefaultTimeZone(const BTimeZone& zone);
137 			status_t			SetPreferredLanguages(const BMessage* msg);
138 			status_t			SetFilesystemTranslationPreferred(
139 									bool preferred);
140 private:
141 			status_t			_Initialize();
142 
143 			status_t			_InitializeCatalogAddOns();
144 			void				_CleanupCatalogAddOns();
145 
146 			status_t			_LoadLocaleSettings();
147 			status_t			_SaveLocaleSettings();
148 
149 			status_t			_LoadTimeSettings();
150 			status_t			_SaveTimeSettings();
151 
152 			status_t			_SetDefaultFormattingConventions(
153 									const BFormattingConventions& conventions);
154 			status_t			_SetDefaultTimeZone(const BTimeZone& zone);
155 			status_t			_SetPreferredLanguages(const BMessage* msg);
156 			void				_SetFilesystemTranslationPreferred(
157 									bool preferred);
158 
159 			status_t			_AddDefaultFormattingConventionsToMessage(
160 									BMessage* message) const;
161 			status_t			_AddDefaultTimeZoneToMessage(
162 									BMessage* message) const;
163 			status_t			_AddPreferredLanguagesToMessage(
164 									BMessage* message) const;
165 			status_t			_AddFilesystemTranslationPreferenceToMessage(
166 									BMessage* message) const;
167 };
168 
169 
170 }	// namespace BPrivate
171 
172 
173 #endif	// _MUTABLE_LOCALE_ROSTER_H_
174