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