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